implement AbstractCloseable - OpenHFT/Chronicle-Core#116

This commit is contained in:
Dmitry Pisklov
2020-05-26 22:15:33 +01:00
parent 1a2468b6d4
commit 9438b1ea5b
6 changed files with 27 additions and 7 deletions
@@ -57,4 +57,9 @@ public interface HashSegmentContext<K, E extends HashEntry<K>> extends HashConte
* Returns the number of <i>present</i> entries in this segment.
*/
long size();
@Override
default boolean isClosed() {
throw new UnsupportedOperationException();
}
}
@@ -22,6 +22,7 @@ import net.openhft.chronicle.bytes.MappedBytesStoreFactory;
import net.openhft.chronicle.bytes.NativeBytesStore;
import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.io.AbstractCloseable;
import net.openhft.chronicle.hash.*;
import net.openhft.chronicle.hash.impl.util.BuildVersion;
import net.openhft.chronicle.hash.impl.util.Cleaner;
@@ -38,7 +39,6 @@ import net.openhft.chronicle.map.ChronicleMapBuilder;
import net.openhft.chronicle.values.Values;
import net.openhft.chronicle.wire.Marshallable;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireInternal;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
@@ -65,9 +65,8 @@ import static net.openhft.chronicle.hash.impl.CompactOffHeapLinearHashTable.*;
import static net.openhft.chronicle.map.ChronicleHashCorruptionImpl.format;
import static net.openhft.chronicle.map.ChronicleHashCorruptionImpl.report;
public abstract class VanillaChronicleHash<K,
C extends HashEntry<K>, SC extends HashSegmentContext<K, ?>,
ECQ extends ExternalHashQueryContext<K>>
public abstract class VanillaChronicleHash<K, C extends HashEntry<K>, SC extends HashSegmentContext<K, ?>, ECQ extends ExternalHashQueryContext<K>>
extends AbstractCloseable
implements ChronicleHash<K, C, SC, ECQ>, Marshallable {
public static final long TIER_COUNTERS_AREA_SIZE = 64;
@@ -660,7 +659,7 @@ public abstract class VanillaChronicleHash<K,
}
@Override
public final void close() {
protected void performClose() {
if (resources.releaseManually()) {
cleanupOnClose();
}
@@ -210,6 +210,11 @@ class OldDeletedEntriesCleanupThread extends Thread
this.interrupt(); // unblock
}
@Override
public boolean isClosed() {
throw new UnsupportedOperationException();
}
private int nextSegmentIndex(int segmentIndex) {
int permutationIndex = inverseSegmentsPermutation[segmentIndex];
int nextPermutationIndex = (permutationIndex + 1) % segments;
@@ -16,6 +16,7 @@
package net.openhft.chronicle.map.impl.stage.query;
import net.openhft.chronicle.core.io.AbstractCloseable;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue;
@@ -23,7 +24,7 @@ import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
@Staged
public class AcquireHandle<K, V> implements Closeable {
public class AcquireHandle<K, V> extends AbstractCloseable {
@StageRef
CheckOnEachPublicOperation checkOnEachPublicOperation;
@@ -33,7 +34,7 @@ public class AcquireHandle<K, V> implements Closeable {
UsingReturnValue<V> usingReturn;
@Override
public void close() {
protected void performClose() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
q.replaceValue(q.entry(), q.wrapValueAsData(usingReturn.returnValue()));
q.close();
@@ -203,6 +203,11 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
m.close();
}
@Override
public boolean isClosed() {
return m.isClosed();
}
@Override
public boolean isOpen() {
return m.isOpen();
@@ -331,6 +331,11 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
map2.close();
}
@Override
public boolean isClosed() {
return false;
}
@Override
public boolean isOpen() {
throw new UnsupportedOperationException();