HCOLL-134 added support to turn off autoReconnectedUponDroppedConnection - because when node discovery is used ( by nodes broadcasting out their host:port over UDP ), when new or restarted nodes are started up. they attempt to find the nodes on the grid by listening to the host and ports of the other nodes, so these nodes will establish the connection when they come back up, hence under these circumstances, polling a dropped node to attempt to reconnect is no-longer required as the remote node will establish the connection its self on startup.

This commit is contained in:
Rob Austin
2014-09-29 15:51:14 +01:00
parent ddac403449
commit 5d4401b5b4
9 changed files with 393 additions and 323 deletions
@@ -17,31 +17,91 @@
package net.openhft.chronicle.map;
import java.net.InetSocketAddress;
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.Arrays.asList;
import static java.util.Collections.unmodifiableSet;
import static java.util.concurrent.TimeUnit.SECONDS;
public abstract class TcpReplicationConfig {
public class TcpReplicationConfig {
private static final int DEFAULT_PACKET_SIZE = 1024 * 8;
private static final long DEFAULT_HEART_BEAT_INTERVAL = 20;
private static final TimeUnit DEFAULT_HEART_BEAT_INTERVAL_UNIT = SECONDS;
/**
* Package-private constructor forbids subclassing from outside of the package
*/
private int serverPort = DEFAULT_PACKET_SIZE;
private Set<InetSocketAddress> endpoints;
private int packetSize = DEFAULT_PACKET_SIZE;
private boolean autoReconnectedUponDroppedConnection = true;
private ThrottlingConfig throttlingConfig = ThrottlingConfig.noThrottling();
private long heartBeatInterval = DEFAULT_HEART_BEAT_INTERVAL;
private TimeUnit heartBeatIntervalUnit = DEFAULT_HEART_BEAT_INTERVAL_UNIT;
TcpReplicationConfig() {
// nothing to do
}
public boolean autoReconnectedUponDroppedConnection() {
return autoReconnectedUponDroppedConnection;
}
public void autoReconnectedUponDroppedConnection(boolean autoReconnectedUponDroppedConnection) {
this.autoReconnectedUponDroppedConnection = autoReconnectedUponDroppedConnection;
}
public ThrottlingConfig throttlingConfig() {
return throttlingConfig;
}
public void throttlingConfig(ThrottlingConfig throttlingConfig) {
this.throttlingConfig = throttlingConfig;
}
public long heartBeatInterval() {
return heartBeatInterval;
}
public TimeUnit heartBeatIntervalUnit() {
return heartBeatIntervalUnit;
}
public int serverPort() {
return serverPort;
}
public void serverPort(int serverPort) {
this.serverPort = serverPort;
}
public Set<InetSocketAddress> endpoints() {
return endpoints;
}
public void endpoints(Set<InetSocketAddress> endpoints) {
for (final InetSocketAddress endpoint : endpoints) {
if (endpoint.getPort() == serverPort && "localhost".equals(endpoint.getHostName()))
throw new IllegalArgumentException("endpoint=" + endpoint
+ " can not point to the same port as the server");
}
this.endpoints = endpoints;
}
public int packetSize() {
return packetSize;
}
public static TcpReplicationConfig of(int serverPort, InetSocketAddress... endpoints) {
return of(serverPort, asList(endpoints));
return of(serverPort, Arrays.asList(endpoints));
}
public static TcpReplicationConfig of(int serverPort, Collection<InetSocketAddress> endpoints) {
@@ -54,63 +114,77 @@ public abstract class TcpReplicationConfig {
throw new IllegalArgumentException("endpoint=" + endpoint
+ " can not point to the same port as the server");
}
return create(serverPort,
unmodifiableSet(new HashSet<InetSocketAddress>(endpoints)),
DEFAULT_PACKET_SIZE, ThrottlingConfig.noThrottling(),
DEFAULT_HEART_BEAT_INTERVAL, DEFAULT_HEART_BEAT_INTERVAL_UNIT);
TcpReplicationConfig tcpReplicationConfig = new TcpReplicationConfig();
tcpReplicationConfig.serverPort(serverPort);
tcpReplicationConfig.endpoints = unmodifiableSet(new HashSet<InetSocketAddress>(endpoints));
return tcpReplicationConfig;
}
static TcpReplicationConfig create(int serverPort, Set<InetSocketAddress> endpoints,
int packetSize, ThrottlingConfig throttlingConfig,
long heartBeatInterval, TimeUnit heartBeatIntervalUnit) {
return new TcpReplicationConfigBean(serverPort, endpoints, packetSize,
throttlingConfig, heartBeatInterval, heartBeatIntervalUnit);
}
public abstract int serverPort();
public abstract Set<InetSocketAddress> endpoints();
public abstract int packetSize();
public TcpReplicationConfig packetSize(int packetSize) {
public void packetSize(int packetSize) {
if (packetSize <= 0)
throw new IllegalArgumentException();
return create(serverPort(), endpoints(), packetSize, throttlingConfig(),
heartBeatInterval(), heartBeatIntervalUnit());
this.packetSize = packetSize;
}
public abstract ThrottlingConfig throttlingConfig();
public TcpReplicationConfig throttlingConfig(ThrottlingConfig throttlingConfig) {
ThrottlingConfig.checkMillisecondBucketInterval(throttlingConfig, "TCP");
return create(serverPort(), endpoints(), packetSize(), throttlingConfig,
heartBeatInterval(), heartBeatIntervalUnit());
public void throttlingConfig(long heartBeatInterval, TimeUnit heartBeatIntervalUnit) {
this.heartBeatInterval = heartBeatInterval;
this.heartBeatIntervalUnit = heartBeatIntervalUnit;
}
abstract long heartBeatInterval();
abstract TimeUnit heartBeatIntervalUnit();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
public long heartBeatInterval(TimeUnit unit) {
return unit.convert(heartBeatInterval(), heartBeatIntervalUnit());
TcpReplicationConfig that = (TcpReplicationConfig) o;
if (autoReconnectedUponDroppedConnection != that.autoReconnectedUponDroppedConnection) return false;
if (heartBeatInterval != that.heartBeatInterval) return false;
if (packetSize != that.packetSize) return false;
if (serverPort != that.serverPort) return false;
if (endpoints != null ? !endpoints.equals(that.endpoints) : that.endpoints != null) return false;
if (heartBeatIntervalUnit != that.heartBeatIntervalUnit) return false;
if (throttlingConfig != null ? !throttlingConfig.equals(that.throttlingConfig) : that.throttlingConfig != null)
return false;
return true;
}
/**
* @param heartBeatInterval heart beat interval
* @param unit the time unit of the interval
* @return this builder back
* @throws IllegalArgumentException if the given heart beat interval is unrecognisably small
* for the current TCP replicator implementation or negative. Current minimum interval
* is 1 millisecond.
*/
public TcpReplicationConfig heartBeatInterval(long heartBeatInterval, TimeUnit unit) {
if (unit.toMillis(heartBeatInterval) < 1) {
throw new IllegalArgumentException(
"Minimum heart beat interval is 1 millisecond, " +
heartBeatInterval + " " + unit + " given");
}
return create(serverPort(), endpoints(), packetSize(), throttlingConfig(),
heartBeatInterval, unit);
@Override
public int hashCode() {
int result = serverPort;
result = 31 * result + (endpoints != null ? endpoints.hashCode() : 0);
result = 31 * result + packetSize;
result = 31 * result + (autoReconnectedUponDroppedConnection ? 1 : 0);
result = 31 * result + (throttlingConfig != null ? throttlingConfig.hashCode() : 0);
result = 31 * result + (int) (heartBeatInterval ^ (heartBeatInterval >>> 32));
result = 31 * result + (heartBeatIntervalUnit != null ? heartBeatIntervalUnit.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "TcpReplicationConfig{" +
"serverPort=" + serverPort +
", endpoints=" + endpoints +
", packetSize=" + packetSize +
", autoReconnectedUponDroppedConnection=" + autoReconnectedUponDroppedConnection +
", throttlingConfig=" + throttlingConfig +
", heartBeatInterval=" + heartBeatInterval +
", heartBeatIntervalUnit=" + heartBeatIntervalUnit +
'}';
}
public TcpReplicationConfig heartBeatInterval(long time, TimeUnit unit) {
this.heartBeatInterval = time;
this.heartBeatIntervalUnit = unit;
return this;
}
}