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
@@ -125,6 +125,7 @@ public abstract class VanillaChronicleHash<K,
public transient CompactOffHeapLinearHashTable hashLookup;
public transient Identity identity;
protected int log2TiersInBulk;
private Runnable preShutdownAction;
/////////////////////////////////////////////////
// Bytes Store (essentially, the base address) and serialization-dependent offsets
protected transient BytesStore bs;
@@ -208,6 +209,8 @@ public abstract class VanillaChronicleHash<K,
tierBulkSizeInBytes = computeTierBulkBytesSize(tiersInBulk);
checksumEntries = privateAPI.checksumEntries();
preShutdownAction = privateAPI.getPreShutdownAction();
}
public static IOException throwRecoveryOrReturnIOException(
@@ -230,6 +233,10 @@ public abstract class VanillaChronicleHash<K,
initTransients();
}
public Runnable getPreShutdownAction() {
return preShutdownAction;
}
protected void readMarshallableFields(@NotNull WireIn wireIn) {
dataFileVersion = wireIn.read(() -> "dataFileVersion").text();