mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Read/Write ChronicleMap's boostrapping header with Wire
This commit is contained in:
@@ -89,8 +89,8 @@ public abstract class CompactOffHeapLinearHashTable {
|
||||
}
|
||||
|
||||
CompactOffHeapLinearHashTable(VanillaChronicleHash h) {
|
||||
this(h.segmentHashLookupCapacity, h.segmentHashLookupEntrySize, h.segmentHashLookupKeyBits,
|
||||
h.segmentHashLookupValueBits);
|
||||
this(h.tierHashLookupCapacity, h.tierHashLookupEntrySize, h.tierHashLookupKeyBits,
|
||||
h.tierHashLookupValueBits);
|
||||
}
|
||||
|
||||
abstract long indexToPos(long index);
|
||||
|
||||
@@ -16,11 +16,18 @@
|
||||
|
||||
package net.openhft.chronicle.hash.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import static net.openhft.chronicle.core.Maths.isPowerOf2;
|
||||
|
||||
public interface HashSplitting extends Serializable {
|
||||
public interface HashSplitting extends Serializable, Marshallable {
|
||||
|
||||
int segmentIndex(long hash);
|
||||
long segmentHash(long hash);
|
||||
@@ -36,7 +43,7 @@ public interface HashSplitting extends Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
enum ForSingleSegment implements HashSplitting {
|
||||
enum ForSingleSegment implements HashSplitting, EnumMarshallable<ForSingleSegment> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -48,13 +55,18 @@ public interface HashSplitting extends Serializable {
|
||||
public long segmentHash(long hash) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForSingleSegment readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
class ForPowerOf2Segments implements HashSplitting {
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
private final int mask;
|
||||
private final int bits;
|
||||
private int mask;
|
||||
private int bits;
|
||||
|
||||
ForPowerOf2Segments(int segments) {
|
||||
mask = segments - 1;
|
||||
@@ -70,6 +82,18 @@ public interface HashSplitting extends Serializable {
|
||||
public long segmentHash(long hash) {
|
||||
return hash >>> bits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wire) throws IORuntimeException {
|
||||
mask = wire.read(() -> "mask").int32();
|
||||
bits = wire.read(() -> "bits").int32();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wire) {
|
||||
wire.write(() -> "mask").int32(mask);
|
||||
wire.write(() -> "bits").int32(bits);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO optimize?
|
||||
@@ -79,7 +103,7 @@ public interface HashSplitting extends Serializable {
|
||||
private static final int MASK = Integer.MAX_VALUE;
|
||||
private static final int BITS = 31;
|
||||
|
||||
private final int segments;
|
||||
private int segments;
|
||||
|
||||
public ForNonPowerOf2Segments(int segments) {
|
||||
this.segments = segments;
|
||||
@@ -94,5 +118,15 @@ public interface HashSplitting extends Serializable {
|
||||
public long segmentHash(long hash) {
|
||||
return hash >>> BITS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wire) throws IORuntimeException {
|
||||
segments = wire.read(() -> "segments").int32();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wire) {
|
||||
wire.write(() -> "segments").int32(segments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.openhft.chronicle.hash.impl;
|
||||
import net.openhft.chronicle.algo.bytes.Access;
|
||||
import net.openhft.chronicle.algo.locks.*;
|
||||
import net.openhft.chronicle.bytes.BytesStore;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.MappedBytesStoreFactory;
|
||||
import net.openhft.chronicle.bytes.NativeBytesStore;
|
||||
import net.openhft.chronicle.core.Maths;
|
||||
@@ -31,6 +32,10 @@ import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.impl.SerializationBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.values.Values;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -54,7 +59,7 @@ import static net.openhft.chronicle.hash.impl.DummyReferenceCounted.DUMMY_REFERE
|
||||
public abstract class VanillaChronicleHash<K,
|
||||
C extends HashEntry<K>, SC extends HashSegmentContext<K, ?>,
|
||||
ECQ extends ExternalHashQueryContext<K>>
|
||||
implements ChronicleHash<K, C, SC, ECQ>, Serializable {
|
||||
implements ChronicleHash<K, C, SC, ECQ>, Serializable, Marshallable {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(VanillaChronicleHash.class);
|
||||
|
||||
@@ -65,7 +70,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Version
|
||||
public final String dataFileVersion;
|
||||
private String dataFileVersion;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// If the hash was created in the first place, or read from disk
|
||||
@@ -73,51 +78,51 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Key Data model
|
||||
public final Class<K> kClass;
|
||||
public final SizeMarshaller keySizeMarshaller;
|
||||
public final SizedReader<K> originalKeyReader;
|
||||
public final DataAccess<K> originalKeyDataAccess;
|
||||
public Class<K> keyClass;
|
||||
public SizeMarshaller keySizeMarshaller;
|
||||
public SizedReader<K> keyReader;
|
||||
public DataAccess<K> keyDataAccess;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Checksum entries
|
||||
public final boolean checksumEntries;
|
||||
public boolean checksumEntries;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Concurrency (number of segments), memory management and dependent fields
|
||||
public final int actualSegments;
|
||||
public final HashSplitting hashSplitting;
|
||||
public int actualSegments;
|
||||
public HashSplitting hashSplitting;
|
||||
|
||||
public final long entriesPerSegment;
|
||||
public long entriesPerSegment;
|
||||
|
||||
public final long chunkSize;
|
||||
public final int maxChunksPerEntry;
|
||||
public final long actualChunksPerSegment;
|
||||
public long chunkSize;
|
||||
public int maxChunksPerEntry;
|
||||
public long actualChunksPerSegment;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Precomputed offsets and sizes for fast Context init
|
||||
final int segmentHeaderSize;
|
||||
int segmentHeaderSize;
|
||||
|
||||
public final int segmentHashLookupValueBits;
|
||||
public final int segmentHashLookupKeyBits;
|
||||
public final int segmentHashLookupEntrySize;
|
||||
public final long segmentHashLookupCapacity;
|
||||
final long segmentHashLookupInnerSize;
|
||||
public final long segmentHashLookupOuterSize;
|
||||
public int tierHashLookupValueBits;
|
||||
public int tierHashLookupKeyBits;
|
||||
public int tierHashLookupEntrySize;
|
||||
public long tierHashLookupCapacity;
|
||||
long tierHashLookupInnerSize;
|
||||
public long tierHashLookupOuterSize;
|
||||
|
||||
public final long segmentFreeListInnerSize;
|
||||
public final long segmentFreeListOuterSize;
|
||||
public long tierFreeListInnerSize;
|
||||
public long tierFreeListOuterSize;
|
||||
|
||||
final long segmentEntrySpaceInnerSize;
|
||||
public final int segmentEntrySpaceInnerOffset;
|
||||
final long segmentEntrySpaceOuterSize;
|
||||
long tierEntrySpaceInnerSize;
|
||||
public int tierEntrySpaceInnerOffset;
|
||||
long tierEntrySpaceOuterSize;
|
||||
|
||||
public final long segmentSize;
|
||||
public long tierSize;
|
||||
|
||||
final long maxExtraTiers;
|
||||
final long tierBulkSizeInBytes;
|
||||
final long tierBulkInnerOffsetToTiers;
|
||||
protected final long tiersInBulk;
|
||||
protected final int log2TiersInBulk;
|
||||
long maxExtraTiers;
|
||||
long tierBulkSizeInBytes;
|
||||
long tierBulkInnerOffsetToTiers;
|
||||
protected long tiersInBulk;
|
||||
protected int log2TiersInBulk;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Bytes Store (essentially, the base address) and serialization-dependent offsets
|
||||
@@ -164,10 +169,10 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
// Data model
|
||||
SerializationBuilder<K> keyBuilder = privateAPI.keyBuilder();
|
||||
kClass = keyBuilder.tClass;
|
||||
keyClass = keyBuilder.tClass;
|
||||
keySizeMarshaller = keyBuilder.sizeMarshaller();
|
||||
originalKeyReader = keyBuilder.reader();
|
||||
originalKeyDataAccess = keyBuilder.dataAccess();
|
||||
keyReader = keyBuilder.reader();
|
||||
keyDataAccess = keyBuilder.dataAccess();
|
||||
|
||||
actualSegments = privateAPI.actualSegments();
|
||||
hashSplitting = HashSplitting.Splitting.forSegments(actualSegments);
|
||||
@@ -181,28 +186,28 @@ public abstract class VanillaChronicleHash<K,
|
||||
// Precomputed offsets and sizes for fast Context init
|
||||
segmentHeaderSize = privateAPI.segmentHeaderSize();
|
||||
|
||||
segmentHashLookupValueBits = valueBits(actualChunksPerSegment);
|
||||
segmentHashLookupKeyBits = keyBits(entriesPerSegment, segmentHashLookupValueBits);
|
||||
segmentHashLookupEntrySize =
|
||||
entrySize(segmentHashLookupKeyBits, segmentHashLookupValueBits);
|
||||
if (!privateAPI.aligned64BitMemoryOperationsAtomic() && segmentHashLookupEntrySize > 4) {
|
||||
tierHashLookupValueBits = valueBits(actualChunksPerSegment);
|
||||
tierHashLookupKeyBits = keyBits(entriesPerSegment, tierHashLookupValueBits);
|
||||
tierHashLookupEntrySize =
|
||||
entrySize(tierHashLookupKeyBits, tierHashLookupValueBits);
|
||||
if (!privateAPI.aligned64BitMemoryOperationsAtomic() && tierHashLookupEntrySize > 4) {
|
||||
throw new IllegalStateException("aligned64BitMemoryOperationsAtomic() == false, " +
|
||||
"but hash lookup slot is " + segmentHashLookupEntrySize);
|
||||
"but hash lookup slot is " + tierHashLookupEntrySize);
|
||||
}
|
||||
segmentHashLookupCapacity = CompactOffHeapLinearHashTable.capacityFor(entriesPerSegment);
|
||||
segmentHashLookupInnerSize = segmentHashLookupCapacity * segmentHashLookupEntrySize;
|
||||
segmentHashLookupOuterSize = CACHE_LINES.align(segmentHashLookupInnerSize, BYTES);
|
||||
tierHashLookupCapacity = CompactOffHeapLinearHashTable.capacityFor(entriesPerSegment);
|
||||
tierHashLookupInnerSize = tierHashLookupCapacity * tierHashLookupEntrySize;
|
||||
tierHashLookupOuterSize = CACHE_LINES.align(tierHashLookupInnerSize, BYTES);
|
||||
|
||||
segmentFreeListInnerSize = LONGS.align(
|
||||
tierFreeListInnerSize = LONGS.align(
|
||||
BYTES.alignAndConvert(actualChunksPerSegment, BITS), BYTES);
|
||||
segmentFreeListOuterSize = CACHE_LINES.align(segmentFreeListInnerSize, BYTES);
|
||||
tierFreeListOuterSize = CACHE_LINES.align(tierFreeListInnerSize, BYTES);
|
||||
|
||||
segmentEntrySpaceInnerSize = chunkSize * actualChunksPerSegment;
|
||||
segmentEntrySpaceInnerOffset = privateAPI.segmentEntrySpaceInnerOffset();
|
||||
segmentEntrySpaceOuterSize = CACHE_LINES.align(
|
||||
segmentEntrySpaceInnerOffset + segmentEntrySpaceInnerSize, BYTES);
|
||||
tierEntrySpaceInnerSize = chunkSize * actualChunksPerSegment;
|
||||
tierEntrySpaceInnerOffset = privateAPI.segmentEntrySpaceInnerOffset();
|
||||
tierEntrySpaceOuterSize = CACHE_LINES.align(
|
||||
tierEntrySpaceInnerOffset + tierEntrySpaceInnerSize, BYTES);
|
||||
|
||||
segmentSize = segmentSize();
|
||||
tierSize = segmentSize();
|
||||
|
||||
maxExtraTiers = privateAPI.maxExtraTiers();
|
||||
tiersInBulk = computeNumberOfTiersInBulk();
|
||||
@@ -213,6 +218,101 @@ public abstract class VanillaChronicleHash<K,
|
||||
checksumEntries = privateAPI.checksumEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wire) throws IORuntimeException {
|
||||
readMarshallableFields(wire);
|
||||
initTransients();
|
||||
}
|
||||
|
||||
protected void readMarshallableFields(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
dataFileVersion = wireIn.read(() -> "dataFileVersion").text();
|
||||
|
||||
keyClass = wireIn.read(() -> "keyClass").typeLiteral();
|
||||
keySizeMarshaller = wireIn.read(() -> "keySizeMarshaller").typedMarshallable();
|
||||
keyReader = wireIn.read(() -> "keyReader").typedMarshallable();
|
||||
keyDataAccess = wireIn.read(() -> "keyDataAccess").typedMarshallable();
|
||||
|
||||
checksumEntries = wireIn.read(() -> "checksumEntries").bool();
|
||||
|
||||
actualSegments = wireIn.read(() -> "actualSegments").int32();
|
||||
hashSplitting = wireIn.read(() -> "hashSplitting").typedMarshallable();
|
||||
|
||||
entriesPerSegment = wireIn.read(() -> "entriesPerSegment").int64();
|
||||
|
||||
chunkSize = wireIn.read(() -> "chunkSize").int64();
|
||||
maxChunksPerEntry = wireIn.read(() -> "maxChunksPerEntry").int32();
|
||||
actualChunksPerSegment = wireIn.read(() -> "actualChunksPerSegment").int64();
|
||||
|
||||
segmentHeaderSize = wireIn.read(() -> "segmentHeaderSize").int32();
|
||||
|
||||
tierHashLookupValueBits = wireIn.read(() -> "tierHashLookupValueBits").int32();
|
||||
tierHashLookupKeyBits = wireIn.read(() -> "tierHashLookupKeyBits").int32();
|
||||
tierHashLookupEntrySize = wireIn.read(() -> "tierHashLookupEntrySize").int32();
|
||||
tierHashLookupCapacity = wireIn.read(() -> "tierHashLookupCapacity").int64();
|
||||
tierHashLookupInnerSize = wireIn.read(() -> "tierHashLookupInnerSize").int64();
|
||||
tierHashLookupOuterSize = wireIn.read(() -> "tierHashLookupOuterSize").int64();
|
||||
|
||||
tierFreeListInnerSize = wireIn.read(() -> "tierFreeListInnerSize").int64();
|
||||
tierFreeListOuterSize = wireIn.read(() -> "tierFreeListOuterSize").int64();
|
||||
|
||||
tierEntrySpaceInnerSize = wireIn.read(() -> "tierEntrySpaceInnerSize").int64();
|
||||
tierEntrySpaceInnerOffset = wireIn.read(() -> "tierEntrySpaceInnerOffset").int32();
|
||||
tierEntrySpaceOuterSize = wireIn.read(() -> "tierEntrySpaceOuterSize").int64();
|
||||
|
||||
tierSize = wireIn.read(() -> "tierSize").int64();
|
||||
|
||||
maxExtraTiers = wireIn.read(() -> "maxExtraTiers").int64();
|
||||
tierBulkSizeInBytes = wireIn.read(() -> "tierBulkSizeInBytes").int64();
|
||||
tierBulkInnerOffsetToTiers = wireIn.read(() -> "tierBulkInnerOffsetToTiers").int64();
|
||||
tiersInBulk = wireIn.read(() -> "tiersInBulk").int64();
|
||||
log2TiersInBulk = wireIn.read(() -> "log2TiersInBulk").int32();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "dataFileVersion").text(dataFileVersion);
|
||||
|
||||
wireOut.write(() -> "keyClass").typeLiteral(keyClass);
|
||||
wireOut.write(() -> "keySizeMarshaller").typedMarshallable(keySizeMarshaller);
|
||||
wireOut.write(() -> "keyReader").typedMarshallable(keyReader);
|
||||
wireOut.write(() -> "keyDataAccess").typedMarshallable(keyDataAccess);
|
||||
|
||||
wireOut.write(() -> "checksumEntries").bool(checksumEntries);
|
||||
|
||||
wireOut.write(() -> "actualSegments").int32(actualSegments);
|
||||
wireOut.write(() -> "hashSplitting").typedMarshallable(hashSplitting);
|
||||
|
||||
wireOut.write(() -> "entriesPerSegment").int64(entriesPerSegment);
|
||||
|
||||
wireOut.write(() -> "chunkSize").int64(chunkSize);
|
||||
wireOut.write(() -> "maxChunksPerEntry").int32(maxChunksPerEntry);
|
||||
wireOut.write(() -> "actualChunksPerSegment").int64(actualChunksPerSegment);
|
||||
|
||||
wireOut.write(() -> "segmentHeaderSize").int32(segmentHeaderSize);
|
||||
|
||||
wireOut.write(() -> "tierHashLookupValueBits").int32(tierHashLookupValueBits);
|
||||
wireOut.write(() -> "tierHashLookupKeyBits").int32(tierHashLookupKeyBits);
|
||||
wireOut.write(() -> "tierHashLookupEntrySize").int32(tierHashLookupEntrySize);
|
||||
wireOut.write(() -> "tierHashLookupCapacity").int64(tierHashLookupCapacity);
|
||||
wireOut.write(() -> "tierHashLookupInnerSize").int64(tierHashLookupInnerSize);
|
||||
wireOut.write(() -> "tierHashLookupOuterSize").int64(tierHashLookupOuterSize);
|
||||
|
||||
wireOut.write(() -> "tierFreeListInnerSize").int64(tierFreeListInnerSize);
|
||||
wireOut.write(() -> "tierFreeListOuterSize").int64(tierFreeListOuterSize);
|
||||
|
||||
wireOut.write(() -> "tierEntrySpaceInnerSize").int64(tierEntrySpaceInnerSize);
|
||||
wireOut.write(() -> "tierEntrySpaceInnerOffset").int32(tierEntrySpaceInnerOffset);
|
||||
wireOut.write(() -> "tierEntrySpaceOuterSize").int64(tierEntrySpaceOuterSize);
|
||||
|
||||
wireOut.write(() -> "tierSize").int64(tierSize);
|
||||
|
||||
wireOut.write(() -> "maxExtraTiers").int64(maxExtraTiers);
|
||||
wireOut.write(() -> "tierBulkSizeInBytes").int64(tierBulkSizeInBytes);
|
||||
wireOut.write(() -> "tierBulkInnerOffsetToTiers").int64(tierBulkInnerOffsetToTiers);
|
||||
wireOut.write(() -> "tiersInBulk").int64(tiersInBulk);
|
||||
wireOut.write(() -> "log2TiersInBulk").int32(log2TiersInBulk);
|
||||
}
|
||||
|
||||
protected VanillaGlobalMutableState createGlobalMutableState() {
|
||||
return Values.newNativeReference(VanillaGlobalMutableState.class);
|
||||
}
|
||||
@@ -222,8 +322,8 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
private long segmentSize() {
|
||||
long ss = segmentHashLookupOuterSize + TIER_COUNTERS_AREA_SIZE +
|
||||
segmentFreeListOuterSize + segmentEntrySpaceOuterSize;
|
||||
long ss = tierHashLookupOuterSize + TIER_COUNTERS_AREA_SIZE +
|
||||
tierFreeListOuterSize + tierEntrySpaceOuterSize;
|
||||
if ((ss & 63L) != 0)
|
||||
throw new AssertionError();
|
||||
return breakL1CacheAssociativityContention(ss);
|
||||
@@ -245,14 +345,14 @@ public abstract class VanillaChronicleHash<K,
|
||||
// TODO review heuristics
|
||||
int tiersInBulk = actualSegments / 8;
|
||||
tiersInBulk = Maths.nextPower2(tiersInBulk, 1);
|
||||
while (segmentSize * tiersInBulk < OS.pageSize()) {
|
||||
while (tierSize * tiersInBulk < OS.pageSize()) {
|
||||
tiersInBulk *= 2;
|
||||
}
|
||||
return tiersInBulk;
|
||||
}
|
||||
|
||||
private long computeTierBulkBytesSize(long tiersInBulk) {
|
||||
return computeTierBulkInnerOffsetToTiers(tiersInBulk) + tiersInBulk * segmentSize;
|
||||
return computeTierBulkInnerOffsetToTiers(tiersInBulk) + tiersInBulk * tierSize;
|
||||
}
|
||||
|
||||
protected long computeTierBulkInnerOffsetToTiers(long tiersInBulk) {
|
||||
@@ -266,13 +366,13 @@ public abstract class VanillaChronicleHash<K,
|
||||
private void initOwnTransients() {
|
||||
globalMutableState = createGlobalMutableState();
|
||||
tierBulkOffsets = new ArrayList<>();
|
||||
if (segmentHashLookupEntrySize == 4) {
|
||||
if (tierHashLookupEntrySize == 4) {
|
||||
hashLookup = new IntCompactOffHeapLinearHashTable(this);
|
||||
} else if (segmentHashLookupEntrySize == 8) {
|
||||
} else if (tierHashLookupEntrySize == 8) {
|
||||
hashLookup = new LongCompactOffHeapLinearHashTable(this);
|
||||
} else {
|
||||
throw new AssertionError("hash lookup slot size could be 4 or 8, " +
|
||||
segmentHashLookupEntrySize + " observed");
|
||||
tierHashLookupEntrySize + " observed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,15 +426,14 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
}
|
||||
|
||||
public final void createMappedStoreAndSegments(File file) throws IOException {
|
||||
public final void createMappedStoreAndSegments(File file, RandomAccessFile raf)
|
||||
throws IOException {
|
||||
// TODO this method had been moved -- not clear where
|
||||
//OS.warnOnWindows(sizeInBytesWithoutTiers());
|
||||
this.file = file;
|
||||
long mapSize = createdOrInMemory ? pageAlign(sizeInBytesWithoutTiers()) :
|
||||
expectedFileSize();
|
||||
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
|
||||
createMappedStoreAndSegments(map(raf, mapSize, 0));
|
||||
}
|
||||
createMappedStoreAndSegments(map(raf, mapSize, 0));
|
||||
}
|
||||
|
||||
private boolean persisted() {
|
||||
@@ -371,7 +470,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
private void zeroOutNewlyMappedTier(BytesStore bytesStore, long segmentOffset) {
|
||||
// Zero out hash lookup, tier data and free list bit set. Leave entry space.
|
||||
bytesStore.zeroOut(segmentOffset, segmentOffset + segmentSize - segmentEntrySpaceOuterSize);
|
||||
bytesStore.zeroOut(segmentOffset, segmentOffset + tierSize - tierEntrySpaceOuterSize);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
@@ -410,7 +509,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public final long sizeInBytesWithoutTiers() {
|
||||
return segmentHeadersOffset() + actualSegments * (segmentHeaderSize + segmentSize);
|
||||
return segmentHeadersOffset() + actualSegments * (segmentHeaderSize + tierSize);
|
||||
}
|
||||
|
||||
public final long expectedFileSize() {
|
||||
@@ -434,9 +533,9 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
public final void checkKey(Object key) {
|
||||
if (!kClass.isInstance(key)) {
|
||||
if (!keyClass.isInstance(key)) {
|
||||
// key.getClass will cause NPE exactly as needed
|
||||
throw new ClassCastException("Key must be a " + kClass.getName() +
|
||||
throw new ClassCastException("Key must be a " + keyClass.getName() +
|
||||
" but was a " + key.getClass());
|
||||
}
|
||||
}
|
||||
@@ -465,7 +564,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
|
||||
private long segmentOffset(long segmentIndex) {
|
||||
return segmentsOffset + segmentIndex * segmentSize;
|
||||
return segmentsOffset + segmentIndex * tierSize;
|
||||
}
|
||||
|
||||
public final int inChunks(long sizeInBytes) {
|
||||
@@ -557,7 +656,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
BytesStore allocatedTierBytes = tierBytesStore(firstFreeTierIndex);
|
||||
long allocatedTierOffset = tierBytesOffset(firstFreeTierIndex);
|
||||
long tierBaseAddr = allocatedTierBytes.address(0) + allocatedTierOffset;
|
||||
long tierCountersAreaAddr = tierBaseAddr + segmentHashLookupOuterSize;
|
||||
long tierCountersAreaAddr = tierBaseAddr + tierHashLookupOuterSize;
|
||||
long nextFreeTierIndex = TierCountersArea.nextTierIndex(tierCountersAreaAddr);
|
||||
// now, when this tier will be a part of the map, the next tier designates
|
||||
// the next tier in the data structure, should be 0
|
||||
@@ -594,7 +693,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
long tierOffset = tierBytesOffset(tierIndex);
|
||||
zeroOutNewlyMappedTier(tierBytesStore, tierOffset);
|
||||
if (tierIndex < lastTierIndex) {
|
||||
long tierCountersAreaOffset = tierOffset + segmentHashLookupOuterSize;
|
||||
long tierCountersAreaOffset = tierOffset + tierHashLookupOuterSize;
|
||||
TierCountersArea.nextTierIndex(tierBytesStore.address(0) + tierCountersAreaOffset,
|
||||
tierIndex + 1);
|
||||
}
|
||||
@@ -632,7 +731,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
if (bulkIndex >= tierBulkOffsets.size())
|
||||
mapTierBulks(bulkIndex);
|
||||
return tierBulkOffsets.get(bulkIndex).offset + tierBulkInnerOffsetToTiers +
|
||||
(extraTierIndex & (tiersInBulk - 1)) * segmentSize;
|
||||
(extraTierIndex & (tiersInBulk - 1)) * tierSize;
|
||||
}
|
||||
|
||||
private TierBulkData tierBulkData(long tierIndexMinusOne) {
|
||||
@@ -655,7 +754,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
protected long tierAddr(TierBulkData tierBulkData, long tierIndexOffsetWithinBulk) {
|
||||
return tierBulkData.bytesStore.address(0) + tierBulkData.offset +
|
||||
tierBulkInnerOffsetToTiers + tierIndexOffsetWithinBulk * segmentSize;
|
||||
tierBulkInnerOffsetToTiers + tierIndexOffsetWithinBulk * tierSize;
|
||||
}
|
||||
|
||||
private void mapTierBulks(int upToBulkIndex) {
|
||||
|
||||
@@ -506,7 +506,7 @@ public abstract class SegmentStages implements SegmentLock, LocksInterface {
|
||||
}
|
||||
|
||||
public long tierCountersAreaAddr() {
|
||||
return segmentBaseAddr + hh.h().segmentHashLookupOuterSize;
|
||||
return segmentBaseAddr + hh.h().tierHashLookupOuterSize;
|
||||
}
|
||||
|
||||
public long nextTierIndex() {
|
||||
@@ -584,14 +584,14 @@ public abstract class SegmentStages implements SegmentLock, LocksInterface {
|
||||
VanillaChronicleHash<?, ?, ?, ?> h = hh.h();
|
||||
|
||||
long segmentBaseAddr = this.segmentBaseAddr;
|
||||
segmentBS.set(segmentBaseAddr, h.segmentSize);
|
||||
segmentBS.set(segmentBaseAddr, h.tierSize);
|
||||
segmentBytes.clear();
|
||||
|
||||
long freeListOffset = h.segmentHashLookupOuterSize + TIER_COUNTERS_AREA_SIZE;
|
||||
long freeListOffset = h.tierHashLookupOuterSize + TIER_COUNTERS_AREA_SIZE;
|
||||
freeList.setOffset(segmentBaseAddr + freeListOffset);
|
||||
|
||||
entrySpaceOffset = freeListOffset + h.segmentFreeListOuterSize +
|
||||
h.segmentEntrySpaceInnerOffset;
|
||||
entrySpaceOffset = freeListOffset + h.tierFreeListOuterSize +
|
||||
h.tierEntrySpaceInnerOffset;
|
||||
}
|
||||
|
||||
@Stage("Segment")
|
||||
|
||||
@@ -28,5 +28,5 @@ public class KeyBytesInterop<K> {
|
||||
|
||||
@StageRef VanillaChronicleHashHolder<K> hh;
|
||||
|
||||
public final SizedReader<K> keyReader = copyIfNeeded(hh.h().originalKeyReader);
|
||||
public final SizedReader<K> keyReader = copyIfNeeded(hh.h().keyReader);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class HashQuery<K> implements HashEntry<K> {
|
||||
@StageRef public HashLookupPos hlp;
|
||||
@StageRef public KeySearch<K> ks;
|
||||
|
||||
final DataAccess<K> innerInputKeyDataAccess = hh.h().originalKeyDataAccess.copy();
|
||||
final DataAccess<K> innerInputKeyDataAccess = hh.h().keyDataAccess.copy();
|
||||
|
||||
/**
|
||||
* This stage exists for hooking {@link #innerInputKeyDataAccess} usage, to trigger {@link
|
||||
|
||||
@@ -18,6 +18,7 @@ package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.ReadBytesMarshallable;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -28,8 +29,7 @@ import java.io.Serializable;
|
||||
* @param <T> type of objects deserialized
|
||||
* @see BytesWriter
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface BytesReader<T> extends Serializable {
|
||||
public interface BytesReader<T> extends Serializable, Marshallable {
|
||||
|
||||
/**
|
||||
* Reads and returns the object from {@link Bytes#readPosition()} (i. e. the current position)
|
||||
|
||||
@@ -18,6 +18,7 @@ package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.WriteBytesMarshallable;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -28,8 +29,7 @@ import java.io.Serializable;
|
||||
* @param <T> the type of objects serialized
|
||||
* @see BytesReader
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface BytesWriter<T> extends Serializable {
|
||||
public interface BytesWriter<T> extends Serializable, Marshallable {
|
||||
|
||||
/**
|
||||
* Serializes the given object to the given {@code out}.
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface DataAccess<T> extends StatefulCopyable<DataAccess<T>>, Serializable {
|
||||
public interface DataAccess<T> extends StatefulCopyable<DataAccess<T>>, Serializable, Marshallable {
|
||||
|
||||
Data<T> getData(@NotNull T instance);
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -58,8 +61,8 @@ public class ListMarshaller<T>
|
||||
implements BytesReader<List<T>>, BytesWriter<List<T>>, StatefulCopyable<ListMarshaller<T>> {
|
||||
|
||||
// Config fields
|
||||
private final BytesReader<T> elementReader;
|
||||
private final BytesWriter<? super T> elementWriter;
|
||||
private BytesReader<T> elementReader;
|
||||
private BytesWriter<? super T> elementWriter;
|
||||
|
||||
public ListMarshaller(BytesReader<T> elementReader, BytesWriter<? super T> elementWriter) {
|
||||
this.elementReader = elementReader;
|
||||
@@ -104,4 +107,16 @@ public class ListMarshaller<T>
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
elementReader = wireIn.read(() -> "elementReader").typedMarshallable();
|
||||
elementWriter = wireIn.read(() -> "elementWriter").typedMarshallable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "elementReader").typedMarshallable(elementReader);
|
||||
wireOut.write(() -> "elementWriter").typedMarshallable(elementWriter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -52,10 +55,10 @@ public class MapMarshaller<K, V>
|
||||
StatefulCopyable<MapMarshaller<K, V>> {
|
||||
|
||||
// Config fields
|
||||
private final BytesReader<K> keyReader;
|
||||
private final BytesWriter<? super K> keyWriter;
|
||||
private final BytesReader<V> valueReader;
|
||||
private final BytesWriter<? super V> valueWriter;
|
||||
private BytesReader<K> keyReader;
|
||||
private BytesWriter<? super K> keyWriter;
|
||||
private BytesReader<V> valueReader;
|
||||
private BytesWriter<? super V> valueWriter;
|
||||
|
||||
// Cache fields
|
||||
private transient Deque<K> orderedKeys;
|
||||
@@ -120,4 +123,21 @@ public class MapMarshaller<K, V>
|
||||
return new MapMarshaller<>(copyIfNeeded(keyReader), copyIfNeeded(keyWriter),
|
||||
copyIfNeeded(valueReader), copyIfNeeded(valueWriter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
keyReader = wireIn.read(() -> "keyReader").typedMarshallable();
|
||||
keyWriter = wireIn.read(() -> "keyWriter").typedMarshallable();
|
||||
valueReader = wireIn.read(() -> "valueReader").typedMarshallable();
|
||||
valueWriter = wireIn.read(() -> "valueWriter").typedMarshallable();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "keyReader").typedMarshallable(keyReader);
|
||||
wireOut.write(() -> "keyWriter").typedMarshallable(keyWriter);
|
||||
wireOut.write(() -> "valueReader").typedMarshallable(valueReader);
|
||||
wireOut.write(() -> "valueWriter").typedMarshallable(valueWriter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -59,8 +62,8 @@ public class SetMarshaller<T>
|
||||
implements BytesReader<Set<T>>, BytesWriter<Set<T>>, StatefulCopyable<SetMarshaller<T>> {
|
||||
|
||||
// Config fields
|
||||
private final BytesReader<T> elementReader;
|
||||
private final BytesWriter<? super T> elementWriter;
|
||||
private BytesReader<T> elementReader;
|
||||
private BytesWriter<? super T> elementWriter;
|
||||
|
||||
/** Cache field */
|
||||
private transient Deque<T> orderedElements;
|
||||
@@ -110,4 +113,17 @@ public class SetMarshaller<T>
|
||||
public SetMarshaller<T> copy() {
|
||||
return new SetMarshaller<>(copyIfNeeded(elementReader), copyIfNeeded(elementWriter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
elementReader = wireIn.read(() -> "elementReader").typedMarshallable();
|
||||
elementWriter = wireIn.read(() -> "elementWriter").typedMarshallable();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "elementReader").typedMarshallable(elementReader);
|
||||
wireOut.write(() -> "elementWriter").typedMarshallable(elementWriter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.openhft.chronicle.hash.serialization;
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.serialization.impl.ConstantSizeMarshaller;
|
||||
import net.openhft.chronicle.hash.serialization.impl.StopBitSizeMarshaller;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -36,7 +37,7 @@ import java.io.Serializable;
|
||||
* value (it's constant size). If the marshaller is fed with the size it is not able store, it could
|
||||
* throw an {@code IllegalArgumentException}.
|
||||
*/
|
||||
public interface SizeMarshaller extends Serializable {
|
||||
public interface SizeMarshaller extends Serializable, Marshallable {
|
||||
|
||||
static SizeMarshaller stopBit() {
|
||||
return StopBitSizeMarshaller.INSTANCE;
|
||||
|
||||
@@ -18,6 +18,7 @@ package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.ChronicleHash;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -31,7 +32,8 @@ import java.io.Serializable;
|
||||
* <p>Implementation example:<pre><code>
|
||||
* class LongPair { long first, second; }
|
||||
*
|
||||
* enum LongPairArrayReader implements{@code SizedReader<LongPair[]>} {
|
||||
* enum LongPairArrayReader
|
||||
* implements{@code SizedReader<LongPair[]>, EnumMarshallable<LongPairArrayReader>} {
|
||||
* INSTANCE;
|
||||
*
|
||||
* {@literal @}Override
|
||||
@@ -60,13 +62,17 @@ import java.io.Serializable;
|
||||
* }
|
||||
* return res;
|
||||
* }
|
||||
*
|
||||
* {@literal @}Override
|
||||
* public LongPairArrayReader readResolve() {
|
||||
* return INSTANCE;
|
||||
* }
|
||||
* }</code></pre>
|
||||
*
|
||||
* @param <T> the type of the object deserialized
|
||||
* @see SizedWriter
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface SizedReader<T> extends Serializable {
|
||||
public interface SizedReader<T> extends Serializable, Marshallable {
|
||||
|
||||
/**
|
||||
* Reads and returns the object from {@link Bytes#readPosition()} (i. e. the current position)
|
||||
|
||||
@@ -18,6 +18,7 @@ package net.openhft.chronicle.hash.serialization;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.ChronicleHash;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -31,7 +32,8 @@ import java.io.Serializable;
|
||||
* <p>Implementation example: <pre><code>
|
||||
* class LongPair { long first, second; }
|
||||
*
|
||||
* enum LongPairArrayWriter implements{@code SizedWriter<LongPair[]>} {
|
||||
* enum LongPairArrayWriter
|
||||
* implements{@code SizedWriter<LongPair[]>, EnumMarshallable<LongPairArrayWriter>} {
|
||||
* INSTANCE;
|
||||
*
|
||||
* {@literal @}Override
|
||||
@@ -47,12 +49,17 @@ import java.io.Serializable;
|
||||
* out.writeLong(pair.second);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* {@literal @}Override
|
||||
* public LongPairArrayWriter readResolve() {
|
||||
* return INSTANCE;
|
||||
* }
|
||||
* }</code></pre>
|
||||
*
|
||||
* @param <T> the type of the object marshalled
|
||||
* @see SizedReader
|
||||
*/
|
||||
public interface SizedWriter<T> extends Serializable {
|
||||
public interface SizedWriter<T> extends Serializable, Marshallable {
|
||||
|
||||
/**
|
||||
* Returns the length (in bytes) of the serialized form of the given object. Serialization form
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum BooleanMarshaller
|
||||
implements SizedReader<Boolean>, BytesReader<Boolean>,
|
||||
SizedWriter<Boolean>, BytesWriter<Boolean> {
|
||||
SizedWriter<Boolean>, BytesWriter<Boolean>, EnumMarshallable<BooleanMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -55,4 +55,9 @@ public enum BooleanMarshaller
|
||||
public void write(Bytes out, @NotNull Boolean toWrite) {
|
||||
out.writeByte((byte) (toWrite ? 'Y' : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.HeapBytesStore;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -93,4 +96,15 @@ public class ByteArrayDataAccess extends AbstractData<byte[]> implements DataAcc
|
||||
public DataAccess<byte[]> copy() {
|
||||
return new ByteArrayDataAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
// no fields to read
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
// no fields to write
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -21,7 +21,8 @@ import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum ByteArraySizedReader implements SizedReader<byte[]> {
|
||||
public enum ByteArraySizedReader
|
||||
implements SizedReader<byte[]>, EnumMarshallable<ByteArraySizedReader> {
|
||||
INSTANCE;
|
||||
|
||||
@NotNull
|
||||
@@ -40,4 +41,9 @@ public enum ByteArraySizedReader implements SizedReader<byte[]> {
|
||||
size + " given. Memory corruption?");
|
||||
return (int) size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteArraySizedReader readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import net.openhft.chronicle.bytes.*;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
@@ -116,4 +118,15 @@ public class ByteBufferDataAccess extends AbstractData<ByteBuffer>
|
||||
public DataAccess<ByteBuffer> copy() {
|
||||
return new ByteBufferDataAccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
// no fields to read
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
// no fields to write
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -23,7 +23,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public enum ByteBufferSizedReader implements SizedReader<ByteBuffer> {
|
||||
public enum ByteBufferSizedReader
|
||||
implements SizedReader<ByteBuffer>, EnumMarshallable<ByteBufferSizedReader> {
|
||||
INSTANCE;
|
||||
|
||||
@NotNull
|
||||
@@ -43,4 +44,9 @@ public enum ByteBufferSizedReader implements SizedReader<ByteBuffer> {
|
||||
using.flip();
|
||||
return using;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBufferSizedReader readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,12 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Byteable;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -89,6 +92,6 @@ public class ByteableDataAccess<T extends Byteable> extends InstanceCreatingMars
|
||||
|
||||
@Override
|
||||
public DataAccess<T> copy() {
|
||||
return new ByteableDataAccess<>(tClass);
|
||||
return new ByteableDataAccess<>(tClass());
|
||||
}
|
||||
}
|
||||
|
||||
+14
-1
@@ -17,9 +17,12 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -27,7 +30,7 @@ public class BytesAsSizedReader<T>
|
||||
implements SizedReader<T>, StatefulCopyable<BytesAsSizedReader<T>> {
|
||||
|
||||
/** Config field */
|
||||
private final BytesReader<T> reader;
|
||||
private BytesReader<T> reader;
|
||||
|
||||
public BytesAsSizedReader(BytesReader<T> reader) {
|
||||
this.reader = reader;
|
||||
@@ -47,4 +50,14 @@ public class BytesAsSizedReader<T>
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
reader = wireIn.read(() -> "reader").typedMarshallable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "reader").typedMarshallable(reader);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -18,9 +18,11 @@ package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.BytesMarshallable;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -41,6 +43,12 @@ public class BytesMarshallableDataAccess<T extends BytesMarshallable>
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
super.readMarshallable(wireIn);
|
||||
initTransients();
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
initTransients();
|
||||
@@ -109,6 +117,6 @@ public class BytesMarshallableDataAccess<T extends BytesMarshallable>
|
||||
|
||||
@Override
|
||||
public DataAccess<T> copy() {
|
||||
return new BytesMarshallableDataAccess<>(tClass);
|
||||
return new BytesMarshallableDataAccess<>(tClass());
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -30,11 +30,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
*
|
||||
* @see CharSequenceBytesWriter
|
||||
*/
|
||||
public enum CharSequenceBytesWriter implements BytesWriter<CharSequence> {
|
||||
public enum CharSequenceBytesWriter
|
||||
implements BytesWriter<CharSequence>, EnumMarshallable<CharSequenceBytesWriter> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public void write(Bytes out, @NotNull CharSequence toWrite) {
|
||||
out.writeUtf8(toWrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequenceBytesWriter readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -18,8 +18,11 @@ package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.BytesUtil;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -70,4 +73,15 @@ public class CharSequenceSizedReader
|
||||
public CharSequenceSizedReader copy() {
|
||||
return new CharSequenceSizedReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
// no fields to read
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
// no fields to write
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -21,7 +21,8 @@ import net.openhft.chronicle.bytes.BytesUtil;
|
||||
import net.openhft.chronicle.hash.serialization.SizedWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum CharSequenceSizedWriter implements SizedWriter<CharSequence> {
|
||||
public enum CharSequenceSizedWriter
|
||||
implements SizedWriter<CharSequence>, EnumMarshallable<CharSequenceSizedWriter> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -33,4 +34,9 @@ public enum CharSequenceSizedWriter implements SizedWriter<CharSequence> {
|
||||
public void write(@NotNull Bytes out, long size, @NotNull CharSequence toWrite) {
|
||||
BytesUtil.appendUtf8(out, toWrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequenceSizedWriter readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -17,12 +17,16 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ConstantSizeMarshaller implements SizeMarshaller {
|
||||
|
||||
/** Config field */
|
||||
private final long constantSize;
|
||||
private long constantSize;
|
||||
|
||||
public ConstantSizeMarshaller(long constantSize) {
|
||||
this.constantSize = constantSize;
|
||||
@@ -62,4 +66,14 @@ public final class ConstantSizeMarshaller implements SizeMarshaller {
|
||||
public long readSize(Bytes in) {
|
||||
return constantSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
constantSize = wireIn.read(() -> "constantSize").int64();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "constantSize").int64(constantSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum DoubleMarshaller
|
||||
implements SizedReader<Double>, BytesReader<Double>,
|
||||
SizedWriter<Double>, BytesWriter<Double> {
|
||||
SizedWriter<Double>, BytesWriter<Double>, EnumMarshallable<DoubleMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@NotNull
|
||||
@@ -55,4 +55,9 @@ public enum DoubleMarshaller
|
||||
public void write(Bytes out, @NotNull Double toWrite) {
|
||||
out.writeDouble(toWrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
+21
-3
@@ -17,11 +17,14 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -34,8 +37,8 @@ public class ExternalBytesMarshallableDataAccess<T> extends InstanceCreatingMars
|
||||
implements DataAccess<T>, Data<T> {
|
||||
|
||||
// Config fields
|
||||
private final SizedReader<T> reader;
|
||||
private final BytesWriter<? super T> writer;
|
||||
private SizedReader<T> reader;
|
||||
private BytesWriter<? super T> writer;
|
||||
|
||||
/** Cache field */
|
||||
private transient Bytes bytes;
|
||||
@@ -120,6 +123,21 @@ public class ExternalBytesMarshallableDataAccess<T> extends InstanceCreatingMars
|
||||
@Override
|
||||
public DataAccess<T> copy() {
|
||||
return new ExternalBytesMarshallableDataAccess<>(
|
||||
tClass, copyIfNeeded(reader), copyIfNeeded(writer));
|
||||
tClass(), copyIfNeeded(reader), copyIfNeeded(writer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
super.readMarshallable(wireIn);
|
||||
reader = wireIn.read(() -> "reader").typedMarshallable();
|
||||
writer = wireIn.read(() -> "writer").typedMarshallable();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
super.writeMarshallable(wireOut);
|
||||
wireOut.write(() -> "reader").typedMarshallable(reader);
|
||||
wireOut.write(() -> "writer").typedMarshallable(writer);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-1
@@ -16,8 +16,11 @@
|
||||
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -29,12 +32,16 @@ import java.io.ObjectOutputStream;
|
||||
public class ExternalizableDataAccess<T extends Externalizable> extends SerializableDataAccess<T> {
|
||||
|
||||
/** Config field */
|
||||
protected final Class<T> tClass;
|
||||
private Class<T> tClass;
|
||||
|
||||
public ExternalizableDataAccess(Class<T> tClass) {
|
||||
this.tClass = tClass;
|
||||
}
|
||||
|
||||
protected Class<T> tClass() {
|
||||
return tClass;
|
||||
}
|
||||
|
||||
protected T createInstance() {
|
||||
try {
|
||||
return tClass.newInstance();
|
||||
@@ -74,4 +81,15 @@ public class ExternalizableDataAccess<T extends Externalizable> extends Serializ
|
||||
public DataAccess<T> copy() {
|
||||
return new ExternalizableDataAccess<>(tClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
tClass = wireIn.read(() -> "tClass").typeLiteral();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "tClass").typeLiteral(tClass);
|
||||
}
|
||||
}
|
||||
|
||||
+25
-6
@@ -16,13 +16,17 @@
|
||||
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* Holds new instance creation logic, common for many {@link DataAccess} and {@link SizedReader}
|
||||
@@ -30,12 +34,9 @@ import java.lang.reflect.Constructor;
|
||||
*
|
||||
* @param <T> the type of objects deserialized
|
||||
*/
|
||||
public abstract class InstanceCreatingMarshaller<T> implements Serializable {
|
||||
public abstract class InstanceCreatingMarshaller<T> implements Serializable, Marshallable {
|
||||
|
||||
/**
|
||||
* The class of objects deserialized.
|
||||
*/
|
||||
protected final Class<T> tClass;
|
||||
private Class<T> tClass;
|
||||
|
||||
/**
|
||||
* Constructor for use in subclasses.
|
||||
@@ -46,6 +47,13 @@ public abstract class InstanceCreatingMarshaller<T> implements Serializable {
|
||||
this.tClass = tClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class of objects deserialized.
|
||||
*/
|
||||
protected Class<T> tClass() {
|
||||
return tClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code T} instance by calling {@link Class#newInstance()}. If you need
|
||||
* different logic, i. e. calling a constructor with parameter, override this method in a
|
||||
@@ -70,4 +78,15 @@ public abstract class InstanceCreatingMarshaller<T> implements Serializable {
|
||||
"Chronicle Map via keyMarshaller[s]() or valueMarshaller[s]() methods", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
//noinspection unchecked
|
||||
tClass = wireIn.read(() -> "tClass").typeLiteral();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "tClass").typeLiteral(tClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum IntegerMarshaller
|
||||
implements SizedReader<Integer>, BytesReader<Integer>,
|
||||
SizedWriter<Integer>, BytesWriter<Integer> {
|
||||
SizedWriter<Integer>, BytesWriter<Integer>, EnumMarshallable<IntegerMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@NotNull
|
||||
@@ -55,4 +55,9 @@ public enum IntegerMarshaller
|
||||
public void write(Bytes out, @NotNull Integer toWrite) {
|
||||
out.writeInt(toWrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntegerMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum LongMarshaller
|
||||
implements SizedReader<Long>, BytesReader<Long>,
|
||||
SizedWriter<Long>, BytesWriter<Long> {
|
||||
SizedWriter<Long>, BytesWriter<Long>, EnumMarshallable<LongMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -55,4 +55,9 @@ public enum LongMarshaller
|
||||
public void write(Bytes out, @NotNull Long toWrite) {
|
||||
out.writeLong(toWrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,6 +37,6 @@ public class NotReusingSizedMarshallableDataAccess<T> extends SizedMarshallableD
|
||||
@Override
|
||||
public DataAccess<T> copy() {
|
||||
return new NotReusingSizedMarshallableDataAccess<>(
|
||||
tClass, copyIfNeeded(sizedReader), copyIfNeeded(sizedWriter));
|
||||
tClass(), copyIfNeeded(sizedReader()), copyIfNeeded(sizedWriter()));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -17,10 +17,13 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -46,7 +49,7 @@ public class SerializableDataAccess<T extends Serializable> extends AbstractData
|
||||
initTransients();
|
||||
}
|
||||
|
||||
private void initTransients() {
|
||||
void initTransients() {
|
||||
bytes = Bytes.allocateElasticDirect(1);
|
||||
out = bytes.outputStream();
|
||||
in = bytes.inputStream();
|
||||
@@ -107,4 +110,15 @@ public class SerializableDataAccess<T extends Serializable> extends AbstractData
|
||||
public DataAccess<T> copy() {
|
||||
return new SerializableDataAccess<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
// no fields to read
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
// no fields to write
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -44,4 +47,14 @@ public class SerializableReader<T extends Serializable>
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
// no fields to read
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
// no fields to write
|
||||
}
|
||||
}
|
||||
|
||||
+29
-3
@@ -17,11 +17,14 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.SizedWriter;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -34,8 +37,8 @@ public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T
|
||||
implements DataAccess<T>, Data<T> {
|
||||
|
||||
// Config fields
|
||||
final SizedReader<T> sizedReader;
|
||||
final SizedWriter<? super T> sizedWriter;
|
||||
private SizedReader<T> sizedReader;
|
||||
private SizedWriter<? super T> sizedWriter;
|
||||
|
||||
/** Cache field */
|
||||
private transient Bytes bytes;
|
||||
@@ -51,6 +54,14 @@ public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T
|
||||
initTransients();
|
||||
}
|
||||
|
||||
SizedReader<T> sizedReader() {
|
||||
return sizedReader;
|
||||
}
|
||||
|
||||
SizedWriter<? super T> sizedWriter() {
|
||||
return sizedWriter;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
initTransients();
|
||||
@@ -120,6 +131,21 @@ public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T
|
||||
@Override
|
||||
public DataAccess<T> copy() {
|
||||
return new SizedMarshallableDataAccess<>(
|
||||
tClass, copyIfNeeded(sizedReader), copyIfNeeded(sizedWriter));
|
||||
tClass(), copyIfNeeded(sizedReader), copyIfNeeded(sizedWriter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
super.readMarshallable(wireIn);
|
||||
sizedReader = wireIn.read(() -> "sizedReader").typedMarshallable();
|
||||
sizedWriter = wireIn.read(() -> "sizedWriter").typedMarshallable();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
super.writeMarshallable(wireOut);
|
||||
wireOut.write(() -> "sizedReader").typedMarshallable(sizedReader);
|
||||
wireOut.write(() -> "sizedWriter").typedMarshallable(sizedWriter);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -23,7 +23,8 @@ import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
public enum StopBitSizeMarshaller implements SizeMarshaller {
|
||||
public enum StopBitSizeMarshaller
|
||||
implements SizeMarshaller, EnumMarshallable<StopBitSizeMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
private static final long MIN_ENCODABLE_SIZE = Long.MIN_VALUE;
|
||||
@@ -75,4 +76,9 @@ public enum StopBitSizeMarshaller implements SizeMarshaller {
|
||||
public long readSize(Bytes in) {
|
||||
return BytesUtil.readStopBit(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StopBitSizeMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -22,7 +22,8 @@ import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum StringBuilderSizedReader implements SizedReader<StringBuilder> {
|
||||
public enum StringBuilderSizedReader
|
||||
implements SizedReader<StringBuilder>, EnumMarshallable<StringBuilderSizedReader> {
|
||||
INSTANCE;
|
||||
|
||||
@NotNull
|
||||
@@ -40,4 +41,9 @@ public enum StringBuilderSizedReader implements SizedReader<StringBuilder> {
|
||||
BytesUtil.parseUtf8(in, using, csLen);
|
||||
return using;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringBuilderSizedReader readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.ListMarshaller;
|
||||
import net.openhft.chronicle.hash.serialization.SetMarshaller;
|
||||
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -66,4 +69,15 @@ public class StringBytesReader
|
||||
public StringBytesReader copy() {
|
||||
return new StringBytesReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
// no fields to read
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
// no fields to write
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,11 @@ package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.BytesUtil;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -58,4 +61,15 @@ public class StringSizedReader implements SizedReader<String>, StatefulCopyable<
|
||||
public StringSizedReader copy() {
|
||||
return new StringSizedReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
// no fields to read
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
// no fields to write
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,15 @@
|
||||
package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Byteable;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.bytes.RandomDataInput;
|
||||
import net.openhft.chronicle.hash.AbstractData;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.values.Copyable;
|
||||
import net.openhft.chronicle.values.Values;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -33,12 +36,12 @@ import static net.openhft.chronicle.bytes.NativeBytesStore.nativeStoreWithFixedC
|
||||
|
||||
public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T> {
|
||||
|
||||
/** The interface of values serialized. */
|
||||
protected final Class<T> valueType;
|
||||
/** Config field */
|
||||
private Class<T> valueType;
|
||||
|
||||
// Cache fields
|
||||
protected transient Class<? extends T> nativeClass;
|
||||
protected transient Class<? extends T> heapClass;
|
||||
private transient Class<? extends T> nativeClass;
|
||||
private transient Class<? extends T> heapClass;
|
||||
private transient Byteable nativeInstance;
|
||||
private transient Copyable nativeInstanceAsCopyable;
|
||||
|
||||
@@ -50,6 +53,19 @@ public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T>
|
||||
initTransients();
|
||||
}
|
||||
|
||||
/** Returns the interface of values serialized. */
|
||||
protected Class<T> valueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
protected Class<? extends T> nativeClass() {
|
||||
return nativeClass;
|
||||
}
|
||||
|
||||
protected Class<? extends T> heapClass() {
|
||||
return heapClass;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
initTransients();
|
||||
@@ -120,4 +136,15 @@ public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T>
|
||||
public DataAccess<T> copy() {
|
||||
return new ValueDataAccess<>(valueType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
valueType = wireIn.read(() -> "valueType").typeLiteral();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "valueType").typeLiteral(valueType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,14 @@ package net.openhft.chronicle.hash.serialization.impl;
|
||||
|
||||
import net.openhft.chronicle.bytes.Byteable;
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.StatefulCopyable;
|
||||
import net.openhft.chronicle.values.Copyable;
|
||||
import net.openhft.chronicle.values.Values;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,12 +35,12 @@ import java.io.ObjectInputStream;
|
||||
public class ValueReader<T>
|
||||
implements SizedReader<T>, BytesReader<T>, StatefulCopyable<ValueReader<T>> {
|
||||
|
||||
/** The interface of values deserialized. */
|
||||
protected final Class<T> valueType;
|
||||
/** Config field */
|
||||
private Class<T> valueType;
|
||||
|
||||
// Cache fields
|
||||
protected transient Class<? extends T> heapClass;
|
||||
protected transient Class<? extends T> nativeClass;
|
||||
private transient Class<? extends T> nativeClass;
|
||||
private transient Class<? extends T> heapClass;
|
||||
private transient Byteable nativeReference;
|
||||
|
||||
public ValueReader(Class<T> valueType) {
|
||||
@@ -45,14 +48,27 @@ public class ValueReader<T>
|
||||
initTransients();
|
||||
}
|
||||
|
||||
/** Returns the interface of values deserialized. */
|
||||
protected Class<T> valueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
protected Class<? extends T> nativeClass() {
|
||||
return nativeClass;
|
||||
}
|
||||
|
||||
protected Class<? extends T> heapClass() {
|
||||
return heapClass;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
private void initTransients() {
|
||||
heapClass = Values.heapClassFor(valueType);
|
||||
nativeClass = Values.nativeClassFor(valueType);
|
||||
heapClass = Values.heapClassFor(valueType);
|
||||
nativeReference = (Byteable) Values.newNativeReference(valueType);
|
||||
}
|
||||
|
||||
@@ -92,4 +108,15 @@ public class ValueReader<T>
|
||||
public ValueReader<T> copy() {
|
||||
return new ValueReader<>(valueType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMarshallable(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
valueType = wireIn.read(() -> "valueType").typeLiteral();
|
||||
initTransients();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
wireOut.write(() -> "valueType").typeLiteral(valueType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.algo.MemoryUnit;
|
||||
import net.openhft.chronicle.bytes.Byteable;
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.BytesStore;
|
||||
import net.openhft.chronicle.core.OS;
|
||||
import net.openhft.chronicle.hash.ChronicleHashBuilder;
|
||||
@@ -31,11 +33,15 @@ import net.openhft.chronicle.map.replication.MapRemoteOperations;
|
||||
import net.openhft.chronicle.set.ChronicleSetBuilder;
|
||||
import net.openhft.chronicle.threads.NamedThreadFactory;
|
||||
import net.openhft.chronicle.values.ValueModel;
|
||||
import net.openhft.chronicle.wire.TextWire;
|
||||
import net.openhft.chronicle.wire.Wire;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -120,6 +126,8 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
return !isNaN(config);
|
||||
}
|
||||
|
||||
private static int MAX_BOOTSTRAPPING_HEADER_SIZE = (int) MemoryUnit.KILOBYTES.toBytes(16);
|
||||
|
||||
// not final because of cloning
|
||||
private ChronicleMapBuilderPrivateAPI<K> privateAPI = new ChronicleMapBuilderPrivateAPI<>(this);
|
||||
|
||||
@@ -515,7 +523,7 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
if (worstAlignmentComputationRequiresValueSize(alignment)) {
|
||||
long constantSizeBeforeAlignment = round(size);
|
||||
if (constantlySizedValues()) {
|
||||
// see segmentEntrySpaceInnerOffset()
|
||||
// see tierEntrySpaceInnerOffset()
|
||||
long totalDataSize = constantSizeBeforeAlignment + constantValueSize();
|
||||
worstAlignment = (int) (alignAddr(totalDataSize, alignment) - totalDataSize);
|
||||
} else {
|
||||
@@ -1364,28 +1372,29 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
for (int i = 0; i < 10; i++) {
|
||||
long fileLength = file.length();
|
||||
if (fileLength > 0) {
|
||||
try (FileInputStream fis = new FileInputStream(file);
|
||||
ObjectInputStream ois = new ObjectInputStream(fis)) {
|
||||
Object m;
|
||||
try {
|
||||
m = ois.readObject();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
VanillaChronicleMap<K, V, ?> map = (VanillaChronicleMap<K, V, ?>) m;
|
||||
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
|
||||
FileChannel fileChannel = raf.getChannel();
|
||||
ByteBuffer headerBuffer = ByteBuffer.allocate(MAX_BOOTSTRAPPING_HEADER_SIZE);
|
||||
fileChannel.read(headerBuffer);
|
||||
headerBuffer.flip();
|
||||
Bytes<ByteBuffer> headerBytes = Bytes.wrapForRead(headerBuffer);
|
||||
headerBytes.readLimit(headerBuffer.limit());
|
||||
Wire wire = new TextWire(headerBytes);
|
||||
VanillaChronicleMap<K, V, ?> map = wire.getValueIn().typedMarshallable();
|
||||
map.initTransientsFromBuilder(this);
|
||||
initTransientsFromReplication(map, singleHashReplication, channel);
|
||||
map.initBeforeMapping(fis.getChannel());
|
||||
|
||||
fileChannel.position(headerBytes.readPosition());
|
||||
map.initBeforeMapping(fileChannel);
|
||||
long expectedFileLength = map.expectedFileSize();
|
||||
if (expectedFileLength != fileLength) {
|
||||
throw new IOException("The file " + file + " the map is serialized from " +
|
||||
"has unexpected length " + fileLength + ", probably corrupted. " +
|
||||
"Expected length is " + expectedFileLength);
|
||||
}
|
||||
map.createMappedStoreAndSegments(file);
|
||||
map.createMappedStoreAndSegments(file, raf);
|
||||
establishReplication(map, singleHashReplication, channel);
|
||||
fis.getChannel().force(true);
|
||||
fileChannel.force(true);
|
||||
// TODO according to Self Boostrapping Data spec, should write "init complete"
|
||||
// byte *after* the above force instruction, see HCOLL-396
|
||||
return map;
|
||||
@@ -1406,12 +1415,17 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
|
||||
VanillaChronicleMap<K, V, ?> map = newMap(singleHashReplication, channel);
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(file);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
|
||||
oos.writeObject(map);
|
||||
oos.flush();
|
||||
map.initBeforeMapping(fos.getChannel());
|
||||
map.createMappedStoreAndSegments(file);
|
||||
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
|
||||
FileChannel fileChannel = raf.getChannel();
|
||||
ByteBuffer headerBuffer = ByteBuffer.allocate(MAX_BOOTSTRAPPING_HEADER_SIZE);
|
||||
Bytes<ByteBuffer> headerBytes = Bytes.wrapForWrite(headerBuffer);
|
||||
Wire wire = new TextWire(headerBytes);
|
||||
wire.getValueOut().typedMarshallable(map);
|
||||
|
||||
headerBuffer.limit((int) headerBytes.writePosition());
|
||||
fileChannel.write(headerBuffer);
|
||||
map.initBeforeMapping(fileChannel);
|
||||
map.createMappedStoreAndSegments(file, raf);
|
||||
}
|
||||
|
||||
return establishReplication(map, singleHashReplication, channel);
|
||||
|
||||
@@ -759,7 +759,7 @@ public class ReplicatedChronicleMap<K, V, R> extends VanillaChronicleMap<K, V, R
|
||||
tierBulkOffsets.get(iterationMainSegmentsAreaOrTierBulk);
|
||||
long tierBaseAddr = tierAddr(tierBulkData,
|
||||
segmentIndexOrTierIndexOffsetWithinBulk);
|
||||
long tierCountersAreaAddr = tierBaseAddr + segmentHashLookupOuterSize;
|
||||
long tierCountersAreaAddr = tierBaseAddr + tierHashLookupOuterSize;
|
||||
context.initSegmentIndex(
|
||||
TierCountersArea.segmentIndex(tierCountersAreaAddr));
|
||||
int tier = TierCountersArea.tier(tierCountersAreaAddr);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.bytes.IORuntimeException;
|
||||
import net.openhft.chronicle.core.io.Closeable;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.impl.VanillaChronicleHash;
|
||||
@@ -30,6 +31,8 @@ import net.openhft.chronicle.map.impl.CompiledMapIterationContext;
|
||||
import net.openhft.chronicle.map.impl.CompiledMapQueryContext;
|
||||
import net.openhft.chronicle.map.impl.ret.InstanceReturnValue;
|
||||
import net.openhft.chronicle.values.Values;
|
||||
import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -49,18 +52,19 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Value Data model
|
||||
final Class<V> vClass;
|
||||
public final SizeMarshaller valueSizeMarshaller;
|
||||
public final SizedReader<V> originalValueReader;
|
||||
public final DataAccess<V> originalValueDataAccess;
|
||||
Class<V> valueClass;
|
||||
public SizeMarshaller valueSizeMarshaller;
|
||||
public SizedReader<V> valueReader;
|
||||
public DataAccess<V> valueDataAccess;
|
||||
|
||||
public final boolean constantlySizedEntry;
|
||||
public boolean constantlySizedEntry;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Memory management and dependent fields
|
||||
public final int alignment;
|
||||
public final int worstAlignment;
|
||||
public final boolean couldNotDetermineAlignmentBeforeAllocation;
|
||||
public int alignment;
|
||||
public int worstAlignment;
|
||||
|
||||
public transient boolean couldNotDetermineAlignmentBeforeAllocation;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Behavior
|
||||
@@ -78,23 +82,51 @@ public class VanillaChronicleMap<K, V, R>
|
||||
public VanillaChronicleMap(ChronicleMapBuilder<K, V> builder) throws IOException {
|
||||
super(builder);
|
||||
SerializationBuilder<V> valueBuilder = builder.valueBuilder;
|
||||
vClass = valueBuilder.tClass;
|
||||
valueClass = valueBuilder.tClass;
|
||||
valueSizeMarshaller = valueBuilder.sizeMarshaller();
|
||||
originalValueReader = valueBuilder.reader();
|
||||
originalValueDataAccess = valueBuilder.dataAccess();
|
||||
valueReader = valueBuilder.reader();
|
||||
valueDataAccess = valueBuilder.dataAccess();
|
||||
|
||||
constantlySizedEntry = builder.constantlySizedEntries();
|
||||
|
||||
// Concurrency (number of segments), memory management and dependent fields
|
||||
alignment = builder.valueAlignment();
|
||||
worstAlignment = builder.worstAlignment();
|
||||
couldNotDetermineAlignmentBeforeAllocation =
|
||||
greatestCommonDivisor((int) chunkSize, alignment) != alignment;
|
||||
|
||||
initTransientsFromBuilder(builder);
|
||||
initTransients();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void readMarshallableFields(@NotNull WireIn wireIn) throws IORuntimeException {
|
||||
super.readMarshallableFields(wireIn);
|
||||
|
||||
valueClass = wireIn.read(() -> "valueClass").typeLiteral();
|
||||
valueSizeMarshaller = wireIn.read(() -> "valueSizeMarshaller").typedMarshallable();
|
||||
valueReader = wireIn.read(() -> "valueReader").typedMarshallable();
|
||||
valueDataAccess = wireIn.read(() -> "valueDataAccess").typedMarshallable();
|
||||
|
||||
constantlySizedEntry = wireIn.read(() -> "constantlySizedEntry").bool();
|
||||
|
||||
alignment = wireIn.read(() -> "alignment").int32();
|
||||
worstAlignment = wireIn.read(() -> "worstAlignment").int32();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeMarshallable(@NotNull WireOut wireOut) {
|
||||
super.writeMarshallable(wireOut);
|
||||
|
||||
wireOut.write(() -> "valueClass").typeLiteral(valueClass);
|
||||
wireOut.write(() -> "valueSizeMarshaller").typedMarshallable(valueSizeMarshaller);
|
||||
wireOut.write(() -> "valueReader").typedMarshallable(valueReader);
|
||||
wireOut.write(() -> "valueDataAccess").typedMarshallable(valueDataAccess);
|
||||
|
||||
wireOut.write(() -> "constantlySizedEntry").bool(constantlySizedEntry);
|
||||
|
||||
wireOut.write(() -> "alignment").int32(alignment);
|
||||
wireOut.write(() -> "worstAlignment").int32(worstAlignment);
|
||||
}
|
||||
|
||||
void initTransientsFromBuilder(ChronicleMapBuilder<K, V> builder) {
|
||||
putReturnsNull = builder.putReturnsNull();
|
||||
removeReturnsNull = builder.removeReturnsNull();
|
||||
@@ -111,6 +143,8 @@ public class VanillaChronicleMap<K, V, R>
|
||||
}
|
||||
|
||||
private void initOwnTransients() {
|
||||
couldNotDetermineAlignmentBeforeAllocation =
|
||||
greatestCommonDivisor((int) chunkSize, alignment) != alignment;
|
||||
cxt = new ThreadLocal<>();
|
||||
}
|
||||
|
||||
@@ -120,8 +154,8 @@ public class VanillaChronicleMap<K, V, R>
|
||||
}
|
||||
|
||||
public final V checkValue(Object value) {
|
||||
if (!vClass.isInstance(value)) {
|
||||
throw new ClassCastException("Value must be a " + vClass.getName() +
|
||||
if (!valueClass.isInstance(value)) {
|
||||
throw new ClassCastException("Value must be a " + valueClass.getName() +
|
||||
" but was a " + value.getClass());
|
||||
}
|
||||
return (V) value;
|
||||
@@ -129,12 +163,12 @@ public class VanillaChronicleMap<K, V, R>
|
||||
|
||||
@Override
|
||||
public Class<K> keyClass() {
|
||||
return kClass;
|
||||
return keyClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<V> valueClass() {
|
||||
return vClass;
|
||||
return valueClass;
|
||||
}
|
||||
|
||||
static <T> T newInstance(Class<T> aClass, boolean isKey) {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public class WrappedValueInstanceDataHolder<V> {
|
||||
|
||||
@StageRef VanillaChronicleMapHolder<?, V, ?> mh;
|
||||
|
||||
private final DataAccess<V> wrappedValueDataAccess = mh.m().originalValueDataAccess.copy();
|
||||
private final DataAccess<V> wrappedValueDataAccess = mh.m().valueDataAccess.copy();
|
||||
|
||||
private WrappedValueInstanceDataHolder<V> next;
|
||||
|
||||
|
||||
@@ -28,6 +28,6 @@ public class ValueBytesInterop<V> {
|
||||
|
||||
@StageRef VanillaChronicleMapHolder<?, V, ?> mh;
|
||||
|
||||
public final SizedReader<V> valueReader = copyIfNeeded(mh.m().originalValueReader);
|
||||
public final SizedReader<V> valueReader = copyIfNeeded(mh.m().valueReader);
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class MapQuery<K, V, R> extends HashQuery<K>
|
||||
|
||||
@StageRef public MapAbsentEntryHolder<K, V> absent;
|
||||
|
||||
final DataAccess<V> innerInputValueDataAccess = mh.m().originalValueDataAccess.copy();
|
||||
final DataAccess<V> innerInputValueDataAccess = mh.m().valueDataAccess.copy();
|
||||
|
||||
/** Same as {@link #inputKeyDataAccessInitialized} */
|
||||
@Stage("InputValueDataAccess") private boolean inputValueDataAccessInitialized = false;
|
||||
|
||||
@@ -20,10 +20,12 @@ import net.openhft.chronicle.bytes.Bytes;
|
||||
import net.openhft.chronicle.hash.Data;
|
||||
import net.openhft.chronicle.hash.serialization.DataAccess;
|
||||
import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
enum DummyValueMarshaller implements DataAccess<DummyValue>, SizedReader<DummyValue> {
|
||||
enum DummyValueMarshaller implements DataAccess<DummyValue>, SizedReader<DummyValue>,
|
||||
EnumMarshallable<DummyValueMarshaller> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
@@ -46,5 +48,10 @@ enum DummyValueMarshaller implements DataAccess<DummyValue>, SizedReader<DummyVa
|
||||
public DummyValue read(@NotNull Bytes in, long size, @Nullable DummyValue using) {
|
||||
return DummyValue.DUMMY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DummyValueMarshaller readResolve() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user