key);
/**
* Checks the given predicate on each entry in this {@code ChronicleHash} until all entries
diff --git a/src/main/java/net/openhft/chronicle/hash/Data.java b/src/main/java/net/openhft/chronicle/hash/Data.java
index 5a14cac67..96cd5f631 100644
--- a/src/main/java/net/openhft/chronicle/hash/Data.java
+++ b/src/main/java/net/openhft/chronicle/hash/Data.java
@@ -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.
*
- * Bytes access: {@link #access()} + {@link #handle()} + {@link #offset()} + {@link #size()}.
+ *
Bytes access: {@link #bytes()} + {@link #offset()} + {@link #size()}.
*
*
Object access: {@link #get()}.
*
@@ -34,19 +38,10 @@ import org.jetbrains.annotations.Nullable;
* accordingly.
*
* @param type of the accessed objects
- * @param type of the handle for bytes access
*/
-public interface Data {
+public interface Data {
- /**
- * Returns access to the value's bytes.
- */
- ReadAccess 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 {
long size();
default long hash(LongHashFunction f) {
- return f.hash(handle(), access(), offset(), size());
+ return f.hash(bytes(), checkedRandomDataInputAccess(), offset(), size());
}
- default boolean equivalent(ReadAccess 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 > boolean equivalent(
- Accessor accessor, S source, long index) {
- return equivalent(accessor.access(source), accessor.handle(source),
- accessor.offset(source, index));
- }
-
- default void writeTo(WriteAccess targetAccess, T2 target, long targetOffset) {
- Access.copy(access(), handle(), offset(), targetAccess, target, targetOffset, size());
- }
-
- default void writeTo(StreamingDataOutput, ?, T2> output) {
- long offset = output.accessPositionOffset();
- output.skip(size());
- writeTo(output.access(), output.accessHandle(), offset);
- }
-
- default > void writeTo(
- Accessor 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 getUsing(@Nullable V usingInstance);
- static 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());
}
}
diff --git a/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java b/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java
index f97cfb732..47ac61431 100644
--- a/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java
+++ b/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java
@@ -25,5 +25,5 @@ public interface HashAbsentEntry {
* Returns the key is going to be inserted into the {@code ChronicleHash}.
*/
@NotNull
- Data absentKey();
+ Data absentKey();
}
diff --git a/src/main/java/net/openhft/chronicle/hash/HashEntry.java b/src/main/java/net/openhft/chronicle/hash/HashEntry.java
index cee107e9a..57e439663 100644
--- a/src/main/java/net/openhft/chronicle/hash/HashEntry.java
+++ b/src/main/java/net/openhft/chronicle/hash/HashEntry.java
@@ -41,7 +41,7 @@ public interface HashEntry {
* Returns the entry key.
*/
@NotNull
- Data key();
+ Data key();
/**
* Removes the entry from the {@code ChronicleHash}.
diff --git a/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java b/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java
index c3bada023..622c9fe2f 100644
--- a/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java
+++ b/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java
@@ -142,7 +142,7 @@ public interface HashQueryContext extends HashContext, InterProcessReadWri
/**
* Returns the queried key as a {@code Data}.
*/
- Data queriedKey();
+ Data queriedKey();
/**
* Returns the entry context, if the entry with the queried key is present
diff --git a/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java b/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java
index 0d82da723..e019f9046 100644
--- a/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java
+++ b/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java
@@ -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 extends AbstractData {
-public abstract class CopyingInstanceData extends AbstractData {
+ 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 access() {
- //noinspection unchecked
- return (ReadAccess) 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
diff --git a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccess.java b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccess.java
deleted file mode 100644
index 65006bbcc..000000000
--- a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccess.java
+++ /dev/null
@@ -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 {
- 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();
- }
-}
diff --git a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccessors.java b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccessors.java
deleted file mode 100644
index 02a0a6aba..000000000
--- a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccessors.java
+++ /dev/null
@@ -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 uncheckedBytesAccessor(Bytes bytes) {
- return bytes instanceof NativeBytes ? GenericBytesAccessor.INSTANCE :
- GenericBytesAccessor.INSTANCE;
- }
-
- enum NativeBytesAccessor implements Accessor.Full {
- INSTANCE;
-
- @Override
- public Access 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 {
- INSTANCE;
-
- @Override
- public Access 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() {}
-}
diff --git a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesReusableBytesStore.java b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesReusableBytesStore.java
new file mode 100644
index 000000000..abdba3cfb
--- /dev/null
+++ b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesReusableBytesStore.java
@@ -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 {
+
+ private Bytes bytes;
+
+ public void setBytes(Bytes bytes) {
+ this.bytes = bytes;
+ }
+
+ @Override
+ public BytesStore 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();
+ }
+}
diff --git a/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java b/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java
index 75bb2dee7..db765a63b 100644
--- a/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java
+++ b/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java
@@ -2,7 +2,7 @@ package net.openhft.chronicle.hash.impl.value.instance;
import net.openhft.chronicle.hash.Data;
-public interface KeyInitableData extends Data {
+public interface KeyInitableData extends Data {
void initKey(K key);
}
diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java
index d778a5c2b..8211d1b83 100644
--- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java
+++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java
@@ -35,7 +35,11 @@ public abstract class CopyingMetaBytesInterop 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);
}
diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java
index 9ce4540f4..e30cf5345 100644
--- a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java
+++ b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java
@@ -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 {
diff --git a/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java b/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java
index 741f4a49a..4274878db 100644
--- a/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java
+++ b/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java
@@ -49,7 +49,7 @@ public interface MapAbsentEntry extends HashAbsentEntry {
* operation are not met
* @see MapEntryOperations#insert(MapAbsentEntry, Data)
*/
- void doInsert(Data value);
+ void doInsert(Data value);
/**
* Returns the default (or nil) value, that should be inserted into the map in
@@ -63,5 +63,5 @@ public interface MapAbsentEntry extends HashAbsentEntry {
* @see MapEntryOperations#defaultValue(MapAbsentEntry)
*/
@NotNull
- Data defaultValue();
+ Data defaultValue();
}
diff --git a/src/main/java/net/openhft/chronicle/map/MapContext.java b/src/main/java/net/openhft/chronicle/map/MapContext.java
index da1710fca..a9274f9ba 100644
--- a/src/main/java/net/openhft/chronicle/map/MapContext.java
+++ b/src/main/java/net/openhft/chronicle/map/MapContext.java
@@ -55,5 +55,5 @@ public interface MapContext extends HashContext, MapEntryOperations<
* @param value the value object to wrap
* @return the value as {@code Data}
*/
- Data wrapValueAsValue(V value);
+ Data wrapValueAsValue(V value);
}
diff --git a/src/main/java/net/openhft/chronicle/map/MapEntry.java b/src/main/java/net/openhft/chronicle/map/MapEntry.java
index 184d6b3ca..cdce98313 100644
--- a/src/main/java/net/openhft/chronicle/map/MapEntry.java
+++ b/src/main/java/net/openhft/chronicle/map/MapEntry.java
@@ -38,7 +38,7 @@ public interface MapEntry extends HashEntry {
* Returns the entry value.
*/
@NotNull
- Data value();
+ Data value();
/**
* Replaces the entry's value with the given {@code newValue}.
@@ -51,7 +51,7 @@ public interface MapEntry extends HashEntry {
* @throws IllegalStateException if some locking/state conditions required to perform replace
* operation are not met
*/
- void doReplaceValue(Data newValue);
+ void doReplaceValue(Data newValue);
/**
* Removes the entry from the map.
diff --git a/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java b/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java
index cd94e4706..ef7b3e3ee 100644
--- a/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java
+++ b/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java
@@ -130,7 +130,7 @@ public interface MapEntryOperations {
* @throws RuntimeException if value replacement was unconditionally unsuccessful due
* to any reason
*/
- default R replaceValue(@NotNull MapEntry entry, Data newValue) {
+ default R replaceValue(@NotNull MapEntry entry, Data newValue) {
entry.doReplaceValue(newValue);
return null;
}
@@ -146,7 +146,7 @@ public interface MapEntryOperations {
* operation are not met
* @throws RuntimeException if insertion was unconditionally unsuccessful due to any reason
*/
- default R insert(@NotNull MapAbsentEntry absentEntry, Data value) {
+ default R insert(@NotNull MapAbsentEntry absentEntry, Data value) {
absentEntry.doInsert(value);
return null;
}
@@ -158,7 +158,7 @@ public interface MapEntryOperations {
*
* @implNote simply delegates to {@link MapAbsentEntry#defaultValue()}.
*/
- default Data defaultValue(@NotNull MapAbsentEntry absentEntry) {
+ default Data defaultValue(@NotNull MapAbsentEntry absentEntry) {
return absentEntry.defaultValue();
}
}
diff --git a/src/main/java/net/openhft/chronicle/map/MapMethods.java b/src/main/java/net/openhft/chronicle/map/MapMethods.java
index 85f6bf114..3228bd28a 100644
--- a/src/main/java/net/openhft/chronicle/map/MapMethods.java
+++ b/src/main/java/net/openhft/chronicle/map/MapMethods.java
@@ -69,7 +69,7 @@ public interface MapMethods {
* q.insert(q.absentEntry(), value);
* }}
*/
- default void put(MapQueryContext q, Data value, ReturnValue returnValue) {
+ default void put(MapQueryContext q, Data value, ReturnValue 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 {
* }
*/
default void putIfAbsent(MapQueryContext q,
- Data value, ReturnValue returnValue) {
+ Data value, ReturnValue returnValue) {
if (tryReturnCurrentValueIfPresent(q, returnValue))
return;
// Key is absent
@@ -234,7 +234,7 @@ public interface MapMethods {
*
* @return if the entry was removed
*/
- default boolean remove(MapQueryContext q, Data value) {
+ default boolean remove(MapQueryContext q, Data 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 {
* }}
*/
default void replace(MapQueryContext q,
- Data value, ReturnValue returnValue) {
+ Data value, ReturnValue 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 {
* @return if the entry was replaced
*/
default boolean replace(MapQueryContext q,
- Data oldValue, Data newValue) {
+ Data oldValue, Data 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 {
V oldValue = entry != null ? entry.value().get() : null;
V newValue = remappingFunction.apply(q.queriedKey().get(), oldValue);
if (newValue != null) {
- Data newValueData = q.wrapValueAsValue(newValue);
+ Data newValueData = q.wrapValueAsValue(newValue);
if (entry != null) {
q.replaceValue(entry, newValueData);
} else {
@@ -409,11 +409,11 @@ public interface MapMethods {
* returnValue.returnValue(entry.value());
* }
*/
- default void merge(MapQueryContext q, Data value,
+ default void merge(MapQueryContext q, Data value,
BiFunction super V, ? super V, ? extends V> remappingFunction,
ReturnValue returnValue) {
q.updateLock().lock();
- Data newValueData;
+ Data newValueData;
MapEntry entry = q.entry();
if (entry != null) {
V oldValue = entry.value().get();
diff --git a/src/main/java/net/openhft/chronicle/map/ReturnValue.java b/src/main/java/net/openhft/chronicle/map/ReturnValue.java
index 417149c00..c264bfcec 100644
--- a/src/main/java/net/openhft/chronicle/map/ReturnValue.java
+++ b/src/main/java/net/openhft/chronicle/map/ReturnValue.java
@@ -22,5 +22,5 @@ import net.openhft.chronicle.hash.Data;
import org.jetbrains.annotations.NotNull;
public interface ReturnValue {
- void returnValue(@NotNull Data value);
+ void returnValue(@NotNull Data value);
}
diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java
index 9ec66b29c..5975cfceb 100644
--- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java
+++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java
@@ -555,7 +555,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon
@NotNull
@Override
- public ExternalMapQueryContext queryContext(Data key) {
+ public ExternalMapQueryContext queryContext(Data key) {
throw new UnsupportedOperationException("Contexts are not supported by stateless clients");
}
diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java
index 75c1ce6db..92c3f35dd 100755
--- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java
+++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java
@@ -171,18 +171,18 @@ public class VanillaChronicleMap>() {
+ queryCxt = new ThreadLocal>() {
@Override
- protected CompiledMapQueryContext initialValue() {
+ protected CompiledMapQueryContext initialValue() {
return new CompiledMapQueryContext<>(VanillaChronicleMap.this);
}
};
}
void initIterationContext() {
- iterCxt = new ThreadLocal>() {
+ iterCxt = new ThreadLocal>() {
@Override
- protected CompiledMapIterationContext initialValue() {
+ protected CompiledMapIterationContext initialValue() {
return new CompiledMapIterationContext<>(VanillaChronicleMap.this);
}
};
@@ -335,23 +335,23 @@ public class VanillaChronicleMap q() {
- return (CompiledMapQueryContext) queryCxt.get();
+ private CompiledMapQueryContext q() {
+ return (CompiledMapQueryContext) queryCxt.get();
}
public QueryContextInterface mapContext() {
- CompiledMapQueryContext q = q().getContext();
+ CompiledMapQueryContext q = q().getContext();
q.initUsed(true);
return q;
}
- private CompiledMapIterationContext i() {
- return (CompiledMapIterationContext) iterCxt.get();
+ private CompiledMapIterationContext i() {
+ return (CompiledMapIterationContext) iterCxt.get();
}
@Override
public IterationContextInterface iterationContext() {
- CompiledMapIterationContext c = i().getContext();
+ CompiledMapIterationContext c = i().getContext();
c.initUsed(true);
return c;
}
@@ -368,7 +368,7 @@ public class VanillaChronicleMap queryContext(Data key) {
+ public QueryContextInterface queryContext(Data key) {
QueryContextInterface q = mapContext();
q.initInputKey(key);
return q;
diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java
index fb0f7cf37..49e5cfaf9 100644
--- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java
+++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java
@@ -1,9 +1,8 @@
package net.openhft.chronicle.map.impl;
-import net.openhft.chronicle.bytes.Access;
-import net.openhft.chronicle.bytes.Accessor;
-import net.openhft.chronicle.bytes.Accessor.Full;
-import net.openhft.chronicle.bytes.ReadAccess;
+import net.openhft.chronicle.bytes.BytesStore;
+import net.openhft.chronicle.bytes.NativeBytesStore;
+import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.HashEntry;
@@ -31,22 +30,22 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
-public class CompiledMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , MapContext , MapEntry , IterationContextInterface , VanillaChronicleMapHolder {
+public class CompiledMapIterationContext, V, VI, MVI extends MetaBytesInterop, R> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , MapContext , MapEntry , IterationContextInterface , VanillaChronicleMapHolder {
public void close() {
- CompiledMapIterationContext.this.closeHashLookupPos();
- CompiledMapIterationContext.this.closeKeyOffset();
- CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext();
- CompiledMapIterationContext.this.closeEntryRemovedOnThisIteration();
- CompiledMapIterationContext.this.closePos();
- CompiledMapIterationContext.this.wrappedValueInstanceValue.closeValue();
- CompiledMapIterationContext.this.closeTheSegmentIndex();
- CompiledMapIterationContext.this.closeKeySize();
- CompiledMapIterationContext.this.closeUsed();
- CompiledMapIterationContext.this.closeAllocatedChunks();
- CompiledMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants();
- CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants();
- CompiledMapIterationContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants();
- CompiledMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants();
+ this.closeTheSegmentIndex();
+ this.wrappedValueInstanceValue.closeValue();
+ this.closeEntryRemovedOnThisIteration();
+ this.wrappedValueInstanceValue.closeNext();
+ this.closeUsed();
+ this.closeKeySize();
+ this.closePos();
+ this.closeAllocatedChunks();
+ this.closeHashLookupPos();
+ this.closeKeyOffset();
+ this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants();
+ this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants();
+ this.closeValueBytesInteropValueMetaInteropDependants();
+ this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants();
}
public void incrementModCountGuarded() {
@@ -69,26 +68,24 @@ public class CompiledMapIterationContext m) {
- contextChain = new ArrayList();
+ contextChain = new ArrayList();
contextChain.add(this);
indexInContextChain = 0;
this.m = m;
- this.entryKey = new EntryKeyBytesData();
- this.entryValue = new EntryValueBytesData();
- this.innerReadLock = new ReadLock();
- this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration();
- this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes();
- this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes);
- this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes)));
- this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes)));
- this.innerWriteLock = new WriteLock();
- this.owner = Thread.currentThread();
- this.innerUpdateLock = new UpdateLock();
this.copies = ThreadLocalCopies.get();
- this.valueInterop = CompiledMapIterationContext.this.m().valueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueInterop);
- this.valueReader = CompiledMapIterationContext.this.m().valueReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueReader);
- this.keyInterop = CompiledMapIterationContext.this.h().keyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyInterop);
- this.keyReader = CompiledMapIterationContext.this.h().keyReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyReader);
+ this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop);
+ this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader);
+ this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop);
+ this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader);
+ this.entryKey = new EntryKeyBytesData();
+ this.innerUpdateLock = new UpdateLock();
+ this.innerReadLock = new ReadLock();
+ this.entryValue = new EntryValueBytesData();
+ this.innerWriteLock = new WriteLock();
+ this.entryBytes = this.h().ms.bytes();
+ this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false);
+ this.owner = Thread.currentThread();
+ this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration();
this.wrappedValueInstanceValue = new WrappedValueInstanceData();
}
@@ -97,26 +94,29 @@ public class CompiledMapIterationContext)(c.m));
- this.entryKey = new EntryKeyBytesData();
- this.entryValue = new EntryValueBytesData();
- this.innerReadLock = new ReadLock();
- this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration();
- this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes();
- this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes);
- this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes)));
- this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes)));
- this.innerWriteLock = new WriteLock();
- this.owner = Thread.currentThread();
- this.innerUpdateLock = new UpdateLock();
this.copies = ThreadLocalCopies.get();
- this.valueInterop = CompiledMapIterationContext.this.m().valueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueInterop);
- this.valueReader = CompiledMapIterationContext.this.m().valueReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueReader);
- this.keyInterop = CompiledMapIterationContext.this.h().keyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyInterop);
- this.keyReader = CompiledMapIterationContext.this.h().keyReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyReader);
+ this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop);
+ this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader);
+ this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop);
+ this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader);
+ this.entryKey = new EntryKeyBytesData();
+ this.innerUpdateLock = new UpdateLock();
+ this.innerReadLock = new ReadLock();
+ this.entryValue = new EntryValueBytesData();
+ this.innerWriteLock = new WriteLock();
+ this.entryBytes = this.h().ms.bytes();
+ this.entryBS = new NativeBytesStore