mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
InstanceConfig should be used at most once
This commit is contained in:
@@ -501,8 +501,6 @@ final class ChannelProvider implements Closeable {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// synchronized on parent instance to prevent possible (but very unlikely) contention
|
||||
// between close() calls on different channels
|
||||
channelDataLock.writeLock().lock();
|
||||
try {
|
||||
chronicleChannelList.remove(chronicleChannels[chronicleChannel]);
|
||||
|
||||
@@ -32,6 +32,8 @@ final class InstanceConfig<K, V>
|
||||
final ReplicationChannel channel;
|
||||
final File file;
|
||||
|
||||
private boolean used = false;
|
||||
|
||||
InstanceConfig(AbstractChronicleMapBuilder<K, V, ?> mapBuilder,
|
||||
SingleChronicleHashReplication singleHashReplication,
|
||||
ReplicationChannel channel,
|
||||
@@ -67,7 +69,15 @@ final class InstanceConfig<K, V>
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleMap<K, V> create() throws IOException {
|
||||
public synchronized ChronicleMap<K, V> create() throws IOException {
|
||||
if (used)
|
||||
throw new IllegalStateException(
|
||||
"A ChronicleMap has already been created using this instance config. " +
|
||||
"Create a new instance config (builder.instance() or call any " +
|
||||
"configuration method on this instance config) to create a new " +
|
||||
"ChronicleMap instance");
|
||||
used = true;
|
||||
return mapBuilder.create(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ final class InstanceConfig<E> implements ChronicleHashInstanceConfig<ChronicleSe
|
||||
|
||||
private final ChronicleHashInstanceConfig<ChronicleMap<E, DummyValue>> mapConfig;
|
||||
|
||||
private boolean used;
|
||||
|
||||
InstanceConfig(ChronicleHashInstanceConfig<ChronicleMap<E, DummyValue>> mapConfig) {
|
||||
this.mapConfig = mapConfig;
|
||||
}
|
||||
@@ -56,7 +58,14 @@ final class InstanceConfig<E> implements ChronicleHashInstanceConfig<ChronicleSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleSet<E> create() throws IOException {
|
||||
public synchronized ChronicleSet<E> create() throws IOException {
|
||||
if (used)
|
||||
throw new IllegalStateException(
|
||||
"A ChronicleSet has already been created using this instance config. " +
|
||||
"Create a new instance config (builder.instance() or call any " +
|
||||
"configuration method on this instance config) to create a new " +
|
||||
"ChronicleSet instance");
|
||||
used = true;
|
||||
return new SetFromMap<>(mapConfig.create());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user