diff --git a/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java b/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java index 12ecc8390..6b3fdb454 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireConnectionHub.java @@ -23,7 +23,7 @@ public class MapWireConnectionHub { private static final Logger LOG = LoggerFactory.getLogger(MapWireHandler.class); public static final int MAP_SERVICE = 3; - private final byte localIdentifier; + protected ChronicleMap channelNameToId; private Supplier>> mapFactory; @@ -42,7 +42,6 @@ public class MapWireConnectionHub { this.mapFactory = mapFactory; - this.localIdentifier = localIdentifier; final TcpTransportAndNetworkConfig tcpConfig = TcpTransportAndNetworkConfig .of(serverPort) @@ -50,10 +49,6 @@ public class MapWireConnectionHub { 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(); diff --git a/src/main/java/net/openhft/chronicle/map/MapWireConnectionHubByName.java b/src/main/java/net/openhft/chronicle/map/MapWireConnectionHubByName.java index 141059f50..15a11b44b 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireConnectionHubByName.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireConnectionHubByName.java @@ -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 implements Map { } 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 implements Map { @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.readObject(CoreFields.reply, wire, null, vClass); + buffer.flip(); + return AbstactStatelessClient.readObject(wire.getValueIn(), null, vClass); } @Override diff --git a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java index d270c42a6..c3fd82368 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java @@ -190,7 +190,7 @@ public class MapWireHandler implements WireHandler, Consumer try { - if (put.contentEquals(eventName)) { + if (putIfAbsent.contentEquals(eventName)) { valueIn.marshallable(wire -> {