mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Renamed IdentifierListener to RemoteNodeValidator and moved this configuration from TcpConfig to Replication builders
This commit is contained in:
@@ -899,7 +899,7 @@ public abstract class AbstractChronicleMapBuilder<K, V,
|
||||
List<Replicator> replicators = new ArrayList<>(2);
|
||||
if (singleHashReplication != null) {
|
||||
if (singleHashReplication.tcpTransportAndNetwork() != null)
|
||||
replicators.add(Replicators.tcp(singleHashReplication.tcpTransportAndNetwork()));
|
||||
replicators.add(Replicators.tcp(singleHashReplication));
|
||||
if (singleHashReplication.udpTransport() != null)
|
||||
replicators.add(Replicators.udp(singleHashReplication.udpTransport()));
|
||||
} else {
|
||||
|
||||
@@ -63,7 +63,7 @@ final class ChannelProvider implements Closeable {
|
||||
final TcpReplicator tcpReplicator = new TcpReplicator(
|
||||
channelProvider.asReplica,
|
||||
channelProvider.asEntryExternalizable,
|
||||
tcpConfig, hub.maxEntrySize(), null);
|
||||
tcpConfig, hub.maxEntrySize(), null, hub.remoteNodeValidator());
|
||||
channelProvider.add(tcpReplicator);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.replication.IdentifierListener;
|
||||
import net.openhft.chronicle.hash.replication.RemoteNodeValidator;
|
||||
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.hash.replication.UdpTransportConfig;
|
||||
import net.openhft.lang.collection.ATSDirectBitSet;
|
||||
@@ -203,13 +204,13 @@ public class NodeDiscovery {
|
||||
|
||||
// we should make a local copy as this may change
|
||||
|
||||
final IdentifierListener identifierListener = new IdentifierListener() {
|
||||
final RemoteNodeValidator remoteNodeValidator = new RemoteNodeValidator() {
|
||||
|
||||
private final ConcurrentMap<Byte, SocketAddress> identifiers = new ConcurrentHashMap<Byte,
|
||||
SocketAddress>();
|
||||
|
||||
@Override
|
||||
public boolean isIdentifierUnique(byte remoteIdentifier, SocketAddress remoteAddress) {
|
||||
public boolean validate(byte remoteIdentifier, SocketAddress remoteAddress) {
|
||||
final SocketAddress lastKnownAddress = identifiers.putIfAbsent(remoteIdentifier, remoteAddress);
|
||||
if (remoteAddress.equals(lastKnownAddress))
|
||||
return true;
|
||||
@@ -224,8 +225,7 @@ public class NodeDiscovery {
|
||||
final TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig
|
||||
.forUnknownTopology(ourAddressAndPort.getPort(),
|
||||
toInetSocketCollection(knownHostPorts))
|
||||
.heartBeatInterval(1, SECONDS)
|
||||
.nonUniqueIdentifierListener(identifierListener);
|
||||
.heartBeatInterval(1, SECONDS);
|
||||
|
||||
|
||||
LOG.info("Using Remote identifier=" + identifier);
|
||||
@@ -234,7 +234,11 @@ public class NodeDiscovery {
|
||||
return ChronicleMapBuilder.of(Integer.class,
|
||||
CharSequence.class)
|
||||
.entries(20000L)
|
||||
.replication(identifier, tcpConfig).create();
|
||||
.replication(SingleChronicleHashReplication.builder()
|
||||
.tcpTransportAndNetwork(tcpConfig)
|
||||
.remoteNodeValidator(remoteNodeValidator)
|
||||
.createWithId(identifier))
|
||||
.create();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.replication.AbstractReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.hash.replication.UdpTransportConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,7 +37,7 @@ final class Replicators {
|
||||
private Replicators() {
|
||||
}
|
||||
|
||||
static Replicator tcp(final TcpTransportAndNetworkConfig replicationConfig) {
|
||||
static Replicator tcp(final AbstractReplication replication) {
|
||||
return new Replicator() {
|
||||
|
||||
@Override
|
||||
@@ -53,8 +54,12 @@ final class Replicators {
|
||||
(keyValueSerializer, (VanillaChronicleMap) chronicleMap,
|
||||
builder.entrySize(true));
|
||||
|
||||
return new TcpReplicator(replica, entryExternalizable, replicationConfig,
|
||||
builder.entrySize(true), statelessServer);
|
||||
TcpTransportAndNetworkConfig tcpConfig = replication.tcpTransportAndNetwork();
|
||||
assert tcpConfig != null;
|
||||
return new TcpReplicator(replica, entryExternalizable,
|
||||
tcpConfig,
|
||||
builder.entrySize(true), statelessServer,
|
||||
replication.remoteNodeValidator());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.replication.IdentifierListener;
|
||||
import net.openhft.chronicle.hash.replication.RemoteNodeValidator;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.hash.replication.ThrottlingConfig;
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
@@ -76,6 +76,7 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
|
||||
private final Replica.EntryExternalizable externalizable;
|
||||
private final TcpTransportAndNetworkConfig replicationConfig;
|
||||
private final StatelessServerConnector statelessServerConnector;
|
||||
private final @Nullable RemoteNodeValidator remoteNodeValidator;
|
||||
|
||||
private long selectorTimeout;
|
||||
|
||||
@@ -91,7 +92,8 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
|
||||
@NotNull final Replica.EntryExternalizable externalizable,
|
||||
@NotNull final TcpTransportAndNetworkConfig replicationConfig,
|
||||
final int maxEntrySizeBytes,
|
||||
@Nullable StatelessServerConnector statelessServerConnector) throws IOException {
|
||||
@Nullable StatelessServerConnector statelessServerConnector,
|
||||
@Nullable RemoteNodeValidator remoteNodeValidator) throws IOException {
|
||||
|
||||
super("TcpSocketReplicator-" + replica.identifier(), replicationConfig.throttlingConfig(),
|
||||
maxEntrySizeBytes);
|
||||
@@ -110,6 +112,8 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
|
||||
this.externalizable = externalizable;
|
||||
this.replicationConfig = replicationConfig;
|
||||
|
||||
this.remoteNodeValidator = remoteNodeValidator;
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
@@ -478,12 +482,11 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
|
||||
// this can occur sometimes when if 2 or more remote node attempt to use node discovery at the
|
||||
// same time
|
||||
|
||||
final IdentifierListener identifierListener =
|
||||
replicationConfig.nonUniqueIdentifierListener();
|
||||
final SocketAddress remoteAddress = socketChannel.getRemoteAddress();
|
||||
|
||||
if ((identifierListener != null && !identifierListener.isIdentifierUnique(remoteIdentifier,
|
||||
remoteAddress)) || remoteIdentifier == localIdentifier)
|
||||
if ((remoteNodeValidator != null &&
|
||||
!remoteNodeValidator.validate(remoteIdentifier, remoteAddress))
|
||||
|| remoteIdentifier == localIdentifier)
|
||||
|
||||
// throwing this exception will cause us to disconnect, both the client and server
|
||||
// will be able to detect the the remote and local identifiers are the same,
|
||||
|
||||
Reference in New Issue
Block a user