mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Use ChronicleMapBuilder to build all ChronicleMap
This commit is contained in:
@@ -18,7 +18,10 @@
|
||||
|
||||
package net.openhft.chronicle.map;
|
||||
|
||||
import net.openhft.chronicle.hash.*;
|
||||
import net.openhft.chronicle.hash.ChronicleHashBuilder;
|
||||
import net.openhft.chronicle.hash.ChronicleHashErrorListener;
|
||||
import net.openhft.chronicle.hash.ChronicleHashErrorListeners;
|
||||
import net.openhft.chronicle.hash.ChronicleHashInstanceBuilder;
|
||||
import net.openhft.chronicle.hash.replication.*;
|
||||
import net.openhft.chronicle.hash.serialization.*;
|
||||
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
|
||||
@@ -188,6 +191,11 @@ public final class ChronicleMapBuilder<K, V> implements Cloneable,
|
||||
return new ChronicleMapBuilder<>(keyClass, valueClass);
|
||||
}
|
||||
|
||||
public static <K, V> ChronicleMapStatelessClientBuilder<K, V> of(
|
||||
@NotNull Class<K> keyClass, @NotNull Class<V> valueClass, InetSocketAddress socketAddress) {
|
||||
return ChronicleMapStatelessClientBuilder.of(socketAddress);
|
||||
}
|
||||
|
||||
private static long roundUpMapHeaderSize(long headerSize) {
|
||||
long roundUp = (headerSize + 127L) & ~127L;
|
||||
if (roundUp - headerSize < 64)
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class ChronicleMapStatelessClientBuilder<K, V> implements
|
||||
ChronicleMap<K, V>>,
|
||||
MapBuilder<ChronicleMapStatelessClientBuilder<K, V>> {
|
||||
|
||||
public static <K, V> ChronicleMapStatelessClientBuilder<K, V> of(
|
||||
static <K, V> ChronicleMapStatelessClientBuilder<K, V> of(
|
||||
InetSocketAddress serverAddress) {
|
||||
return new ChronicleMapStatelessClientBuilder<>(serverAddress);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package net.openhft.chronicle.set;
|
||||
|
||||
import net.openhft.chronicle.hash.ChronicleHashStatelessClientBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapStatelessClientBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -34,7 +35,8 @@ public final class ChronicleSetStatelessClientBuilder<E> implements
|
||||
private final ChronicleMapStatelessClientBuilder<E, DummyValue> mapClientBuilder;
|
||||
|
||||
ChronicleSetStatelessClientBuilder(InetSocketAddress serverAddress) {
|
||||
this.mapClientBuilder = ChronicleMapStatelessClientBuilder.of(serverAddress);
|
||||
Class<E> eClass = null;
|
||||
this.mapClientBuilder = ChronicleMapBuilder.of(eClass, DummyValue.class, serverAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ package eg;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapStatelessClientBuilder;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@@ -102,8 +101,8 @@ public class BGChronicleTest {
|
||||
public Void call() throws IOException {
|
||||
InetSocketAddress serverAddress =
|
||||
REPLICAS > 1 && clientId % 2 == 0 ? remoteAddress2 : remoteAddress;
|
||||
try (ChronicleMap<byte[], byte[]> map = ChronicleMapStatelessClientBuilder
|
||||
.<byte[], byte[]>of(serverAddress)
|
||||
try (ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder
|
||||
.of(byte[].class, byte[].class, serverAddress)
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
.create()) {
|
||||
@@ -138,8 +137,8 @@ public class BGChronicleTest {
|
||||
futureList2.add(es.submit(new Callable<long[]>() {
|
||||
@Override
|
||||
public long[] call() throws IOException, InterruptedException {
|
||||
try (ChronicleMap<byte[], byte[]> map = ChronicleMapStatelessClientBuilder
|
||||
.<byte[], byte[]>of(remoteAddress)
|
||||
try (ChronicleMap<byte[], byte[]> map = ChronicleMapBuilder
|
||||
.of(byte[].class, byte[].class, remoteAddress)
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
.create()) {
|
||||
|
||||
@@ -1126,12 +1126,12 @@ public class CHMUseCasesTest {
|
||||
}));
|
||||
|
||||
try {
|
||||
map.putMapped(1.0, new UnaryOperator<Double>() {
|
||||
@Override
|
||||
public Double update(Double s) {
|
||||
return s + 1;
|
||||
}
|
||||
});
|
||||
map.putMapped(1.0, new UnaryOperator<Double>() {
|
||||
@Override
|
||||
public Double update(Double s) {
|
||||
return s + 1;
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception todoMoreSpecificException) {
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ public class StatelessClientTest {
|
||||
serverMap.put(10, new StringBuilder("Hello World"));
|
||||
|
||||
try (ChronicleMap<Integer, StringBuilder> statelessMap =
|
||||
ChronicleMapStatelessClientBuilder
|
||||
.<Integer, StringBuilder>of(new InetSocketAddress("localhost", port))
|
||||
ChronicleMapBuilder
|
||||
.of(Integer.class, StringBuilder.class, new InetSocketAddress("localhost", port))
|
||||
.putReturnsNull(true)
|
||||
.create()) {
|
||||
String actual = statelessMap.getMapped(10, ToString.INSTANCE);
|
||||
|
||||
@@ -21,7 +21,6 @@ package net.openhft.chronicle.map.example;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapStatelessClientBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -42,11 +41,11 @@ public class ServersMapMain {
|
||||
file.deleteOnExit();
|
||||
final ChronicleMap<byte[], byte[]> serverMap =
|
||||
ChronicleMapBuilder.of(byte[].class, byte[].class)
|
||||
.putReturnsNull(true)
|
||||
.constantKeySizeBySample(new byte[8])
|
||||
.constantValueSizeBySample(new byte[32])
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(port))
|
||||
.createPersistedTo(file);
|
||||
.putReturnsNull(true)
|
||||
.constantKeySizeBySample(new byte[8])
|
||||
.constantValueSizeBySample(new byte[32])
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(port))
|
||||
.createPersistedTo(file);
|
||||
System.out.println("Server started");
|
||||
System.in.read();
|
||||
serverMap.close();
|
||||
@@ -55,8 +54,8 @@ public class ServersMapMain {
|
||||
public static void startRemoteClient(String hostname) throws IOException {
|
||||
final ChronicleMap<byte[], byte[]> map;
|
||||
if (stateless) {
|
||||
map = ChronicleMapStatelessClientBuilder
|
||||
.<byte[], byte[]>of(new InetSocketAddress(hostname, port))
|
||||
map = ChronicleMapBuilder
|
||||
.of(byte[].class, byte[].class, new InetSocketAddress(hostname, port))
|
||||
.putReturnsNull(true)
|
||||
.create();
|
||||
} else {
|
||||
@@ -65,8 +64,8 @@ public class ServersMapMain {
|
||||
TcpTransportAndNetworkConfig tcpConfig =
|
||||
TcpTransportAndNetworkConfig.of(port, new InetSocketAddress(hostname, port));
|
||||
|
||||
map = ChronicleMapBuilder.of(
|
||||
byte[].class, byte[].class)
|
||||
map = ChronicleMapBuilder
|
||||
.of(byte[].class, byte[].class)
|
||||
.putReturnsNull(true)
|
||||
.replication((byte) 1, tcpConfig)
|
||||
.createPersistedTo(file);
|
||||
|
||||
@@ -21,7 +21,6 @@ package net.openhft.chronicle.map.example;
|
||||
import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
|
||||
import net.openhft.chronicle.map.ChronicleMap;
|
||||
import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.chronicle.map.ChronicleMapStatelessClientBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -56,8 +55,8 @@ public class StringsMapMain {
|
||||
public static void startRemoteClient(String hostname) throws IOException {
|
||||
final ChronicleMap<CharSequence, CharSequence> map;
|
||||
if (stateless) {
|
||||
map = ChronicleMapStatelessClientBuilder
|
||||
.<CharSequence, CharSequence>of(new InetSocketAddress(hostname, port))
|
||||
map = ChronicleMapBuilder
|
||||
.of(CharSequence.class, CharSequence.class, new InetSocketAddress(hostname, port))
|
||||
.putReturnsNull(true)
|
||||
.create();
|
||||
} else {
|
||||
|
||||
@@ -267,8 +267,8 @@ public class StatelessChronicleMapTest extends JSR166TestCase {
|
||||
.replication((byte) 2, TcpTransportAndNetworkConfig.of(port))
|
||||
.create();
|
||||
|
||||
final ChronicleMap<byte[], byte[]> statelessMap = ChronicleMapStatelessClientBuilder
|
||||
.<byte[], byte[]>of(new InetSocketAddress("localhost", port))
|
||||
final ChronicleMap<byte[], byte[]> statelessMap = ChronicleMapBuilder
|
||||
.of(byte[].class, byte[].class, new InetSocketAddress("localhost", port))
|
||||
.putReturnsNull(true)
|
||||
.create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user