HCOLL-200 fixed - testBootstrapAndHeartbeat

This commit is contained in:
Rob Austin
2014-11-11 16:46:32 +00:00
parent 546d5fccb2
commit 6816810b90
5 changed files with 88 additions and 82 deletions
@@ -397,6 +397,8 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
*/
B replication(byte identifier, TcpTransportAndNetworkConfig tcpTransportAndNetwork);
B replication(byte identifier);
StatelessClientConfig<C> statelessClient(InetSocketAddress remoteAddress);
ChronicleHashInstanceConfig<C> instance();
@@ -116,9 +116,6 @@ public abstract class AbstractReplication {
if (identifier <= 0)
throw new IllegalArgumentException("Identifier must be positive, " + identifier +
" given");
if (udpConfig == null && tcpConfig == null)
throw new IllegalStateException(
"At least one transport method (TCP or UDP) should be configured");
}
}
}
@@ -55,18 +55,18 @@ import java.util.concurrent.TimeUnit;
import static net.openhft.chronicle.map.Objects.builderEquals;
/**
* {@code AbstractChronicleMapBuilder} manages most of {@link ChronicleMap} configurations; has two
* concrete subclasses: {@link ChronicleMapBuilder} should be used to create maps with ordinary
* values, {@link OffHeapUpdatableChronicleMapBuilder} -- maps with {@link Byteable} values, which
* point directly to off-heap memory; could be used as a classic builder and/or factory. This means
* {@code AbstractChronicleMapBuilder} manages most of {@link ChronicleMap} configurations; has two concrete
* subclasses: {@link ChronicleMapBuilder} should be used to create maps with ordinary values, {@link
* OffHeapUpdatableChronicleMapBuilder} -- maps with {@link Byteable} values, which point directly to off-heap
* memory; could be used as a classic builder and/or factory. This means
* that in addition to the standard builder usage pattern: <pre>{@code
* ChronicleMap<Key, Value> map = ChronicleMapBuilder
* .of(Key.class, Value.class)
* .entries(100500)
* // ... other configurations
* .create();}</pre>
* one of concrete {@code AbstractChronicleMapBuilder} subclasses, {@link ChronicleMapBuilder} or
* {@link OffHeapUpdatableChronicleMapBuilder}, could be prepared and used to create many similar
* one of concrete {@code AbstractChronicleMapBuilder} subclasses, {@link ChronicleMapBuilder} or {@link
* OffHeapUpdatableChronicleMapBuilder}, could be prepared and used to create many similar
* maps: <pre>{@code
* OffHeapUpdatableChronicleMapBuilder<Key, Value> builder = OffHeapUpdatableChronicleMapBuilder
* .of(Key.class, Value.class)
@@ -77,17 +77,16 @@ import static net.openhft.chronicle.map.Objects.builderEquals;
* i. e. created {@code ChronicleMap} instances don't depend on the builder.
*
* <p>{@code AbstractChronicleMapBuilder} and it's subclasses are mutable, see a note in {@link
* ChronicleHashBuilder} interface documentation. </p> <p>Later in this documentation,
* "ChronicleMap" means "ChronicleMaps, created by {@code AbstractChronicleMapBuilder}", unless
* specified different, because theoretically someone might provide {@code ChronicleMap}
* implementations with completely different properties. </p> <p>{@code ChronicleMap}
* ("ChronicleMaps, created by {@code AbstractChronicleMapBuilder}") currently doesn't support
* resizing. That is why you should <i>always</i> configure {@linkplain #entries(long) number of
* entries} you are going to insert into the created map <i>at most</i>. See {@link #entries(long)}
* method documentation for more information on this. </p> <p>{@code ChronicleMap} allocates memory
* by equally sized chunks. This size is called {@linkplain #entrySize(int) entry size}, you are
* strongly recommended to configure it to achieve least memory consumption and best speed. See
* {@link #entrySize(int)} method documentation for more information on this. </p>
* ChronicleHashBuilder} interface documentation. </p> <p>Later in this documentation, "ChronicleMap" means
* "ChronicleMaps, created by {@code AbstractChronicleMapBuilder}", unless specified different, because
* theoretically someone might provide {@code ChronicleMap} implementations with completely different
* properties. </p> <p>{@code ChronicleMap} ("ChronicleMaps, created by {@code AbstractChronicleMapBuilder}")
* currently doesn't support resizing. That is why you should <i>always</i> configure {@linkplain
* #entries(long) number of entries} you are going to insert into the created map <i>at most</i>. See {@link
* #entries(long)} method documentation for more information on this. </p> <p>{@code ChronicleMap} allocates
* memory by equally sized chunks. This size is called {@linkplain #entrySize(int) entry size}, you are
* strongly recommended to configure it to achieve least memory consumption and best speed. See {@link
* #entrySize(int)} method documentation for more information on this. </p>
*
* @param <K> key type of the maps, produced by this builder
* @param <V> value type of the maps, produced by this builder
@@ -205,9 +204,9 @@ public abstract class AbstractChronicleMapBuilder<K, V,
* .keySize(10)
* // shouldn't specify valueSize(), because it is statically known
* .create();}</pre>
* (Note that 10 is chosen as key size in bytes despite strings in Java are UTF-16 encoded (and
* each character takes 2 bytes on-heap), because default off-heap {@link String} encoding is
* UTF-8 in {@code ChronicleMap}.)
* (Note that 10 is chosen as key size in bytes despite strings in Java are UTF-16 encoded (and each
* character takes 2 bytes on-heap), because default off-heap {@link String} encoding is UTF-8 in {@code
* ChronicleMap}.)
*
* @see #constantKeySizeBySample(Object)
* @see #entrySize(int)
@@ -270,11 +269,11 @@ public abstract class AbstractChronicleMapBuilder<K, V,
* {@inheritDoc}
*
* <p>In fully default case you can expect entry size to be about 256 bytes. But it is strongly
* recommended always to configure {@linkplain #keySize(int) key size} and {@linkplain
* #valueSize(int) value size}, if they couldn't be derived statically. </p> <p>If entry size is
* not configured explicitly by calling this method, it is computed based on {@linkplain
* #metaDataBytes(int) meta data bytes}, plus {@linkplain #keySize(int) key size}, plus
* {@linkplain #valueSize(int) value size}, plus a few bytes required by implementations. </p>
* recommended always to configure {@linkplain #keySize(int) key size} and {@linkplain #valueSize(int)
* value size}, if they couldn't be derived statically. </p> <p>If entry size is not configured explicitly
* by calling this method, it is computed based on {@linkplain #metaDataBytes(int) meta data bytes}, plus
* {@linkplain #keySize(int) key size}, plus {@linkplain #valueSize(int) value size}, plus a few bytes
* required by implementations. </p>
*
* @see #entries(long)
*/
@@ -468,20 +467,18 @@ public abstract class AbstractChronicleMapBuilder<K, V,
}
/**
* Configures if the maps created by this builder should return {@code null} instead of previous
* mapped values on {@link ChronicleMap#put(Object, Object) ChornicleMap.put(key, value)}
* calls.
* Configures if the maps created by this builder should return {@code null} instead of previous mapped
* values on {@link ChronicleMap#put(Object, Object) ChornicleMap.put(key, value)} calls.
*
* <p>{@link Map#put(Object, Object) Map.put()} returns the previous value, functionality which
* is rarely used but fairly cheap for {@link HashMap}. In the case, for an off heap collection,
* it has to create a new object and deserialize the data from off-heap memory. It's expensive
* for something you probably don't use. </p> <p>By default, of cause, {@code ChronicleMap}
* conforms the general {@code Map} contract and returns the previous mapped value on {@code
* put()} calls. </p>
* <p>{@link Map#put(Object, Object) Map.put()} returns the previous value, functionality which is rarely
* used but fairly cheap for {@link HashMap}. In the case, for an off heap collection, it has to create a
* new object and deserialize the data from off-heap memory. It's expensive for something you probably
* don't use. </p> <p>By default, of cause, {@code ChronicleMap} conforms the general {@code Map} contract
* and returns the previous mapped value on {@code put()} calls. </p>
*
* @param putReturnsNull {@code true} if you want {@link ChronicleMap#put(Object, Object)
* ChronicleMap.put()} to not return the value that was replaced but
* instead return {@code null}
* ChronicleMap.put()} to not return the value that was replaced but instead return
* {@code null}
* @return an instance of the map builder back
* @see #removeReturnsNull(boolean)
*/
@@ -495,17 +492,17 @@ public abstract class AbstractChronicleMapBuilder<K, V,
}
/**
* Configures if the maps created by this builder should return {@code null} instead of the last
* mapped value on {@link ChronicleMap#remove(Object) ChronicleMap.remove(key)} calls.
* Configures if the maps created by this builder should return {@code null} instead of the last mapped
* value on {@link ChronicleMap#remove(Object) ChronicleMap.remove(key)} calls.
*
* <p>{@link Map#remove(Object) Map.remove()} returns the previous value, functionality which is
* rarely used but fairly cheap for {@link HashMap}. In the case, for an off heap collection, it
* has to create a new object and deserialize the data from off-heap memory. It's expensive for
* something you probably don't use. </p>
* <p>{@link Map#remove(Object) Map.remove()} returns the previous value, functionality which is rarely
* used but fairly cheap for {@link HashMap}. In the case, for an off heap collection, it has to create a
* new object and deserialize the data from off-heap memory. It's expensive for something you probably
* don't use. </p>
*
* @param removeReturnsNull {@code true} if you want {@link ChronicleMap#remove(Object)
* ChronicleMap.remove()} to not return the value of the removed entry
* but instead return {@code null}
* ChronicleMap.remove()} to not return the value of the removed entry but
* instead return {@code null}
* @return an instance of the map builder back
* @see #putReturnsNull(boolean)
*/
@@ -650,19 +647,18 @@ public abstract class AbstractChronicleMapBuilder<K, V,
}
/**
* Configures factory which is used to create a new value instance, if value class is either
* {@link Byteable}, {@link BytesMarshallable} or {@link Externalizable} subclass in maps,
* created by this builder.
* Configures factory which is used to create a new value instance, if value class is either {@link
* Byteable}, {@link BytesMarshallable} or {@link Externalizable} subclass in maps, created by this
* builder.
*
* <p>Default value deserialization factory is {@link NewInstanceObjectFactory}, which creates a
* new value instance using {@link Class#newInstance()} default constructor. You could provide
* an {@link AllocateInstanceObjectFactory}, which uses {@code Unsafe.allocateInstance(Class)}
* (you might want to do this for better performance or if you don't want to initialize fields),
* or a factory which calls a value class constructor with some arguments, or a factory which
* internally delegates to instance pool or {@link ThreadLocal}, to reduce allocations. </p>
* <p>Default value deserialization factory is {@link NewInstanceObjectFactory}, which creates a new value
* instance using {@link Class#newInstance()} default constructor. You could provide an {@link
* AllocateInstanceObjectFactory}, which uses {@code Unsafe.allocateInstance(Class)} (you might want to do
* this for better performance or if you don't want to initialize fields), or a factory which calls a
* value class constructor with some arguments, or a factory which internally delegates to instance pool
* or {@link ThreadLocal}, to reduce allocations. </p>
*
* @param valueDeserializationFactory the value factory used to produce instances to deserialize
* data in
* @param valueDeserializationFactory the value factory used to produce instances to deserialize data in
* @return this builder back
*/
public B valueDeserializationFactory(@NotNull ObjectFactory<V> valueDeserializationFactory) {
@@ -680,8 +676,8 @@ public abstract class AbstractChronicleMapBuilder<K, V,
}
/**
* Specifies the value to be put for each key queried in {@link ChronicleMap#acquireUsing
* acquireUsing()} method, if the key is absent in the map, created by this builder.
* Specifies the value to be put for each key queried in {@link ChronicleMap#acquireUsing acquireUsing()}
* method, if the key is absent in the map, created by this builder.
*
* <p>This configuration overrides any previous {@link #defaultValueProvider(DefaultValueProvider)}
* configuration to this {@code AbstractChronicleMapBuilder}. </p>
@@ -703,8 +699,8 @@ public abstract class AbstractChronicleMapBuilder<K, V,
* Specifies the function to obtain a value for the key during {@link ChronicleMap#acquireUsing
* acquireUsing()} calls, if the key is absent in the map, created by this builder.
*
* <p>This configuration overrides any previous {@link #defaultValue(Object)} configuration to
* this {@code AbstractChronicleMapBuilder}. </p>
* <p>This configuration overrides any previous {@link #defaultValue(Object)} configuration to this {@code
* AbstractChronicleMapBuilder}. </p>
*
* @param defaultValueProvider the strategy to obtain a default value by the absent key
* @return this builder object back
@@ -754,6 +750,13 @@ public abstract class AbstractChronicleMapBuilder<K, V,
return self();
}
@Override
public B replication(byte identifier) {
return replication(SingleChronicleHashReplication.builder().createWithId(identifier));
}
@Override
public B replication(byte identifier, TcpTransportAndNetworkConfig tcpTransportAndNetwork) {
return replication(SingleChronicleHashReplication.builder()
@@ -18,7 +18,10 @@
package net.openhft.chronicle.set;
import net.openhft.chronicle.hash.*;
import net.openhft.chronicle.hash.ChronicleHashBuilder;
import net.openhft.chronicle.hash.ChronicleHashErrorListener;
import net.openhft.chronicle.hash.ChronicleHashInstanceConfig;
import net.openhft.chronicle.hash.StatelessClientConfig;
import net.openhft.chronicle.hash.replication.SingleChronicleHashReplication;
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
import net.openhft.chronicle.hash.replication.TimeProvider;
@@ -39,8 +42,8 @@ import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
/**
* {@code ChronicleSetBuilder} manages the whole set of {@link ChronicleSet} configurations, could
* be used as a classic builder and/or factory.
* {@code ChronicleSetBuilder} manages the whole set of {@link ChronicleSet} configurations, could be used as
* a classic builder and/or factory.
*
* <p>{@code ChronicleMapBuilder} is mutable, see a note in {@link ChronicleHashBuilder} interface
* documentation.
@@ -104,9 +107,9 @@ public class ChronicleSetBuilder<E>
* .keySize(10)
* .create();}</pre>
*
* <p>(Note that 10 is chosen as key size in bytes despite strings in Java are UTF-16 encoded
* (and each character takes 2 bytes on-heap), because default off-heap {@link String} encoding
* is UTF-8 in {@code ChronicleSet}.)
* <p>(Note that 10 is chosen as key size in bytes despite strings in Java are UTF-16 encoded (and each
* character takes 2 bytes on-heap), because default off-heap {@link String} encoding is UTF-8 in {@code
* ChronicleSet}.)
*
* @see #constantKeySizeBySample(Object)
* @see #entrySize(int)
@@ -136,13 +139,13 @@ public class ChronicleSetBuilder<E>
/**
* {@inheritDoc}
*
* <p>In fully default case you can expect entry size to be about 120-130 bytes. But it is
* strongly recommended always to configure {@linkplain #keySize(int) key size}, if they
* couldn't be derived statically.
* <p>In fully default case you can expect entry size to be about 120-130 bytes. But it is strongly
* recommended always to configure {@linkplain #keySize(int) key size}, if they couldn't be derived
* statically.
*
* <p>If entry size is not configured explicitly by calling this method, it is computed based on
* {@linkplain #metaDataBytes(int) meta data bytes}, plus {@linkplain #keySize(int) key size},
* plus a few bytes required by implementations.
* {@linkplain #metaDataBytes(int) meta data bytes}, plus {@linkplain #keySize(int) key size}, plus a few
* bytes required by implementations.
*/
@Override
public ChronicleSetBuilder<E> entrySize(int entrySize) {
@@ -245,10 +248,10 @@ public class ChronicleSetBuilder<E>
/**
* {@inheritDoc}
*
* <p>Actually this is just a convenience method supporting key marshaller configurations, made
* initially during {@link #of(Class)} call. Because if you {@linkplain
* #keyMarshaller(BytesMarshaller) configure} own custom key marshaller, this method doesn't
* take any effect on the maps constructed by this builder.
* <p>Actually this is just a convenience method supporting key marshaller configurations, made initially
* during {@link #of(Class)} call. Because if you {@linkplain #keyMarshaller(BytesMarshaller) configure}
* own custom key marshaller, this method doesn't take any effect on the maps constructed by this
* builder.
*
* @see #of(Class)
*/
@@ -277,6 +280,12 @@ public class ChronicleSetBuilder<E>
return this;
}
@Override
public ChronicleSetBuilder<E> replication(byte identifier) {
chronicleMapBuilder.replication(identifier);
return this;
}
@Override
public StatelessClientConfig<ChronicleSet<E>> statelessClient(
InetSocketAddress remoteAddress) {