mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-234 fixing CHMUseCaseTest
This commit is contained in:
@@ -37,14 +37,16 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
final ChronicleMapBuilderI<K, V> delegate;
|
||||
|
||||
/**
|
||||
* Returns a new {@code ChronicleMapBuilder} instance which is able to {@linkplain #create() create} maps
|
||||
* with the specified key and value classes.
|
||||
* Returns a new {@code ChronicleMapBuilder} instance which is able to {@linkplain #create()
|
||||
* create} maps with the specified key and value classes.
|
||||
*
|
||||
* <p>{@code ChronicleMapBuilder} analyzes provided key and value classes and automatically chooses the
|
||||
* most specific internal builder.
|
||||
* <p>{@code ChronicleMapBuilder} analyzes provided key and value classes and automatically
|
||||
* chooses the most specific internal builder.
|
||||
*
|
||||
* @param keyClass class object used to infer key type and discover it's properties via reflection
|
||||
* @param valueClass class object used to infer value type and discover it's properties via reflection
|
||||
* @param keyClass class object used to infer key type and discover it's properties via
|
||||
* reflection
|
||||
* @param valueClass class object used to infer value type and discover it's properties via
|
||||
* reflection
|
||||
* @param <K> key type of the maps, created by the returned builder
|
||||
* @param <V> value type of the maps, created by the returned builder
|
||||
* @return a new builder for the given key and value classes
|
||||
@@ -67,6 +69,26 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
return new ChronicleMapBuilder<K, V>(builder);
|
||||
}
|
||||
|
||||
// todo - work in progress this will be changed me not today, so don't refactor this !
|
||||
public static <T> T newInstance(Class<T> interfaceClass, boolean isKey) {
|
||||
|
||||
|
||||
if (interfaceClass.isEnum())
|
||||
return isKey ? DataValueClasses.newDirectReference(interfaceClass) : DataValueClasses
|
||||
.newDirectInstance(interfaceClass);
|
||||
|
||||
else if (!offHeapReference(interfaceClass) && !interfaceClass.isInterface() &&
|
||||
!builtInType(interfaceClass)) {
|
||||
|
||||
// if (())
|
||||
// interfaceClass = DataValueClasses.directClassFor(interfaceClass);
|
||||
return DataValueClasses.newInstance(interfaceClass);
|
||||
|
||||
}
|
||||
return DataValueClasses.newDirectInstance(interfaceClass);
|
||||
|
||||
}
|
||||
|
||||
static boolean builtInType(Class clazz) {
|
||||
return clazz.getClassLoader() == Class.class.getClassLoader();
|
||||
}
|
||||
@@ -83,9 +105,9 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
* {@inheritDoc} With respect to {@linkplain #entryAndValueAlignment(Alignment) alignment}.
|
||||
*
|
||||
* <p>Note that the actual entrySize will be aligned to 4 (default {@linkplain
|
||||
* #entryAndValueAlignment(Alignment) entry alignment}). I. e. if you set entry size to 30, and entry
|
||||
* alignment is set to {@link Alignment#OF_4_BYTES}, the actual entry size will be 32 (30 aligned to 4
|
||||
* bytes).
|
||||
* #entryAndValueAlignment(Alignment) entry alignment}). I. e. if you set entry size to 30, and
|
||||
* entry alignment is set to {@link Alignment#OF_4_BYTES}, the actual entry size will be 32 (30
|
||||
* aligned to 4 bytes).
|
||||
*
|
||||
* @see #entryAndValueAlignment(Alignment) // * @see #entries(long)
|
||||
*/
|
||||
@@ -96,16 +118,16 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures alignment strategy of address in memory of entries and independently of address in memory of
|
||||
* values within entries in ChronicleMaps, created by this builder.
|
||||
* Configures alignment strategy of address in memory of entries and independently of address in
|
||||
* memory of values within entries in ChronicleMaps, created by this builder.
|
||||
*
|
||||
* <p>Useful when values of the map are updated intensively, particularly fields with volatile access,
|
||||
* because it doesn't work well if the value crosses cache lines. Also, on some (nowadays rare)
|
||||
* architectures any misaligned memory access is more expensive than aligned.
|
||||
* <p>Useful when values of the map are updated intensively, particularly fields with volatile
|
||||
* access, because it doesn't work well if the value crosses cache lines. Also, on some
|
||||
* (nowadays rare) architectures any misaligned memory access is more expensive than aligned.
|
||||
*
|
||||
* <p>Note that {@linkplain #entrySize(int) entry size} will be aligned according to this alignment. I. e.
|
||||
* if you set {@code entrySize(20)} and {@link Alignment#OF_8_BYTES}, actual entry size will be 24 (20
|
||||
* aligned to 8 bytes).
|
||||
* <p>Note that {@linkplain #entrySize(int) entry size} will be aligned according to this
|
||||
* alignment. I. e. if you set {@code entrySize(20)} and {@link Alignment#OF_8_BYTES}, actual
|
||||
* entry size will be 24 (20 aligned to 8 bytes).
|
||||
*
|
||||
* <p>Default is {@link Alignment#OF_4_BYTES} for Byteable values.
|
||||
*
|
||||
@@ -119,11 +141,11 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc} Also, it overrides any previous {@link #prepareValueBytesOnAcquire} configuration to this
|
||||
* {@code ChronicleMapBuilder}.
|
||||
* {@inheritDoc} Also, it overrides any previous {@link #prepareValueBytesOnAcquire}
|
||||
* configuration to this {@code ChronicleMapBuilder}.
|
||||
*
|
||||
* <p>By default, the default value is not specified, default {@linkplain #prepareValueBytesOnAcquire
|
||||
* prepare value bytes routine} is specified instead.
|
||||
* <p>By default, the default value is not specified, default {@linkplain
|
||||
* #prepareValueBytesOnAcquire prepare value bytes routine} is specified instead.
|
||||
*
|
||||
* @see #defaultValueProvider(DefaultValueProvider)
|
||||
* @see #prepareValueBytesOnAcquire(PrepareValueBytes)
|
||||
@@ -135,15 +157,16 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the procedure which is called on the bytes, which later the returned value is pointing to,
|
||||
* if the key is absent, on {@link ChronicleMap#acquireUsing(Object, Object) acquireUsing()} call on maps,
|
||||
* created by this builder. See {@link PrepareValueBytes} for more information.
|
||||
* Configures the procedure which is called on the bytes, which later the returned value is
|
||||
* pointing to, if the key is absent, on {@link ChronicleMap#acquireUsing(Object, Object)
|
||||
* acquireUsing()} call on maps, created by this builder. See {@link PrepareValueBytes} for more
|
||||
* information.
|
||||
*
|
||||
* <p>The default preparation callback zeroes out the value bytes.
|
||||
*
|
||||
* @param prepareValueBytes what to do with the value bytes before assigning them into the {@link
|
||||
* net.openhft.lang.model.Byteable} value to return from {@code acquireUsing()}
|
||||
* call
|
||||
* @param prepareValueBytes what to do with the value bytes before assigning them into the
|
||||
* {@link net.openhft.lang.model.Byteable} value to return from {@code
|
||||
* acquireUsing()} call
|
||||
* @return this builder back
|
||||
* @see PrepareValueBytes
|
||||
* @see #defaultValue(Object)
|
||||
@@ -168,16 +191,17 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the optimal number of bytes, taken by serialized form of values, put into maps, created by
|
||||
* this builder. If value size is always the same, call {@link #constantValueSizeBySample(Object)} method
|
||||
* instead of this one.
|
||||
* Configures the optimal number of bytes, taken by serialized form of values, put into maps,
|
||||
* created by this builder. If value size is always the same, call {@link
|
||||
* #constantValueSizeBySample(Object)} method instead of this one.
|
||||
*
|
||||
* <p>If value is a boxed primitive type, i. e. if value size is known statically, it is automatically
|
||||
* accounted and shouldn't be specified by user.
|
||||
* <p>If value is a boxed primitive type, i. e. if value size is known statically, it is
|
||||
* automatically accounted and shouldn't be specified by user.
|
||||
*
|
||||
* <p>If value size varies moderately, specify the size higher than average, but lower than the maximum
|
||||
* possible, to minimize average memory overuse. If value size varies in a wide range, it's better to use
|
||||
* {@linkplain #entrySize(int) entry size} in "chunk" mode and configure it directly.
|
||||
* <p>If value size varies moderately, specify the size higher than average, but lower than the
|
||||
* maximum possible, to minimize average memory overuse. If value size varies in a wide range,
|
||||
* it's better to use {@linkplain #entrySize(int) entry size} in "chunk" mode and configure it
|
||||
* directly.
|
||||
*
|
||||
* @param valueSize number of bytes, taken by serialized form of values
|
||||
* @return this {@code ChronicleMapOnHeapUpdatableBuilder} back
|
||||
@@ -192,15 +216,16 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the constant number of bytes, taken by serialized form of values, put into maps, created by
|
||||
* this builder. This is done by providing the {@code sampleValue}, all values should take the same number
|
||||
* of bytes in serialized form, as this sample object.
|
||||
* Configures the constant number of bytes, taken by serialized form of values, put into maps,
|
||||
* created by this builder. This is done by providing the {@code sampleValue}, all values should
|
||||
* take the same number of bytes in serialized form, as this sample object.
|
||||
*
|
||||
* <p>If values are of boxed primitive type or {@link net.openhft.lang.model.Byteable} subclass, i. e. if
|
||||
* value size is known statically, it is automatically accounted and this method shouldn't be called.
|
||||
* <p>If values are of boxed primitive type or {@link net.openhft.lang.model.Byteable} subclass,
|
||||
* i. e. if value size is known statically, it is automatically accounted and this method
|
||||
* shouldn't be called.
|
||||
*
|
||||
* <p>If value size varies, method {@link #valueSize(int)} or {@link #entrySize(int)} should be called
|
||||
* instead of this one.
|
||||
* <p>If value size varies, method {@link #valueSize(int)} or {@link #entrySize(int)} should be
|
||||
* called instead of this one.
|
||||
*
|
||||
* @param sampleValue the sample value
|
||||
* @return this builder back
|
||||
@@ -233,8 +258,8 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws IllegalStateException if custom value marshaller is specified or value class is not either
|
||||
* {@code BytesMarshallable} or {@code Externalizable}
|
||||
* @throws IllegalStateException if custom value marshaller is specified or value class is not
|
||||
* either {@code BytesMarshallable} or {@code Externalizable}
|
||||
*/
|
||||
|
||||
@Override
|
||||
@@ -246,8 +271,8 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>By default, default value provider is not specified, {@link #defaultValue(Object) default value} is
|
||||
* specified instead.
|
||||
* <p>By default, default value provider is not specified, {@link #defaultValue(Object) default
|
||||
* value} is specified instead.
|
||||
*
|
||||
* @see #defaultValue(Object)
|
||||
*/
|
||||
@@ -258,8 +283,8 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the {@code BytesMarshaller} used to serialize/deserialize values to/from off-heap memory in
|
||||
* maps, created by this builder. See <a href="https://github.com/OpenHFT/Chronicle-Map#serialization">the
|
||||
* Configures the {@code BytesMarshaller} used to serialize/deserialize values to/from off-heap
|
||||
* memory in maps, created by this builder. See <a href="https://github.com/OpenHFT/Chronicle-Map#serialization">the
|
||||
* section about serialization in ChronicleMap manual</a> for more information.
|
||||
*
|
||||
* @param valueMarshaller the marshaller used to serialize values
|
||||
@@ -277,20 +302,21 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the marshallers, used to serialize/deserialize values to/from off-heap memory in maps,
|
||||
* created by this builder. See <a href="https://github.com/OpenHFT/Chronicle-Map#serialization">the
|
||||
* Configures the marshallers, used to serialize/deserialize values to/from off-heap memory in
|
||||
* maps, created by this builder. See <a href="https://github.com/OpenHFT/Chronicle-Map#serialization">the
|
||||
* section about serialization in ChronicleMap manual</a> for more information.
|
||||
*
|
||||
* <p>Configuring marshalling this way results to a little bit more compact in-memory layout of the map,
|
||||
* comparing to a single interface configuration: {@link #valueMarshaller(BytesMarshaller)}.
|
||||
* <p>Configuring marshalling this way results to a little bit more compact in-memory layout of
|
||||
* the map, comparing to a single interface configuration: {@link #valueMarshaller(BytesMarshaller)}.
|
||||
*
|
||||
* <p>Passing {@link net.openhft.chronicle.hash.serialization.BytesInterop} instead of plain {@link
|
||||
* net.openhft.chronicle.hash.serialization.BytesWriter} is, of cause, possible, but currently pointless
|
||||
* for values.
|
||||
* <p>Passing {@link net.openhft.chronicle.hash.serialization.BytesInterop} instead of plain
|
||||
* {@link net.openhft.chronicle.hash.serialization.BytesWriter} is, of cause, possible, but
|
||||
* currently pointless for values.
|
||||
*
|
||||
* @param valueWriter the new value object → {@link net.openhft.lang.io.Bytes} writer (interop)
|
||||
* @param valueWriter the new value object → {@link net.openhft.lang.io.Bytes} writer
|
||||
* (interop) strategy
|
||||
* @param valueReader the new {@link net.openhft.lang.io.Bytes} → value object reader
|
||||
* strategy
|
||||
* @param valueReader the new {@link net.openhft.lang.io.Bytes} → value object reader strategy
|
||||
* @return this builder back
|
||||
* @see #valueMarshaller(BytesMarshaller)
|
||||
*/
|
||||
@@ -301,19 +327,21 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the marshaller used to serialize actual value sizes to off-heap memory in maps, created by
|
||||
* this builder.
|
||||
* Configures the marshaller used to serialize actual value sizes to off-heap memory in maps,
|
||||
* created by this builder.
|
||||
*
|
||||
* <p>Default value size marshaller is so-called {@linkplain net.openhft.chronicle.hash.serialization.SizeMarshallers#stopBit()
|
||||
* stop bit encoding marshalling}. If {@linkplain #constantValueSizeBySample(Object) constant value size}
|
||||
* is configured, or defaulted if the value type is always constant and {@code ChronicleHashBuilder}
|
||||
* implementation knows about it, this configuration takes no effect, because a special {@link
|
||||
* net.openhft.chronicle.hash.serialization.SizeMarshaller} implementation, which doesn't actually do any
|
||||
* marshalling, and just returns the known constant size on {@link net.openhft.chronicle.hash.serialization.SizeMarshaller#readSize(
|
||||
*net.openhft.lang.io.Bytes)} calls, is used instead of any {@code SizeMarshaller} configured using this
|
||||
* method.
|
||||
* stop bit encoding marshalling}. If {@linkplain #constantValueSizeBySample(Object) constant
|
||||
* value size} is configured, or defaulted if the value type is always constant and {@code
|
||||
* ChronicleHashBuilder} implementation knows about it, this configuration takes no effect,
|
||||
* because a special {@link net.openhft.chronicle.hash.serialization.SizeMarshaller}
|
||||
* implementation, which doesn't actually do any marshalling, and just returns the known
|
||||
* constant size on {@link net.openhft.chronicle.hash.serialization.SizeMarshaller#readSize(
|
||||
*net.openhft.lang.io.Bytes)} calls, is used instead of any {@code SizeMarshaller} configured
|
||||
* using this method.
|
||||
*
|
||||
* @param valueSizeMarshaller the new marshaller, used to serialize actual value sizes to off-heap memory
|
||||
* @param valueSizeMarshaller the new marshaller, used to serialize actual value sizes to
|
||||
* off-heap memory
|
||||
* @return this builder back
|
||||
*/
|
||||
@Override
|
||||
@@ -498,13 +526,14 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bootstrapOnlyLocalEntries if set to true - when a new node joins a TCP replication grid, the new
|
||||
* node will be populated with data, only for the nodes that created that
|
||||
* data. Otherwise, all the nodes will publish all the data they have (
|
||||
* potentially swamping the new node with duplicates ) however this does
|
||||
* guarantee that all the data is replicated over to the new node, and is
|
||||
* useful especially in the case that the originating node is not
|
||||
* currently running.
|
||||
* @param bootstrapOnlyLocalEntries if set to true - when a new node joins a TCP replication
|
||||
* grid, the new node will be populated with data, only for the
|
||||
* nodes that created that data. Otherwise, all the nodes will
|
||||
* publish all the data they have ( potentially swamping the
|
||||
* new node with duplicates ) however this does guarantee that
|
||||
* all the data is replicated over to the new node, and is
|
||||
* useful especially in the case that the originating node is
|
||||
* not currently running.
|
||||
*/
|
||||
public ChronicleMapBuilder<K, V> bootstrapOnlyLocalEntries(boolean bootstrapOnlyLocalEntries) {
|
||||
delegate.bootstrapOnlyLocalEntries(bootstrapOnlyLocalEntries);
|
||||
@@ -512,11 +541,13 @@ public final class ChronicleMapBuilder<K, V> implements ChronicleMapBuilderI<K,
|
||||
}
|
||||
|
||||
public ChronicleMapBuilderI<K, V> checkSerializedValues() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
// throw new UnsupportedOperationException("Not implemented");
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChronicleMapBuilder<K, V> disableOversizedEntries(boolean disableOversizedEntries) {
|
||||
// throw an exception rather than use oversized entries to test the size is as expected.
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
// throw new UnsupportedOperationException("Not implemented");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user