mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
JLANG-39 HCOLL-214 refactored builders (leaved a single builder class), fixes in DataValueBytesMarshallers implementation
This commit is contained in:
@@ -23,20 +23,28 @@ import net.openhft.chronicle.hash.StatelessClientConfig;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* @author Rob Austin.
|
||||
*/
|
||||
class StatelessMapConfig<K, V> implements StatelessClientConfig<ChronicleMap<K, V>> {
|
||||
|
||||
private final AbstractChronicleMapBuilder<K, V, ?> mapBuilder;
|
||||
private final ChronicleMapBuilder<K, V> mapBuilder;
|
||||
private final InetSocketAddress remoteAddress;
|
||||
private long timeoutMs = TimeUnit.SECONDS.toMillis(10);
|
||||
private final long timeoutMs;
|
||||
private final String name;
|
||||
|
||||
StatelessMapConfig(AbstractChronicleMapBuilder<K, V, ?> mapBuilder,
|
||||
InetSocketAddress remoteAddress) {
|
||||
private final AtomicBoolean used;
|
||||
|
||||
StatelessMapConfig(ChronicleMapBuilder<K, V> mapBuilder,
|
||||
InetSocketAddress remoteAddress, long timeoutMs,
|
||||
String name, AtomicBoolean used) {
|
||||
this.mapBuilder = mapBuilder;
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.timeoutMs = timeoutMs;
|
||||
this.name = name;
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
public long timeoutMs() {
|
||||
@@ -49,12 +57,28 @@ class StatelessMapConfig<K, V> implements StatelessClientConfig<ChronicleMap<K,
|
||||
|
||||
@Override
|
||||
public StatelessMapConfig<K, V> timeout(long timeout, TimeUnit units) {
|
||||
this.timeoutMs = units.toMillis(timeout);
|
||||
return this;
|
||||
return new StatelessMapConfig<>(mapBuilder, remoteAddress, units.toMillis(timeout),
|
||||
name, used);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatelessClientConfig<ChronicleMap<K, V>> name(String name) {
|
||||
return new StatelessMapConfig<>(mapBuilder, remoteAddress, timeoutMs, name, used);
|
||||
}
|
||||
|
||||
String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChronicleMap<K, V> create() throws IOException {
|
||||
return mapBuilder.createStatelessMap(this);
|
||||
if (!used.getAndSet(true)) {
|
||||
return mapBuilder.createStatelessClient(this);
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
"A stateless client has already been created using this config chain. " +
|
||||
"Create a new StatelessClientConfig (builder.statelessClient()) " +
|
||||
"to create a new stateless client");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user