diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index b3ada99b8..409d86a99 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -47,6 +47,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; +import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; @@ -212,6 +213,7 @@ public final class ChronicleMapBuilder implements private boolean removeReturnsNull = false; private boolean replicated; private boolean persisted; + private String replicatedMapClassName = ReplicatedChronicleMap.class.getName(); ChronicleMapBuilder(Class keyClass, Class valueClass) { keyBuilder = new SerializationBuilder<>(keyClass); @@ -1480,6 +1482,11 @@ public final class ChronicleMapBuilder implements return this; } + public ChronicleMapBuilder replicatedMapClassName(final String replicatedMapClassName) { + this.replicatedMapClassName = replicatedMapClassName; + return this; + } + @Override public ChronicleMap createPersistedTo(File file) throws IOException { // clone() to make this builder instance thread-safe, because createWithFile() method @@ -1811,11 +1818,18 @@ public final class ChronicleMapBuilder implements } } + @SuppressWarnings("unchecked") private VanillaChronicleMap newMap() throws IOException { preMapConstruction(); if (replicated) { - return new ReplicatedChronicleMap<>(this); + try { + return (VanillaChronicleMap) Class.forName(replicatedMapClassName). + getDeclaredConstructor(getClass()).newInstance(this); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | + InvocationTargetException | ClassNotFoundException e) { + throw new IllegalStateException("Cannot load specified implementation class: " + replicatedMapClassName); + } } else { return new VanillaChronicleMap<>(this); }