Allow ReplicatedChronicleMap to be accessed without configuring replicators

This commit is contained in:
leventov
2015-10-22 00:19:59 +03:00
parent 4c04a942f7
commit 07b75d8b8a
3 changed files with 114 additions and 3 deletions
@@ -1633,7 +1633,6 @@ public final class ChronicleMapBuilder<K, V> implements
persisted = false;
try {
// pushingToMapEventListener();
VanillaChronicleMap<K, ?, ?, V, ?, ?, ?> map = newMap(singleHashReplication, channel);
// TODO this method had been moved
// if(OS.warnOnWindows(map.sizeInBytesWithoutTiers())){
@@ -1737,12 +1736,17 @@ public final class ChronicleMapBuilder<K, V> implements
replicators.add(Replicators.tcp(singleHashReplication));
if (singleHashReplication.udpTransport() != null)
replicators.add(Replicators.udp(singleHashReplication.udpTransport()));
} else {
} else if (channel != null) {
ReplicationHub hub = channel.hub();
ChannelProvider provider = ChannelProvider.getProvider(hub);
ChannelProvider.ChronicleChannel ch = provider.createChannel(channel.channelId());
replicators.add(ch);
} else {
assert persisted && !((ReplicatedChronicleMap) map).createdOrInMemory :
"No Replicators for replicated ChronicleMap could be only on " +
"deserialization/access of existing replicated ChronicleMap, " +
"when replication in not needed in this JVM/run";
}
for (Replicator replicator : replicators) {
Closeable token = replicator.applyTo(this, result, result,
@@ -128,7 +128,6 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
throws IOException {
super(builder);
this.timeProvider = builder.timeProvider();
this.remoteOperations = (MapRemoteOperations<K, V, R>) builder.remoteOperations;
this.localIdentifier = replication.identifier();
this.bootstrapOnlyLocalEntries = replication.bootstrapOnlyLocalEntries();
@@ -177,6 +176,12 @@ public class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? sup
tierBulkModIterFrameForIteration = new ConcurrentFlatBitSetFrame(tierBulkBitSetSize);
}
@Override
void initTransientsFromBuilder(ChronicleMapBuilder<K, V> builder) {
super.initTransientsFromBuilder(builder);
this.remoteOperations = (MapRemoteOperations<K, V, R>) builder.remoteOperations;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initOwnTransients();