mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Revert 'Make working with new bytes' and a couple of fixes
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
<groupId>net.openhft</groupId>
|
||||
<artifactId>chronicle-bom</artifactId>
|
||||
<type>pom</type>
|
||||
<version>1.3.3-SNAPSHOT</version>
|
||||
<version>1.4.0</version>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -90,7 +90,6 @@
|
||||
<dependency>
|
||||
<groupId>net.openhft</groupId>
|
||||
<artifactId>chronicle-bytes</artifactId>
|
||||
<version>1.0.5-alpha</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -118,11 +117,6 @@
|
||||
<artifactId>pax-url-aether</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.openhft</groupId>
|
||||
<artifactId>chronicle-network</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -26,7 +26,7 @@ import net.openhft.chronicle.algo.hashing.LongHashFunction;
|
||||
* but Java 8 doesn't allow to override {@code Object}'s methods by default implementations
|
||||
* in interfaces.
|
||||
*/
|
||||
public abstract class AbstractData<V, T> implements Data<V, T> {
|
||||
public abstract class AbstractData<V> implements Data<V> {
|
||||
|
||||
/**
|
||||
* Constructor for use by subclasses.
|
||||
@@ -49,7 +49,7 @@ public abstract class AbstractData<V, T> implements Data<V, T> {
|
||||
public boolean equals(Object obj) {
|
||||
return obj != null &&
|
||||
obj instanceof Data &&
|
||||
Data.bytesEquivalent(this, (Data<?, ?>) obj);
|
||||
Data.bytesEquivalent(this, (Data<?>) obj);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,7 +86,7 @@ public interface ChronicleHash<K, C extends KeyContext<K>, EQC extends ExternalH
|
||||
* @param key the queried key as {@code Data}
|
||||
* @return the context to perform operations with the key
|
||||
*/
|
||||
@NotNull EQC queryContext(Data<K, ?> key);
|
||||
@NotNull EQC queryContext(Data<K> key);
|
||||
|
||||
/**
|
||||
* Checks the given predicate on each entry in this {@code ChronicleHash} until all entries
|
||||
|
||||
@@ -18,14 +18,18 @@
|
||||
|
||||
package net.openhft.chronicle.hash;
|
||||
|
||||
import net.openhft.chronicle.bytes.*;
|
||||
import net.openhft.chronicle.algo.hashing.LongHashFunction;
|
||||
import net.openhft.chronicle.bytes.BytesUtil;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.bytes.RandomDataOutput;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.openhft.chronicle.algo.bytes.Access.checkedRandomDataInputAccess;
|
||||
|
||||
/**
|
||||
* Dual bytes/object access to keys/values/elements.
|
||||
*
|
||||
* <p>Bytes access: {@link #access()} + {@link #handle()} + {@link #offset()} + {@link #size()}.
|
||||
* <p>Bytes access: {@link #bytes()} + {@link #offset()} + {@link #size()}.
|
||||
*
|
||||
* <p>Object access: {@link #get()}.
|
||||
*
|
||||
@@ -34,19 +38,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
* accordingly.
|
||||
*
|
||||
* @param <V> type of the accessed objects
|
||||
* @param <T> type of the handle for bytes access
|
||||
*/
|
||||
public interface Data<V, T> {
|
||||
public interface Data<V> {
|
||||
|
||||
/**
|
||||
* Returns access to the value's bytes.
|
||||
*/
|
||||
ReadAccess<T> access();
|
||||
|
||||
/**
|
||||
* Returns a handle to access the value's bytes.
|
||||
*/
|
||||
T handle();
|
||||
RandomDataInput bytes();
|
||||
|
||||
/**
|
||||
* Returns the offset to the value's bytes.
|
||||
@@ -59,33 +54,15 @@ public interface Data<V, T> {
|
||||
long size();
|
||||
|
||||
default long hash(LongHashFunction f) {
|
||||
return f.hash(handle(), access(), offset(), size());
|
||||
return f.hash(bytes(), checkedRandomDataInputAccess(), offset(), size());
|
||||
}
|
||||
|
||||
default <T2> boolean equivalent(ReadAccess<T2> access, T2 handle, long offset) {
|
||||
return Access.equivalent(access(), handle(), offset(), access, handle, offset, size());
|
||||
default boolean equivalent(RandomDataInput source, long sourceOffset) {
|
||||
return BytesUtil.bytesEqual(source, sourceOffset, bytes(), offset(), size());
|
||||
}
|
||||
|
||||
default <S, T2, A extends ReadAccess<T2>> boolean equivalent(
|
||||
Accessor<S, T2, A> accessor, S source, long index) {
|
||||
return equivalent(accessor.access(source), accessor.handle(source),
|
||||
accessor.offset(source, index));
|
||||
}
|
||||
|
||||
default <T2> void writeTo(WriteAccess<T2> targetAccess, T2 target, long targetOffset) {
|
||||
Access.copy(access(), handle(), offset(), targetAccess, target, targetOffset, size());
|
||||
}
|
||||
|
||||
default <T2> void writeTo(StreamingDataOutput<?, ?, T2> output) {
|
||||
long offset = output.accessPositionOffset();
|
||||
output.skip(size());
|
||||
writeTo(output.access(), output.accessHandle(), offset);
|
||||
}
|
||||
|
||||
default <S, T2, A extends WriteAccess<T2>> void writeTo(
|
||||
Accessor<S, T2, A> targetAccessor, S target, long index) {
|
||||
writeTo(targetAccessor.access(target), targetAccessor.handle(target),
|
||||
targetAccessor.offset(target, index));
|
||||
default void writeTo(RandomDataOutput target, long targetOffset) {
|
||||
target.write(targetOffset, bytes(), offset(), size());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,10 +79,9 @@ public interface Data<V, T> {
|
||||
*/
|
||||
V getUsing(@Nullable V usingInstance);
|
||||
|
||||
static <T1, T2> boolean bytesEquivalent(Data<?, T1> v1, Data<?, T2> v2) {
|
||||
if (v1.size() != v2.size())
|
||||
static boolean bytesEquivalent(Data<?> d1, Data<?> d2) {
|
||||
if (d1.size() != d2.size())
|
||||
return false;
|
||||
return Access.equivalent(v1.access(), v1.handle(), v1.offset(),
|
||||
v2.access(), v2.handle(), v2.offset(), v1.size());
|
||||
return BytesUtil.bytesEqual(d1.bytes(), d1.offset(), d2.bytes(), d2.offset(), d1.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,5 @@ public interface HashAbsentEntry<K> {
|
||||
* Returns the key is going to be inserted into the {@code ChronicleHash}.
|
||||
*/
|
||||
@NotNull
|
||||
Data<K, ?> absentKey();
|
||||
Data<K> absentKey();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface HashEntry<K> {
|
||||
* Returns the entry key.
|
||||
*/
|
||||
@NotNull
|
||||
Data<K, ?> key();
|
||||
Data<K> key();
|
||||
|
||||
/**
|
||||
* Removes the entry from the {@code ChronicleHash}.
|
||||
|
||||
@@ -142,7 +142,7 @@ public interface HashQueryContext<K> extends HashContext<K>, InterProcessReadWri
|
||||
/**
|
||||
* Returns the queried key as a {@code Data}.
|
||||
*/
|
||||
Data<K, ?> queriedKey();
|
||||
Data<K> queriedKey();
|
||||
|
||||
/**
|
||||
* Returns the entry context, if the entry with the queried key is <i>present</i>
|
||||
|
||||
@@ -18,50 +18,48 @@
|
||||
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.ReadAccess;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.lang.io.DirectBytes;
|
||||
import net.openhft.lang.io.DirectStore;
|
||||
import net.openhft.lang.io.serialization.JDKObjectSerializer;
|
||||
|
||||
import static net.openhft.chronicle.hash.impl.JavaLangBytesAccessors.uncheckedBytesAccessor;
|
||||
public abstract class CopyingInstanceData<I> extends AbstractData<I> {
|
||||
|
||||
public abstract class CopyingInstanceData<I, T> extends AbstractData<I, T> {
|
||||
private final JavaLangBytesReusableBytesStore bytesStore =
|
||||
new JavaLangBytesReusableBytesStore();
|
||||
|
||||
public static DirectBytes getBuffer(DirectBytes b, long capacity) {
|
||||
public DirectBytes getBuffer(DirectBytes b, long capacity) {
|
||||
if (b != null) {
|
||||
if (b.capacity() >= capacity) {
|
||||
return (DirectBytes) b.clear();
|
||||
} else {
|
||||
DirectStore store = (DirectStore) b.store();
|
||||
store.resize(capacity, false);
|
||||
return store.bytes();
|
||||
DirectBytes bytes = store.bytes();
|
||||
bytesStore.setBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
} else {
|
||||
return new DirectStore(JDKObjectSerializer.INSTANCE, Math.max(1, capacity), true)
|
||||
.bytes();
|
||||
DirectBytes bytes = new DirectStore(JDKObjectSerializer.INSTANCE,
|
||||
Math.max(1, capacity), true).bytes();
|
||||
bytesStore.setBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomDataInput bytes() {
|
||||
return bytesStore;
|
||||
}
|
||||
|
||||
public abstract I instance();
|
||||
|
||||
public abstract DirectBytes buffer();
|
||||
|
||||
@Override
|
||||
public ReadAccess<T> access() {
|
||||
//noinspection unchecked
|
||||
return (ReadAccess<T>) uncheckedBytesAccessor(buffer()).access(buffer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T handle() {
|
||||
//noinspection unchecked
|
||||
return (T) uncheckedBytesAccessor(buffer()).handle(buffer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset() {
|
||||
return uncheckedBytesAccessor(buffer()).offset(buffer(), 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,93 +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.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Access;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
enum JavaLangBytesAccess implements Access<Bytes> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public byte readByte(Bytes handle, long offset) {
|
||||
return handle.readByte(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort(Bytes handle, long offset) {
|
||||
return handle.readShort(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char readChar(Bytes handle, long offset) {
|
||||
return handle.readChar(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(Bytes handle, long offset) {
|
||||
return handle.readInt(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong(Bytes handle, long offset) {
|
||||
return handle.readLong(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeByte(Bytes handle, long offset, byte i8) {
|
||||
handle.writeByte(offset, i8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeShort(Bytes handle, long offset, short i) {
|
||||
handle.writeShort(offset, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeChar(Bytes handle, long offset, char c) {
|
||||
handle.writeChar(offset, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeInt(Bytes handle, long offset, int i) {
|
||||
handle.writeInt(offset, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLong(Bytes handle, long offset, long i) {
|
||||
handle.writeLong(offset, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeFloat(Bytes handle, long offset, float d) {
|
||||
handle.writeFloat(offset, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDouble(Bytes handle, long offset, double d) {
|
||||
handle.writeDouble(offset, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteOrder byteOrder(Bytes handle) {
|
||||
return handle.byteOrder();
|
||||
}
|
||||
}
|
||||
@@ -1,74 +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.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Access;
|
||||
import net.openhft.chronicle.bytes.Accessor;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.NativeBytes;
|
||||
|
||||
import static net.openhft.chronicle.bytes.Access.nativeAccess;
|
||||
|
||||
public final class JavaLangBytesAccessors {
|
||||
|
||||
public static Accessor.Full<Bytes, ?> uncheckedBytesAccessor(Bytes bytes) {
|
||||
return bytes instanceof NativeBytes ? GenericBytesAccessor.INSTANCE :
|
||||
GenericBytesAccessor.INSTANCE;
|
||||
}
|
||||
|
||||
enum NativeBytesAccessor implements Accessor.Full<Bytes, Void> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Access<Void> access(Bytes source) {
|
||||
return nativeAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void handle(Bytes source) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset(Bytes source, long index) {
|
||||
return source.address() + index;
|
||||
}
|
||||
}
|
||||
|
||||
enum GenericBytesAccessor implements Accessor.Full<Bytes, Bytes> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Access<Bytes> access(Bytes source) {
|
||||
return JavaLangBytesAccess.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bytes handle(Bytes source) {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long offset(Bytes source, long index) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
private JavaLangBytesAccessors() {}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.BytesStore;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class JavaLangBytesReusableBytesStore
|
||||
implements BytesStore<JavaLangBytesReusableBytesStore, Void> {
|
||||
|
||||
private Bytes bytes;
|
||||
|
||||
public void setBytes(Bytes bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesStore<JavaLangBytesReusableBytesStore, Void> copy() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long capacity() {
|
||||
return bytes.capacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long address() throws UnsupportedOperationException {
|
||||
return bytes.address();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void underlyingObject() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compareAndSwapInt(long offset, int expected, int value) {
|
||||
return bytes.compareAndSwapInt(offset, expected, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compareAndSwapLong(long offset, long expected, long value) {
|
||||
return bytes.compareAndSwapLong(offset, expected, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte(long offset) {
|
||||
return bytes.readByte(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort(long offset) {
|
||||
return bytes.readShort(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt(long offset) {
|
||||
return bytes.readInt(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong(long offset) {
|
||||
return bytes.readLong(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat(long offset) {
|
||||
return bytes.readFloat(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble(long offset) {
|
||||
return bytes.readDouble(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nativeRead(long position, long address, long size) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeByte(long offset, byte i8) {
|
||||
bytes.writeByte(offset, i8);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeShort(long offset, short i) {
|
||||
bytes.writeShort(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeInt(long offset, int i) {
|
||||
bytes.writeInt(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeOrderedInt(long offset, int i) {
|
||||
bytes.writeOrderedInt(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeLong(long offset, long i) {
|
||||
bytes.writeLong(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeOrderedLong(long offset, long i) {
|
||||
bytes.writeOrderedLong(offset, i);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeFloat(long offset, float d) {
|
||||
bytes.writeFloat(offset, d);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore writeDouble(long offset, double d) {
|
||||
bytes.writeDouble(offset, d);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore write(long offsetInRDO,
|
||||
byte[] bs, int offset, int length) {
|
||||
bytes.write(offsetInRDO, bs, offset, length);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(long offsetInRDO, ByteBuffer bb, int offset, int length) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaLangBytesReusableBytesStore write(long offsetInRDO,
|
||||
RandomDataInput input, long offset, long length) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nativeWrite(long address, long position, long size) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reserve() throws IllegalStateException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() throws IllegalStateException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long refCount() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package net.openhft.chronicle.hash.impl.value.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
|
||||
public interface KeyInitableData<K, T> extends Data<K, T> {
|
||||
public interface KeyInitableData<K> extends Data<K> {
|
||||
|
||||
void initKey(K key);
|
||||
}
|
||||
|
||||
+5
-1
@@ -35,7 +35,11 @@ public abstract class CopyingMetaBytesInterop<E, W> extends BasicCopyingMetaByte
|
||||
throw new IllegalStateException("We try to figure out size of objects " +
|
||||
"in serialized form, but it exceeds " +
|
||||
MAX_REASONABLE_SERIALIZED_SIZE + " bytes. We assume this is " +
|
||||
"a error and throw exception at this point. If you really " +
|
||||
"a error and throw exception at this point. There could be two reasons:\n" +
|
||||
"1) The given object is not Serializable. Configure ChronicleMapBuilder" +
|
||||
".keyMarshallers/valueMarshallers to handle the given objects.\n" +
|
||||
"2) Your object are very large in serialized form (larger than " +
|
||||
MAX_REASONABLE_SERIALIZED_SIZE + " bytes). If you really " +
|
||||
"want larger keys/values, use ChronicleMapBuilder." +
|
||||
"keySize(int)/valueSize(int)/entrySize(int) configurations", ex);
|
||||
}
|
||||
|
||||
@@ -256,12 +256,17 @@ abstract class AbstractChannelReplicator implements Closeable {
|
||||
|
||||
public void closeResources() {
|
||||
isClosed = true;
|
||||
// context.close();
|
||||
executorService.shutdown();
|
||||
|
||||
|
||||
try {
|
||||
executorService.awaitTermination(5, TimeUnit.MILLISECONDS);
|
||||
if (!executorService.awaitTermination(5, TimeUnit.MILLISECONDS)) {
|
||||
executorService.shutdownNow();
|
||||
try {
|
||||
executorService.awaitTermination(10, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error("", e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
executorService.shutdownNow();
|
||||
try {
|
||||
|
||||
@@ -49,7 +49,7 @@ public interface MapAbsentEntry<K, V> extends HashAbsentEntry<K> {
|
||||
* operation are not met
|
||||
* @see MapEntryOperations#insert(MapAbsentEntry, Data)
|
||||
*/
|
||||
void doInsert(Data<V, ?> value);
|
||||
void doInsert(Data<V> value);
|
||||
|
||||
/**
|
||||
* Returns the <i>default</i> (or <i>nil</i>) value, that should be inserted into the map in
|
||||
@@ -63,5 +63,5 @@ public interface MapAbsentEntry<K, V> extends HashAbsentEntry<K> {
|
||||
* @see MapEntryOperations#defaultValue(MapAbsentEntry)
|
||||
*/
|
||||
@NotNull
|
||||
Data<V, ?> defaultValue();
|
||||
Data<V> defaultValue();
|
||||
}
|
||||
|
||||
@@ -55,5 +55,5 @@ public interface MapContext<K, V, R> extends HashContext<K>, MapEntryOperations<
|
||||
* @param value the value object to wrap
|
||||
* @return the value as {@code Data}
|
||||
*/
|
||||
Data<V, ?> wrapValueAsValue(V value);
|
||||
Data<V> wrapValueAsValue(V value);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface MapEntry<K, V> extends HashEntry<K> {
|
||||
* Returns the entry value.
|
||||
*/
|
||||
@NotNull
|
||||
Data<V, ?> value();
|
||||
Data<V> value();
|
||||
|
||||
/**
|
||||
* Replaces the entry's value with the given {@code newValue}.
|
||||
@@ -51,7 +51,7 @@ public interface MapEntry<K, V> extends HashEntry<K> {
|
||||
* @throws IllegalStateException if some locking/state conditions required to perform replace
|
||||
* operation are not met
|
||||
*/
|
||||
void doReplaceValue(Data<V, ?> newValue);
|
||||
void doReplaceValue(Data<V> newValue);
|
||||
|
||||
/**
|
||||
* Removes the entry from the map.
|
||||
|
||||
@@ -130,7 +130,7 @@ public interface MapEntryOperations<K, V, R> {
|
||||
* @throws RuntimeException if value replacement was unconditionally unsuccessful due
|
||||
* to any reason
|
||||
*/
|
||||
default R replaceValue(@NotNull MapEntry<K, V> entry, Data<V, ?> newValue) {
|
||||
default R replaceValue(@NotNull MapEntry<K, V> entry, Data<V> newValue) {
|
||||
entry.doReplaceValue(newValue);
|
||||
return null;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public interface MapEntryOperations<K, V, R> {
|
||||
* operation are not met
|
||||
* @throws RuntimeException if insertion was unconditionally unsuccessful due to any reason
|
||||
*/
|
||||
default R insert(@NotNull MapAbsentEntry<K, V> absentEntry, Data<V, ?> value) {
|
||||
default R insert(@NotNull MapAbsentEntry<K, V> absentEntry, Data<V> value) {
|
||||
absentEntry.doInsert(value);
|
||||
return null;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public interface MapEntryOperations<K, V, R> {
|
||||
*
|
||||
* @implNote simply delegates to {@link MapAbsentEntry#defaultValue()}.
|
||||
*/
|
||||
default Data<V, ?> defaultValue(@NotNull MapAbsentEntry<K, V> absentEntry) {
|
||||
default Data<V> defaultValue(@NotNull MapAbsentEntry<K, V> absentEntry) {
|
||||
return absentEntry.defaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public interface MapMethods<K, V, R> {
|
||||
* q.insert(q.absentEntry(), value);
|
||||
* }}</pre>
|
||||
*/
|
||||
default void put(MapQueryContext<K, V, R> q, Data<V, ?> value, ReturnValue<V> returnValue) {
|
||||
default void put(MapQueryContext<K, V, R> q, Data<V> value, ReturnValue<V> returnValue) {
|
||||
// We cannot read the previous value under read lock, because then we will need
|
||||
// to release the read lock -> acquire write lock, the value might be updated in
|
||||
// between, that will break ConcurrentMap.put() atomicity guarantee. So, we acquire
|
||||
@@ -108,7 +108,7 @@ public interface MapMethods<K, V, R> {
|
||||
* }</pre>
|
||||
*/
|
||||
default void putIfAbsent(MapQueryContext<K, V, R> q,
|
||||
Data<V, ?> value, ReturnValue<V> returnValue) {
|
||||
Data<V> value, ReturnValue<V> returnValue) {
|
||||
if (tryReturnCurrentValueIfPresent(q, returnValue))
|
||||
return;
|
||||
// Key is absent
|
||||
@@ -234,7 +234,7 @@ public interface MapMethods<K, V, R> {
|
||||
*
|
||||
* @return if the entry was removed
|
||||
*/
|
||||
default boolean remove(MapQueryContext<K, V, R> q, Data<V, ?> value) {
|
||||
default boolean remove(MapQueryContext<K, V, R> q, Data<V> value) {
|
||||
// remove(key, value) should find the entry & remove most of the time,
|
||||
// so don't try to check key presence and value equivalence under read lock first,
|
||||
// as in putIfAbsent()/acquireUsing(), start with update lock:
|
||||
@@ -263,7 +263,7 @@ public interface MapMethods<K, V, R> {
|
||||
* }}</pre>
|
||||
*/
|
||||
default void replace(MapQueryContext<K, V, R> q,
|
||||
Data<V, ?> value, ReturnValue<V> returnValue) {
|
||||
Data<V> value, ReturnValue<V> returnValue) {
|
||||
// replace(key, value) should find the key & put the value most of the time,
|
||||
// so don't try to check key presence under read lock first,
|
||||
// as in putIfAbsent()/acquireUsing(), start with update lock:
|
||||
@@ -294,7 +294,7 @@ public interface MapMethods<K, V, R> {
|
||||
* @return if the entry was replaced
|
||||
*/
|
||||
default boolean replace(MapQueryContext<K, V, R> q,
|
||||
Data<V, ?> oldValue, Data<V, ?> newValue) {
|
||||
Data<V> oldValue, Data<V> newValue) {
|
||||
// replace(key, old, new) should find the entry & put new value most of the time,
|
||||
// so don't try to check key presence and value equivalence under read lock first,
|
||||
// as in putIfAbsent()/acquireUsing(), start with update lock:
|
||||
@@ -337,7 +337,7 @@ public interface MapMethods<K, V, R> {
|
||||
V oldValue = entry != null ? entry.value().get() : null;
|
||||
V newValue = remappingFunction.apply(q.queriedKey().get(), oldValue);
|
||||
if (newValue != null) {
|
||||
Data<V, ?> newValueData = q.wrapValueAsValue(newValue);
|
||||
Data<V> newValueData = q.wrapValueAsValue(newValue);
|
||||
if (entry != null) {
|
||||
q.replaceValue(entry, newValueData);
|
||||
} else {
|
||||
@@ -409,11 +409,11 @@ public interface MapMethods<K, V, R> {
|
||||
* returnValue.returnValue(entry.value());
|
||||
* }</pre>
|
||||
*/
|
||||
default void merge(MapQueryContext<K, V, R> q, Data<V, ?> value,
|
||||
default void merge(MapQueryContext<K, V, R> q, Data<V> value,
|
||||
BiFunction<? super V, ? super V, ? extends V> remappingFunction,
|
||||
ReturnValue<V> returnValue) {
|
||||
q.updateLock().lock();
|
||||
Data<V, ?> newValueData;
|
||||
Data<V> newValueData;
|
||||
MapEntry<K, V> entry = q.entry();
|
||||
if (entry != null) {
|
||||
V oldValue = entry.value().get();
|
||||
|
||||
@@ -22,5 +22,5 @@ import net.openhft.chronicle.hash.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ReturnValue<V> {
|
||||
void returnValue(@NotNull Data<V, ?> value);
|
||||
void returnValue(@NotNull Data<V> value);
|
||||
}
|
||||
|
||||
@@ -555,7 +555,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable, Clon
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ExternalMapQueryContext<K, V, ?> queryContext(Data<K, ?> key) {
|
||||
public ExternalMapQueryContext<K, V, ?> queryContext(Data<K> key) {
|
||||
throw new UnsupportedOperationException("Contexts are not supported by stateless clients");
|
||||
}
|
||||
|
||||
|
||||
@@ -171,18 +171,18 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
}
|
||||
|
||||
void initQueryContext() {
|
||||
queryCxt = new ThreadLocal<CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R, ?>>() {
|
||||
queryCxt = new ThreadLocal<CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R>>() {
|
||||
@Override
|
||||
protected CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R, ?> initialValue() {
|
||||
protected CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> initialValue() {
|
||||
return new CompiledMapQueryContext<>(VanillaChronicleMap.this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void initIterationContext() {
|
||||
iterCxt = new ThreadLocal<CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R, ?>>() {
|
||||
iterCxt = new ThreadLocal<CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R>>() {
|
||||
@Override
|
||||
protected CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R, ?> initialValue() {
|
||||
protected CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> initialValue() {
|
||||
return new CompiledMapIterationContext<>(VanillaChronicleMap.this);
|
||||
}
|
||||
};
|
||||
@@ -335,23 +335,23 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
return valueSize;
|
||||
}
|
||||
|
||||
private CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R, ?> q() {
|
||||
return (CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R, ?>) queryCxt.get();
|
||||
private CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> q() {
|
||||
return (CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R>) queryCxt.get();
|
||||
}
|
||||
|
||||
public QueryContextInterface<K, V, R> mapContext() {
|
||||
CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R, ?> q = q().getContext();
|
||||
CompiledMapQueryContext<K, KI, MKI, V, VI, MVI, R> q = q().getContext();
|
||||
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();
|
||||
private CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> i() {
|
||||
return (CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R>) iterCxt.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IterationContextInterface<K, V> iterationContext() {
|
||||
CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R, ?> c = i().getContext();
|
||||
CompiledMapIterationContext<K, KI, MKI, V, VI, MVI, R> c = i().getContext();
|
||||
c.initUsed(true);
|
||||
return c;
|
||||
}
|
||||
@@ -368,7 +368,7 @@ public class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public QueryContextInterface<K, V, R> queryContext(Data<K, ?> key) {
|
||||
public QueryContextInterface<K, V, R> queryContext(Data<K> key) {
|
||||
QueryContextInterface<K, V, R> q = mapContext();
|
||||
q.initInputKey(key);
|
||||
return q;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+1219
-1269
File diff suppressed because it is too large
Load Diff
+2040
-2086
File diff suppressed because it is too large
Load Diff
@@ -6,19 +6,19 @@ 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.value.instance.ValueInitableData;
|
||||
import net.openhft.chronicle.map.impl.data.instance.ValueInitableData;
|
||||
|
||||
public interface QueryContextInterface<K, V, R> extends ExternalMapQueryContext<K, V, R> {
|
||||
|
||||
void initInputKey(Data<K, ?> inputKey);
|
||||
void initInputKey(Data<K> inputKey);
|
||||
|
||||
KeyInitableData<K, ?> inputKeyInstanceValue();
|
||||
KeyInitableData<K> inputKeyInstanceValue();
|
||||
|
||||
InstanceReturnValue<V> defaultReturnValue();
|
||||
|
||||
UsableReturnValue<V> usingReturnValue();
|
||||
|
||||
ValueInitableData<V, ?> inputValueInstanceValue();
|
||||
ValueInitableData<V> inputValueInstanceValue();
|
||||
|
||||
MapKeyContext<K, V> deprecatedMapKeyContext();
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.openhft.chronicle.map.impl.data.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
|
||||
public interface ValueInitableData<V> extends Data<V> {
|
||||
|
||||
void initValue(V value);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.openhft.chronicle.map.impl.value.instance;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
|
||||
public interface ValueInitableData<V, T> extends Data<V, T> {
|
||||
|
||||
void initValue(V value);
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public interface MapRemoteOperations<K, V, R> {
|
||||
* @param q the remote operation context
|
||||
* @param newValue the new value to put
|
||||
*/
|
||||
default void put(MapRemoteQueryContext<K, V, R> q, Data<V, ?> newValue) {
|
||||
default void put(MapRemoteQueryContext<K, V, R> q, Data<V> newValue) {
|
||||
MapReplicableEntry<K, V> entry = q.entry();
|
||||
if (entry != null) {
|
||||
if (decideOnRemoteModification(entry, q) == ACCEPT) {
|
||||
|
||||
@@ -20,7 +20,6 @@ package net.openhft.chronicle.map.replication;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.replication.HashRemoteQueryContext;
|
||||
import net.openhft.chronicle.hash.replication.RemoteOperationContext;
|
||||
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
@@ -54,5 +53,5 @@ public interface MapRemoteQueryContext<K, V, R> extends MapQueryContext<K, V, R>
|
||||
*
|
||||
* @return dummy value of all zeros, of the minimum possible size.
|
||||
*/
|
||||
Data<V, ?> dummyZeroValue();
|
||||
Data<V> dummyZeroValue();
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class SetFromMap<E> extends AbstractSet<E>
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ExternalSetQueryContext<E, ?> queryContext(Data<E, ?> key) {
|
||||
public ExternalSetQueryContext<E, ?> queryContext(Data<E> key) {
|
||||
//TODO
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class BiMapTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(MapQueryContext<K, V, DualLockSuccess> q, Data<V, ?> value,
|
||||
public void put(MapQueryContext<K, V, DualLockSuccess> q, Data<V> value,
|
||||
ReturnValue<V> returnValue) {
|
||||
while (true) {
|
||||
q.updateLock().lock();
|
||||
@@ -59,7 +59,7 @@ public class BiMapTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putIfAbsent(MapQueryContext<K, V, DualLockSuccess> q, Data<V, ?> value,
|
||||
public void putIfAbsent(MapQueryContext<K, V, DualLockSuccess> q, Data<V> value,
|
||||
ReturnValue<V> returnValue) {
|
||||
while (true) {
|
||||
try {
|
||||
@@ -88,7 +88,7 @@ public class BiMapTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(MapQueryContext<K, V, DualLockSuccess> q, Data<V, ?> value) {
|
||||
public boolean remove(MapQueryContext<K, V, DualLockSuccess> q, Data<V> value) {
|
||||
while (true) {
|
||||
q.updateLock().lock();
|
||||
MapEntry<K, V> entry = q.entry();
|
||||
@@ -116,14 +116,14 @@ public class BiMapTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(MapQueryContext<K, V, DualLockSuccess> q, Data<V, ?> value,
|
||||
public void replace(MapQueryContext<K, V, DualLockSuccess> q, Data<V> value,
|
||||
ReturnValue<V> returnValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(MapQueryContext<K, V, DualLockSuccess> q, Data<V, ?> oldValue,
|
||||
Data<V, ?> newValue) {
|
||||
public boolean replace(MapQueryContext<K, V, DualLockSuccess> q, Data<V> oldValue,
|
||||
Data<V> newValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class BiMapTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(MapQueryContext<K, V, DualLockSuccess> q, Data<V, ?> value,
|
||||
public void merge(MapQueryContext<K, V, DualLockSuccess> q, Data<V> value,
|
||||
BiFunction<? super V, ? super V, ? extends V> remappingFunction,
|
||||
ReturnValue<V> returnValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -171,13 +171,13 @@ public class BiMapTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualLockSuccess replaceValue(@NotNull MapEntry<K, V> entry, Data<V, ?> newValue) {
|
||||
public DualLockSuccess replaceValue(@NotNull MapEntry<K, V> entry, Data<V> newValue) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualLockSuccess insert(@NotNull MapAbsentEntry<K, V> absentEntry,
|
||||
Data<V, ?> value) {
|
||||
Data<V> value) {
|
||||
try (ExternalMapQueryContext<V, K, ?> rq = reverse.queryContext(value)) {
|
||||
if (!rq.updateLock().tryLock())
|
||||
return FAIL;
|
||||
@@ -187,7 +187,7 @@ public class BiMapTest {
|
||||
reverseAbsentEntry.doInsert(absentEntry.absentKey());
|
||||
return SUCCESS;
|
||||
} else {
|
||||
Data<K, ?> reverseKey = rq.entry().value();
|
||||
Data<K> reverseKey = rq.entry().value();
|
||||
if (reverseKey.equals(absentEntry.absentKey())) {
|
||||
// recover
|
||||
absentEntry.doInsert(value);
|
||||
|
||||
@@ -141,7 +141,7 @@ public class GuavaTest extends TestCase {
|
||||
|
||||
@Override
|
||||
public Void replaceValue(@NotNull MapEntry<CharSequence, CharSequence> entry,
|
||||
net.openhft.chronicle.hash.Data<CharSequence, ?> newValue) {
|
||||
net.openhft.chronicle.hash.Data<CharSequence> newValue) {
|
||||
Assert.assertEquals(m, entry.context().map());
|
||||
m.put(entry.key().get().toString(), newValue.get().toString());
|
||||
return MapEntryOperations.super.replaceValue(entry, newValue);
|
||||
@@ -149,7 +149,7 @@ public class GuavaTest extends TestCase {
|
||||
|
||||
@Override
|
||||
public Void insert(@NotNull MapAbsentEntry<CharSequence, CharSequence> absentEntry,
|
||||
Data<CharSequence, ?> value) {
|
||||
Data<CharSequence> value) {
|
||||
Assert.assertEquals(m, absentEntry.context().map());
|
||||
m.put(absentEntry.absentKey().get().toString(), value.get().toString());
|
||||
return MapEntryOperations.super.insert(absentEntry, value);
|
||||
|
||||
@@ -23,13 +23,13 @@ public class ListenersTest {
|
||||
return MapEntryOperations.super.remove(entry);
|
||||
}
|
||||
@Override
|
||||
public Void replaceValue(@NotNull MapEntry<K, V> entry, Data<V, ?> newValue) {
|
||||
public Void replaceValue(@NotNull MapEntry<K, V> entry, Data<V> newValue) {
|
||||
replaceValueCount.incrementAndGet();
|
||||
return MapEntryOperations.super.replaceValue(entry, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void insert(@NotNull MapAbsentEntry<K, V> absentEntry, Data<V, ?> value) {
|
||||
public Void insert(@NotNull MapAbsentEntry<K, V> absentEntry, Data<V> value) {
|
||||
insertCount.incrementAndGet();
|
||||
return MapEntryOperations.super.insert(absentEntry, value);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class ListenersTest {
|
||||
.mapMethods(new MapMethods<Integer, Integer, Void>() {
|
||||
@Override
|
||||
public void put(MapQueryContext<Integer, Integer, Void> q,
|
||||
net.openhft.chronicle.hash.Data<Integer, ?> value,
|
||||
net.openhft.chronicle.hash.Data<Integer> value,
|
||||
ReturnValue<Integer> returnValue) {
|
||||
if (q.queriedKey().get() == 2) {
|
||||
MapMethods.super.put(q, value, NullReturnValue.get());
|
||||
|
||||
@@ -28,7 +28,7 @@ class LoggingMapEntryOperations<K, V> implements MapEntryOperations<K, V, Void>
|
||||
static final Logger LOG = LoggerFactory.getLogger(LoggingMapEntryOperations.class);
|
||||
|
||||
@Override
|
||||
public Void replaceValue(@NotNull MapEntry<K, V> entry, Data<V, ?> newValue) {
|
||||
public Void replaceValue(@NotNull MapEntry<K, V> entry, Data<V> newValue) {
|
||||
LOG.info("replace: old key: {}, old value: {}, new value: {}",
|
||||
entry.key(), entry.value(), newValue);
|
||||
entry.doReplaceValue(newValue);
|
||||
|
||||
@@ -34,32 +34,21 @@ public class MarkTest {
|
||||
|
||||
@Test(timeout = 25000)
|
||||
public void inMemoryTest() {
|
||||
test(new SerializableFunction<ChronicleMapBuilder<Integer, Integer>, ChronicleMap<Integer, Integer>>() {
|
||||
@Override
|
||||
public ChronicleMap<Integer, Integer> apply(
|
||||
ChronicleMapBuilder<Integer, Integer> builder) {
|
||||
return builder.create();
|
||||
}
|
||||
});
|
||||
test(builder -> builder.create());
|
||||
}
|
||||
|
||||
@Test(timeout = 25000)
|
||||
@Test
|
||||
public void persistedTest() {
|
||||
int rnd = new Random().nextInt();
|
||||
final File db = Paths.get(System.getProperty("java.io.tmpdir"), "mark" + rnd).toFile();
|
||||
if (db.exists())
|
||||
db.delete();
|
||||
try {
|
||||
test(new SerializableFunction<ChronicleMapBuilder<Integer, Integer>,
|
||||
ChronicleMap<Integer, Integer>>() {
|
||||
@Override
|
||||
public ChronicleMap<Integer, Integer> apply(
|
||||
ChronicleMapBuilder<Integer, Integer> builder) {
|
||||
try {
|
||||
return builder.createPersistedTo(db);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
test(builder -> {
|
||||
try {
|
||||
return builder.createPersistedTo(db);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
});
|
||||
System.out.println(MemoryUnit.BYTES.toMegabytes(db.length()) + " MB");
|
||||
|
||||
@@ -294,7 +294,7 @@ public class ReplicationCheckingMap<K, V> implements ChronicleMap<K, V> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ExternalMapQueryContext<K, V, ?> queryContext(net.openhft.chronicle.hash.Data<K, ?> key) {
|
||||
public ExternalMapQueryContext<K, V, ?> queryContext(net.openhft.chronicle.hash.Data<K> key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,6 @@ import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.replication.MapRemoteOperations;
|
||||
import net.openhft.chronicle.map.replication.MapRemoteQueryContext;
|
||||
import net.openhft.chronicle.map.replication.MapReplicableEntry;
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
import net.openhft.lang.model.Byteable;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.IntValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -18,13 +14,12 @@ import org.junit.Test;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static net.openhft.lang.MemoryUnit.MEGABYTES;
|
||||
import static net.openhft.chronicle.map.TcpReplicationSoakCrdtTest.GrowOnlySetValuedMapEntryOperations.growOnlySetValuedMapEntryOperations;
|
||||
import static net.openhft.chronicle.map.TcpReplicationSoakCrdtTest.GrowOnlySetValuedMapRemoteOperations.growOnlySetValuedMapRemoteOperations;
|
||||
import static net.openhft.lang.MemoryUnit.MEGABYTES;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TcpReplicationSoakCrdtTest {
|
||||
@@ -63,7 +58,7 @@ public class TcpReplicationSoakCrdtTest {
|
||||
private GrowOnlySetValuedMapRemoteOperations() {}
|
||||
|
||||
@Override
|
||||
public void put(MapRemoteQueryContext<K, Set<E>, Void> q, Data<Set<E>, ?> newValue) {
|
||||
public void put(MapRemoteQueryContext<K, Set<E>, Void> q, Data<Set<E>> newValue) {
|
||||
MapReplicableEntry<K, Set<E>> entry = q.entry();
|
||||
if (entry != null) {
|
||||
Set<E> merged = new HashSet<>(entry.value().get());
|
||||
|
||||
+4
-4
@@ -31,22 +31,22 @@ public class SimpleMapOperationsListeningTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void replaceValue(@NotNull MapEntry<K, V> entry, Data<V, ?> newValue) {
|
||||
public Void replaceValue(@NotNull MapEntry<K, V> entry, Data<V> newValue) {
|
||||
System.out.println("replace " + entry.key() + ": " + entry.value() + " -> " + newValue);
|
||||
entry.doReplaceValue(newValue);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void insert(@NotNull MapAbsentEntry<K, V> absentEntry, Data<V, ?> value) {
|
||||
public Void insert(@NotNull MapAbsentEntry<K, V> absentEntry, Data<V> value) {
|
||||
System.out.println("insert " + absentEntry.absentKey() + " -> " + value);
|
||||
absentEntry.doInsert(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Data<V, ?> defaultValue(@NotNull MapAbsentEntry<K, V> absentEntry) {
|
||||
Data<V, ?> defaultValue = absentEntry.defaultValue();
|
||||
public Data<V> defaultValue(@NotNull MapAbsentEntry<K, V> absentEntry) {
|
||||
Data<V> defaultValue = absentEntry.defaultValue();
|
||||
System.out.println("default " + absentEntry.absentKey() + " -> " + defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ExternalMapQueryContext<K, V, ?> queryContext(Data<K, ?> key) {
|
||||
public ExternalMapQueryContext<K, V, ?> queryContext(Data<K> key) {
|
||||
return d.queryContext(key);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user