create MapClosable which replaces the default isClosed() method that was removed from chronicle closable

This commit is contained in:
Rob Austin
2020-05-29 16:40:58 +01:00
parent 1a2468b6d4
commit f042add96b
6 changed files with 57 additions and 80 deletions
@@ -16,7 +16,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.core.io.DefaultCloseable;
import net.openhft.chronicle.hash.ChronicleHashBuilderPrivateAPI;
import net.openhft.chronicle.hash.ReplicatedHashSegmentContext;
import net.openhft.chronicle.hash.replication.ReplicableEntry;
@@ -34,14 +34,13 @@ import static net.openhft.chronicle.hash.replication.TimeProvider.currentTime;
import static net.openhft.chronicle.hash.replication.TimeProvider.systemTimeIntervalBetween;
class OldDeletedEntriesCleanupThread extends Thread
implements Closeable, Predicate<ReplicableEntry> {
implements DefaultCloseable, Predicate<ReplicableEntry> {
private static final Logger LOG = LoggerFactory.getLogger(OldDeletedEntriesCleanupThread.class);
/**
* Don't store a strong ref to a map in order to avoid it's leaking, if the user forgets to
* close() map, from where this thread is shut down explicitly. Dereference map within
* a single method, {@link #cleanupSegment()}. The map has a chance to be collected by GC when
* this thread is sleeping after cleaning up a segment.
* Don't store a strong ref to a map in order to avoid it's leaking, if the user forgets to close() map, from where this thread is shut down
* explicitly. Dereference map within a single method, {@link #cleanupSegment()}. The map has a chance to be collected by GC when this thread is
* sleeping after cleaning up a segment.
*/
private final WeakReference<ReplicatedChronicleMap<?, ?, ?>> mapRef;
/**
@@ -22,7 +22,6 @@ import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.bytes.PointerBytesStore;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.hash.ChronicleHashClosedException;
import net.openhft.chronicle.hash.ChronicleHashCorruption;
import net.openhft.chronicle.hash.Data;
@@ -88,9 +87,8 @@ public class VanillaChronicleMap<K, V, R>
/////////////////////////////////////////////////
private transient String name;
/**
* identityString is initialized lazily in {@link #toIdentityString()} rather than in
* {@link #initOwnTransients()} because it depends on {@link #file()} which is set after
* initOwnTransients().
* identityString is initialized lazily in {@link #toIdentityString()} rather than in {@link #initOwnTransients()} because it depends on {@link
* #file()} which is set after initOwnTransients().
*/
private transient String identityString;
private transient boolean defaultEntryOperationsAndMethods;
@@ -131,7 +129,7 @@ public class VanillaChronicleMap<K, V, R>
alignment = wireIn.read(() -> "alignment").int32();
worstAlignment = wireIn.read(() -> "worstAlignment").int32();
maxBloatFactor = wireIn.read(() -> "maxBloatFactor").float64();
maxBloatFactor = wireIn.read(() -> "maxBloatFactor").float64();
}
@Override
@@ -279,7 +277,7 @@ public class VanillaChronicleMap<K, V, R>
@NotNull
@Override
public final Closeable acquireContext(K key, V usingValue) {
public final MapClosable acquireContext(K key, V usingValue) {
QueryContextInterface<K, V, R> q = queryContext(key);
// TODO optimize to update lock in certain cases
try {
@@ -17,10 +17,10 @@
package net.openhft.chronicle.map.impl;
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.map.ExternalMapQueryContext;
import net.openhft.chronicle.map.MapClosable;
import net.openhft.chronicle.map.impl.ret.InstanceReturnValue;
import net.openhft.chronicle.map.impl.ret.UsableReturnValue;
@@ -38,7 +38,7 @@ public interface QueryContextInterface<K, V, R> extends ExternalMapQueryContext<
DataAccess<V> inputValueDataAccess();
Closeable acquireHandle();
MapClosable acquireHandle();
void initSegmentIndex(int segmentIndex);
@@ -16,14 +16,14 @@
package net.openhft.chronicle.map.impl.stage.query;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.map.MapClosable;
import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
@Staged
public class AcquireHandle<K, V> implements Closeable {
public class AcquireHandle<K, V> implements MapClosable {
@StageRef
CheckOnEachPublicOperation checkOnEachPublicOperation;