> {
private TcpTransportAndNetworkConfig tcpConfig = null;
private UdpTransportConfig udpConfig = null;
private RemoteNodeValidator remoteNodeValidator = null;
private ConnectionListener connectionListener = null;
private boolean bootstrapOnlyLocalEntries = false;
private EngineReplicationLangBytesConsumer engineReplicationLangBytesConsumer;
// package-private to forbid subclassing from outside of the package
Builder() {
}
@NotNull
public B engineReplication(EngineReplicationLangBytesConsumer
engineReplicationLangBytesConsumer) {
this.engineReplicationLangBytesConsumer = engineReplicationLangBytesConsumer;
return (B) this;
}
EngineReplicationLangBytesConsumer engineReplicationLangBytesConsumer() {
return engineReplicationLangBytesConsumer;
}
@NotNull
public B tcpTransportAndNetwork(@Nullable TcpTransportAndNetworkConfig tcpConfig) {
this.tcpConfig = tcpConfig;
return (B) this;
}
/**
* Configures UDP transport settings, used by Replications, created by this builder. {@code
* null} means that UDP transport shouldn't being used.
*
* @param udpConfig the new UDP transport config for replications, created by this builder.
* @return this builder back, for chaining
* @see AbstractReplication#udpTransport()
*/
@NotNull
public B udpTransport(@Nullable UdpTransportConfig udpConfig) {
this.udpConfig = udpConfig;
return (B) this;
}
@NotNull
public B remoteNodeValidator(@Nullable RemoteNodeValidator remoteNodeValidator) {
this.remoteNodeValidator = remoteNodeValidator;
return (B) this;
}
@NotNull
public B connectionListener(@Nullable ConnectionListener connectionListener) {
this.connectionListener = connectionListener;
return (B) this;
}
/**
* Configures if the node, provided with replication, created by this builder, should
* replicate only local data, last updated with own identifier, or all data currently
* present on the node, when a new node joins the replication grid.
*
* Default configuration is {@code false}, potentially swamping new nodes with
* duplicates. However, this does guarantee that all the data is replicated over to the new
* node and is useful especially in the case that the originating node of some data is not
* currently running.
*
* @param bootstrapOnlyLocalEntries if a node provided with this replication should
* replicate only local data to the new nodes joining the
* replication network
* @return this builder back
*/
@NotNull
public B bootstrapOnlyLocalEntries(boolean bootstrapOnlyLocalEntries) {
this.bootstrapOnlyLocalEntries = bootstrapOnlyLocalEntries;
return (B) this;
}
/**
* Creates a Replication instance with the given node (server) identifier.
*
* @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.
*/
@NotNull
public abstract R createWithId(byte identifier);
void check(byte identifier) {
if (identifier <= 0)
throw new IllegalArgumentException("Identifier must be positive, " + identifier +
" given");
}
@Override
public String toString() {
return ", udpConfig=" + udpConfig +
", remoteNodeValidator=" + remoteNodeValidator;
}
}
}