Skip to content

Commit

Permalink
Add ChronicleSetBuilder.entryOperations() and .remoteOperations() int…
Browse files Browse the repository at this point in the history
…erception configuration methods; Rename SetRemoteOperations.insert() to put(), for consistency with MapRemoteOperations
  • Loading branch information
leventov committed Nov 28, 2015
1 parent ec3bd94 commit bfa9988
Show file tree
Hide file tree
Showing 30 changed files with 464 additions and 99 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -152,7 +152,7 @@
<dependency>
<groupId>net.openhft</groupId>
<artifactId>stage-compiler</artifactId>
<version>1.7</version>
<version>1.8</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -238,6 +238,7 @@
<exclude>net/openhft/chronicle/map/VanillaChronicleMap.java</exclude>
<exclude>net/openhft/chronicle/map/Replica.java</exclude>
<exclude>net/openhft/chronicle/map/ReplicatedChronicleMap.java</exclude>
<exclude>net/openhft/chronicle/set/DummyValueData.java</exclude>
</sourceFileExcludes>
<failOnError>false</failOnError>
<additionalparam>-Xdoclint:none</additionalparam>
Expand Down
Expand Up @@ -25,6 +25,7 @@
import net.openhft.chronicle.hash.impl.stage.entry.SegmentStages;
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.set.SetEntry;
import net.openhft.sg.Stage;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
Expand All @@ -33,7 +34,7 @@
import static net.openhft.chronicle.hash.impl.stage.query.KeySearch.SearchState.PRESENT;

@Staged
public abstract class HashQuery<K> implements HashEntry<K> {
public abstract class HashQuery<K> implements SetEntry<K> {

@StageRef public VanillaChronicleHashHolder<K> hh;
@StageRef public SegmentStages s;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/openhft/chronicle/map/MapContext.java
Expand Up @@ -16,6 +16,7 @@

package net.openhft.chronicle.map;

import net.openhft.chronicle.hash.ChronicleHash;
import net.openhft.chronicle.hash.HashContext;
import net.openhft.chronicle.hash.Data;

Expand All @@ -35,9 +36,7 @@ public interface MapContext<K, V, R>
* Returns the accessed {@code ChronicleMap}. Synonym to {@link #map()}.
*/
@Override
default ChronicleMap<K, V> hash() {
return map();
}
ChronicleHash<K, ?, ?, ?> hash();

/**
* Returns the accessed {@code ChronicleMap}. Synonym to {@link #hash()}.
Expand Down
Expand Up @@ -30,6 +30,7 @@
import net.openhft.chronicle.map.impl.CompiledMapIterationContext;
import net.openhft.chronicle.map.impl.CompiledMapQueryContext;
import net.openhft.chronicle.map.impl.ret.InstanceReturnValue;
import net.openhft.chronicle.set.ChronicleSet;
import net.openhft.chronicle.values.Values;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
Expand Down Expand Up @@ -72,6 +73,9 @@ public class VanillaChronicleMap<K, V, R>
transient boolean removeReturnsNull;

transient Set<Entry<K, V>> entrySet;

/** @see net.openhft.chronicle.set.SetFromMap */
public transient ChronicleSet<K> chronicleSet;

public transient MapEntryOperations<K, V, R> entryOperations;
public transient MapMethods<K, V, R> methods;
Expand Down
Expand Up @@ -58,7 +58,6 @@
MapAbsent.class,
DefaultValue.class,
ValueBytesInterop.class,
MapAbsentHolder.class,

QueryAlloc.class,
},
Expand Down
Expand Up @@ -67,7 +67,6 @@
ReplicatedMapAbsent.class,
DefaultValue.class,
ValueBytesInterop.class,
ReplicatedMapAbsentHolder.class,
ReplicationUpdate.class,
ReplicatedInput.class,

Expand Down
Expand Up @@ -20,6 +20,7 @@
import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.VanillaChronicleMap;
import net.openhft.chronicle.set.ChronicleSet;

public interface VanillaChronicleMapHolder<K, V, R> extends VanillaChronicleHashHolder<K> {

Expand All @@ -33,4 +34,6 @@ public interface VanillaChronicleMapHolder<K, V, R> extends VanillaChronicleHash
default ChronicleMap<K, V> map() {
return m();
}

ChronicleSet<K> set();
}
Expand Up @@ -47,7 +47,7 @@ public void doReplaceValue(Data<V> newValue) {

@NotNull
@Override
public MapContext<K, V, ?> context() {
public WrappedValueInstanceValueHolder<K, V, ?> context() {
return wrappedValueInstanceValueHolder;
}
}
Expand Up @@ -20,22 +20,23 @@
import net.openhft.chronicle.hash.impl.stage.replication.ReplicableEntryDelegating;
import net.openhft.chronicle.hash.replication.ReplicableEntry;
import net.openhft.chronicle.map.MapAbsentEntry;
import net.openhft.chronicle.map.MapContext;
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
import net.openhft.chronicle.map.impl.stage.map.WrappedValueInstanceValueHolder;
import net.openhft.chronicle.set.SetAbsentEntry;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import org.jetbrains.annotations.NotNull;

@Staged
public class ReplicatedMapAbsentDelegatingForIteration<K, V>
implements MapAbsentEntry<K, V>, ReplicableEntryDelegating {
implements MapAbsentEntry<K, V>, SetAbsentEntry<K>, ReplicableEntryDelegating {

@StageRef ReplicatedMapSegmentIteration<K, V, ?> delegate;
@StageRef ReplicatedMapEntryStages<K, V> e;

@NotNull
@Override
public MapContext<K, V, ?> context() {
public WrappedValueInstanceValueHolder<K, V, ?> context() {
return delegate.context();
}

Expand All @@ -44,6 +45,11 @@ public void doInsert(Data<V> value) {
delegate.doInsert(value);
}

@Override
public void doInsert() {
delegate.doInsert();
}

@NotNull
@Override
public Data<V> defaultValue() {
Expand Down
Expand Up @@ -19,14 +19,16 @@
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.ReplicatedHashSegmentContext;
import net.openhft.chronicle.hash.impl.CompactOffHeapLinearHashTable;
import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder;
import net.openhft.chronicle.hash.replication.ReplicableEntry;
import net.openhft.chronicle.map.MapAbsentEntry;
import net.openhft.chronicle.map.MapEntry;
import net.openhft.chronicle.map.impl.ReplicatedIterationContext;
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
import net.openhft.chronicle.set.DummyValueData;
import net.openhft.chronicle.set.SetAbsentEntry;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;

Expand All @@ -36,9 +38,9 @@
@Staged
public abstract class ReplicatedMapSegmentIteration<K, V, R> extends MapSegmentIteration<K, V, R>
implements ReplicatedIterationContext<K, V, R>, ReplicableEntry,
ReplicatedHashSegmentContext<K, MapEntry<K, V>>, MapAbsentEntry<K, V> {
ReplicatedHashSegmentContext<K, MapEntry<K, V>>, MapAbsentEntry<K, V>, SetAbsentEntry<K> {

@StageRef VanillaChronicleHashHolder<?> hh;
@StageRef VanillaChronicleMapHolder<K, V, R> mh;
@StageRef ReplicatedMapEntryStages<K, V> e;
@StageRef ReplicationUpdate<K> ru;
@StageRef DummyValueZeroData<V> dummyValue;
Expand Down Expand Up @@ -73,7 +75,7 @@ public boolean forEachSegmentReplicableEntryWhile(
return true;
boolean interrupted = false;
long startPos = 0L;
CompactOffHeapLinearHashTable hashLookup = hh.h().hashLookup;
CompactOffHeapLinearHashTable hashLookup = mh.h().hashLookup;
while (!hashLookup.empty(hashLookup.readEntry(s.tierBaseAddr, startPos))) {
startPos = hashLookup.step(startPos);
}
Expand Down Expand Up @@ -155,4 +157,11 @@ public void doInsert(Data<V> value) {
"Entry is present in the map when doInsert() is called");
}
}

@Override
public void doInsert() {
if (mh.set() == null)
throw new IllegalStateException("Called SetAbsentEntry.doInsert() from Map context");
doInsert((Data<V>) DummyValueData.INSTANCE);
}
}
Expand Up @@ -16,11 +16,13 @@

package net.openhft.chronicle.map.impl.stage.map;

import net.openhft.chronicle.hash.ChronicleHash;
import net.openhft.chronicle.hash.impl.stage.hash.Chaining;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.ReplicatedChronicleMap;
import net.openhft.chronicle.map.impl.ReplicatedChronicleMapHolder;
import net.openhft.chronicle.set.ChronicleSet;
import net.openhft.sg.Staged;

@Staged
Expand Down Expand Up @@ -49,4 +51,13 @@ public ReplicatedChronicleMap<K, V, R> m() {
public ChronicleMap<K, V> map() {
return m();
}

@Override
public ChronicleSet<K> set() {
return m.chronicleSet;
}

public ChronicleHash<K, ?, ?, ?> hash() {
return set() != null ? set() : map();
}
}
Expand Up @@ -16,11 +16,13 @@

package net.openhft.chronicle.map.impl.stage.map;

import net.openhft.chronicle.hash.ChronicleHash;
import net.openhft.chronicle.hash.impl.stage.hash.Chaining;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.map.VanillaChronicleMap;
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
import net.openhft.chronicle.set.ChronicleSet;
import net.openhft.sg.Staged;

@Staged
Expand Down Expand Up @@ -49,4 +51,13 @@ public VanillaChronicleMap<K, V, R> m() {
public ChronicleMap<K, V> map() {
return m();
}

@Override
public ChronicleSet<K> set() {
return m.chronicleSet;
}

public ChronicleHash<K, ?, ?, ?> hash() {
return set() != null ? set() : map();
}
}
Expand Up @@ -20,11 +20,13 @@
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.map.MapContext;
import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceDataHolder;
import net.openhft.chronicle.set.SetContext;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;

@Staged
public abstract class WrappedValueInstanceValueHolder<K, V, R> implements MapContext<K, V, R> {
public abstract class WrappedValueInstanceValueHolder<K, V, R>
implements MapContext<K, V, R>, SetContext<K, R> {

@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
@StageRef
Expand Down
Expand Up @@ -17,17 +17,12 @@
package net.openhft.chronicle.map.impl.stage.query;

import net.openhft.chronicle.map.MapAbsentEntry;
import net.openhft.chronicle.map.impl.MapAbsentEntryHolder;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import net.openhft.chronicle.set.SetAbsentEntry;
import org.jetbrains.annotations.NotNull;

@Staged
public class MapAbsentHolder<K, V> implements MapAbsentEntryHolder<K, V> {

@StageRef MapAbsent<K, V> ab;
public interface Absent<K, V> extends MapAbsentEntry<K, V>, SetAbsentEntry<K> {

@NotNull
@Override
public MapAbsentEntry<K, V> absent() {
return ab;
}
MapAndSetContext<K, V, ?> context();
}
Expand Up @@ -23,23 +23,26 @@
import net.openhft.chronicle.hash.impl.stage.query.HashQuery.EntryPresence;
import net.openhft.chronicle.hash.impl.stage.query.KeySearch;
import net.openhft.chronicle.map.MapAbsentEntry;
import net.openhft.chronicle.map.MapContext;
import net.openhft.chronicle.map.impl.VanillaChronicleMapHolder;
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
import net.openhft.chronicle.set.DummyValueData;
import net.openhft.chronicle.set.SetAbsentEntry;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import org.jetbrains.annotations.NotNull;

import static net.openhft.chronicle.hash.impl.stage.query.KeySearch.SearchState.PRESENT;

@Staged
public abstract class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
public abstract class MapAbsent<K, V> implements Absent<K, V> {

@StageRef public KeySearch<K> ks;
@StageRef MapQuery<K, V, ?> q;
@StageRef MapEntryStages<K, V> e;
@StageRef public HashLookupSearch hashLookupSearch;
@StageRef public CheckOnEachPublicOperation checkOnEachPublicOperation;
@StageRef public SegmentStages s;
@StageRef VanillaChronicleMapHolder<K, V, ?> mh;

void putEntry(Data<V> value) {
assert ks.searchStateAbsent();
Expand All @@ -52,7 +55,7 @@ void putEntry(Data<V> value) {

@NotNull
@Override
public MapContext<K, V, ?> context() {
public MapQuery<K, V, ?> context() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return q;
}
Expand Down Expand Up @@ -82,4 +85,11 @@ public void doInsert(Data<V> value) {
"Entry is present in the map when doInsert() is called");
}
}

@Override
public void doInsert() {
if (mh.set() == null)
throw new IllegalStateException("Called SetAbsentEntry.doInsert() from Map context");
doInsert((Data<V>) DummyValueData.INSTANCE);
}
}
Expand Up @@ -14,11 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.openhft.chronicle.map.impl;
package net.openhft.chronicle.map.impl.stage.query;

import net.openhft.chronicle.map.MapAbsentEntry;
import net.openhft.chronicle.map.MapContext;
import net.openhft.chronicle.set.SetContext;

public interface MapAbsentEntryHolder<K, V> {

MapAbsentEntry<K, V> absent();
public interface MapAndSetContext<K, V, R> extends MapContext<K, V, R>, SetContext<K, R> {
}

0 comments on commit bfa9988

Please sign in to comment.