Made TcpConfig back immutable; Draw the borderline: Builders are mutable, Configs are immutable (hence ChronicleHashInstanceBuilder and StatelessClientBuilder renamed to Configs; improved TcpConfig static factory naming

This commit is contained in:
leventov
2014-11-07 12:24:52 +03:00
parent 4a51b129a3
commit 4c86dae04f
29 changed files with 198 additions and 215 deletions
+1 -1
View File
@@ -1023,7 +1023,7 @@ but in your example you should choose the host of the state-full server and the
.statelessClient(new InetSocketAddress(<host of state-full server>, <port of state-full server>))
```
the ".statelessClient(..)" returns an instance of `StatelessClientBuilder`, which has only a few
the ".statelessClient(..)" returns an instance of `StatelessClientConfig`, which has only a few
own configurations and `create()` method to create a new stateless client.
method tells `ChronicleMap` that its going to build a stateless client.
If you don’t add this line a normal state-full `ChronicleMap` will be created. For this example
@@ -340,7 +340,7 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
*
* @param replication the replication config
* @return this builder back
* @see ChronicleHashInstanceBuilder#replicated(SimpleReplication)
* @see ChronicleHashInstanceConfig#replicated(SimpleReplication)
* @see #replication(byte, TcpConfig)
*/
B replication(SimpleReplication replication);
@@ -353,13 +353,13 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
* @param tcpTransportAndNetwork configuration of tcp connection and network
* @return this builder back
* @see #replication(SimpleReplication)
* @see ChronicleHashInstanceBuilder#replicated(byte, TcpConfig)
* @see ChronicleHashInstanceConfig#replicated(byte, TcpConfig)
*/
B replication(byte identifier, TcpConfig tcpTransportAndNetwork);
StatelessClientBuilder<C> statelessClient(InetSocketAddress remoteAddress);
StatelessClientConfig<C> statelessClient(InetSocketAddress remoteAddress);
ChronicleHashInstanceBuilder<C> instance();
ChronicleHashInstanceConfig<C> instance();
/**
* Creates a new hash container, storing it's data in off-heap memory, not mapped to any file.
@@ -401,7 +401,7 @@ public interface ChronicleHashBuilder<K, C extends ChronicleHash,
* @see ChronicleHash#file()
* @see ChronicleHash#close()
* @see #create()
* @see ChronicleHashInstanceBuilder#persistedTo(File)
* @see ChronicleHashInstanceConfig#persistedTo(File)
*/
C createPersistedTo(File file) throws IOException;
@@ -23,11 +23,11 @@ import net.openhft.chronicle.hash.replication.TcpConfig;
import java.io.File;
import java.io.IOException;
public interface ChronicleHashInstanceBuilder<C extends ChronicleHash> {
public interface ChronicleHashInstanceConfig<C extends ChronicleHash> {
ChronicleHashInstanceBuilder<C> replicated(byte identifier, TcpConfig tcpTransportAndNetwork);
ChronicleHashInstanceConfig<C> replicated(byte identifier, TcpConfig tcpTransportAndNetwork);
ChronicleHashInstanceBuilder<C> replicated(SimpleReplication replication);
ChronicleHashInstanceConfig<C> replicated(SimpleReplication replication);
/**
* Configures replication of the hash containers, created by this builder, via so called
@@ -49,9 +49,9 @@ public interface ChronicleHashInstanceBuilder<C extends ChronicleHash> {
* @return this builder object back
* @see #replicated(SimpleReplication)
*/
ChronicleHashInstanceBuilder<C> replicatedViaChannel(ReplicationChannel channel);
ChronicleHashInstanceConfig<C> replicatedViaChannel(ReplicationChannel channel);
ChronicleHashInstanceBuilder<C> persistedTo(File file);
ChronicleHashInstanceConfig<C> persistedTo(File file);
C create() throws IOException;
}
@@ -1,27 +0,0 @@
/*
* Copyright 2014 Higher Frequency Trading
*
* http://www.higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.hash;
/**
* @author Rob Austin.
*/
public interface ReplicationConfig<B> {
}
@@ -38,8 +38,8 @@ import java.util.concurrent.TimeUnit;
* @param <C> the type of {@code ChronicleHash} accessed remotely, {@code ChronicleMap} or
* {@code ChronicleSet}
*/
public interface StatelessClientBuilder<C extends ChronicleHash> {
StatelessClientBuilder<C> timeout(long timeout, TimeUnit units);
public interface StatelessClientConfig<C extends ChronicleHash> {
StatelessClientConfig<C> timeout(long timeout, TimeUnit units);
C create() throws IOException;
}
@@ -16,8 +16,6 @@
package net.openhft.chronicle.hash.replication;
import net.openhft.chronicle.hash.ReplicationConfig;
import java.io.IOException;
public final class ReplicationHub extends AbstractReplication {
@@ -16,6 +16,7 @@
package net.openhft.chronicle.hash.replication;
//TODO better name
public final class SimpleReplication extends AbstractReplication {
public static Builder builder() {
@@ -18,48 +18,84 @@
package net.openhft.chronicle.hash.replication;
import net.openhft.chronicle.hash.ReplicationConfig;
import org.jetbrains.annotations.NotNull;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import static java.util.Collections.unmodifiableSet;
import static java.util.concurrent.TimeUnit.SECONDS;
public class TcpConfig implements ReplicationConfig {
public final class TcpConfig {
private static final int DEFAULT_PACKET_SIZE = 1024 * 8;
private static final long DEFAULT_HEART_BEAT_INTERVAL = 20;
private static final TimeUnit DEFAULT_HEART_BEAT_INTERVAL_UNIT = SECONDS;
private int serverPort = DEFAULT_PACKET_SIZE;
private Set<InetSocketAddress> endpoints;
private int packetSize = DEFAULT_PACKET_SIZE;
private boolean autoReconnectedUponDroppedConnection = true;
private ThrottlingConfig throttlingConfig = ThrottlingConfig.noThrottling();
private long heartBeatInterval = DEFAULT_HEART_BEAT_INTERVAL;
private TimeUnit heartBeatIntervalUnit = DEFAULT_HEART_BEAT_INTERVAL_UNIT;
private IdentifierListener identifierListener;
private final int serverPort;
private final Set<InetSocketAddress> endpoints;
private final int packetSize;
private final boolean autoReconnectedUponDroppedConnection;
private final ThrottlingConfig throttlingConfig;
private final long heartBeatInterval;
private final TimeUnit heartBeatIntervalUnit;
private final IdentifierListener identifierListener;
TcpConfig() {
private TcpConfig(int serverPort, Set<InetSocketAddress> endpoints, int packetSize,
boolean autoReconnectedUponDroppedConnection,
ThrottlingConfig throttlingConfig, long heartBeatInterval,
TimeUnit heartBeatIntervalUnit, IdentifierListener identifierListener) {
this.serverPort = serverPort;
this.endpoints = endpoints;
this.packetSize = packetSize;
this.autoReconnectedUponDroppedConnection = autoReconnectedUponDroppedConnection;
this.throttlingConfig = throttlingConfig;
this.heartBeatInterval = heartBeatInterval;
this.heartBeatIntervalUnit = heartBeatIntervalUnit;
this.identifierListener = identifierListener;
}
public static TcpConfig forSendingNode(int serverPort, InetSocketAddress... endpoints) {
return forSendingNode(serverPort, Arrays.asList(endpoints));
}
public static TcpConfig forSendingNode(int serverPort,
Collection<InetSocketAddress> endpoints) {
if (endpoints.isEmpty())
throw new IllegalArgumentException("There should be some endpoints");
return unknownTopology(serverPort, endpoints);
}
public static TcpConfig forReceivingOnlyNode(int serverPort) {
return unknownTopology(serverPort, Collections.<InetSocketAddress>emptyList());
}
public static TcpConfig unknownTopology(int serverPort,
Collection<InetSocketAddress> endpoints) {
for (final InetSocketAddress endpoint : endpoints) {
if (endpoint.getPort() == serverPort && "localhost".equals(endpoint.getHostName()))
throw new IllegalArgumentException("endpoint=" + endpoint
+ " can not point to the same port as the server");
}
return new TcpConfig(
serverPort, unmodifiableSet(new HashSet<InetSocketAddress>(endpoints)),
DEFAULT_PACKET_SIZE,
true, // autoReconnectedUponDroppedConnection
ThrottlingConfig.noThrottling(),
DEFAULT_HEART_BEAT_INTERVAL,
DEFAULT_HEART_BEAT_INTERVAL_UNIT,
null); // identifierListener
}
public IdentifierListener nonUniqueIdentifierListener() {
return identifierListener;
}
public TcpConfig nonUniqueIdentifierListener(@NotNull final IdentifierListener
identifierListener) {
this.identifierListener = identifierListener;
return this;
public TcpConfig nonUniqueIdentifierListener(final IdentifierListener identifierListener) {
return new TcpConfig(serverPort, endpoints, packetSize,
autoReconnectedUponDroppedConnection, throttlingConfig, heartBeatInterval,
heartBeatIntervalUnit, identifierListener);
}
public boolean autoReconnectedUponDroppedConnection() {
@@ -67,17 +103,20 @@ public class TcpConfig implements ReplicationConfig {
}
public TcpConfig autoReconnectedUponDroppedConnection(boolean autoReconnectedUponDroppedConnection) {
this.autoReconnectedUponDroppedConnection = autoReconnectedUponDroppedConnection;
return this;
return new TcpConfig(serverPort, endpoints, packetSize,
autoReconnectedUponDroppedConnection, throttlingConfig, heartBeatInterval,
heartBeatIntervalUnit, identifierListener);
}
public ThrottlingConfig throttlingConfig() {
public ThrottlingConfig throttlingConfig() {
return throttlingConfig;
}
public TcpConfig throttlingConfig(ThrottlingConfig throttlingConfig) {
this.throttlingConfig = throttlingConfig;
return this;
ThrottlingConfig.checkMillisecondBucketInterval(throttlingConfig, "TCP");
return new TcpConfig(serverPort, endpoints, packetSize,
autoReconnectedUponDroppedConnection, throttlingConfig, heartBeatInterval,
heartBeatIntervalUnit, identifierListener);
}
public long heartBeatInterval(TimeUnit unit) {
@@ -89,8 +128,9 @@ public class TcpConfig implements ReplicationConfig {
}
public TcpConfig serverPort(int serverPort) {
this.serverPort = serverPort;
return this;
return new TcpConfig(serverPort, endpoints, packetSize,
autoReconnectedUponDroppedConnection, throttlingConfig, heartBeatInterval,
heartBeatIntervalUnit, identifierListener);
}
public Set<InetSocketAddress> endpoints() {
@@ -98,58 +138,32 @@ public class TcpConfig implements ReplicationConfig {
}
public TcpConfig endpoints(Set<InetSocketAddress> endpoints) {
for (final InetSocketAddress endpoint : endpoints) {
if (endpoint.getPort() == serverPort && "localhost".equals(endpoint.getHostName()))
throw new IllegalArgumentException("endpoint=" + endpoint
+ " can not point to the same port as the server");
}
this.endpoints = endpoints;
return this;
return new TcpConfig(serverPort, endpoints, packetSize,
autoReconnectedUponDroppedConnection, throttlingConfig, heartBeatInterval,
heartBeatIntervalUnit, identifierListener);
}
public int packetSize() {
return packetSize;
}
public static TcpConfig of(int serverPort, InetSocketAddress... endpoints) {
return of(serverPort, Arrays.asList(endpoints));
}
public static TcpConfig of(int serverPort, Collection<InetSocketAddress> endpoints) {
// at least in tests, we configure "receive-only" replication without endpoints.
// TODO decide what to do with this case
// if (endpoints.isEmpty())
// throw new IllegalArgumentException("There should be some endpoints");
for (final InetSocketAddress endpoint : endpoints) {
if (endpoint.getPort() == serverPort && "localhost".equals(endpoint.getHostName()))
throw new IllegalArgumentException("endpoint=" + endpoint
+ " can not point to the same port as the server");
}
TcpConfig tcpConfig = new TcpConfig();
tcpConfig.serverPort(serverPort);
tcpConfig.endpoints = unmodifiableSet(new HashSet<InetSocketAddress>(endpoints));
return tcpConfig;
}
public TcpConfig packetSize(int packetSize) {
if (packetSize <= 0)
throw new IllegalArgumentException();
this.packetSize = packetSize;
return this;
return new TcpConfig(serverPort, endpoints, packetSize,
autoReconnectedUponDroppedConnection, throttlingConfig, heartBeatInterval,
heartBeatIntervalUnit, identifierListener);
}
public TcpConfig throttlingConfig(long heartBeatInterval, TimeUnit heartBeatIntervalUnit) {
this.heartBeatInterval = heartBeatInterval;
this.heartBeatIntervalUnit = heartBeatIntervalUnit;
return this;
public TcpConfig heartBeatInterval(long heartBeatInterval, TimeUnit heartBeatIntervalUnit) {
return new TcpConfig(serverPort, endpoints, packetSize,
autoReconnectedUponDroppedConnection, throttlingConfig, heartBeatInterval,
heartBeatIntervalUnit, identifierListener);
}
@@ -196,12 +210,4 @@ public class TcpConfig implements ReplicationConfig {
", heartBeatIntervalUnit=" + heartBeatIntervalUnit +
'}';
}
public TcpConfig heartBeatInterval(long time, TimeUnit unit) {
this.heartBeatInterval = time;
this.heartBeatIntervalUnit = unit;
return this;
}
}
@@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
public class ThrottlingConfig {
private static final long DEFAULT_BUCKET_INTERVAL = 100L;
@@ -79,7 +78,7 @@ public class ThrottlingConfig {
return create(maxBits, perUnit, DEFAULT_BUCKET_INTERVAL, DEFAULT_BUCKET_INTERVAL_UNIT);
}
public static void checkMillisecondBucketInterval(ThrottlingConfig config, String replicator) {
static void checkMillisecondBucketInterval(ThrottlingConfig config, String replicator) {
if (config.bucketInterval(MILLISECONDS) < 1) {
throw new IllegalArgumentException(
"Minimum throttle bucketing interval of 1 millisecond is supported by " +
@@ -18,7 +18,6 @@
package net.openhft.chronicle.hash.replication;
import net.openhft.chronicle.hash.ReplicationConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -26,7 +25,7 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
public final class UdpConfig implements ReplicationConfig {
public final class UdpConfig {
private final InetAddress address;
private final int port;
private final NetworkInterface networkInterface;
@@ -50,6 +49,7 @@ public final class UdpConfig implements ReplicationConfig {
this.throttlingConfig = throttlingConfig;
}
// TODO better name
public static UdpConfig simple(@NotNull InetAddress address, int port) {
if (address.isMulticastAddress())
throw new IllegalArgumentException();
@@ -619,9 +619,9 @@ public abstract class AbstractChronicleMapBuilder<K, V,
}
@Override
public StatelessClientBuilder<ChronicleMap<K, V>> statelessClient(
public StatelessClientConfig<ChronicleMap<K, V>> statelessClient(
InetSocketAddress remoteAddress) {
return new StatelessMapBuilder<>(this.clone(), remoteAddress);
return new StatelessMapConfig<>(this.clone(), remoteAddress);
}
/**
@@ -736,8 +736,8 @@ public abstract class AbstractChronicleMapBuilder<K, V,
}
@Override
public ChronicleHashInstanceBuilder<ChronicleMap<K, V>> instance() {
return new InstanceBuilder<>(this.clone(), simpleReplication, null, null);
public ChronicleHashInstanceConfig<ChronicleMap<K, V>> instance() {
return new InstanceConfig<>(this.clone(), simpleReplication, null, null);
}
@Override
@@ -750,7 +750,7 @@ public abstract class AbstractChronicleMapBuilder<K, V,
return createWithoutFile(simpleReplication, null);
}
ChronicleMap<K, V> create(InstanceBuilder<K, V> ib) throws IOException {
ChronicleMap<K, V> create(InstanceConfig<K, V> ib) throws IOException {
if (ib.file != null) {
return createWithFile(ib.file, ib.simpleReplication, ib.channel);
} else {
@@ -830,7 +830,7 @@ public abstract class AbstractChronicleMapBuilder<K, V,
return establishReplication(map, simpleReplication, channel);
}
ChronicleMap<K, V> createStatelessMap(StatelessMapBuilder<K, V> statelessBuilder)
ChronicleMap<K, V> createStatelessMap(StatelessMapConfig<K, V> statelessBuilder)
throws IOException {
preMapConstruction(false);
return new StatelessChronicleMap<K, V>(
@@ -16,7 +16,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.ChronicleHashInstanceBuilder;
import net.openhft.chronicle.hash.ChronicleHashInstanceConfig;
import net.openhft.chronicle.hash.replication.ReplicationChannel;
import net.openhft.chronicle.hash.replication.SimpleReplication;
import net.openhft.chronicle.hash.replication.TcpConfig;
@@ -24,18 +24,18 @@ import net.openhft.chronicle.hash.replication.TcpConfig;
import java.io.File;
import java.io.IOException;
final class InstanceBuilder<K, V>
implements ChronicleHashInstanceBuilder<ChronicleMap<K, V>> {
final class InstanceConfig<K, V>
implements ChronicleHashInstanceConfig<ChronicleMap<K, V>> {
final AbstractChronicleMapBuilder<K, V, ?> mapBuilder;
final SimpleReplication simpleReplication;
final ReplicationChannel channel;
final File file;
InstanceBuilder(AbstractChronicleMapBuilder<K, V, ?> mapBuilder,
SimpleReplication simpleReplication,
ReplicationChannel channel,
File file) {
InstanceConfig(AbstractChronicleMapBuilder<K, V, ?> mapBuilder,
SimpleReplication simpleReplication,
ReplicationChannel channel,
File file) {
this.mapBuilder = mapBuilder;
this.simpleReplication = simpleReplication;
this.channel = channel;
@@ -43,27 +43,27 @@ final class InstanceBuilder<K, V>
}
@Override
public ChronicleHashInstanceBuilder<ChronicleMap<K, V>> replicated(
public ChronicleHashInstanceConfig<ChronicleMap<K, V>> replicated(
byte identifier, TcpConfig tcpTransportAndNetwork) {
return replicated(SimpleReplication.builder()
.tcpTransportAndNetwork(tcpTransportAndNetwork).create(identifier));
}
@Override
public ChronicleHashInstanceBuilder<ChronicleMap<K, V>> replicated(
public ChronicleHashInstanceConfig<ChronicleMap<K, V>> replicated(
SimpleReplication replication) {
return new InstanceBuilder<>(mapBuilder, replication, null, file);
return new InstanceConfig<>(mapBuilder, replication, null, file);
}
@Override
public ChronicleHashInstanceBuilder<ChronicleMap<K, V>> replicatedViaChannel(
public ChronicleHashInstanceConfig<ChronicleMap<K, V>> replicatedViaChannel(
ReplicationChannel channel) {
return new InstanceBuilder<>(mapBuilder, null, channel, file);
return new InstanceConfig<>(mapBuilder, null, channel, file);
}
@Override
public ChronicleHashInstanceBuilder<ChronicleMap<K, V>> persistedTo(File file) {
return new InstanceBuilder<>(mapBuilder, simpleReplication, channel, file);
public ChronicleHashInstanceConfig<ChronicleMap<K, V>> persistedTo(File file) {
return new InstanceConfig<>(mapBuilder, simpleReplication, channel, file);
}
@Override
@@ -222,8 +222,10 @@ public class NodeDiscovery {
knownNodes.add(ourAddressAndPort, identifier);
final TcpConfig tcpConfig = TcpConfig
.of(ourAddressAndPort.getPort(), toInetSocketArray(knownHostPorts))
.heartBeatInterval(1, SECONDS).nonUniqueIdentifierListener(identifierListener);
.unknownTopology(ourAddressAndPort.getPort(),
toInetSocketCollection(knownHostPorts))
.heartBeatInterval(1, SECONDS)
.nonUniqueIdentifierListener(identifierListener);
LOG.info("Using Remote identifier=" + identifier);
@@ -236,24 +238,22 @@ public class NodeDiscovery {
}
private InetSocketAddress[] toInetSocketArray(Set<AddressAndPort> source) throws
UnknownHostException {
private static Collection<InetSocketAddress> toInetSocketCollection(Set<AddressAndPort> source)
throws UnknownHostException {
// make a safe copy
final HashSet<AddressAndPort> addressAndPorts = new HashSet<AddressAndPort>(source);
if (addressAndPorts.isEmpty())
return new InetSocketAddress[0];
return Collections.emptyList();
final InetSocketAddress[] addresses = new InetSocketAddress[addressAndPorts.size()];
int i = 0;
ArrayList<InetSocketAddress> addresses =
new ArrayList<InetSocketAddress>(addressAndPorts.size());
for (final AddressAndPort addressAndPort : addressAndPorts) {
addresses[i++] = new InetSocketAddress(InetAddress.getByAddress(addressAndPort.address())
.getHostAddress(), addressAndPort.port());
addresses.add(new InetSocketAddress(InetAddress.getByAddress(addressAndPort.address())
.getHostAddress(), addressAndPort.port()));
}
return addresses;
}
@@ -60,7 +60,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
private volatile SocketChannel clientChannel;
private CloseablesManager closeables;
private final StatelessMapBuilder builder;
private final StatelessMapConfig builder;
private int maxEntrySize;
private final Class<K> kClass;
private final Class<V> vClass;
@@ -96,7 +96,7 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
private long transactionID;
StatelessChronicleMap(final StatelessMapBuilder builder,
StatelessChronicleMap(final StatelessMapConfig builder,
final AbstractChronicleMapBuilder chronicleMapBuilder) throws IOException {
this.builder = builder;
this.keyValueSerializer = new KeyValueSerializer<K, V>(chronicleMapBuilder.keyBuilder,
@@ -18,7 +18,7 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.StatelessClientBuilder;
import net.openhft.chronicle.hash.StatelessClientConfig;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -27,14 +27,14 @@ import java.util.concurrent.TimeUnit;
/**
* @author Rob Austin.
*/
class StatelessMapBuilder<K, V> implements StatelessClientBuilder<ChronicleMap<K, V>> {
class StatelessMapConfig<K, V> implements StatelessClientConfig<ChronicleMap<K, V>> {
private final AbstractChronicleMapBuilder<K, V, ?> mapBuilder;
private final InetSocketAddress remoteAddress;
private long timeoutMs = TimeUnit.SECONDS.toMillis(10);
StatelessMapBuilder(AbstractChronicleMapBuilder<K, V, ?> mapBuilder,
InetSocketAddress remoteAddress) {
StatelessMapConfig(AbstractChronicleMapBuilder<K, V, ?> mapBuilder,
InetSocketAddress remoteAddress) {
this.mapBuilder = mapBuilder;
this.remoteAddress = remoteAddress;
}
@@ -48,7 +48,7 @@ class StatelessMapBuilder<K, V> implements StatelessClientBuilder<ChronicleMap<K
}
@Override
public StatelessMapBuilder<K, V> timeout(long timeout, TimeUnit units) {
public StatelessMapConfig<K, V> timeout(long timeout, TimeUnit units) {
this.timeoutMs = units.toMillis(timeout);
return this;
}
@@ -261,14 +261,14 @@ public class ChronicleSetBuilder<E>
}
@Override
public StatelessClientBuilder<ChronicleSet<E>> statelessClient(
public StatelessClientConfig<ChronicleSet<E>> statelessClient(
InetSocketAddress remoteAddress) {
return new StatelessSetBuilder<>(chronicleMapBuilder.statelessClient(remoteAddress));
return new StatelessSetConfig<>(chronicleMapBuilder.statelessClient(remoteAddress));
}
@Override
public ChronicleHashInstanceBuilder<ChronicleSet<E>> instance() {
return new InstanceBuilder<>(chronicleMapBuilder.instance());
public ChronicleHashInstanceConfig<ChronicleSet<E>> instance() {
return new InstanceConfig<>(chronicleMapBuilder.instance());
}
@Override
@@ -16,7 +16,7 @@
package net.openhft.chronicle.set;
import net.openhft.chronicle.hash.ChronicleHashInstanceBuilder;
import net.openhft.chronicle.hash.ChronicleHashInstanceConfig;
import net.openhft.chronicle.hash.replication.ReplicationChannel;
import net.openhft.chronicle.hash.replication.SimpleReplication;
import net.openhft.chronicle.hash.replication.TcpConfig;
@@ -25,38 +25,38 @@ import net.openhft.chronicle.map.ChronicleMap;
import java.io.File;
import java.io.IOException;
final class InstanceBuilder<E> implements ChronicleHashInstanceBuilder<ChronicleSet<E>> {
final class InstanceConfig<E> implements ChronicleHashInstanceConfig<ChronicleSet<E>> {
private final ChronicleHashInstanceBuilder<ChronicleMap<E, DummyValue>> mapBuilder;
private final ChronicleHashInstanceConfig<ChronicleMap<E, DummyValue>> mapConfig;
InstanceBuilder(ChronicleHashInstanceBuilder<ChronicleMap<E, DummyValue>> mapBuilder) {
this.mapBuilder = mapBuilder;
InstanceConfig(ChronicleHashInstanceConfig<ChronicleMap<E, DummyValue>> mapConfig) {
this.mapConfig = mapConfig;
}
@Override
public ChronicleHashInstanceBuilder<ChronicleSet<E>> replicated(
public ChronicleHashInstanceConfig<ChronicleSet<E>> replicated(
byte identifier, TcpConfig tcpTransportAndNetwork) {
return new InstanceBuilder<>(mapBuilder.replicated(identifier, tcpTransportAndNetwork));
return new InstanceConfig<>(mapConfig.replicated(identifier, tcpTransportAndNetwork));
}
@Override
public ChronicleHashInstanceBuilder<ChronicleSet<E>> replicated(SimpleReplication replication) {
return new InstanceBuilder<>(mapBuilder.replicated(replication));
public ChronicleHashInstanceConfig<ChronicleSet<E>> replicated(SimpleReplication replication) {
return new InstanceConfig<>(mapConfig.replicated(replication));
}
@Override
public ChronicleHashInstanceBuilder<ChronicleSet<E>> replicatedViaChannel(
public ChronicleHashInstanceConfig<ChronicleSet<E>> replicatedViaChannel(
ReplicationChannel channel) {
return new InstanceBuilder<>(mapBuilder.replicatedViaChannel(channel));
return new InstanceConfig<>(mapConfig.replicatedViaChannel(channel));
}
@Override
public ChronicleHashInstanceBuilder<ChronicleSet<E>> persistedTo(File file) {
return new InstanceBuilder<>(mapBuilder.persistedTo(file));
public ChronicleHashInstanceConfig<ChronicleSet<E>> persistedTo(File file) {
return new InstanceConfig<>(mapConfig.persistedTo(file));
}
@Override
public ChronicleSet<E> create() throws IOException {
return new SetFromMap<>(mapBuilder.create());
return new SetFromMap<>(mapConfig.create());
}
}
@@ -16,23 +16,23 @@
package net.openhft.chronicle.set;
import net.openhft.chronicle.hash.StatelessClientBuilder;
import net.openhft.chronicle.hash.StatelessClientConfig;
import net.openhft.chronicle.map.ChronicleMap;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
final class StatelessSetBuilder<E> implements StatelessClientBuilder<ChronicleSet<E>> {
final class StatelessSetConfig<E> implements StatelessClientConfig<ChronicleSet<E>> {
private final StatelessClientBuilder<ChronicleMap<E, DummyValue>> mapClientBuilder;
private final StatelessClientConfig<ChronicleMap<E, DummyValue>> mapClientBuilder;
StatelessSetBuilder(StatelessClientBuilder<ChronicleMap<E, DummyValue>> mapClientBuilder) {
StatelessSetConfig(StatelessClientConfig<ChronicleMap<E, DummyValue>> mapClientBuilder) {
this.mapClientBuilder = mapClientBuilder;
}
@Override
public StatelessClientBuilder<ChronicleSet<E>> timeout(long timeout, TimeUnit units) {
return new StatelessSetBuilder<>(mapClientBuilder.timeout(timeout, units));
public StatelessClientConfig<ChronicleSet<E>> timeout(long timeout, TimeUnit units) {
return new StatelessSetConfig<>(mapClientBuilder.timeout(timeout, units));
}
@Override
@@ -25,6 +25,7 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/**
@@ -71,7 +72,7 @@ public class Builder {
final byte identifier,
final int serverPort,
final InetSocketAddress... endpoints) throws IOException {
TcpConfig tcpConfig = TcpConfig.of(serverPort, endpoints)
TcpConfig tcpConfig = TcpConfig.unknownTopology(serverPort, Arrays.asList(endpoints))
.heartBeatInterval(1L, TimeUnit.SECONDS);
return ChronicleMapBuilder.of(kClass, vClass)
.replication(identifier, tcpConfig);
@@ -54,7 +54,7 @@ public class ChannelReplicationTest {
public void setup() throws IOException {
{
TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
hubA = ReplicationHub.builder()
@@ -68,7 +68,7 @@ public class ChannelReplicationTest {
{
TcpConfig tcpConfig =
TcpConfig.of(8087).heartBeatInterval(1, SECONDS);
TcpConfig.forReceivingOnlyNode(8087).heartBeatInterval(1, SECONDS);
hubB = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig)
.create((byte) 2);
@@ -30,6 +30,8 @@ import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import static net.openhft.chronicle.hash.replication.TcpConfig.forSendingNode;
/**
* Test ReplicatedChronicleMap where the Replicated is over a TCP Socket
*
@@ -85,7 +87,7 @@ public class EventListenerTestWithTCPSocketReplication {
// we connect the maps via a TCP socket connection on port 8077
TcpConfig tcpConfig = TcpConfig.of(8076, new InetSocketAddress("localhost", 8077));
TcpConfig tcpConfig = forSendingNode(8076, new InetSocketAddress("localhost", 8077));
ChronicleMapBuilder<Integer, CharSequence> map1Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -96,7 +98,7 @@ public class EventListenerTestWithTCPSocketReplication {
// ---------- SERVER2 2 on the same server as ----------
{
TcpConfig tcpConfig = TcpConfig.of(8077);
TcpConfig tcpConfig = TcpConfig.forReceivingOnlyNode(8077);
ChronicleMapBuilder<Integer, CharSequence> map2Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -158,7 +160,7 @@ public class EventListenerTestWithTCPSocketReplication {
// we connect the maps via a TCP socket connection on port 8077
TcpConfig tcpConfig = TcpConfig.of(8076, new InetSocketAddress("localhost", 8077));
TcpConfig tcpConfig = forSendingNode(8076, new InetSocketAddress("localhost", 8077));
ChronicleMapBuilder<Integer, CharSequence> map1Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -170,7 +172,7 @@ public class EventListenerTestWithTCPSocketReplication {
// ---------- SERVER2 2 on the same server as ----------
{
TcpConfig tcpConfig = TcpConfig.of(8077);
TcpConfig tcpConfig = TcpConfig.forReceivingOnlyNode(8077);
ChronicleMapBuilder<Integer, CharSequence> map2Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -233,7 +235,7 @@ public class EventListenerTestWithTCPSocketReplication {
// we connect the maps via a TCP socket connection on port 8077
TcpConfig tcpConfig = TcpConfig.of(8076, new InetSocketAddress("localhost", 8077));
TcpConfig tcpConfig = forSendingNode(8076, new InetSocketAddress("localhost", 8077));
ChronicleMapBuilder<Integer, CharSequence> map1Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -245,7 +247,7 @@ public class EventListenerTestWithTCPSocketReplication {
// ---------- SERVER2 2 on the same server as ----------
{
TcpConfig tcpConfig = TcpConfig.of(8077);
TcpConfig tcpConfig = TcpConfig.forReceivingOnlyNode(8077);
ChronicleMapBuilder<Integer, CharSequence> map2Builder =
ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000L)
@@ -63,7 +63,7 @@ public class PostChannelCreationTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
hubA = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig)
@@ -82,7 +82,7 @@ public class PostChannelCreationTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8087, new InetSocketAddress("localhost", 8086))
.forSendingNode(8087, new InetSocketAddress("localhost", 8086))
.heartBeatInterval(1, SECONDS);
hubB = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig)
@@ -61,7 +61,7 @@ public class SingleMapChannelTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
int maxEntrySize = 1024;
byte identifier= 1;
@@ -78,7 +78,7 @@ public class SingleMapChannelTest {
{
final TcpConfig tcpConfig = TcpConfig
.of(8087, new InetSocketAddress("localhost", 8086))
.forSendingNode(8087, new InetSocketAddress("localhost", 8086))
.heartBeatInterval(1, SECONDS);
hubB = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig).create((byte) 2);
@@ -56,7 +56,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -99,7 +99,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -140,7 +140,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -173,7 +173,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
serverMap.put(10, "EXAMPLE-10");
}
@@ -212,7 +212,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
serverMap.put(10, "EXAMPLE-10");
}
@@ -244,7 +244,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
}
@@ -287,7 +287,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086))
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086))
.putReturnsNull(true)
.create();
}
@@ -333,7 +333,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086))
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086))
.putReturnsNull(true)
.removeReturnsNull(true)
.create();
@@ -372,7 +372,7 @@ public class StatelessClientTest {
// server
{
serverMap = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086))
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086))
.putReturnsNull(true)
.removeReturnsNull(true)
.create();
@@ -415,9 +415,9 @@ public class StatelessClientTest {
// server
{
serverMap1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8086)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8086)).create();
serverMap2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(8077)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8077)).create();
}
@@ -26,6 +26,7 @@ import org.junit.Test;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -47,7 +48,7 @@ public class TCPSocketReplicationTest3wayPutReturnsNull {
final byte identifier,
final int serverPort,
final InetSocketAddress... endpoints) throws IOException {
TcpConfig tcpConfig = TcpConfig.of(serverPort, endpoints);
TcpConfig tcpConfig = TcpConfig.unknownTopology(serverPort, Arrays.asList(endpoints));
return (T) ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.putReturnsNull(true)
@@ -30,7 +30,6 @@ import java.net.InetSocketAddress;
import static java.util.concurrent.TimeUnit.SECONDS;
import static net.openhft.chronicle.map.Builder.getPersistenceFile;
import static net.openhft.chronicle.hash.replication.TcpConfig.of;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -47,7 +46,7 @@ public class TwoMapOnDifferentServers {
public void setup() throws IOException {
final TcpConfig tcpConfig =
of(8076, new InetSocketAddress("localhost", 8077))
TcpConfig.forSendingNode(8076, new InetSocketAddress("localhost", 8077))
.heartBeatInterval(1, SECONDS);
@@ -57,7 +56,8 @@ public class TwoMapOnDifferentServers {
map2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
.entries(20000)
.replication((byte) 2, of(8077).heartBeatInterval(1, SECONDS)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(8077)
.heartBeatInterval(1, SECONDS)).create();
}
@After
@@ -70,7 +70,7 @@ public class ChannelExample {
byte identifier = (byte) 1;
TcpConfig tcpConfig = TcpConfig
.of(8086, new InetSocketAddress("localhost", 8087))
.forSendingNode(8086, new InetSocketAddress("localhost", 8087))
.heartBeatInterval(1, SECONDS);
@@ -105,7 +105,7 @@ public class ChannelExample {
byte identifier = (byte) 2;
TcpConfig tcpConfig =
TcpConfig.of(8087).heartBeatInterval(1, SECONDS);
TcpConfig.forReceivingOnlyNode(8087).heartBeatInterval(1, SECONDS);
hubOnServer2 = ReplicationHub.builder()
.tcpTransportAndNetwork(tcpConfig)
@@ -192,7 +192,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
final ChronicleMap<Integer, String> serverMap =
ChronicleMapBuilder.of(Integer.class, String.class)
.replication((byte) 1, TcpConfig.of(port)).create();
.replication((byte) 1, TcpConfig.forReceivingOnlyNode(port)).create();
final ChronicleMap<Integer, String> statelessMap = ChronicleMapBuilder.of(Integer
.class, String.class)
@@ -206,7 +206,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
IOException {
final ChronicleMap<CharSequence, CharSequence> serverMap = ChronicleMapBuilder.of(CharSequence.class, CharSequence.class)
.replication((byte) 2, TcpConfig.of(port)).create();
.replication((byte) 2, TcpConfig.forReceivingOnlyNode(port)).create();
final ChronicleMap<CharSequence, CharSequence> statelessMap = ChronicleMapBuilder.of(CharSequence
@@ -18,6 +18,7 @@
package net.openhft.chronicle.set;
import net.openhft.chronicle.hash.replication.TcpConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -25,10 +26,11 @@ 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;
import static net.openhft.chronicle.map.Builder.getPersistenceFile;
import static net.openhft.chronicle.hash.replication.TcpConfig.of;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -51,7 +53,7 @@ public class SetForTCPSocketReplicationTest3way {
final int serverPort,
final InetSocketAddress... endpoints) throws IOException {
return (T) ChronicleSetBuilder.of(Integer.class)
.replication(identifier, of(serverPort, endpoints)
.replication(identifier, TcpConfig.unknownTopology(serverPort, asList(endpoints))
.heartBeatInterval(1L, SECONDS))
.createPersistedTo(getPersistenceFile());
}