HCOLL-134 changed the default so that is does not autoReconnectedUponDroppedConnection, however it better if most of the test cases have this can you can guarantee that the server is ready to accept TCP/IP before the client.

This commit is contained in:
Rob Austin
2014-11-21 11:04:26 +00:00
parent a8479ee02f
commit ae26c293c7
12 changed files with 107 additions and 43 deletions
@@ -20,7 +20,10 @@ package net.openhft.chronicle.hash.replication;
import java.io.Serializable;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static java.util.Collections.unmodifiableSet;
@@ -40,6 +43,7 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
private final ThrottlingConfig throttlingConfig;
private final long heartBeatInterval;
private final TimeUnit heartBeatIntervalUnit;
private String name = "(unknown)";
private TcpTransportAndNetworkConfig(int serverPort, Set<InetSocketAddress> endpoints,
int packetSize,
@@ -70,7 +74,7 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
return new TcpTransportAndNetworkConfig(
serverPort, unmodifiableSet(new HashSet<InetSocketAddress>(endpoints)),
DEFAULT_PACKET_SIZE,
true, // autoReconnectedUponDroppedConnection
false, // autoReconnectedUponDroppedConnection
ThrottlingConfig.noThrottling(),
DEFAULT_HEART_BEAT_INTERVAL,
DEFAULT_HEART_BEAT_INTERVAL_UNIT);
@@ -131,6 +135,14 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
return packetSize;
}
/**
* @param name the name used here is reflected in the Tcp Replicator and is typically used when debugging
*/
public TcpTransportAndNetworkConfig name(String name) {
this.name = name;
return this;
}
public TcpTransportAndNetworkConfig packetSize(int packetSize) {
if (packetSize <= 0)
throw new IllegalArgumentException();
@@ -181,7 +193,8 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
@Override
public String toString() {
return "TcpReplicationConfig{" +
"serverPort=" + serverPort +
"name=" + name() +
", serverPort=" + serverPort +
", endpoints=" + endpoints +
", packetSize=" + packetSize +
", autoReconnectedUponDroppedConnection=" + autoReconnectedUponDroppedConnection +
@@ -190,4 +203,11 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
", heartBeatIntervalUnit=" + heartBeatIntervalUnit +
'}';
}
/**
* @return the name of this configuration
*/
public String name() {
return this.name;
}
}
@@ -172,7 +172,7 @@ public class NodeDiscovery {
// the identifiers will come back to the callback on the nio thread, the update arrives at the
// onRemoteNodeEvent
Thread.sleep(200);
Thread.sleep(1000);
byte identifier;
@@ -191,7 +191,7 @@ public class NodeDiscovery {
final ProposedNodes proposedNodes = new
ProposedNodes(ourAddressAndPort, identifier);
Thread.sleep(100);
Thread.sleep(1000);
countDownLatch.set(new CountDownLatch(1));
@@ -245,16 +245,18 @@ public class NodeDiscovery {
// add our identifier and host:port to the list of known identifiers
knownNodes.add(ourAddressAndPort, identifier);
final TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig
/* final TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig
.of(ourAddressAndPort.getPort(),
toInetSocketCollection(knownHostPorts0))
.heartBeatInterval(1, SECONDS);
toInetSocketCollection(knownHostPorts0));
*/
LOG.info("Using Remote identifier=" + identifier);
nodeDiscoveryEventListenerAtomicReference.set(null);
TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig.of(8123, new
InetSocketAddress("192.168.1.253", 8123));
final ReplicationHub replicationHub = ReplicationHub.builder()
.maxEntrySize(10 * 1024)
.tcpTransportAndNetwork(tcpConfig)
@@ -79,6 +79,7 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
private final
@Nullable
RemoteNodeValidator remoteNodeValidator;
private final String name;
private long selectorTimeout;
@@ -115,7 +116,7 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
this.replicationConfig = replicationConfig;
this.remoteNodeValidator = remoteNodeValidator;
this.name = replicationConfig.name();
start();
}
@@ -159,11 +160,17 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
if (!key.isValid())
continue;
if (key.isAcceptable())
if (key.isAcceptable()) {
if (LOG.isDebugEnabled())
LOG.info("onAccept - " + name);
onAccept(key);
}
if (key.isConnectable())
if (key.isConnectable()) {
if (LOG.isDebugEnabled())
LOG.debug("onConnect - " + name);
onConnect(key);
}
if (key.isReadable())
onRead(key, approxTime);
@@ -206,6 +213,8 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
} catch (Exception e) {
LOG.error("", e);
} finally {
if (LOG.isDebugEnabled())
LOG.debug("closing name=" + name);
if (!isClosed) {
close();
}
@@ -593,11 +602,13 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable
int len = attached.entryReader.readSocketToBuffer(socketChannel);
if (len == -1) {
socketChannel.shutdownInput();
socketChannel.shutdownOutput();
//todo we should call close, but if we do it breaks the bootstrap test case, further
// investigation required
if (replicationConfig.autoReconnectedUponDroppedConnection()) {
AbstractConnector connector = attached.connector;
if (connector != null)
connector.connectLater();
} else
socketChannel.close();
return;
}