mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Add throwExceptionIfClosed(); to most public methods for classes implementing Closeable, https://github.com/OpenHFT/Chronicle-Core/issues/116
This commit is contained in:
@@ -38,7 +38,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;
|
||||
|
||||
@@ -233,11 +232,13 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wire) {
|
||||
;
|
||||
readMarshallableFields(wire);
|
||||
initTransients();
|
||||
}
|
||||
|
||||
public Runnable getPreShutdownAction() {
|
||||
throwExceptionIfClosed();
|
||||
return preShutdownAction;
|
||||
}
|
||||
|
||||
@@ -291,6 +292,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
;
|
||||
wireOut.write(() -> "dataFileVersion").text(dataFileVersion);
|
||||
|
||||
wireOut.write(() -> "keyClass").typeLiteral(keyClass);
|
||||
@@ -338,6 +340,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public VanillaGlobalMutableState globalMutableState() {
|
||||
throwExceptionIfClosed();
|
||||
return globalMutableState;
|
||||
}
|
||||
|
||||
@@ -379,6 +382,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void initTransients() {
|
||||
throwExceptionIfClosed();
|
||||
initOwnTransients();
|
||||
}
|
||||
|
||||
@@ -472,14 +476,17 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void setResourcesName() {
|
||||
throwExceptionIfClosed();
|
||||
resources.setChronicleHashIdentityString(toIdentityString());
|
||||
}
|
||||
|
||||
public void registerCleaner() {
|
||||
throwExceptionIfClosed();
|
||||
this.cleaner = CleanerUtils.createCleaner(this, resources);
|
||||
}
|
||||
|
||||
public void addToOnExitHook() {
|
||||
throwExceptionIfClosed();
|
||||
if (!skipCloseOnExitHook) {
|
||||
ChronicleHashCloseOnExitHook.add(this);
|
||||
}
|
||||
@@ -611,12 +618,14 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void onHeaderCreated() {
|
||||
throwExceptionIfClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the version of Chronicle Map that was used to create the current data file
|
||||
*/
|
||||
public String persistedDataVersion() {
|
||||
throwExceptionIfClosed();
|
||||
return dataFileVersion;
|
||||
}
|
||||
|
||||
@@ -636,6 +645,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public long mapHeaderInnerSize() {
|
||||
throwExceptionIfClosed();
|
||||
return headerSize + globalMutableStateTotalUsedSize();
|
||||
}
|
||||
|
||||
@@ -680,6 +690,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
throwExceptionIfClosed();
|
||||
return !resources.closed();
|
||||
}
|
||||
|
||||
@@ -698,6 +709,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public long bsAddress() {
|
||||
throwExceptionIfClosed();
|
||||
return bs.addressForRead(0);
|
||||
}
|
||||
|
||||
@@ -729,6 +741,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
@Override
|
||||
public int segments() {
|
||||
throwExceptionIfClosed();
|
||||
return actualSegments;
|
||||
}
|
||||
|
||||
@@ -737,6 +750,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void globalMutableStateLock() {
|
||||
throwExceptionIfClosed();
|
||||
globalMutableStateLockAcquisitionStrategy.acquire(
|
||||
globalMutableStateLockTryAcquireOperation, globalMutableStateLockingStrategy,
|
||||
nativeAccess(), null,
|
||||
@@ -744,6 +758,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void globalMutableStateUnlock() {
|
||||
throwExceptionIfClosed();
|
||||
globalMutableStateLockingStrategy.unlock(nativeAccess(), null,
|
||||
globalMutableStateAddress() + GLOBAL_MUTABLE_STATE_LOCK_OFFSET);
|
||||
}
|
||||
@@ -752,15 +767,18 @@ public abstract class VanillaChronicleHash<K,
|
||||
* For tests
|
||||
*/
|
||||
public boolean hasExtraTierBulks() {
|
||||
throwExceptionIfClosed();
|
||||
return globalMutableState.getAllocatedExtraTierBulks() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offHeapMemoryUsed() {
|
||||
throwExceptionIfClosed();
|
||||
return resources.totalMemory();
|
||||
}
|
||||
|
||||
public long allocateTier() {
|
||||
throwExceptionIfClosed();
|
||||
globalMutableStateLock();
|
||||
try {
|
||||
long tiersInUse = globalMutableState.getExtraTiersInUse();
|
||||
@@ -837,6 +855,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void msync() throws IOException {
|
||||
throwExceptionIfClosed();
|
||||
if (persisted()) {
|
||||
msync(bsAddress(), bs.capacity());
|
||||
}
|
||||
@@ -857,6 +876,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void linkAndZeroOutFreeTiers(long firstTierIndex, long lastTierIndex) {
|
||||
throwExceptionIfClosed();
|
||||
for (long tierIndex = firstTierIndex; tierIndex <= lastTierIndex; tierIndex++) {
|
||||
long tierOffset = tierBytesOffset(tierIndex);
|
||||
BytesStore tierBytesStore = tierBytesStore(tierIndex);
|
||||
@@ -870,10 +890,12 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public long extraTierIndexToTierIndex(long extraTierIndex) {
|
||||
throwExceptionIfClosed();
|
||||
return actualSegments + extraTierIndex + 1;
|
||||
}
|
||||
|
||||
public long tierIndexToBaseAddr(long tierIndex) {
|
||||
throwExceptionIfClosed();
|
||||
// tiers are 1-counted, to allow tierIndex = 0 to be un-initialized in off-heap memory,
|
||||
// convert into 0-based form
|
||||
long tierIndexMinusOne = tierIndex - 1;
|
||||
@@ -883,6 +905,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public BytesStore tierBytesStore(long tierIndex) {
|
||||
throwExceptionIfClosed();
|
||||
long tierIndexMinusOne = tierIndex - 1;
|
||||
if (tierIndexMinusOne < actualSegments)
|
||||
return bs;
|
||||
@@ -890,6 +913,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public long tierBytesOffset(long tierIndex) {
|
||||
throwExceptionIfClosed();
|
||||
long tierIndexMinusOne = tierIndex - 1;
|
||||
if (tierIndexMinusOne < actualSegments)
|
||||
return segmentOffset(tierIndexMinusOne);
|
||||
@@ -1025,6 +1049,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public void addCloseable(Closeable closeable) {
|
||||
throwExceptionIfClosed();
|
||||
resources.addCloseable(closeable);
|
||||
}
|
||||
|
||||
@@ -1032,6 +1057,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
* For testing only
|
||||
*/
|
||||
public List<WeakReference<ContextHolder>> allContexts() {
|
||||
throwExceptionIfClosed();
|
||||
return Collections.unmodifiableList(resources.contexts());
|
||||
}
|
||||
|
||||
@@ -1056,6 +1082,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
*/
|
||||
public class Identity {
|
||||
public VanillaChronicleHash hash() {
|
||||
throwExceptionIfClosed();
|
||||
return VanillaChronicleHash.this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
|
||||
}
|
||||
|
||||
public long tierEntriesForIteration() {
|
||||
throwExceptionIfClosed();
|
||||
return s.tierEntries();
|
||||
}
|
||||
|
||||
@@ -67,6 +68,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
|
||||
public abstract boolean hashLookupEntryInit();
|
||||
|
||||
public void initHashLookupEntry(long entry) {
|
||||
throwExceptionIfClosed();
|
||||
hashLookupEntry = entry;
|
||||
}
|
||||
|
||||
@@ -74,6 +76,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
|
||||
|
||||
@Override
|
||||
public boolean forEachSegmentEntryWhile(Predicate<? super E> predicate) {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
s.innerUpdateLock.lock();
|
||||
return innerForEachSegmentEntryWhile(predicate);
|
||||
@@ -174,10 +177,12 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
|
||||
}
|
||||
|
||||
public void hookAfterEachIteration() {
|
||||
throwExceptionIfClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachSegmentEntry(Consumer<? super E> action) {
|
||||
throwExceptionIfClosed();
|
||||
forEachSegmentEntryWhile(e -> {
|
||||
action.accept(e);
|
||||
return true;
|
||||
@@ -185,6 +190,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
|
||||
}
|
||||
|
||||
public void checkEntryNotRemovedOnThisIteration() {
|
||||
throwExceptionIfClosed();
|
||||
if (entryRemovedOnThisIterationInit()) {
|
||||
throw new IllegalStateException(
|
||||
hh.h().toIdentityString() + ": Entry was already removed on this iteration");
|
||||
@@ -193,6 +199,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
|
||||
|
||||
@Override
|
||||
public void doRemove() {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
s.innerWriteLock.lock();
|
||||
try {
|
||||
@@ -204,6 +211,7 @@ public abstract class HashSegmentIteration<K, E extends HashEntry<K>>
|
||||
}
|
||||
|
||||
public void iterationRemove() {
|
||||
throwExceptionIfClosed();
|
||||
// this condition mean -- some other entry taken place of the removed one
|
||||
if (hh.h().hashLookup.remove(s.tierBaseAddr, hlp.hashLookupPos) != hlp.hashLookupPos) {
|
||||
// if so, should make step back, to compensate step forward on the next iteration,
|
||||
|
||||
@@ -44,6 +44,7 @@ public abstract class SegmentsRecovery implements IterationContext {
|
||||
public void recoverSegments(
|
||||
ChronicleHashCorruption.Listener corruptionListener,
|
||||
ChronicleHashCorruptionImpl corruption) {
|
||||
throwExceptionIfClosed();
|
||||
VanillaChronicleHash<?, ?, ?, ?> h = hh.h();
|
||||
for (int segmentIndex = 0; segmentIndex < h.actualSegments; segmentIndex++) {
|
||||
s.initSegmentIndex(segmentIndex);
|
||||
|
||||
@@ -114,6 +114,7 @@ class OldDeletedEntriesCleanupThread extends Thread
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
throwExceptionIfClosed();
|
||||
if (System.currentTimeMillis() - startTime < 1_000)
|
||||
return;
|
||||
|
||||
@@ -175,6 +176,7 @@ class OldDeletedEntriesCleanupThread extends Thread
|
||||
|
||||
@Override
|
||||
public boolean test(ReplicableEntry e) {
|
||||
throwExceptionIfClosed();
|
||||
if (shutdown)
|
||||
return false;
|
||||
if (e instanceof MapAbsentEntry) {
|
||||
|
||||
@@ -154,6 +154,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
;
|
||||
super.writeMarshallable(wireOut);
|
||||
|
||||
wireOut.write(() -> "tierModIterBitSetSizeInBits").int64(tierModIterBitSetSizeInBits);
|
||||
@@ -171,11 +172,13 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
|
||||
@Override
|
||||
public ReplicatedGlobalMutableState globalMutableState() {
|
||||
throwExceptionIfClosed();
|
||||
return (ReplicatedGlobalMutableState) super.globalMutableState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initTransients() {
|
||||
throwExceptionIfClosed();
|
||||
super.initTransients();
|
||||
initOwnTransients();
|
||||
}
|
||||
@@ -232,21 +235,25 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
|
||||
@Override
|
||||
public long mapHeaderInnerSize() {
|
||||
throwExceptionIfClosed();
|
||||
return super.mapHeaderInnerSize() + (segmentModIterBitSetsForIdentifierOuterSize * 128);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoteNodeCouldBootstrapFrom(byte remoteIdentifier, long bootstrapTimestamp) {
|
||||
throwExceptionIfClosed();
|
||||
remoteNodeCouldBootstrapFrom[remoteIdentifier] = bootstrapTimestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long remoteNodeCouldBootstrapFrom(byte remoteIdentifier) {
|
||||
throwExceptionIfClosed();
|
||||
return remoteNodeCouldBootstrapFrom[remoteIdentifier];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHeaderCreated() {
|
||||
throwExceptionIfClosed();
|
||||
// Pad modification iterators at 3 cache lines from the end of the map header,
|
||||
// to avoid false sharing with the header of the first segment
|
||||
startOfModificationIterators = super.mapHeaderInnerSize() +
|
||||
@@ -261,6 +268,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
|
||||
@Override
|
||||
public byte identifier() {
|
||||
throwExceptionIfClosed();
|
||||
byte id = localIdentifier;
|
||||
if (id == 0) {
|
||||
throw new IllegalStateException("Replication identifier is not set for this\n" +
|
||||
@@ -282,6 +290,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
|
||||
@Override
|
||||
public ModificationIterator acquireModificationIterator(byte remoteIdentifier) {
|
||||
throwExceptionIfClosed();
|
||||
ModificationIterator modificationIterator = modificationIterators.get(remoteIdentifier);
|
||||
if (modificationIterator != null)
|
||||
return modificationIterator;
|
||||
@@ -324,6 +333,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
}
|
||||
|
||||
public ModificationIterator[] acquireAllModificationIterators() {
|
||||
throwExceptionIfClosed();
|
||||
for (int remoteIdentifier = 0; remoteIdentifier < 128; remoteIdentifier++) {
|
||||
if (globalMutableState().getModificationIteratorInitAt(remoteIdentifier)) {
|
||||
acquireModificationIterator((byte) remoteIdentifier);
|
||||
@@ -339,19 +349,25 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
}
|
||||
}
|
||||
|
||||
public long changeCount() { return changeCount.get(); }
|
||||
public long changeCount() {
|
||||
throwExceptionIfClosed();
|
||||
return changeCount.get();
|
||||
}
|
||||
|
||||
public void raiseChange(long tierIndex, long pos) {
|
||||
throwExceptionIfClosed();
|
||||
// -1 is invalid remoteIdentifier => raise change for all
|
||||
changeCount.incrementAndGet();
|
||||
raiseChangeForAllExcept(tierIndex, pos, (byte) -1);
|
||||
}
|
||||
|
||||
public void raiseChangeFor(long tierIndex, long pos, byte remoteIdentifier) {
|
||||
throwExceptionIfClosed();
|
||||
acquireModificationIterator(remoteIdentifier).raiseChange0(tierIndex, pos);
|
||||
}
|
||||
|
||||
public void raiseChangeForAllExcept(long tierIndex, long pos, byte remoteIdentifier) {
|
||||
throwExceptionIfClosed();
|
||||
updateModificationIteratorsArray();
|
||||
if (tierIndex <= actualSegments) {
|
||||
long segmentIndex = tierIndex - 1;
|
||||
@@ -373,6 +389,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
}
|
||||
|
||||
public void dropChange(long tierIndex, long pos) {
|
||||
throwExceptionIfClosed();
|
||||
updateModificationIteratorsArray();
|
||||
if (tierIndex <= actualSegments) {
|
||||
long segmentIndex = tierIndex - 1;
|
||||
@@ -392,10 +409,12 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
}
|
||||
|
||||
public void dropChangeFor(long tierIndex, long pos, byte remoteIdentifier) {
|
||||
throwExceptionIfClosed();
|
||||
acquireModificationIterator(remoteIdentifier).dropChange0(tierIndex, pos);
|
||||
}
|
||||
|
||||
public void moveChange(long oldTierIndex, long oldPos, long newTierIndex, long newPos) {
|
||||
throwExceptionIfClosed();
|
||||
updateModificationIteratorsArray();
|
||||
if (oldTierIndex <= actualSegments) {
|
||||
long oldSegmentIndex = oldTierIndex - 1;
|
||||
@@ -450,6 +469,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
}
|
||||
|
||||
public boolean isChanged(long tierIndex, long pos) {
|
||||
throwExceptionIfClosed();
|
||||
updateModificationIteratorsArray();
|
||||
if (tierIndex <= actualSegments) {
|
||||
long segmentIndex = tierIndex - 1;
|
||||
@@ -473,12 +493,14 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
|
||||
@Override
|
||||
public boolean identifierCheck(@NotNull ReplicableEntry entry, int chronicleId) {
|
||||
throwExceptionIfClosed();
|
||||
return entry.originIdentifier() == identifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternalEntry(
|
||||
ReplicableEntry entry, Bytes payload, @NotNull Bytes destination, int chronicleId, ArrayList<String> keys) {
|
||||
throwExceptionIfClosed();
|
||||
if (payload != null)
|
||||
writePayload(payload, destination);
|
||||
if (entry != null)
|
||||
@@ -571,6 +593,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
*/
|
||||
@Override
|
||||
public void readExternalEntry(@NotNull Bytes source, byte remoteNodeIdentifier) {
|
||||
throwExceptionIfClosed();
|
||||
byte hunk = source.readByte();
|
||||
if (hunk == BOOTSTRAP_TIME_HUNK) {
|
||||
setRemoteNodeCouldBootstrapFrom(remoteNodeIdentifier, source.readLong());
|
||||
@@ -681,6 +704,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
}
|
||||
|
||||
public void setModificationNotifier(@NotNull ModificationNotifier modificationNotifier) {
|
||||
throwExceptionIfClosed();
|
||||
this.modificationNotifier = modificationNotifier;
|
||||
}
|
||||
|
||||
@@ -735,6 +759,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
throwExceptionIfClosed();
|
||||
return nextEntryPos(null, 0) != NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -823,6 +848,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
*/
|
||||
@Override
|
||||
public boolean nextEntry(@NotNull Callback callback, int chronicleId) {
|
||||
throwExceptionIfClosed();
|
||||
while (true) {
|
||||
long nextEntryPos = nextEntryPos(callback, chronicleId);
|
||||
if (nextEntryPos == NOT_FOUND)
|
||||
@@ -873,6 +899,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
|
||||
@Override
|
||||
public void dirtyEntries(long fromTimeStamp) {
|
||||
throwExceptionIfClosed();
|
||||
try (CompiledReplicatedMapIterationContext<K, V, R> c = iterationContext()) {
|
||||
// iterate over all the segments and mark bit in the modification iterator
|
||||
// that correspond to entries with an older timestamp
|
||||
@@ -934,6 +961,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
}
|
||||
|
||||
public void clearRange0(long tierIndex, long pos, long endPosExclusive) {
|
||||
throwExceptionIfClosed();
|
||||
if (tierIndex <= actualSegments) {
|
||||
long segmentIndex = tierIndex - 1;
|
||||
long offsetToTierBitSet = segmentIndex * tierModIterBitSetOuterSize;
|
||||
|
||||
@@ -134,6 +134,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
;
|
||||
super.writeMarshallable(wireOut);
|
||||
|
||||
wireOut.write(() -> "valueClass").typeLiteral(valueClass);
|
||||
@@ -161,6 +162,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public void initTransients() {
|
||||
throwExceptionIfClosed();
|
||||
super.initTransients();
|
||||
initOwnTransients();
|
||||
}
|
||||
@@ -168,6 +170,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
public void recover(
|
||||
ChronicleHashResources resources, ChronicleHashCorruption.Listener corruptionListener,
|
||||
ChronicleHashCorruptionImpl corruption) throws IOException {
|
||||
throwExceptionIfClosed();
|
||||
basicRecover(resources, corruptionListener, corruption);
|
||||
try (IterationContext<K, V, ?> iterationContext = iterationContext()) {
|
||||
iterationContext.recoverSegments(corruptionListener, corruption);
|
||||
@@ -212,21 +215,25 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public Class<K> keyClass() {
|
||||
throwExceptionIfClosed();
|
||||
return (Class<K>) keyClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type keyType() {
|
||||
throwExceptionIfClosed();
|
||||
return keyClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<V> valueClass() {
|
||||
throwExceptionIfClosed();
|
||||
return (Class<V>) valueClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type valueType() {
|
||||
throwExceptionIfClosed();
|
||||
return valueClass;
|
||||
}
|
||||
|
||||
@@ -240,11 +247,13 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public int remainingAutoResizes() {
|
||||
throwExceptionIfClosed();
|
||||
return (int) (maxTiers() - tiersUsed());
|
||||
}
|
||||
|
||||
@Override
|
||||
public short percentageFreeSpace() {
|
||||
throwExceptionIfClosed();
|
||||
|
||||
double totalUsed = 0;
|
||||
double totalSize = 0;
|
||||
@@ -310,11 +319,13 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
throwExceptionIfClosed();
|
||||
return mapHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
throwExceptionIfClosed();
|
||||
return mapEquals(obj);
|
||||
}
|
||||
|
||||
@@ -330,6 +341,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public String toIdentityString() {
|
||||
throwExceptionIfClosed();
|
||||
if (identityString == null)
|
||||
identityString = makeIdentityString();
|
||||
return identityString;
|
||||
@@ -347,6 +359,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
throwExceptionIfClosed();
|
||||
forEachEntry(c -> c.context().remove(c));
|
||||
}
|
||||
|
||||
@@ -357,6 +370,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
}
|
||||
|
||||
public void alignReadPosition(Bytes entry) {
|
||||
throwExceptionIfClosed();
|
||||
long positionAddr = entry.addressForRead(entry.readPosition());
|
||||
long skip = alignAddr(positionAddr, alignment) - positionAddr;
|
||||
if (skip > 0)
|
||||
@@ -520,6 +534,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
throwExceptionIfClosed();
|
||||
return defaultEntryOperationsAndMethods ? optimizedGet(key, null) : defaultGet(key);
|
||||
}
|
||||
|
||||
@@ -693,6 +708,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V getUsing(K key, V usingValue) {
|
||||
throwExceptionIfClosed();
|
||||
return defaultEntryOperationsAndMethods ? optimizedGet(key, usingValue) :
|
||||
defaultGetUsing(key, usingValue);
|
||||
}
|
||||
@@ -707,6 +723,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V acquireUsing(K key, V usingValue) {
|
||||
throwExceptionIfClosed();
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
return acquireUsingBody(q, usingValue);
|
||||
}
|
||||
@@ -720,6 +737,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V putIfAbsent(K key, V value) {
|
||||
throwExceptionIfClosed();
|
||||
checkValue(value);
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
methods.putIfAbsent(q, q.inputValueDataAccess().getData(value), q.defaultReturnValue());
|
||||
@@ -729,6 +747,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public boolean remove(Object key, Object value) {
|
||||
throwExceptionIfClosed();
|
||||
if (value == null)
|
||||
return false; // ConcurrentHashMap compatibility
|
||||
V v = checkValue(value);
|
||||
@@ -739,6 +758,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public boolean replace(K key, V oldValue, V newValue) {
|
||||
throwExceptionIfClosed();
|
||||
checkValue(oldValue);
|
||||
checkValue(newValue);
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
@@ -749,6 +769,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V replace(K key, V value) {
|
||||
throwExceptionIfClosed();
|
||||
checkValue(value);
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
methods.replace(q, q.inputValueDataAccess().getData(value), q.defaultReturnValue());
|
||||
@@ -758,6 +779,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
throwExceptionIfClosed();
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
return methods.containsKey(q);
|
||||
}
|
||||
@@ -765,6 +787,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
throwExceptionIfClosed();
|
||||
checkValue(value);
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
Data<V> valueData = q.inputValueDataAccess().getData(value);
|
||||
@@ -777,6 +800,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
throwExceptionIfClosed();
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
InstanceReturnValue<V> returnValue =
|
||||
removeReturnsNull ? NullReturnValue.get() : q.defaultReturnValue();
|
||||
@@ -788,6 +812,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
@Override
|
||||
public V merge(K key, V value,
|
||||
BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
|
||||
throwExceptionIfClosed();
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
methods.merge(q, q.inputValueDataAccess().getData(value), remappingFunction,
|
||||
q.defaultReturnValue());
|
||||
@@ -797,6 +822,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
|
||||
throwExceptionIfClosed();
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
methods.compute(q, remappingFunction, q.defaultReturnValue());
|
||||
return q.defaultReturnValue().returnValue();
|
||||
@@ -805,6 +831,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
|
||||
throwExceptionIfClosed();
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
methods.computeIfAbsent(q, mappingFunction, q.defaultReturnValue());
|
||||
return q.defaultReturnValue().returnValue();
|
||||
@@ -814,6 +841,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
@Override
|
||||
public V computeIfPresent(K key,
|
||||
BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
|
||||
throwExceptionIfClosed();
|
||||
try (QueryContextInterface<K, V, R> q = queryContext(key)) {
|
||||
methods.computeIfPresent(q, remappingFunction, q.defaultReturnValue());
|
||||
return q.defaultReturnValue().returnValue();
|
||||
@@ -821,6 +849,7 @@ public class VanillaChronicleMap<K, V, R>
|
||||
}
|
||||
|
||||
public void verifyTierCountersAreaData() {
|
||||
throwExceptionIfClosed();
|
||||
for (int i = 0; i < actualSegments; i++) {
|
||||
try (MapSegmentContext<K, V, ?> c = segmentContext(i)) {
|
||||
Method verifyTierCountersAreaData =
|
||||
|
||||
@@ -40,11 +40,13 @@ public abstract class MapSegmentIteration<K, V, R> extends HashSegmentIteration<
|
||||
|
||||
@Override
|
||||
public void hookAfterEachIteration() {
|
||||
throwExceptionIfClosed();
|
||||
wrappedValueInstanceDataHolder.closeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
try {
|
||||
entry.innerDefaultReplaceValue(newValue);
|
||||
|
||||
+11
@@ -60,21 +60,25 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
|
||||
@Override
|
||||
public boolean shouldTestEntry() {
|
||||
throwExceptionIfClosed();
|
||||
return entriesToTest == ALL || !e.entryDeleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object entryForIteration() {
|
||||
throwExceptionIfClosed();
|
||||
return !e.entryDeleted() ? entryDelegating : absentEntryDelegating;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long tierEntriesForIteration() {
|
||||
throwExceptionIfClosed();
|
||||
return entriesToTest == ALL ? s.tierEntries() : s.tierEntries() - s.tierDeleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doReplaceValue(Data<V> newValue) {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
try {
|
||||
entry.innerDefaultReplaceValue(newValue);
|
||||
@@ -87,6 +91,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
|
||||
@Override
|
||||
public boolean forEachSegmentEntryWhile(Predicate<? super MapEntry<K, V>> predicate) {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
initEntriesToTest(PRESENT);
|
||||
s.innerUpdateLock.lock();
|
||||
@@ -96,6 +101,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
@Override
|
||||
public boolean forEachSegmentReplicableEntryWhile(
|
||||
Predicate<? super ReplicableEntry> predicate) {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
initEntriesToTest(ALL);
|
||||
s.innerUpdateLock.lock();
|
||||
@@ -104,6 +110,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
|
||||
@Override
|
||||
public void forEachSegmentReplicableEntry(Consumer<? super ReplicableEntry> action) {
|
||||
throwExceptionIfClosed();
|
||||
forEachSegmentReplicableEntryWhile(e -> {
|
||||
action.accept(e);
|
||||
return true;
|
||||
@@ -112,6 +119,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
|
||||
@Override
|
||||
public void doRemove() {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
try {
|
||||
if (e.valueSize > dummyValue.size())
|
||||
@@ -128,6 +136,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
|
||||
@Override
|
||||
public void doRemoveCompletely() {
|
||||
throwExceptionIfClosed();
|
||||
boolean wasDeleted = e.entryDeleted();
|
||||
super.doRemove();
|
||||
ru.dropChange();
|
||||
@@ -136,6 +145,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
}
|
||||
|
||||
public void doInsert(Data<V> value) {
|
||||
throwExceptionIfClosed();
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
if (e.entryDeleted()) {
|
||||
try {
|
||||
@@ -155,6 +165,7 @@ public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentI
|
||||
}
|
||||
|
||||
public void doInsert() {
|
||||
throwExceptionIfClosed();
|
||||
if (mh.set() == null)
|
||||
throw new IllegalStateException(mh.h().toIdentityString() +
|
||||
": Called SetAbsentEntry.doInsert() from Map context");
|
||||
|
||||
@@ -51,34 +51,42 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
throwExceptionIfClosed();
|
||||
m.clear();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
throwExceptionIfClosed();
|
||||
return m.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
throwExceptionIfClosed();
|
||||
return m.isEmpty();
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
throwExceptionIfClosed();
|
||||
return m.containsKey(o);
|
||||
}
|
||||
|
||||
public boolean remove(Object o) {
|
||||
throwExceptionIfClosed();
|
||||
return m.remove(o, DUMMY_VALUE);
|
||||
}
|
||||
|
||||
public boolean add(E e) {
|
||||
throwExceptionIfClosed();
|
||||
return m.putIfAbsent(e, DUMMY_VALUE) == null;
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
throwExceptionIfClosed();
|
||||
return s.iterator();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
throwExceptionIfClosed();
|
||||
return s.toArray();
|
||||
}
|
||||
|
||||
@@ -92,6 +100,7 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
|
||||
@Override
|
||||
public String toIdentityString() {
|
||||
throwExceptionIfClosed();
|
||||
return "ChronicleSet{" +
|
||||
"name=" + name() +
|
||||
", file=" + file() +
|
||||
@@ -100,43 +109,52 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
throwExceptionIfClosed();
|
||||
return s.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
throwExceptionIfClosed();
|
||||
return o == this || s.equals(o);
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
throwExceptionIfClosed();
|
||||
return s.containsAll(c);
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
throwExceptionIfClosed();
|
||||
return s.removeAll(c);
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throwExceptionIfClosed();
|
||||
return s.retainAll(c);
|
||||
}
|
||||
// addAll is the only inherited implementation
|
||||
|
||||
@Override
|
||||
public long longSize() {
|
||||
throwExceptionIfClosed();
|
||||
return m.longSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offHeapMemoryUsed() {
|
||||
throwExceptionIfClosed();
|
||||
return m.offHeapMemoryUsed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<E> keyClass() {
|
||||
throwExceptionIfClosed();
|
||||
return m.keyClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type keyType() {
|
||||
throwExceptionIfClosed();
|
||||
return m.keyType();
|
||||
}
|
||||
|
||||
@@ -171,6 +189,7 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
|
||||
@Override
|
||||
public int segments() {
|
||||
throwExceptionIfClosed();
|
||||
return m.segments();
|
||||
}
|
||||
|
||||
@@ -178,23 +197,27 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
|
||||
@Override
|
||||
public boolean forEachEntryWhile(Predicate<? super SetEntry<E>> predicate) {
|
||||
throwExceptionIfClosed();
|
||||
Objects.requireNonNull(predicate);
|
||||
return m.forEachEntryWhile(e -> predicate.test(((SetEntry<E>) e)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachEntry(Consumer<? super SetEntry<E>> action) {
|
||||
throwExceptionIfClosed();
|
||||
Objects.requireNonNull(action);
|
||||
m.forEachEntry(e -> action.accept(((SetEntry<E>) e)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public File file() {
|
||||
throwExceptionIfClosed();
|
||||
return m.file();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
throwExceptionIfClosed();
|
||||
return m.name();
|
||||
}
|
||||
|
||||
@@ -205,6 +228,7 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
throwExceptionIfClosed();
|
||||
return m.isOpen();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user