add pre-shutdown action to be executed inside ChronicleHashCloseOnExitHook.

This is useful when we want to do an orderly shutdown.
For example: To carry out graceful shutdown and explicitly control when a ChronicleHash
is closed, a pre-shutdown action can be a wait on a CountDownLatch that would be released
appropriately.
This commit is contained in:
udaysagar2177
2018-09-21 00:36:04 -07:00
parent ccb6577c3d
commit 9eed0e3265
9 changed files with 105 additions and 11 deletions
@@ -181,6 +181,7 @@ public final class ChronicleMapBuilder<K, V> implements
MapMethods<K, V, ?> methods = DefaultSpi.mapMethods();
MapEntryOperations<K, V, ?> entryOperations = mapEntryOperations();
MapRemoteOperations<K, V, ?> remoteOperations = mapRemoteOperations();
Runnable preShutdownAction;
private String name;
// not final because of cloning
private ChronicleMapBuilderPrivateAPI<K, V> privateAPI =
@@ -1587,6 +1588,11 @@ public final class ChronicleMapBuilder<K, V> implements
corruptionListener);
}
@Override
public void setPreShutdownAction(Runnable preShutdownAction) {
this.preShutdownAction = preShutdownAction;
}
@Override
public ChronicleMap<K, V> create() {
// clone() to make this builder instance thread-safe, because createWithoutFile() method