Moved Replicator and Replicators to separate files for more convenient Intellij browsing

This commit is contained in:
leventov
2014-10-28 04:12:36 +03:00
parent 76bcc72ac5
commit 16f1e6aa46
3 changed files with 115 additions and 76 deletions
@@ -1533,79 +1533,4 @@ 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>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 to wrap.
* @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(AbstractChronicleMapBuilder 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(AbstractChronicleMapBuilder 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(AbstractChronicleMapBuilder builder,
Replica map, Replica.EntryExternalizable entryExternalizable, final ChronicleMap chronicleMap)
throws IOException {
return new UdpReplicator(map, entryExternalizable, replicationConfig,
builder.entrySize());
}
};
}
}
}