mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -37,7 +37,7 @@ public interface ChronicleHash extends Closeable {
|
||||
*
|
||||
* @return the file this {@link ChronicleMap} or {@link ChronicleSet} is mapped to,
|
||||
* or {@code null} if it is not mapped to any file
|
||||
* @see ChronicleHashBuilder#file(java.io.File)
|
||||
* @see ChronicleHashBuilder#createPersistedTo(File)
|
||||
* @see ChronicleHashBuilder#create()
|
||||
*/
|
||||
File file();
|
||||
|
||||
@@ -21,6 +21,7 @@ package net.openhft.chronicle.hash;
|
||||
import net.openhft.chronicle.hash.replication.SimpleReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpConfig;
|
||||
import net.openhft.chronicle.hash.replication.TimeProvider;
|
||||
import net.openhft.chronicle.hash.serialization.*;
|
||||
import net.openhft.chronicle.map.*;
|
||||
import net.openhft.chronicle.set.ChronicleSet;
|
||||
import net.openhft.chronicle.set.ChronicleSetBuilder;
|
||||
@@ -212,7 +213,7 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
|
||||
* like iteration. If timeout expires, {@link ChronicleHashErrorListener#onLockTimeout(long)} is
|
||||
* called, and then thread tries to obtain the segment lock one more time, and so in a loop,
|
||||
* until thread is interrupted. However, you can configure {@linkplain #errorListener(
|
||||
*ChronicleHashErrorListener) error listener} to throw an exception on the first (or n-th) lock
|
||||
* ChronicleHashErrorListener) error listener} to throw an exception on the first (or n-th) lock
|
||||
* acquisition fail.
|
||||
*
|
||||
* <p>Default lock time out is 2 seconds.
|
||||
@@ -286,10 +287,49 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
|
||||
*
|
||||
* @param keyMarshaller the marshaller used to serialize keys
|
||||
* @return this builder back
|
||||
* @see #keyMarshallers(BytesWriter, BytesReader)
|
||||
* @see #objectSerializer(ObjectSerializer)
|
||||
*/
|
||||
B keyMarshaller(@NotNull BytesMarshaller<K> keyMarshaller);
|
||||
|
||||
/**
|
||||
* Configures the marshallers, used to serialize/deserialize keys to/from off-heap
|
||||
* memory in hash containers, 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 #keyMarshaller(BytesMarshaller)}.
|
||||
*
|
||||
* <p>Passing {@link BytesInterop} (which is a subinterface of {@link BytesWriter}) as the
|
||||
* first argument is supported, and even more advantageous from performance perspective.
|
||||
*
|
||||
* @param keyWriter the new key object -> {@link Bytes} writer (interop) strategy
|
||||
* @param keyReader the new {@link Bytes} -> key object reader strategy
|
||||
* @return this builder back
|
||||
* @see #keyMarshaller(BytesMarshaller)
|
||||
*/
|
||||
B keyMarshallers(@NotNull BytesWriter<K> keyWriter, @NotNull BytesReader<K> keyReader);
|
||||
|
||||
/**
|
||||
* Configures the marshaller used to serialize actual key sizes to off-heap memory
|
||||
* in hash containers, created by this builder.
|
||||
*
|
||||
* <p>Default key size marshaller is so-called {@linkplain SizeMarshallers#stopBit()
|
||||
* stop bit encoding marshalling}. If {@linkplain #constantKeySizeBySample(Object) constant key
|
||||
* size} is configured, or defaulted if the key type is always constant and {@code
|
||||
* ChronicleHashBuilder} implementation knows about it, this configuration takes no effect,
|
||||
* because a special {@link SizeMarshaller} implementation, which doesn't actually do any
|
||||
* marshalling, and just returns the known constant size on {@link SizeMarshaller#readSize(
|
||||
* Bytes)} calls, is used instead of any {@code SizeMarshaller} configured using this method.
|
||||
*
|
||||
* @param keySizeMarshaller the new marshaller, used to serialize actual key sizes to off-heap
|
||||
* memory
|
||||
* @return this builder back
|
||||
*/
|
||||
B keySizeMarshaller(@NotNull SizeMarshaller keySizeMarshaller);
|
||||
|
||||
/**
|
||||
* Configures factory which is used to create a new key instance, if key class is either
|
||||
* {@link Byteable}, {@link BytesMarshallable} or {@link Externalizable} subclass in maps,
|
||||
|
||||
+5
-4
@@ -16,19 +16,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.hash.exceptions;
|
||||
package net.openhft.chronicle.hash;
|
||||
|
||||
/**
|
||||
* TODO mention in docs
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public class TimeoutRuntimeException extends RuntimeException {
|
||||
public class RemoteCallTimeoutException extends RuntimeException {
|
||||
|
||||
|
||||
public TimeoutRuntimeException(String s) {
|
||||
public RemoteCallTimeoutException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public TimeoutRuntimeException() {
|
||||
public RemoteCallTimeoutException() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,14 @@ package net.openhft.chronicle.hash.replication;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class AbstractReplication {
|
||||
protected final byte localIdentifier;
|
||||
protected final UdpConfig udpConfig;
|
||||
protected final TcpConfig tcpConfig;
|
||||
private final byte localIdentifier;
|
||||
private final TcpConfig tcpConfig;
|
||||
private final UdpConfig udpConfig;
|
||||
|
||||
AbstractReplication(byte localIdentifier, Builder builder) {
|
||||
udpConfig = builder.udpConfig;
|
||||
this.localIdentifier = localIdentifier;
|
||||
tcpConfig = builder.tcpConfig;
|
||||
udpConfig = builder.udpConfig;
|
||||
}
|
||||
|
||||
public byte identifier() {
|
||||
@@ -44,8 +44,8 @@ class AbstractReplication {
|
||||
}
|
||||
|
||||
static abstract class Builder<B extends Builder> {
|
||||
protected UdpConfig udpConfig = null;
|
||||
protected TcpConfig tcpConfig = null;
|
||||
private TcpConfig tcpConfig = null;
|
||||
private UdpConfig udpConfig = null;
|
||||
|
||||
public B tcpTransportAndNetwork(TcpConfig tcpConfig) {
|
||||
this.tcpConfig = tcpConfig;
|
||||
|
||||
@@ -62,6 +62,16 @@ public final class ReplicationHub extends AbstractReplication {
|
||||
|
||||
private Builder() {}
|
||||
|
||||
@Override
|
||||
public Builder tcpTransportAndNetwork(TcpConfig tcpConfig) {
|
||||
return super.tcpTransportAndNetwork(tcpConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder udpTransport(UdpConfig udpConfig) {
|
||||
return super.udpTransport(udpConfig);
|
||||
}
|
||||
|
||||
public Builder maxEntrySize(int maxEntrySize) {
|
||||
this.maxEntrySize = maxEntrySize;
|
||||
return this;
|
||||
|
||||
@@ -34,5 +34,15 @@ public final class SimpleReplication extends AbstractReplication {
|
||||
check();
|
||||
return new SimpleReplication(identifier, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder tcpTransportAndNetwork(TcpConfig tcpConfig) {
|
||||
return super.tcpTransportAndNetwork(tcpConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder udpTransport(UdpConfig udpConfig) {
|
||||
return super.udpTransport(udpConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,15 +64,15 @@ public final class TcpConfig {
|
||||
Collection<InetSocketAddress> endpoints) {
|
||||
if (endpoints.isEmpty())
|
||||
throw new IllegalArgumentException("There should be some endpoints");
|
||||
return unknownTopology(serverPort, endpoints);
|
||||
return forUnknownTopology(serverPort, endpoints);
|
||||
}
|
||||
|
||||
public static TcpConfig forReceivingOnlyNode(int serverPort) {
|
||||
return unknownTopology(serverPort, Collections.<InetSocketAddress>emptyList());
|
||||
return forUnknownTopology(serverPort, Collections.<InetSocketAddress>emptyList());
|
||||
}
|
||||
|
||||
public static TcpConfig unknownTopology(int serverPort,
|
||||
Collection<InetSocketAddress> endpoints) {
|
||||
public static TcpConfig forUnknownTopology(int serverPort,
|
||||
Collection<InetSocketAddress> endpoints) {
|
||||
for (final InetSocketAddress endpoint : endpoints) {
|
||||
if (endpoint.getPort() == serverPort && "localhost".equals(endpoint.getHostName()))
|
||||
throw new IllegalArgumentException("endpoint=" + endpoint
|
||||
|
||||
@@ -20,6 +20,9 @@ package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.*;
|
||||
import net.openhft.chronicle.hash.replication.*;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaProvider;
|
||||
@@ -602,7 +605,20 @@ public abstract class AbstractChronicleMapBuilder<K, V,
|
||||
*/
|
||||
@Override
|
||||
public B keyMarshaller(@NotNull BytesMarshaller<K> keyMarshaller) {
|
||||
keyBuilder.marshaller(keyMarshaller, null);
|
||||
keyBuilder.marshaller(keyMarshaller);
|
||||
return self();
|
||||
}
|
||||
|
||||
@Override
|
||||
public B keyMarshallers(@NotNull BytesWriter<K> keyWriter, @NotNull BytesReader<K> keyReader) {
|
||||
keyBuilder.writer(keyWriter);
|
||||
keyBuilder.reader(keyReader);
|
||||
return self();
|
||||
}
|
||||
|
||||
@Override
|
||||
public B keySizeMarshaller(@NotNull SizeMarshaller keySizeMarshaller) {
|
||||
keyBuilder.sizeMarshaller(keySizeMarshaller);
|
||||
return self();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.ChronicleHashBuilder;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.*;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.serialization.BytesMarshallable;
|
||||
import net.openhft.lang.io.serialization.BytesMarshaller;
|
||||
@@ -218,16 +217,68 @@ public final class ChronicleMapBuilder<K, V>
|
||||
return super.defaultValueProvider(defaultValueProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return this builder back
|
||||
* @see #valueMarshallers(BytesWriter, BytesReader)
|
||||
* @see OffHeapUpdatableChronicleMapBuilder
|
||||
* @see #objectSerializer(ObjectSerializer)
|
||||
*/
|
||||
public ChronicleMapBuilder<K, V> valueMarshaller(
|
||||
@NotNull BytesMarshaller<V> valueMarshaller) {
|
||||
valueBuilder.marshaller(valueMarshaller, null);
|
||||
valueBuilder.marshaller(valueMarshaller);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>Passing {@link BytesInterop} instead of plain {@link BytesWriter} is, of cause, possible,
|
||||
* but currently pointless for values.
|
||||
*
|
||||
* @param valueWriter the new value object -> {@link Bytes} writer (interop) strategy
|
||||
* @param valueReader the new {@link Bytes} -> value object reader strategy
|
||||
* @return this builder back
|
||||
* @see #valueMarshaller(BytesMarshaller)
|
||||
*/
|
||||
public ChronicleMapBuilder<K, V> valueMarshallers(
|
||||
BytesWriter<V> valueWriter, BytesReader<V> valueReader) {
|
||||
@NotNull BytesWriter<V> valueWriter, @NotNull BytesReader<V> valueReader) {
|
||||
valueBuilder.writer(valueWriter);
|
||||
valueBuilder.reader(valueReader, valueBuilder.factory());
|
||||
valueBuilder.reader(valueReader);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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 SizeMarshaller} implementation, which doesn't actually do any
|
||||
* marshalling, and just returns the known constant size on {@link SizeMarshaller#readSize(
|
||||
* 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
|
||||
* @return this builder back
|
||||
*/
|
||||
public ChronicleMapBuilder<K, V> valueSizeMarshaller(
|
||||
@NotNull SizeMarshaller valueSizeMarshaller) {
|
||||
valueBuilder.sizeMarshaller(valueSizeMarshaller);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,14 +16,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.hash.exceptions;
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
public class IORuntimeException extends RuntimeException{
|
||||
class IORuntimeException extends RuntimeException{
|
||||
|
||||
public IORuntimeException(IOException e) {
|
||||
super(e);
|
||||
@@ -222,7 +222,7 @@ public class NodeDiscovery {
|
||||
knownNodes.add(ourAddressAndPort, identifier);
|
||||
|
||||
final TcpConfig tcpConfig = TcpConfig
|
||||
.unknownTopology(ourAddressAndPort.getPort(),
|
||||
.forUnknownTopology(ourAddressAndPort.getPort(),
|
||||
toInetSocketCollection(knownHostPorts))
|
||||
.heartBeatInterval(1, SECONDS)
|
||||
.nonUniqueIdentifierListener(identifierListener);
|
||||
|
||||
@@ -60,7 +60,7 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
|
||||
private enum CopyingInterop {FROM_MARSHALLER, FROM_WRITER}
|
||||
|
||||
private final Serializable bufferIdentity;
|
||||
private final Role role;
|
||||
final Class<E> eClass;
|
||||
private boolean instancesAreMutable;
|
||||
private SizeMarshaller sizeMarshaller = stopBit();
|
||||
@@ -70,11 +70,10 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
private MetaBytesInterop<E, ?> metaInterop;
|
||||
private MetaProvider<E, ?, ?> metaInteropProvider;
|
||||
private long maxSize;
|
||||
private ObjectFactory<E> factory;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
SerializationBuilder(Class<E> eClass, Role role) {
|
||||
this.bufferIdentity = role;
|
||||
this.role = role;
|
||||
this.eClass = eClass;
|
||||
instancesAreMutable = instancesAreMutable(eClass);
|
||||
|
||||
@@ -83,39 +82,39 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
NullObjectFactory.<E>of();
|
||||
|
||||
if (concreteClass(eClass) && Byteable.class.isAssignableFrom(eClass)) {
|
||||
ByteableMarshaller agileBytesMarshaller = ByteableMarshaller.of((Class) eClass);
|
||||
sizeMarshaller(agileBytesMarshaller)
|
||||
.reader(agileBytesMarshaller, factory)
|
||||
.interop(agileBytesMarshaller);
|
||||
ByteableMarshaller byteableMarshaller = ByteableMarshaller.of((Class) eClass);
|
||||
sizeMarshaller(byteableMarshaller)
|
||||
.reader(byteableMarshaller)
|
||||
.interop(byteableMarshaller);
|
||||
} else if (eClass == CharSequence.class || eClass == String.class) {
|
||||
reader((BytesReader<E>) CharSequenceReader.of(), factory);
|
||||
reader((BytesReader<E>) CharSequenceReader.of());
|
||||
writer((BytesWriter<E>) CharSequenceWriter.instance());
|
||||
} else if (eClass == Void.class) {
|
||||
sizeMarshaller(VoidMarshaller.INSTANCE)
|
||||
.reader((BytesReader<E>) VoidMarshaller.INSTANCE, factory)
|
||||
.reader((BytesReader<E>) VoidMarshaller.INSTANCE)
|
||||
.interop((BytesInterop<E>) VoidMarshaller.INSTANCE);
|
||||
} else if (eClass == Long.class) {
|
||||
sizeMarshaller(LongMarshaller.INSTANCE)
|
||||
.reader((BytesReader<E>) LongMarshaller.INSTANCE, factory)
|
||||
.reader((BytesReader<E>) LongMarshaller.INSTANCE)
|
||||
.interop((BytesInterop<E>) LongMarshaller.INSTANCE);
|
||||
} else if (eClass == Double.class) {
|
||||
sizeMarshaller(DoubleMarshaller.INSTANCE)
|
||||
.reader((BytesReader<E>) DoubleMarshaller.INSTANCE, factory)
|
||||
.reader((BytesReader<E>) DoubleMarshaller.INSTANCE)
|
||||
.interop((BytesInterop<E>) DoubleMarshaller.INSTANCE);
|
||||
} else if (eClass == Integer.class) {
|
||||
sizeMarshaller(IntegerMarshaller.INSTANCE)
|
||||
.reader((BytesReader<E>) IntegerMarshaller.INSTANCE, factory)
|
||||
.reader((BytesReader<E>) IntegerMarshaller.INSTANCE)
|
||||
.interop((BytesInterop<E>) IntegerMarshaller.INSTANCE);
|
||||
} else if (eClass == byte[].class) {
|
||||
reader((BytesReader<E>) ByteArrayMarshaller.INSTANCE, factory);
|
||||
reader((BytesReader<E>) ByteArrayMarshaller.INSTANCE);
|
||||
interop((BytesInterop<E>) ByteArrayMarshaller.INSTANCE);
|
||||
} else if (eClass == char[].class) {
|
||||
reader((BytesReader<E>) CharArrayMarshaller.INSTANCE, factory);
|
||||
reader((BytesReader<E>) CharArrayMarshaller.INSTANCE);
|
||||
interop((BytesInterop<E>) CharArrayMarshaller.INSTANCE);
|
||||
} else if (concreteClass(eClass)) {
|
||||
BytesMarshaller<E> marshaller = chooseMarshaller(eClass, eClass);
|
||||
if (marshaller != null)
|
||||
marshaller(marshaller, factory);
|
||||
marshaller(marshaller);
|
||||
}
|
||||
if (concreteClass(eClass) && marshallerUseFactory(eClass)) {
|
||||
factory(factory);
|
||||
@@ -150,17 +149,15 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
return copyingInterop(CopyingInterop.FROM_WRITER)
|
||||
.setInterop(writer)
|
||||
.metaInterop(CopyingMetaBytesInterop
|
||||
.<E, BytesWriter<E>>forBytesWriter(bufferIdentity));
|
||||
.<E, BytesWriter<E>>forBytesWriter(role));
|
||||
}
|
||||
|
||||
public SerializationBuilder<E> marshaller(BytesMarshaller<E> marshaller,
|
||||
ObjectFactory<E> factory) {
|
||||
if (factory == null) factory = this.factory;
|
||||
public SerializationBuilder<E> marshaller(BytesMarshaller<E> marshaller) {
|
||||
return copyingInterop(CopyingInterop.FROM_MARSHALLER)
|
||||
.reader(BytesReaders.fromBytesMarshaller(marshaller), factory)
|
||||
.reader(BytesReaders.fromBytesMarshaller(marshaller))
|
||||
.setInterop(marshaller)
|
||||
.metaInterop(CopyingMetaBytesInterop
|
||||
.<E, BytesMarshaller<E>>forBytesMarshaller(bufferIdentity));
|
||||
.<E, BytesMarshaller<E>>forBytesMarshaller(role));
|
||||
}
|
||||
|
||||
public SerializationBuilder<E> maxSize(long maxSize) {
|
||||
@@ -218,10 +215,7 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
|
||||
public SerializationBuilder<E> objectSerializer(ObjectSerializer serializer) {
|
||||
if (reader == null || interop == null) {
|
||||
ObjectFactory<E> factory = this.factory;
|
||||
if (factory == null)
|
||||
factory = NullObjectFactory.INSTANCE;
|
||||
marshaller(new SerializableMarshaller(serializer), factory);
|
||||
marshaller(new SerializableMarshaller(serializer));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -244,10 +238,8 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
return reader;
|
||||
}
|
||||
|
||||
public SerializationBuilder<E> reader(BytesReader<E> reader, ObjectFactory<E> factory) {
|
||||
public SerializationBuilder<E> reader(BytesReader<E> reader) {
|
||||
this.reader = reader;
|
||||
if (factory != null)
|
||||
this.factory = factory;
|
||||
return this;
|
||||
|
||||
}
|
||||
@@ -281,10 +273,6 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectFactory<E> factory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SerializationBuilder<E> factory(ObjectFactory<E> factory) {
|
||||
if (!marshallerUseFactory(eClass)) {
|
||||
@@ -292,19 +280,17 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
" value don't use object factory");
|
||||
} else if (interop instanceof ByteableMarshaller) {
|
||||
if (factory instanceof AllocateInstanceObjectFactory) {
|
||||
ByteableMarshaller agileBytesMarshaller =
|
||||
ByteableMarshaller byteableMarshaller =
|
||||
ByteableMarshaller.of((Class) eClass);
|
||||
sizeMarshaller(agileBytesMarshaller)
|
||||
.reader(agileBytesMarshaller, factory)
|
||||
.interop(agileBytesMarshaller);
|
||||
sizeMarshaller(byteableMarshaller)
|
||||
.reader(byteableMarshaller)
|
||||
.interop(byteableMarshaller);
|
||||
} else {
|
||||
ByteableMarshaller agileBytesMarshaller =
|
||||
ByteableMarshaller byteableMarshaller =
|
||||
ByteableMarshaller.of((Class) eClass, (ObjectFactory) factory);
|
||||
ObjectFactory<E> factory1 = factory;
|
||||
if (factory1 == null) factory1 = this.factory;
|
||||
sizeMarshaller(agileBytesMarshaller)
|
||||
.reader(agileBytesMarshaller, factory1)
|
||||
.interop(agileBytesMarshaller);
|
||||
sizeMarshaller(byteableMarshaller)
|
||||
.reader(byteableMarshaller)
|
||||
.interop(byteableMarshaller);
|
||||
}
|
||||
} else if (interop instanceof BytesMarshallableMarshaller) {
|
||||
if (factory instanceof AllocateInstanceObjectFactory) {
|
||||
@@ -329,11 +315,12 @@ final class SerializationBuilder<E> implements Cloneable {
|
||||
} else {
|
||||
// interop is custom, it is user's responsibility to use the same factory inside
|
||||
// marshaller and standalone
|
||||
String role = this.role.toString().toLowerCase();
|
||||
throw new IllegalStateException(
|
||||
"Change the value factory simultaneously with marshaller " +
|
||||
"using *AndFactory() method");
|
||||
role + "DeserializationFactory() should be called " +
|
||||
"only if the Map " + role + " type is Byteable, BytesMarshallable " +
|
||||
"or Externalizable subtype and no custom marshallers were configured.");
|
||||
}
|
||||
this.factory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import com.sun.jdi.connect.spi.ClosedConnectionException;
|
||||
import net.openhft.chronicle.hash.exceptions.IORuntimeException;
|
||||
import net.openhft.chronicle.hash.exceptions.TimeoutRuntimeException;
|
||||
import net.openhft.chronicle.hash.RemoteCallTimeoutException;
|
||||
import net.openhft.lang.io.ByteBufferBytes;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.threadlocal.ThreadLocalCopies;
|
||||
@@ -942,7 +941,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
|
||||
|
||||
private void checkTimeout(long timeoutTime) {
|
||||
if (timeoutTime < System.currentTimeMillis())
|
||||
throw new TimeoutRuntimeException();
|
||||
throw new RemoteCallTimeoutException();
|
||||
}
|
||||
|
||||
private void writeSizeAndTransactionIdAt(long locationOfSize, final long transactionId) {
|
||||
|
||||
@@ -78,7 +78,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
final VW originalValueWriter;
|
||||
final MVW originalMetaValueWriter;
|
||||
final MetaProvider<V, VW, MVW> metaValueWriterProvider;
|
||||
final ObjectFactory<V> valueFactory;
|
||||
final DefaultValueProvider<K, V> defaultValueProvider;
|
||||
final PrepareValueBytesAsWriter<K> prepareValueBytesAsWriter;
|
||||
final int metaDataBytes;
|
||||
@@ -128,7 +127,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
originalValueWriter = (VW) valueBuilder.interop();
|
||||
originalMetaValueWriter = (MVW) valueBuilder.metaInterop();
|
||||
metaValueWriterProvider = (MetaProvider) valueBuilder.metaInteropProvider();
|
||||
valueFactory = valueBuilder.factory();
|
||||
defaultValueProvider = builder.defaultValueProvider();
|
||||
prepareValueBytesAsWriter = builder.prepareValueBytesAsWriter();
|
||||
|
||||
|
||||
@@ -22,6 +22,9 @@ import net.openhft.chronicle.hash.*;
|
||||
import net.openhft.chronicle.hash.replication.SimpleReplication;
|
||||
import net.openhft.chronicle.hash.replication.TcpConfig;
|
||||
import net.openhft.chronicle.hash.replication.TimeProvider;
|
||||
import net.openhft.chronicle.hash.serialization.BytesReader;
|
||||
import net.openhft.chronicle.hash.serialization.BytesWriter;
|
||||
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.lang.io.serialization.BytesMarshaller;
|
||||
@@ -53,7 +56,8 @@ public class ChronicleSetBuilder<E>
|
||||
|
||||
ChronicleSetBuilder(Class<E> keyClass) {
|
||||
chronicleMapBuilder = ChronicleMapBuilder.of(keyClass, DummyValue.class)
|
||||
.valueMarshallers(DummyValueMarshaller.INSTANCE, DummyValueMarshaller.INSTANCE);
|
||||
.valueMarshallers(DummyValueMarshaller.INSTANCE, DummyValueMarshaller.INSTANCE)
|
||||
.valueSizeMarshaller(DummyValueMarshaller.INSTANCE);
|
||||
}
|
||||
|
||||
public static <K> ChronicleSetBuilder<K> of(Class<K> keyClass) {
|
||||
@@ -225,6 +229,19 @@ public class ChronicleSetBuilder<E>
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleSetBuilder<E> keyMarshallers(@NotNull BytesWriter<E> keyWriter,
|
||||
@NotNull BytesReader<E> keyReader) {
|
||||
chronicleMapBuilder.keyMarshallers(keyWriter, keyReader);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleSetBuilder<E> keySizeMarshaller(@NotNull SizeMarshaller keySizeMarshaller) {
|
||||
chronicleMapBuilder.keySizeMarshaller(keySizeMarshaller);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user