HCOLL-167 now using the builder to create the Stateless client

This commit is contained in:
Rob Austin
2014-10-20 16:30:08 +01:00
parent c047e59d56
commit 1b40eb8147
12 changed files with 634 additions and 696 deletions
@@ -1525,4 +1525,74 @@ class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
}
abstract class Replicator {
/**
* A constructor for use in subclasses.
*/
protected Replicator() {
}
/**
* Applies the replicator to the map instance and returns a Closeable token to manage resources,
* associated with the replication.
* <p/>
* <p>This method isn't intended to be called from the client code.
*
* @param builder the builder from which the map was constructed. The replicator may obtain some
* map configurations, not accessible via the map instance.
* @param map a replicated map instance. Provides basic tools for replication implementation.
* @param entryExternalizable the callback for ser/deser implementation in the replicator
* @param chronicleMap
* @return a {@code Closeable} token to control replication resources.
* It should be closed on closing the replicated map.
* @throws java.io.IOException if an io error occurred during the replicator setup
* @throws IllegalStateException if this replicator doesn't support application to more than
* one map (or the specified number of maps), and this replicator has already been
* applied to a map (or the specified number of maps)
*/
protected abstract Closeable applyTo(ChronicleMapBuilder builder,
Replica map, Replica.EntryExternalizable entryExternalizable, final ChronicleMap chronicleMap)
throws IOException;
}
final class Replicators {
private Replicators() {
}
static Replicator tcp(final TcpReplicationConfig replicationConfig) {
return new Replicator() {
@Override
protected Closeable applyTo(ChronicleMapBuilder builder,
Replica replica, Replica.EntryExternalizable entryExternalizable,
final ChronicleMap chronicleMap) throws IOException {
final KeyValueSerializer keyValueSerializer = new KeyValueSerializer(builder
.keyBuilder, builder.valueBuilder);
StatelessServerConnector statelessServer = new StatelessServerConnector
(keyValueSerializer, chronicleMap, builder.entrySize());
return new TcpReplicator(replica, entryExternalizable, replicationConfig,
builder.entrySize(), statelessServer);
}
};
}
static Replicator udp(
final UdpReplicationConfig replicationConfig) {
return new Replicator() {
@Override
protected Closeable applyTo(ChronicleMapBuilder builder,
Replica map, Replica.EntryExternalizable entryExternalizable, final ChronicleMap chronicleMap)
throws IOException {
return new UdpReplicator(map, entryExternalizable, replicationConfig,
builder.entrySize());
}
};
}
}