Moved name() from TcpTransportAndNetworkConfig to AbstractReplication

This commit is contained in:
leventov
2015-02-03 22:37:41 +07:00
parent 8ed1c8d2af
commit 5fe9e686d2
12 changed files with 126 additions and 76 deletions
@@ -36,6 +36,7 @@ public abstract class AbstractReplication implements Serializable {
@Nullable
transient RemoteNodeValidator remoteNodeValidator;
private final boolean bootstrapOnlyLocalEntries;
private final String name;
// package-private to forbid subclassing from outside of the package
AbstractReplication(byte localIdentifier, Builder builder) {
@@ -44,6 +45,7 @@ public abstract class AbstractReplication implements Serializable {
udpConfig = builder.udpConfig;
remoteNodeValidator = builder.remoteNodeValidator;
bootstrapOnlyLocalEntries = builder.bootstrapOnlyLocalEntries;
name = builder.name;
}
@Override
@@ -52,7 +54,8 @@ public abstract class AbstractReplication implements Serializable {
", tcpConfig=" + tcpConfig +
", udpConfig=" + udpConfig +
", remoteNodeValidator=" + remoteNodeValidator +
", bootstrapOnlyLocalEntries=" + bootstrapOnlyLocalEntries;
", bootstrapOnlyLocalEntries=" + bootstrapOnlyLocalEntries +
", name=" + name;
}
public byte identifier() {
@@ -77,6 +80,10 @@ public abstract class AbstractReplication implements Serializable {
public boolean bootstrapOnlyLocalEntries() {
return bootstrapOnlyLocalEntries;
}
public String name() {
return name;
}
/**
* Builder of {@link AbstractReplication} configurations. This class and it's subclasses are
@@ -93,6 +100,7 @@ public abstract class AbstractReplication implements Serializable {
private UdpTransportConfig udpConfig = null;
private RemoteNodeValidator remoteNodeValidator = null;
private boolean bootstrapOnlyLocalEntries = false;
private String name = "(unknown)";
// package-private to forbid subclassing from outside of the package
Builder() {
@@ -146,6 +154,17 @@ public abstract class AbstractReplication implements Serializable {
return (B) this;
}
/**
* Configures replication "name", which could appear in log messages and replication
* thread names. Default is {@code "(unknown)"}.
*
* @param name human-readable replication name
* @return this builder back
*/
public B name(String name) {
this.name = name;
return (B) this;
}
/**
* Creates a Replication instance with the given node (server) identifier.
@@ -153,10 +172,10 @@ public abstract class AbstractReplication implements Serializable {
* @param identifier the node (server) identifier of the returned replication
* @return a new Replication instance with the specified node (server) identifier
* @throws IllegalArgumentException if the given identifier is non-positive
* @throws IllegalStateException if neither {@link #tcpTransportAndNetwork(TcpTransportAndNetworkConfig)}
* nor {@link #udpTransport(UdpTransportConfig)} are
* configured to non-{@code null}. At least one of the
* transport-level configs should be specified.
* @throws IllegalStateException if neither {@link #tcpTransportAndNetwork(
* TcpTransportAndNetworkConfig)} nor {@link #udpTransport(UdpTransportConfig)} are
* configured to non-{@code null}. At least one of the transport-level configs
* should be specified.
*/
@NotNull
public abstract R createWithId(byte identifier);
@@ -166,11 +185,5 @@ public abstract class AbstractReplication implements Serializable {
throw new IllegalArgumentException("Identifier must be positive, " + identifier +
" given");
}
@Override
public String toString() {
return ", udpConfig=" + udpConfig +
", remoteNodeValidator=" + remoteNodeValidator;
}
}
}
@@ -42,7 +42,6 @@ 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 tcpBufferSize,
@@ -138,16 +137,6 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
return tcpBufferSize;
}
/**
* @param name the name used here is reflected in the Tcp Replicator and is typically used when
* debugging
* @return self
*/
public TcpTransportAndNetworkConfig name(String name) {
this.name = name;
return this;
}
public TcpTransportAndNetworkConfig tcpBufferSize(int tcpBufferSize) {
if (tcpBufferSize <= 0)
throw new IllegalArgumentException();
@@ -200,8 +189,7 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
@Override
public String toString() {
return "TcpReplicationConfig{" +
"name=" + name() +
", serverPort=" + serverPort +
"serverPort=" + serverPort +
", endpoints=" + endpoints +
", tcpBufferSize=" + tcpBufferSize +
", autoReconnectedUponDroppedConnection=" + autoReconnectedUponDroppedConnection +
@@ -210,11 +198,4 @@ public final class TcpTransportAndNetworkConfig implements Serializable {
", heartBeatIntervalUnit=" + heartBeatIntervalUnit +
'}';
}
/**
* @return the name of this configuration
*/
public String name() {
return this.name;
}
}
@@ -66,7 +66,7 @@ final class ChannelProvider implements Closeable {
final TcpReplicator tcpReplicator = new TcpReplicator(
channelProvider.asReplica,
channelProvider.asEntryExternalizable,
tcpConfig, hub.remoteNodeValidator(), null);
tcpConfig, hub.remoteNodeValidator(), null, hub.name());
channelProvider.add(tcpReplicator);
}
@@ -126,7 +126,8 @@ final class Replicators {
return new TcpReplicator(replica, entryExternalizable,
tcpConfig,
replication.remoteNodeValidator(), statelessClientParameters);
replication.remoteNodeValidator(), statelessClientParameters,
replication.name());
}
};
}
@@ -123,7 +123,8 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
@NotNull final Replica.EntryExternalizable externalizable,
@NotNull final TcpTransportAndNetworkConfig replicationConfig,
@Nullable final RemoteNodeValidator remoteNodeValidator,
@Nullable final StatelessClientParameters statelessClientParameters)
@Nullable final StatelessClientParameters statelessClientParameters,
String name)
throws IOException {
super("TcpSocketReplicator-" + replica.identifier(), replicationConfig.throttlingConfig());
@@ -144,7 +145,7 @@ final class TcpReplicator<K, V> extends AbstractChannelReplicator implements Clo
this.replicationConfig = replicationConfig;
this.remoteNodeValidator = remoteNodeValidator;
this.name = replicationConfig.name();
this.name = name;
start();
}