mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Try to close alive ChronicleMaps on JVM shutdown
This commit is contained in:
@@ -164,12 +164,25 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
private transient ArrayList<WeakReference<ChainingInterface>> allContexts;
|
||||
|
||||
public VanillaChronicleHash(ChronicleMapBuilder<K, ?> builder) {
|
||||
createdOrInMemory = true;
|
||||
/**
|
||||
* {@link net.openhft.chronicle.map.ChronicleMapCloseOnExitHook} needs to use
|
||||
* {@code VanillaChronicleHash}es as WeakHashMap keys, but with identity comparison, not Map's
|
||||
* equals() and hashCode().
|
||||
*/
|
||||
public class Identity {
|
||||
public VanillaChronicleHash hash() {
|
||||
return VanillaChronicleHash.this;
|
||||
}
|
||||
}
|
||||
|
||||
public transient Identity identity;
|
||||
|
||||
public VanillaChronicleHash(ChronicleMapBuilder<K, ?> builder) {
|
||||
// Version
|
||||
dataFileVersion = BuildVersion.version();
|
||||
|
||||
createdOrInMemory = true;
|
||||
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
ChronicleHashBuilderPrivateAPI<K, ?> privateAPI =
|
||||
(ChronicleHashBuilderPrivateAPI<K, ?>) builder.privateAPI();
|
||||
@@ -231,13 +244,13 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
protected void readMarshallableFields(@NotNull WireIn wireIn) {
|
||||
dataFileVersion = wireIn.read(() -> "dataFileVersion").text();
|
||||
|
||||
// Previously this assignment was done in default field initializer, but with Wire
|
||||
// serialization VanillaChronicleMap instance is created with unsafe.allocateInstance(),
|
||||
// that doesn't guarantee (?) to initialize fields with default values (false for boolean)
|
||||
createdOrInMemory = false;
|
||||
|
||||
dataFileVersion = wireIn.read(() -> "dataFileVersion").text();
|
||||
|
||||
keyClass = wireIn.read(() -> "keyClass").typeLiteral();
|
||||
keySizeMarshaller = wireIn.read(() -> "keySizeMarshaller").typedMarshallable();
|
||||
keyReader = wireIn.read(() -> "keyReader").typedMarshallable();
|
||||
@@ -385,6 +398,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
tierHashLookupSlotSize + " observed");
|
||||
}
|
||||
allContexts = new ArrayList<>();
|
||||
identity = new Identity();
|
||||
}
|
||||
|
||||
public final void initBeforeMapping(
|
||||
|
||||
Reference in New Issue
Block a user