mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-352 Changed garbage-free Chronicle-Map iterations API from old to new Contexts; Add SegmentContexts API
This commit is contained in:
@@ -1,21 +1,11 @@
|
||||
package net.openhft.chronicle.map.impl;
|
||||
|
||||
import net.openhft.chronicle.map.MapEntry;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import net.openhft.chronicle.map.MapSegmentContext;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface IterationContextInterface<K, V> extends MapEntry<K, V>, AutoCloseable {
|
||||
public interface IterationContextInterface<K, V, R> extends MapEntry<K, V>,
|
||||
MapSegmentContext<K, V, R> {
|
||||
long pos();
|
||||
|
||||
void initTheSegmentIndex(int segmentIndex);
|
||||
|
||||
MapKeyContext<K, V> deprecatedMapKeyContextOnIteration();
|
||||
|
||||
boolean forEachRemoving(Predicate<? super MapEntry<K, V>> action);
|
||||
|
||||
@Override
|
||||
void close();
|
||||
|
||||
long size();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import net.openhft.chronicle.hash.impl.stage.hash.ThreadLocalCopiesHolder;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.DeprecatedMapKeyContextOnIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.IterationCheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.MapSegmentIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
|
||||
@@ -65,8 +64,6 @@ import net.openhft.sg.Staged;
|
||||
EntryValueBytesData.class,
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
|
||||
DeprecatedMapKeyContextOnIteration.class,
|
||||
})
|
||||
public class MapIterationContext {
|
||||
}
|
||||
|
||||
+2
-1
@@ -4,7 +4,8 @@ import net.openhft.chronicle.hash.replication.ReplicableEntry;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface ReplicatedIterationContextInterface<K, V> extends IterationContextInterface<K, V> {
|
||||
public interface ReplicatedIterationContextInterface<K, V, R>
|
||||
extends IterationContextInterface<K, V, R> {
|
||||
|
||||
void forEachReplicableEntry(Consumer<? super ReplicableEntry> action);
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.EntryValueBytesData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceData;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.DeprecatedMapKeyContextOnIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.IterationCheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.map.impl.stage.iter.ReplicatedMapSegmentIteration;
|
||||
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
|
||||
@@ -70,8 +69,6 @@ import net.openhft.sg.Staged;
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
|
||||
DeprecatedMapKeyContextOnIteration.class,
|
||||
|
||||
DummyValueZeroData.class,
|
||||
})
|
||||
public class ReplicatedMapIterationContext {
|
||||
|
||||
@@ -31,7 +31,7 @@ public interface VanillaChronicleMapHolder<K, KI, MKI extends MetaBytesInterop<K
|
||||
VanillaChronicleMap<K, KI, MKI, V, VI, MVI, R> m();
|
||||
|
||||
@Override
|
||||
default VanillaChronicleHash<K, KI, MKI, ?, ?> h() {
|
||||
default VanillaChronicleHash<K, KI, MKI, ?, ?, ?> h() {
|
||||
return m();
|
||||
}
|
||||
|
||||
|
||||
-128
@@ -1,128 +0,0 @@
|
||||
package net.openhft.chronicle.map.impl.stage.iter;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
|
||||
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
|
||||
import net.openhft.chronicle.hash.locks.InterProcessLock;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.sg.StageRef;
|
||||
import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public class DeprecatedMapKeyContextOnIteration<K, V> implements MapKeyContext<K, V> {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef SegmentStages s;
|
||||
@StageRef MapSegmentIteration<K, V> it;
|
||||
@StageRef MapEntryOperationsDelegation<K, V, ?> ops;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
|
||||
@Override
|
||||
public long valueOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long valueSize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.valueSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valueEqualTo(V value) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return Data.bytesEquivalent(e.entryValue, it.context().wrapValueAsData(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return it.value().get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getUsing(V usingValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return it.value().getUsing(usingValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean put(V newValue) {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
ops.replaceValue(it, it.context().wrapValueAsData(newValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public K key() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return it.key().get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Bytes entry() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.entryBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keyOffset() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keyOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long keySize() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return e.keySize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
ops.remove(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException("close() is not supported during iteration");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock readLock() {
|
||||
throw unsupportedLocks();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock updateLock() {
|
||||
throw unsupportedLocks();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public InterProcessLock writeLock() {
|
||||
throw unsupportedLocks();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private UnsupportedOperationException unsupportedLocks() {
|
||||
return new UnsupportedOperationException(
|
||||
"Lock operations are not supported (and not needed!) during iteration");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ import net.openhft.sg.Staged;
|
||||
@Staged
|
||||
public class IterationCheckOnEachPublicOperation extends CheckOnEachPublicOperation {
|
||||
|
||||
@StageRef MapSegmentIteration<?, ?> iteration;
|
||||
@StageRef MapSegmentIteration<?, ?, ?> iteration;
|
||||
|
||||
@Override
|
||||
public void checkOnEachPublicOperation() {
|
||||
|
||||
@@ -30,11 +30,10 @@ import net.openhft.sg.Staged;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Staged
|
||||
public abstract class MapSegmentIteration<K, V> extends HashSegmentIteration<K, MapEntry<K, V>>
|
||||
implements MapEntry<K, V>, IterationContextInterface<K, V> {
|
||||
public abstract class MapSegmentIteration<K, V, R> extends HashSegmentIteration<K, MapEntry<K, V>>
|
||||
implements MapEntry<K, V>, IterationContextInterface<K, V, R> {
|
||||
|
||||
@StageRef MapEntryStages<K, V> entry;
|
||||
@StageRef public DeprecatedMapKeyContextOnIteration<K, V> deprecatedMapKeyContextOnIteration;
|
||||
@StageRef WrappedValueInstanceValueHolder<K, V, ?> wrappedValueInstanceValueHolder;
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ import net.openhft.sg.Staged;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Staged
|
||||
public abstract class ReplicatedMapSegmentIteration<K, V> extends MapSegmentIteration<K, V>
|
||||
implements ReplicatedIterationContextInterface<K, V>, ReplicableEntry {
|
||||
public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentIteration<K, V, R>
|
||||
implements ReplicatedIterationContextInterface<K, V, R>, ReplicableEntry {
|
||||
|
||||
@StageRef ReplicatedMapEntryStages<K, V, ?> e;
|
||||
@StageRef ReplicationUpdate<K> ru;
|
||||
|
||||
Reference in New Issue
Block a user