From 49172e4b3baf489bc730e8d916188c733770c77a Mon Sep 17 00:00:00 2001 From: leventov Date: Fri, 7 Nov 2014 16:15:37 +0300 Subject: [PATCH 1/2] HCOLL-136 added keyMarshallers(), keySizeMarshaller() and valueSizeMarshaller() methods to Builder interfaces; removed factory field from SerializationBuilder and VanillaChronicleMap as unused --- .../openhft/chronicle/hash/ChronicleHash.java | 2 +- .../chronicle/hash/ChronicleHashBuilder.java | 42 +++++++++- .../map/AbstractChronicleMapBuilder.java | 18 ++++- .../chronicle/map/ChronicleMapBuilder.java | 61 +++++++++++++-- .../chronicle/map/SerializationBuilder.java | 77 ++++++++----------- .../chronicle/map/VanillaChronicleMap.java | 2 - .../chronicle/set/ChronicleSetBuilder.java | 19 ++++- 7 files changed, 165 insertions(+), 56 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java index 93b34eaa8..e10a6f245 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java @@ -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(); diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java index 4f86d0980..7a1caecdc 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHashBuilder.java @@ -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 ChronicleHashBuilderDefault lock time out is 2 seconds. @@ -286,10 +287,49 @@ public interface ChronicleHashBuilder keyMarshaller); + /** + * Configures the marshallers, used to serialize/deserialize keys to/from off-heap + * memory in hash containers, created by this builder. See + * the section about + * serialization in ChronicleMap manual for more information. + * + *

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)}. + * + *

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 keyWriter, @NotNull BytesReader keyReader); + + /** + * Configures the marshaller used to serialize actual key sizes to off-heap memory + * in hash containers, created by this builder. + * + *

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, diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java index 44c578a79..65ac1f37d 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java @@ -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 keyMarshaller) { - keyBuilder.marshaller(keyMarshaller, null); + keyBuilder.marshaller(keyMarshaller); + return self(); + } + + @Override + public B keyMarshallers(@NotNull BytesWriter keyWriter, @NotNull BytesReader keyReader) { + keyBuilder.writer(keyWriter); + keyBuilder.reader(keyReader); + return self(); + } + + @Override + public B keySizeMarshaller(@NotNull SizeMarshaller keySizeMarshaller) { + keyBuilder.sizeMarshaller(keySizeMarshaller); return self(); } diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index 65828fc97..f2118d8c8 100644 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -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 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 + * the + * section about serialization in ChronicleMap manual 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 valueMarshaller( @NotNull BytesMarshaller 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 + * the section about + * serialization in ChronicleMap manual for more information. + * + *

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)}. + * + *

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 valueMarshallers( - BytesWriter valueWriter, BytesReader valueReader) { + @NotNull BytesWriter valueWriter, @NotNull BytesReader 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. + * + *

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 valueSizeMarshaller( + @NotNull SizeMarshaller valueSizeMarshaller) { + valueBuilder.sizeMarshaller(valueSizeMarshaller); return this; } } diff --git a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java index 3c6b46510..99adb577c 100644 --- a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java @@ -60,7 +60,7 @@ final class SerializationBuilder implements Cloneable { private enum CopyingInterop {FROM_MARSHALLER, FROM_WRITER} - private final Serializable bufferIdentity; + private final Role role; final Class eClass; private boolean instancesAreMutable; private SizeMarshaller sizeMarshaller = stopBit(); @@ -70,11 +70,10 @@ final class SerializationBuilder implements Cloneable { private MetaBytesInterop metaInterop; private MetaProvider metaInteropProvider; private long maxSize; - private ObjectFactory factory; @SuppressWarnings("unchecked") SerializationBuilder(Class eClass, Role role) { - this.bufferIdentity = role; + this.role = role; this.eClass = eClass; instancesAreMutable = instancesAreMutable(eClass); @@ -83,39 +82,39 @@ final class SerializationBuilder implements Cloneable { NullObjectFactory.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) CharSequenceReader.of(), factory); + reader((BytesReader) CharSequenceReader.of()); writer((BytesWriter) CharSequenceWriter.instance()); } else if (eClass == Void.class) { sizeMarshaller(VoidMarshaller.INSTANCE) - .reader((BytesReader) VoidMarshaller.INSTANCE, factory) + .reader((BytesReader) VoidMarshaller.INSTANCE) .interop((BytesInterop) VoidMarshaller.INSTANCE); } else if (eClass == Long.class) { sizeMarshaller(LongMarshaller.INSTANCE) - .reader((BytesReader) LongMarshaller.INSTANCE, factory) + .reader((BytesReader) LongMarshaller.INSTANCE) .interop((BytesInterop) LongMarshaller.INSTANCE); } else if (eClass == Double.class) { sizeMarshaller(DoubleMarshaller.INSTANCE) - .reader((BytesReader) DoubleMarshaller.INSTANCE, factory) + .reader((BytesReader) DoubleMarshaller.INSTANCE) .interop((BytesInterop) DoubleMarshaller.INSTANCE); } else if (eClass == Integer.class) { sizeMarshaller(IntegerMarshaller.INSTANCE) - .reader((BytesReader) IntegerMarshaller.INSTANCE, factory) + .reader((BytesReader) IntegerMarshaller.INSTANCE) .interop((BytesInterop) IntegerMarshaller.INSTANCE); } else if (eClass == byte[].class) { - reader((BytesReader) ByteArrayMarshaller.INSTANCE, factory); + reader((BytesReader) ByteArrayMarshaller.INSTANCE); interop((BytesInterop) ByteArrayMarshaller.INSTANCE); } else if (eClass == char[].class) { - reader((BytesReader) CharArrayMarshaller.INSTANCE, factory); + reader((BytesReader) CharArrayMarshaller.INSTANCE); interop((BytesInterop) CharArrayMarshaller.INSTANCE); } else if (concreteClass(eClass)) { BytesMarshaller 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 implements Cloneable { return copyingInterop(CopyingInterop.FROM_WRITER) .setInterop(writer) .metaInterop(CopyingMetaBytesInterop - .>forBytesWriter(bufferIdentity)); + .>forBytesWriter(role)); } - public SerializationBuilder marshaller(BytesMarshaller marshaller, - ObjectFactory factory) { - if (factory == null) factory = this.factory; + public SerializationBuilder marshaller(BytesMarshaller marshaller) { return copyingInterop(CopyingInterop.FROM_MARSHALLER) - .reader(BytesReaders.fromBytesMarshaller(marshaller), factory) + .reader(BytesReaders.fromBytesMarshaller(marshaller)) .setInterop(marshaller) .metaInterop(CopyingMetaBytesInterop - .>forBytesMarshaller(bufferIdentity)); + .>forBytesMarshaller(role)); } public SerializationBuilder maxSize(long maxSize) { @@ -218,10 +215,7 @@ final class SerializationBuilder implements Cloneable { public SerializationBuilder objectSerializer(ObjectSerializer serializer) { if (reader == null || interop == null) { - ObjectFactory 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 implements Cloneable { return reader; } - public SerializationBuilder reader(BytesReader reader, ObjectFactory factory) { + public SerializationBuilder reader(BytesReader reader) { this.reader = reader; - if (factory != null) - this.factory = factory; return this; } @@ -281,10 +273,6 @@ final class SerializationBuilder implements Cloneable { return this; } - public ObjectFactory factory() { - return factory; - } - @SuppressWarnings("unchecked") public SerializationBuilder factory(ObjectFactory factory) { if (!marshallerUseFactory(eClass)) { @@ -292,19 +280,17 @@ final class SerializationBuilder 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 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 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; } diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 98a46941c..23ba887ec 100644 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -76,7 +76,6 @@ class VanillaChronicleMap, final VW originalValueWriter; final MVW originalMetaValueWriter; final MetaProvider metaValueWriterProvider; - final ObjectFactory valueFactory; final DefaultValueProvider defaultValueProvider; final PrepareValueBytesAsWriter prepareValueBytesAsWriter; final int metaDataBytes; @@ -126,7 +125,6 @@ class VanillaChronicleMap, originalValueWriter = (VW) valueBuilder.interop(); originalMetaValueWriter = (MVW) valueBuilder.metaInterop(); metaValueWriterProvider = (MetaProvider) valueBuilder.metaInteropProvider(); - valueFactory = valueBuilder.factory(); defaultValueProvider = builder.defaultValueProvider(); prepareValueBytesAsWriter = builder.prepareValueBytesAsWriter(); diff --git a/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java b/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java index fd607424c..3150e7b80 100644 --- a/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java +++ b/src/main/java/net/openhft/chronicle/set/ChronicleSetBuilder.java @@ -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 ChronicleSetBuilder(Class keyClass) { chronicleMapBuilder = ChronicleMapBuilder.of(keyClass, DummyValue.class) - .valueMarshallers(DummyValueMarshaller.INSTANCE, DummyValueMarshaller.INSTANCE); + .valueMarshallers(DummyValueMarshaller.INSTANCE, DummyValueMarshaller.INSTANCE) + .valueSizeMarshaller(DummyValueMarshaller.INSTANCE); } public static ChronicleSetBuilder of(Class keyClass) { @@ -225,6 +229,19 @@ public class ChronicleSetBuilder return this; } + @Override + public ChronicleSetBuilder keyMarshallers(@NotNull BytesWriter keyWriter, + @NotNull BytesReader keyReader) { + chronicleMapBuilder.keyMarshallers(keyWriter, keyReader); + return this; + } + + @Override + public ChronicleSetBuilder keySizeMarshaller(@NotNull SizeMarshaller keySizeMarshaller) { + chronicleMapBuilder.keySizeMarshaller(keySizeMarshaller); + return this; + } + /** * {@inheritDoc} * From 8d64a6f8e8ec8a6c1f97780e7a763ac82a51425f Mon Sep 17 00:00:00 2001 From: leventov Date: Fri, 7 Nov 2014 16:37:27 +0300 Subject: [PATCH 2/2] Minor API cleanups --- ...xception.java => RemoteCallTimeoutException.java} | 9 +++++---- .../hash/replication/AbstractReplication.java | 12 ++++++------ .../chronicle/hash/replication/ReplicationHub.java | 10 ++++++++++ .../hash/replication/SimpleReplication.java | 10 ++++++++++ .../chronicle/hash/replication/TcpConfig.java | 8 ++++---- .../{hash/exceptions => map}/IORuntimeException.java | 4 ++-- .../net/openhft/chronicle/map/NodeDiscovery.java | 2 +- .../openhft/chronicle/map/StatelessChronicleMap.java | 5 ++--- src/test/java/net/openhft/chronicle/map/Builder.java | 2 +- .../TCPSocketReplicationTest3wayPutReturnsNull.java | 2 +- .../set/SetForTCPSocketReplicationTest3way.java | 3 +-- 11 files changed, 43 insertions(+), 24 deletions(-) rename src/main/java/net/openhft/chronicle/hash/{exceptions/TimeoutRuntimeException.java => RemoteCallTimeoutException.java} (76%) rename src/main/java/net/openhft/chronicle/{hash/exceptions => map}/IORuntimeException.java (88%) diff --git a/src/main/java/net/openhft/chronicle/hash/exceptions/TimeoutRuntimeException.java b/src/main/java/net/openhft/chronicle/hash/RemoteCallTimeoutException.java similarity index 76% rename from src/main/java/net/openhft/chronicle/hash/exceptions/TimeoutRuntimeException.java rename to src/main/java/net/openhft/chronicle/hash/RemoteCallTimeoutException.java index 477e5b56e..eedb9a276 100644 --- a/src/main/java/net/openhft/chronicle/hash/exceptions/TimeoutRuntimeException.java +++ b/src/main/java/net/openhft/chronicle/hash/RemoteCallTimeoutException.java @@ -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(); } } diff --git a/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java b/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java index ac269165b..53bc4f538 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/AbstractReplication.java @@ -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 { - protected UdpConfig udpConfig = null; - protected TcpConfig tcpConfig = null; + private TcpConfig tcpConfig = null; + private UdpConfig udpConfig = null; public B tcpTransportAndNetwork(TcpConfig tcpConfig) { this.tcpConfig = tcpConfig; diff --git a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java index 6c833c8f1..6b75785a6 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/ReplicationHub.java @@ -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; diff --git a/src/main/java/net/openhft/chronicle/hash/replication/SimpleReplication.java b/src/main/java/net/openhft/chronicle/hash/replication/SimpleReplication.java index 0f716083f..b32dbda8a 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/SimpleReplication.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/SimpleReplication.java @@ -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); + } } } diff --git a/src/main/java/net/openhft/chronicle/hash/replication/TcpConfig.java b/src/main/java/net/openhft/chronicle/hash/replication/TcpConfig.java index 66332f21e..97f97de26 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/TcpConfig.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/TcpConfig.java @@ -64,15 +64,15 @@ public final class TcpConfig { Collection 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.emptyList()); + return forUnknownTopology(serverPort, Collections.emptyList()); } - public static TcpConfig unknownTopology(int serverPort, - Collection endpoints) { + public static TcpConfig forUnknownTopology(int serverPort, + Collection endpoints) { for (final InetSocketAddress endpoint : endpoints) { if (endpoint.getPort() == serverPort && "localhost".equals(endpoint.getHostName())) throw new IllegalArgumentException("endpoint=" + endpoint diff --git a/src/main/java/net/openhft/chronicle/hash/exceptions/IORuntimeException.java b/src/main/java/net/openhft/chronicle/map/IORuntimeException.java similarity index 88% rename from src/main/java/net/openhft/chronicle/hash/exceptions/IORuntimeException.java rename to src/main/java/net/openhft/chronicle/map/IORuntimeException.java index 48fafd020..e58603bd8 100644 --- a/src/main/java/net/openhft/chronicle/hash/exceptions/IORuntimeException.java +++ b/src/main/java/net/openhft/chronicle/map/IORuntimeException.java @@ -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); diff --git a/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java b/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java index 97eca2983..10b2954c2 100644 --- a/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java +++ b/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java @@ -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); diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 77784449a..38eee0456 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -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 implements ChronicleMap, Closeable { private void checkTimeout(long timeoutTime) { if (timeoutTime < System.currentTimeMillis()) - throw new TimeoutRuntimeException(); + throw new RemoteCallTimeoutException(); } private void writeSizeAndTransactionIdAt(long locationOfSize, final long transactionId) { diff --git a/src/test/java/net/openhft/chronicle/map/Builder.java b/src/test/java/net/openhft/chronicle/map/Builder.java index 41db8cced..8b5fd4afd 100644 --- a/src/test/java/net/openhft/chronicle/map/Builder.java +++ b/src/test/java/net/openhft/chronicle/map/Builder.java @@ -72,7 +72,7 @@ public class Builder { final byte identifier, final int serverPort, final InetSocketAddress... endpoints) throws IOException { - TcpConfig tcpConfig = TcpConfig.unknownTopology(serverPort, Arrays.asList(endpoints)) + TcpConfig tcpConfig = TcpConfig.forUnknownTopology(serverPort, Arrays.asList(endpoints)) .heartBeatInterval(1L, TimeUnit.SECONDS); return ChronicleMapBuilder.of(kClass, vClass) .replication(identifier, tcpConfig); diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest3wayPutReturnsNull.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest3wayPutReturnsNull.java index 98636a26b..cbe2fb665 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest3wayPutReturnsNull.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest3wayPutReturnsNull.java @@ -48,7 +48,7 @@ public class TCPSocketReplicationTest3wayPutReturnsNull { final byte identifier, final int serverPort, final InetSocketAddress... endpoints) throws IOException { - TcpConfig tcpConfig = TcpConfig.unknownTopology(serverPort, Arrays.asList(endpoints)); + TcpConfig tcpConfig = TcpConfig.forUnknownTopology(serverPort, Arrays.asList(endpoints)); return (T) ChronicleMapBuilder.of(Integer.class, CharSequence.class) .putReturnsNull(true) diff --git a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplicationTest3way.java b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplicationTest3way.java index 89325d86e..c7d7864ee 100644 --- a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplicationTest3way.java +++ b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplicationTest3way.java @@ -26,7 +26,6 @@ import org.junit.Test; import java.io.Closeable; import java.io.IOException; import java.net.InetSocketAddress; -import java.util.Arrays; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.SECONDS; @@ -53,7 +52,7 @@ public class SetForTCPSocketReplicationTest3way { final int serverPort, final InetSocketAddress... endpoints) throws IOException { return (T) ChronicleSetBuilder.of(Integer.class) - .replication(identifier, TcpConfig.unknownTopology(serverPort, asList(endpoints)) + .replication(identifier, TcpConfig.forUnknownTopology(serverPort, asList(endpoints)) .heartBeatInterval(1L, SECONDS)) .createPersistedTo(getPersistenceFile()); }