Moved DefaultValueProvider to the new Contexts API; removed defaultValue() SPI from MapEntryOperations (essentially replaced by DefaultValueProvider); Removed the old contexts, KeyContext and MapKeyContext completely

This commit is contained in:
leventov
2015-07-24 21:36:55 +03:00
parent 9fe1dab477
commit 340ab09409
23 changed files with 89 additions and 389 deletions
@@ -95,7 +95,6 @@ nested = {
InputSecondValueBytesData.class,
WrappedValueInstanceData.class,
DeprecatedMapKeyContextOnQuery.class,
AcquireHandle.class,
DefaultReturnValue.class,
UsingReturnValue.class,
@@ -4,10 +4,9 @@ import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.value.instance.KeyInitableData;
import net.openhft.chronicle.map.ExternalMapQueryContext;
import net.openhft.chronicle.map.MapKeyContext;
import net.openhft.chronicle.map.impl.data.instance.ValueInitializableData;
import net.openhft.chronicle.map.impl.ret.InstanceReturnValue;
import net.openhft.chronicle.map.impl.ret.UsableReturnValue;
import net.openhft.chronicle.map.impl.data.instance.ValueInitializableData;
public interface QueryContextInterface<K, V, R> extends ExternalMapQueryContext<K, V, R> {
@@ -21,8 +20,6 @@ public interface QueryContextInterface<K, V, R> extends ExternalMapQueryContext<
ValueInitializableData<V> inputValueInstanceValue();
MapKeyContext<K, V> deprecatedMapKeyContext();
Closeable acquireHandle();
void initTheSegmentIndex(int segmentIndex);
@@ -41,7 +41,10 @@ import net.openhft.chronicle.map.impl.stage.data.instance.WrappedValueInstanceDa
import net.openhft.chronicle.map.impl.stage.entry.ReplicatedMapEntryStages;
import net.openhft.chronicle.map.impl.stage.input.MapInputBytesValues;
import net.openhft.chronicle.map.impl.stage.input.ReplicatedInput;
import net.openhft.chronicle.map.impl.stage.map.*;
import net.openhft.chronicle.map.impl.stage.map.MapEntryOperationsDelegation;
import net.openhft.chronicle.map.impl.stage.map.ReplicatedChronicleMapHolderImpl;
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
import net.openhft.chronicle.map.impl.stage.map.WrappedValueInstanceValueHolder;
import net.openhft.chronicle.map.impl.stage.query.*;
import net.openhft.chronicle.map.impl.stage.replication.ReplicationUpdate;
import net.openhft.chronicle.map.impl.stage.ret.BytesReturnValue;
@@ -100,7 +103,6 @@ nested = {
InputSecondValueBytesData.class,
WrappedValueInstanceData.class,
DeprecatedMapKeyContextOnQuery.class,
AcquireHandle.class,
DefaultReturnValue.class,
UsingReturnValue.class,
@@ -32,7 +32,7 @@ public abstract class MapEntryOperationsDelegation<K, V, R> implements MapContex
@Override
public Data<V> defaultValue(@NotNull MapAbsentEntry<K, V> absentEntry) {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return mh.m().entryOperations.defaultValue(absentEntry);
return mh.m().defaultValueProvider.defaultValue(absentEntry);
}
@Override
@@ -19,17 +19,11 @@
package net.openhft.chronicle.map.impl.stage.query;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.hash.locks.InterProcessLock;
import net.openhft.chronicle.map.MapEntry;
import net.openhft.chronicle.map.MapKeyContext;
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
import net.openhft.chronicle.map.impl.stage.ret.UsingReturnValue;
import net.openhft.lang.io.Bytes;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import org.jetbrains.annotations.NotNull;
@Staged
public class AcquireHandle<K, V> implements Closeable {
@@ -1,148 +0,0 @@
/*
* Copyright 2015 Higher Frequency Trading
*
* http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.map.impl.stage.query;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation;
import net.openhft.chronicle.hash.locks.InterProcessLock;
import net.openhft.chronicle.map.MapEntry;
import net.openhft.chronicle.map.MapKeyContext;
import net.openhft.chronicle.map.impl.stage.entry.MapEntryStages;
import net.openhft.lang.io.Bytes;
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;
import org.jetbrains.annotations.NotNull;
@Staged
public class DeprecatedMapKeyContextOnQuery<K, V> implements MapKeyContext<K, V> {
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
@StageRef MapEntryStages<K, V> e;
@StageRef MapQuery<K, V, ?> q;
@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, q.wrapValueAsData(value));
}
@Override
public V get() {
return containsKey() ? q.value().get() : null;
}
@Override
public V getUsing(V usingValue) {
return containsKey() ? q.value().getUsing(usingValue) : null;
}
@Override
public boolean put(V newValue) {
checkOnEachPublicOperation.checkOnEachPublicOperation();
updateLock().lock();
MapEntry<K, V> entry = q.entry();
if (entry != null) {
q.replaceValue(entry, q.wrapValueAsData(newValue));
} else {
q.insert(q.absentEntry(), q.wrapValueAsData(newValue));
}
return true;
}
@NotNull
@Override
public K key() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return q.queriedKey().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 q.entry() != null;
}
@Override
public boolean remove() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
updateLock().lock();
MapEntry<K, V> entry = q.entry();
if (entry != null) {
q.remove(entry);
return true;
} else {
return false;
}
}
@Override
public void close() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
q.close();
}
@NotNull
@Override
public InterProcessLock readLock() {
return q.readLock();
}
@NotNull
@Override
public InterProcessLock updateLock() {
return q.updateLock();
}
@NotNull
@Override
public InterProcessLock writeLock() {
return q.writeLock();
}
}
@@ -23,7 +23,6 @@ public class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
@StageRef public CheckOnEachPublicOperation checkOnEachPublicOperation;
@StageRef public SegmentStages s;
@StageRef VanillaChronicleMapHolder<K, ?, ?, V, ?, ?, ?> mh;
@StageRef public DeprecatedMapKeyContextOnQuery<K, V> deprecatedMapKeyContext;
void putEntry(Data<V> value) {
assert q.searchStateAbsent();
@@ -69,6 +68,12 @@ public class MapAbsent<K, V> implements MapAbsentEntry<K, V> {
@Override
public Data<V> defaultValue() {
checkOnEachPublicOperation.checkOnEachPublicOperation();
return q.wrapValueAsData(mh.m().defaultValue(deprecatedMapKeyContext));
if (mh.m().constantValueProvider == null) {
throw new IllegalStateException("to call acquireUsing(), " +
"or defaultValue() on AbsentEntry, you should configure " +
"ChronicleMapBuilder.defaultValue(), or use one of the 'known' value types: " +
"boxed primitives, or so-called data-value-generated interface as a value");
}
return context().wrapValueAsData(mh.m().constantValueProvider.defaultValue());
}
}
@@ -49,7 +49,6 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
@StageRef VanillaChronicleMapHolder<K, ?, ?, V, ?, ?, R> mh;
@StageRef MapEntryStages<K, V> e;
@StageRef SearchAllocatedChunks allocatedChunks;
@StageRef public DeprecatedMapKeyContextOnQuery<K, V> deprecatedMapKeyContext;
@StageRef public AcquireHandle<K, V> acquireHandle;
@StageRef public InputValueInstanceData<V, ?, ?> inputValueInstanceValue;