mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Removed ChronicleHash.context() method and changed acquireContext() return type from deprecated MapKeyContext to Closeable
This commit is contained in:
@@ -48,12 +48,6 @@ public interface ChronicleHash<K, C extends KeyContext<K>, EQC extends ExternalH
|
||||
|
||||
long longSize();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #queryContext} instead
|
||||
*/
|
||||
@Deprecated
|
||||
C context(K key);
|
||||
|
||||
/**
|
||||
* @return the class of {@code <K>}
|
||||
*/
|
||||
|
||||
@@ -37,22 +37,24 @@ interface AbstractChronicleMap<K, V> extends ChronicleMap<K, V>, Serializable {
|
||||
@Override
|
||||
default <R> R getMapped(K key, @NotNull SerializableFunction<? super V, R> function) {
|
||||
requireNonNull(function);
|
||||
try (MapKeyContext<K, V> c = context(key)) {
|
||||
return c.containsKey() ? function.apply(c.get()) : null;
|
||||
try (ExternalMapQueryContext<K, V, ?> c = queryContext(key)) {
|
||||
MapEntry<K, V> entry = c.entry();
|
||||
return entry != null ? function.apply(entry.value().get()) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default V putMapped(K key, @NotNull UnaryOperator<V> unaryOperator) {
|
||||
requireNonNull(unaryOperator);
|
||||
try (MapKeyContext<K, V> c = context(key)) {
|
||||
try (ExternalMapQueryContext<K, V, ?> c = queryContext(key)) {
|
||||
// putMapped() should find a value, update & put most of the time,
|
||||
// so don't try to check key presence under read lock first,
|
||||
// as in putIfAbsent()/acquireUsing(), start with update lock:
|
||||
c.updateLock().lock();
|
||||
if (c.containsKey()) {
|
||||
V newValue = unaryOperator.update(c.get());
|
||||
c.put(newValue);
|
||||
MapEntry<K, V> entry = c.entry();
|
||||
if (entry != null) {
|
||||
V newValue = unaryOperator.update(entry.value().get());
|
||||
c.replaceValue(entry, c.wrapValueAsData(newValue));
|
||||
return newValue;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.ChronicleHash;
|
||||
import net.openhft.chronicle.hash.ExternalHashQueryContext;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
@@ -34,8 +33,6 @@ import java.io.Serializable;
|
||||
import java.lang.Object;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Extension of {@link ConcurrentMap} interface, stores the data off-heap.
|
||||
@@ -142,13 +139,8 @@ public interface ChronicleMap<K, V>
|
||||
*/
|
||||
V acquireUsing(@NotNull K key, V usingValue);
|
||||
|
||||
/**
|
||||
* @deprecated this method has incoherent, unclear semantics. Use {@link #queryContext(Object)}
|
||||
* instead
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
MapKeyContext<K, V> acquireContext(@NotNull K key, @NotNull V usingValue);
|
||||
net.openhft.chronicle.core.io.Closeable acquireContext(@NotNull K key, @NotNull V usingValue);
|
||||
|
||||
/**
|
||||
* Apply a mapping to the value returned by a key and return a result. A read lock is assumed.
|
||||
@@ -208,7 +200,7 @@ public interface ChronicleMap<K, V>
|
||||
*
|
||||
* {@link ChronicleMap#getUsing(Object, Object) }
|
||||
* {@link ChronicleMap#acquireUsing(Object, Object) }
|
||||
* {@link ChronicleMap#acquireContext(Object, Object) }
|
||||
* {@link ChronicleMap#acquireContext(Object, Object)}
|
||||
*
|
||||
* for example like this :
|
||||
*
|
||||
@@ -232,8 +224,8 @@ public interface ChronicleMap<K, V>
|
||||
* following methods :
|
||||
*
|
||||
* {@link ChronicleMap#getUsing(Object, Object) }
|
||||
* {@link ChronicleMap#acquireUsing(Object, Object) }
|
||||
* {@link ChronicleMap#acquireContext(Object, Object) }
|
||||
* {@link ChronicleMap#acquireUsing(Object, Object)}
|
||||
* {@link ChronicleMap#acquireContext(Object, Object)}
|
||||
*
|
||||
* for example like this :
|
||||
*
|
||||
|
||||
@@ -70,12 +70,20 @@ class ReplicationHubFindByName<K> implements FindByName {
|
||||
|
||||
int withChannelId = nextFreeChannel.incrementAndGet();
|
||||
|
||||
try (MapKeyContext<CharSequence, MapInstanceBuilder> c = map.context(config.name)) {
|
||||
try (ExternalMapQueryContext<CharSequence, MapInstanceBuilder, ?> c =
|
||||
map.queryContext(config.name)) {
|
||||
c.updateLock().lock();
|
||||
MapInstanceBuilder value =
|
||||
config.replicatedViaChannel(replicationHub.createChannel(withChannelId));
|
||||
boolean added = !c.containsKey();
|
||||
c.put(value);
|
||||
boolean added;
|
||||
MapEntry<CharSequence, MapInstanceBuilder> entry = c.entry();
|
||||
if (entry != null) {
|
||||
c.replaceValue(entry, c.wrapValueAsData(value));
|
||||
added = false;
|
||||
} else {
|
||||
c.insert(c.absentEntry(), c.wrapValueAsData(value));
|
||||
added = true;
|
||||
}
|
||||
|
||||
if (added) {
|
||||
// establish the new map based on this channel ID
|
||||
|
||||
@@ -542,11 +542,6 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
return fetchLong(LONG_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapKeyContext<K, V> context(K key) {
|
||||
throw new UnsupportedOperationException("Contexts are not supported by stateless clients");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ExternalMapQueryContext<K, V, ?> queryContext(K key) {
|
||||
@@ -598,7 +593,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapKeyContext<K, V> acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
public net.openhft.chronicle.core.io.Closeable acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
throw new UnsupportedOperationException("Contexts are not supported by stateless clients");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.KeyContext;
|
||||
import net.openhft.chronicle.hash.impl.VanillaChronicleHash;
|
||||
@@ -203,11 +204,6 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
return (V) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapKeyContext<K, V> context(K key) {
|
||||
return queryContext(key).deprecatedMapKeyContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int actualSegments() {
|
||||
return actualSegments;
|
||||
@@ -279,16 +275,15 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final MapKeyContext<K, V> acquireContext(K key, V usingValue) {
|
||||
public final Closeable acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
QueryContextInterface<K, V, R> q = queryContext(key);
|
||||
// TODO optimize to update lock in certain cases
|
||||
try {
|
||||
q.writeLock().lock();
|
||||
acquireUsingBody(q, usingValue);
|
||||
return q.deprecatedMapAcquireContext();
|
||||
return q.acquireHandle();
|
||||
} catch (Throwable e) {
|
||||
try {
|
||||
q.close();
|
||||
@@ -298,7 +293,7 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static <V> void checkAcquiredUsing(V acquired, V using) {
|
||||
if (acquired != using) {
|
||||
throw new IllegalArgumentException("acquire*() MUST reuse the given " +
|
||||
@@ -348,7 +343,7 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
q.initUsed(true);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
private CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> i() {
|
||||
return (CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R>) iterCxt.get();
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ class WriteThroughEntry<K, V> extends AbstractMap.SimpleEntry<K, V> {
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
try (MapKeyContext<K, V> c = map.context(getKey())) {
|
||||
c.put(value);
|
||||
}
|
||||
map.put(getKey(), value);
|
||||
return super.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ nested = {
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
DeprecatedMapKeyContextOnQuery.class,
|
||||
DeprecatedMapAcquireContextOnQuery.class,
|
||||
AcquireHandle.class,
|
||||
DefaultReturnValue.class,
|
||||
UsingReturnValue.class,
|
||||
})
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.openhft.chronicle.map.impl;
|
||||
|
||||
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.ret.InstanceReturnValue;
|
||||
import net.openhft.chronicle.map.impl.ret.UsableReturnValue;
|
||||
import net.openhft.chronicle.map.impl.data.instance.ValueInitableData;
|
||||
import net.openhft.chronicle.map.impl.data.instance.ValueInitializableData;
|
||||
|
||||
public interface QueryContextInterface<K, V, R> extends ExternalMapQueryContext<K, V, R> {
|
||||
|
||||
@@ -18,11 +19,11 @@ public interface QueryContextInterface<K, V, R> extends ExternalMapQueryContext<
|
||||
|
||||
UsableReturnValue<V> usingReturnValue();
|
||||
|
||||
ValueInitableData<V> inputValueInstanceValue();
|
||||
ValueInitializableData<V> inputValueInstanceValue();
|
||||
|
||||
MapKeyContext<K, V> deprecatedMapKeyContext();
|
||||
|
||||
MapKeyContext<K, V> deprecatedMapAcquireContext();
|
||||
|
||||
Closeable acquireHandle();
|
||||
|
||||
void initTheSegmentIndex(int segmentIndex);
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import net.openhft.chronicle.map.impl.stage.data.DummyValueZeroData;
|
||||
import net.openhft.chronicle.map.impl.stage.data.bytes.*;
|
||||
import net.openhft.chronicle.map.impl.stage.data.instance.InputValueInstanceData;
|
||||
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.entry.ReplicatedMapEntryStages;
|
||||
import net.openhft.chronicle.map.impl.stage.input.MapInputBytesValues;
|
||||
import net.openhft.chronicle.map.impl.stage.input.ReplicatedInput;
|
||||
@@ -102,7 +101,7 @@ nested = {
|
||||
|
||||
WrappedValueInstanceData.class,
|
||||
DeprecatedMapKeyContextOnQuery.class,
|
||||
DeprecatedMapAcquireContextOnQuery.class,
|
||||
AcquireHandle.class,
|
||||
DefaultReturnValue.class,
|
||||
UsingReturnValue.class,
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package net.openhft.chronicle.map.impl.data.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
|
||||
public interface ValueInitableData<V> extends Data<V> {
|
||||
public interface ValueInitializableData<V> extends Data<V> {
|
||||
|
||||
void initValue(V value);
|
||||
}
|
||||
@@ -34,7 +34,6 @@ public class EntryValueBytesData<V> extends AbstractData<V> {
|
||||
@StageRef MapEntryStages<?, V> entry;
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
|
||||
|
||||
@Stage("CachedEntryValue") private V cachedEntryValue;
|
||||
@Stage("CachedEntryValue") private boolean cachedEntryValueRead = false;
|
||||
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ package net.openhft.chronicle.map.impl.stage.data.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.impl.CopyingInstanceData;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.map.impl.data.instance.ValueInitableData;
|
||||
import net.openhft.chronicle.map.impl.data.instance.ValueInitializableData;
|
||||
import net.openhft.chronicle.map.impl.stage.map.ValueBytesInterop;
|
||||
import net.openhft.lang.io.DirectBytes;
|
||||
import net.openhft.sg.Stage;
|
||||
@@ -29,7 +29,7 @@ import net.openhft.sg.Staged;
|
||||
|
||||
@Staged
|
||||
public abstract class InputValueInstanceData<V, VI, MVI extends MetaBytesInterop<V, ? super VI>>
|
||||
extends CopyingInstanceData<V> implements ValueInitableData<V> {
|
||||
extends CopyingInstanceData<V> implements ValueInitializableData<V> {
|
||||
|
||||
@StageRef ValueBytesInterop<V, VI, MVI> vi;
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.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 {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
@StageRef MapQuery<K, V, ?> q;
|
||||
@StageRef UsingReturnValue<V> usingReturn;
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
q.replaceValue(q.entry(), q.wrapValueAsData(usingReturn.returnValue()));
|
||||
q.close();
|
||||
}
|
||||
}
|
||||
-152
@@ -1,152 +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.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 DeprecatedMapAcquireContextOnQuery<K, V> implements MapKeyContext<K, V> {
|
||||
|
||||
@StageRef CheckOnEachPublicOperation checkOnEachPublicOperation;
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
@StageRef MapQuery<K, V, ?> q;
|
||||
@StageRef UsingReturnValue<V> usingReturn;
|
||||
|
||||
@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() {
|
||||
assert containsKey();
|
||||
return usingReturn.returnValue();
|
||||
}
|
||||
|
||||
@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();
|
||||
put(usingReturn.returnValue());
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
|
||||
@StageRef MapEntryStages<K, V> e;
|
||||
@StageRef SearchAllocatedChunks allocatedChunks;
|
||||
@StageRef public DeprecatedMapKeyContextOnQuery<K, V> deprecatedMapKeyContext;
|
||||
@StageRef public DeprecatedMapAcquireContextOnQuery<K, V> deprecatedMapAcquireContext;
|
||||
@StageRef public AcquireHandle<K, V> acquireHandle;
|
||||
|
||||
@StageRef public InputValueInstanceData<V, ?, ?> inputValueInstanceValue;
|
||||
|
||||
|
||||
@@ -123,11 +123,6 @@ class SetFromMap<E> extends AbstractSet<E>
|
||||
return m.longSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyContext context(E key) {
|
||||
return m.context(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<E> keyClass() {
|
||||
return m.keyClass();
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package eg;
|
||||
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -51,8 +50,7 @@ public class TestNesterInterfaceMarshal {
|
||||
TestInstrumentVOInterface intrumentVOInterface = map.newValueInstance();
|
||||
|
||||
|
||||
try (MapKeyContext<?, TestInstrumentVOInterface> wc = map.acquireContext
|
||||
("KEY1", intrumentVOInterface)) {
|
||||
try (Closeable c = map.acquireContext("KEY1", intrumentVOInterface)) {
|
||||
intrumentVOInterface.setSymbol("Flyer");
|
||||
intrumentVOInterface.setCurrencyCode("USA");
|
||||
intrumentVOInterface.setSizeOfInstrumentIDArray(2);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.fromdocs.BondVOInterface;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
@@ -257,11 +258,10 @@ public class ChronicleMapImportExportTest {
|
||||
LongValue value = expected.newValueInstance();
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, LongValue> context = expected.acquireContext("one", value)) {
|
||||
assertEquals(0, context.get().getValue());
|
||||
assert value == context.get();
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (Closeable c =
|
||||
expected.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
expected.getAll(file);
|
||||
@@ -294,14 +294,12 @@ public class ChronicleMapImportExportTest {
|
||||
final BondVOInterface value = expected.newValueInstance();
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext context = expected.acquireContext("one", value)) {
|
||||
try (Closeable c = expected.acquireContext("one", value)) {
|
||||
value.setCoupon(8.98);
|
||||
BondVOInterface.MarketPx marketPxIntraDayHistoryAt =
|
||||
value.getMarketPxIntraDayHistoryAt(1);
|
||||
|
||||
marketPxIntraDayHistoryAt.setAskPx(12.0);
|
||||
|
||||
assert value == context.get();
|
||||
}
|
||||
|
||||
expected.getAll(file);
|
||||
|
||||
@@ -20,6 +20,8 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.primitives.Ints;
|
||||
import net.openhft.chronicle.bytes.BytesStore;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
@@ -732,7 +734,8 @@ public class ChronicleMapTest {
|
||||
map.getUsing(key, value);
|
||||
|
||||
} else {
|
||||
try (MapKeyContext wc = map.acquireContext(key, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
if (value.length() < value0.length() - 1)
|
||||
value.append(value0);
|
||||
else if (value.length() > value0.length())
|
||||
@@ -824,8 +827,8 @@ public class ChronicleMapTest {
|
||||
map.getUsing(key, value);
|
||||
|
||||
} else {
|
||||
try (MapKeyContext wc = map.acquireContext(key,
|
||||
value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
if (value.length() < value0.length() - 1)
|
||||
value.append(value0);
|
||||
else if (value.length() > value0.length())
|
||||
@@ -923,21 +926,27 @@ public class ChronicleMapTest {
|
||||
long n;
|
||||
// 75% read
|
||||
if (rand.nextBoolean() || rand.nextBoolean()) {
|
||||
try (MapKeyContext<?, LongValue> c = map.context(sb)) {
|
||||
if (c.containsKey()) {
|
||||
try (ExternalMapQueryContext<?, LongValue, ?> c =
|
||||
map.queryContext(sb)) {
|
||||
MapEntry<?, LongValue> entry = c.entry();
|
||||
if (entry != null) {
|
||||
// Attempt to pass abstraction hierarchies
|
||||
n = c.entry().readVolatileLong(c.valueOffset()) + 1;
|
||||
Data<LongValue> v = entry.value();
|
||||
n = v.bytes().readVolatileLong(v.offset()) + 1;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try (MapKeyContext<?, LongValue> wc = map.context(sb)) {
|
||||
wc.updateLock().lock();
|
||||
if (wc.containsKey()) {
|
||||
n = wc.entry().addLong(wc.valueOffset(), 1);
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c =
|
||||
map.queryContext(sb)) {
|
||||
c.updateLock().lock();
|
||||
MapEntry<?, LongValue> entry = c.entry();
|
||||
if (entry != null) {
|
||||
Data<LongValue> v = entry.value();
|
||||
n = ((BytesStore) v.bytes()).addAndGetLong(v.offset(), 1);
|
||||
} else {
|
||||
wc.put(ONE);
|
||||
c.insert(c.absentEntry(), c.wrapValueAsData(ONE));
|
||||
n = 1;
|
||||
}
|
||||
}
|
||||
@@ -1012,7 +1021,8 @@ public class ChronicleMapTest {
|
||||
j += independence) {
|
||||
key.setValue(j * factor);
|
||||
long n;
|
||||
try (MapKeyContext wc = map.acquireContext(key, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
n = value.addValue(1);
|
||||
}
|
||||
assert n > 0 && n < 1000 : "Counter corrupted " + n;
|
||||
@@ -1638,48 +1648,47 @@ public class ChronicleMapTest {
|
||||
LongValue value = nativeLongValue();
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assertEquals(0, context.get().getValue());
|
||||
assert value == context.get();
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c = map.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was added
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(true, context.containsKey());
|
||||
LongValue v = context.getUsing(value);
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
MapEntry<CharSequence, LongValue> entry = c.entry();
|
||||
assertNotNull(entry);
|
||||
LongValue v = entry.value().getUsing(value);
|
||||
assert v == value;
|
||||
assertEquals(1, v.getValue());
|
||||
}
|
||||
|
||||
// this will remove the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
context.remove();
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
c.updateLock().lock();
|
||||
c.remove(c.entry());
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
context.updateLock().lock();
|
||||
assertEquals(false, context.containsKey());
|
||||
assertEquals(null, context.get());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
c.updateLock().lock();
|
||||
assertNotNull(c.absentEntry());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assert value == context.get();
|
||||
assertEquals(0, context.get().getValue());
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assert value == context.get();
|
||||
context.get().addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
LongValue v = context.getUsing(value);
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
LongValue v = c.entry().value().getUsing(value);
|
||||
assert value == v;
|
||||
assertEquals(1, context.get().getValue());
|
||||
assertEquals(1, c.entry().value().get().getValue());
|
||||
}
|
||||
|
||||
map.close();
|
||||
@@ -1733,7 +1742,7 @@ public class ChronicleMapTest {
|
||||
|
||||
try (final ChronicleMap<CharSequence, String> map = builder.create()) {
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, String> context = map.acquireContext("one", "")) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c = map.acquireContext("one", "")) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
@@ -1751,7 +1760,8 @@ public class ChronicleMapTest {
|
||||
.create()) {
|
||||
StringBuilder value = new StringBuilder();
|
||||
|
||||
try (MapKeyContext<?, CharSequence> context = map.acquireContext("one", value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.append("Hello World");
|
||||
}
|
||||
|
||||
@@ -1771,56 +1781,58 @@ public class ChronicleMapTest {
|
||||
|
||||
LongValue value = DataValueClasses.newDirectReference(LongValue.class);
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(false, context.containsKey());
|
||||
assertEquals(null, context.get());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
assertNotNull(c.absentEntry());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.setValue(10);
|
||||
}
|
||||
|
||||
// this will add the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was added
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(true, context.containsKey());
|
||||
assertEquals(11, context.get().getValue());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
MapEntry<CharSequence, LongValue> entry = c.entry();
|
||||
assertNotNull(entry);
|
||||
assertEquals(11, entry.value().get().getValue());
|
||||
}
|
||||
|
||||
// this will remove the entry
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
context.remove();
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
c.updateLock().lock();
|
||||
c.remove(c.entry());
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
assertEquals(false, context.containsKey());
|
||||
assertEquals(null, context.get());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
assertNotNull(c.absentEntry());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
assertEquals(0, context.get().getValue());
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
assertEquals(0, value.getValue());
|
||||
}
|
||||
|
||||
value.setValue(1);
|
||||
|
||||
try (MapKeyContext<?, LongValue> lockedEntry = map.context("one")) {
|
||||
assertEquals(1, lockedEntry.get().getValue());
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
assertEquals(1, c.entry().value().get().getValue());
|
||||
}
|
||||
|
||||
try (MapKeyContext<?, LongValue> context = map.acquireContext("one", value)) {
|
||||
LongValue value1 = context.get();
|
||||
value1.addValue(1);
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext("one", value)) {
|
||||
value.addValue(1);
|
||||
}
|
||||
|
||||
// check that the entry was removed
|
||||
try (MapKeyContext<?, LongValue> context = map.context("one")) {
|
||||
LongValue value1 = context.get();
|
||||
try (ExternalMapQueryContext<CharSequence, LongValue, ?> c = map.queryContext("one")) {
|
||||
LongValue value1 = c.entry().value().get();
|
||||
assertEquals(2, value1.getValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.openhft.chronicle.map;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.model.constraints.MaxSize;
|
||||
import net.openhft.lang.values.IntValue;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -74,7 +73,8 @@ public class DemoChronicleMapTest {
|
||||
for (int i = 0; i < maxEntries; i++) {
|
||||
key.setValue(i);
|
||||
|
||||
try (MapKeyContext wc = map.acquireContext(key, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map.acquireContext(key, value)) {
|
||||
value.setSymbol("IBM-" + i);
|
||||
value.addAtomicOrderQty(1000);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.function.SerializableFunction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
@@ -277,12 +278,8 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapKeyContext<K, V> acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapKeyContext<K, V> context(K key) {
|
||||
public Closeable acquireContext(
|
||||
@NotNull K key, @NotNull V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Closeable;
|
||||
@@ -92,7 +91,8 @@ public class TCPSocketReplicationNativeTest {
|
||||
|
||||
LongValue value = DataValueClasses.newDirectReference(LongValue.class);
|
||||
|
||||
try (MapKeyContext<Integer, LongValue> c = map1.acquireContext(1, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext(1, value)) {
|
||||
value.setValue(10);
|
||||
}
|
||||
|
||||
@@ -108,11 +108,13 @@ public class TCPSocketReplicationNativeTest {
|
||||
|
||||
LongValue value = DataValueClasses.newDirectReference(LongValue.class);
|
||||
|
||||
try (MapKeyContext<Integer, LongValue> c = map1.acquireContext(1, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext(1, value)) {
|
||||
value.setValue(10);
|
||||
}
|
||||
|
||||
try (MapKeyContext<Integer, LongValue> c = map1.acquireContext(1, value)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext(1, value)) {
|
||||
value.setValue(20);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.openhft.chronicle.map;
|
||||
import eg.TestInstrumentVOInterface;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -46,7 +45,7 @@ public class TcpReplicationWithAcquireContextTest {
|
||||
TestInstrumentVOInterface instrumentVOInterface = map1.newValueInstance();
|
||||
|
||||
|
||||
try (MapKeyContext<?, TestInstrumentVOInterface> wc =
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
map1.acquireContext("KEY1", instrumentVOInterface)) {
|
||||
instrumentVOInterface.setSymbol("Flyer");
|
||||
instrumentVOInterface.setCurrencyCode("USA");
|
||||
|
||||
@@ -20,7 +20,7 @@ package net.openhft.chronicle.map.fromdocs;
|
||||
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.MapKeyContext;
|
||||
import net.openhft.chronicle.map.ExternalMapQueryContext;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -60,7 +60,8 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
.createPersistedTo(file);
|
||||
|
||||
BondVOInterface bondVO = chm.newValueInstance();
|
||||
try (MapKeyContext wc = chm.acquireContext("369604103", bondVO)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
chm.acquireContext("369604103", bondVO)) {
|
||||
bondVO.setIssueDate(parseYYYYMMDD("20130915"));
|
||||
bondVO.setMaturityDate(parseYYYYMMDD("20140915"));
|
||||
bondVO.setCoupon(5.0 / 100); // 5.0%
|
||||
@@ -80,8 +81,9 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
.entries(1000)
|
||||
.createPersistedTo(file);
|
||||
|
||||
try (MapKeyContext<String, BondVOInterface> c = chmB.context("369604103")) {
|
||||
BondVOInterface bond = c.get();
|
||||
try (ExternalMapQueryContext<String, BondVOInterface, ?> c =
|
||||
chmB.queryContext("369604103")) {
|
||||
BondVOInterface bond = c.entry().value().get();
|
||||
if (bond != null) {
|
||||
assertEquals(5.0 / 100, bond.getCoupon(), 0.0);
|
||||
|
||||
@@ -97,7 +99,8 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
|
||||
BondVOInterface bond = chm.newValueInstance();
|
||||
// lookup the key and give me a reference I can update in a thread safe way.
|
||||
try (MapKeyContext<String, BondVOInterface> c = chm.acquireContext("369604103", bond)) {
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
chm.acquireContext("369604103", bond)) {
|
||||
// found a key and bond has been set
|
||||
// get directly without touching the rest of the record.
|
||||
long _matDate = bond.getMaturityDate();
|
||||
|
||||
@@ -110,9 +110,10 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
return d.containsValue(value);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapKeyContext<K, V> context(K key) {
|
||||
return d.context(key);
|
||||
public net.openhft.chronicle.core.io.Closeable acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
return d.acquireContext(key, usingValue);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -180,12 +181,6 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
return d.acquireUsing(key, usingValue);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MapKeyContext<K, V> acquireContext(@NotNull K key, @NotNull V usingValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R getMapped(K key, @NotNull SerializableFunction<? super V, R> function) {
|
||||
return d.getMapped(key, function);
|
||||
|
||||
Reference in New Issue
Block a user