Removed ChronicleHash.context() method and changed acquireContext() return type from deprecated MapKeyContext to Closeable

This commit is contained in:
leventov
2015-07-24 03:43:50 +03:00
parent 5b23bd6f45
commit 912a3cc2fc
27 changed files with 689 additions and 667 deletions
@@ -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,
@@ -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;
@@ -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();
}
}
@@ -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;