mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
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:
@@ -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;
|
||||
|
||||
|
||||
+5
-5
@@ -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> {
|
||||
|
||||
|
||||
}
|
||||
+2
-2
@@ -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>(
|
||||
|
||||
+14
-14
@@ -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,
|
||||
|
||||
+5
-5
@@ -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
|
||||
|
||||
+14
-14
@@ -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());
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -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
|
||||
Reference in New Issue
Block a user