CE-23 now supports map.get() on the server using the same map that wire uses

This commit is contained in:
Rob Austin
2015-04-22 16:43:11 +01:00
parent 2c79275d8e
commit bd643b106f
3 changed files with 14 additions and 16 deletions
@@ -23,7 +23,7 @@ public class MapWireConnectionHub<K, V> {
private static final Logger LOG = LoggerFactory.getLogger(MapWireHandler.class);
public static final int MAP_SERVICE = 3;
private final byte localIdentifier;
protected ChronicleMap<String, Integer> channelNameToId;
private Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> mapFactory;
@@ -42,7 +42,6 @@ public class MapWireConnectionHub<K, V> {
this.mapFactory = mapFactory;
this.localIdentifier = localIdentifier;
final TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig
.of(serverPort)
@@ -50,10 +49,6 @@ public class MapWireConnectionHub<K, V> {
hub = ReplicationHub.builder().tcpTransportAndNetwork(tcpConfig).createWithId(localIdentifier);
// this is how you add maps after the custer is created
of(byte[].class, byte[].class)
.instance().replicatedViaChannel(hub.createChannel((short) 1)).create();
channelNameToId = (ChronicleMap) channelNameToIdFactory.get()
.replicatedViaChannel(hub.createChannel(MAP_SERVICE)).create();
@@ -3,7 +3,6 @@ package net.openhft.chronicle.map;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub.CoreFields;
import net.openhft.chronicle.wire.TextWire;
import net.openhft.chronicle.wire.ValueOut;
import net.openhft.chronicle.wire.Wire;
import org.jetbrains.annotations.NotNull;
@@ -75,14 +74,16 @@ public class MapWireConnectionHubByName<K, V> implements Map<K, V> {
}
private byte[] bytes(Object key) {
ValueOut valueOut = toWire().getValueOut();
AbstactStatelessClient.writeField(key, valueOut);
buffer.flip();
byte[] bytes = new byte[(int) buffer.limit()];
buffer.read(bytes);
return bytes;
final Wire wire = toWire();
AbstactStatelessClient.writeField(key, wire.getValueOut());
wire.bytes().flip();
return toWire().getValueIn().bytes();
}
@Override
public boolean containsValue(Object value) {
return map.containsValue(bytes(value));
@@ -91,13 +92,15 @@ public class MapWireConnectionHubByName<K, V> implements Map<K, V> {
@Override
public V get(Object key) {
byte[] bytes = map.get(bytes(key));
final byte[] bytes1 = bytes(key);
byte[] bytes = map.get(bytes1);
if (bytes == null)
return null;
final Wire wire = toWire(bytes);
return AbstactStatelessClient.<V>readObject(CoreFields.reply, wire, null, vClass);
buffer.flip();
return AbstactStatelessClient.<V>readObject(wire.getValueIn(), null, vClass);
}
@Override
@@ -190,7 +190,7 @@ public class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers>
try {
if (put.contentEquals(eventName)) {
if (putIfAbsent.contentEquals(eventName)) {
valueIn.marshallable(wire -> {