From 15c61e5341d4c0f553475146bc3659961c0643dd Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 16 Apr 2015 22:06:46 +0100 Subject: [PATCH] CE-23 added ( the first version ) of the server side of entry set itterator --- ...ClientWiredStatelessChronicleEntrySet.java | 42 ++++--------------- .../map/ClientWiredStatelessChronicleMap.java | 26 ------------ .../chronicle/map/MapStatelessClient.java | 10 +++-- .../openhft/chronicle/map/MapWireHandler.java | 24 +++++++++-- .../map/TCPSocketReplicationIntValueTest.java | 1 + 5 files changed, 35 insertions(+), 68 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleEntrySet.java b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleEntrySet.java index 053276911..36a820af5 100644 --- a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleEntrySet.java +++ b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleEntrySet.java @@ -12,11 +12,11 @@ import java.util.Map; import java.util.Set; import java.util.function.Consumer; -import static net.openhft.chronicle.map.ClientWiredStatelessChronicleEntrySet.EventId.*; +import static net.openhft.chronicle.map.ClientWiredStatelessChronicleEntrySet.EntrySetEventId.*; import static net.openhft.chronicle.map.ClientWiredStatelessChronicleEntrySet.Params.key; -class ClientWiredStatelessChronicleEntrySet extends MapStatelessClient +class ClientWiredStatelessChronicleEntrySet extends MapStatelessClient implements Set> { public ClientWiredStatelessChronicleEntrySet(@NotNull final String channelName, @@ -28,35 +28,6 @@ class ClientWiredStatelessChronicleEntrySet extends MapStatelessClient toParameters(@NotNull EventId eventId, Object... args) { - - return out -> { - final WireKey[] paramNames = eventId.params(); - - if (paramNames.length == 1) { - writeField(out, args[0]); - return; - } - - assert args.length == paramNames.length : - "looks like you are missing the paramameter in the EventId, EventId=" + - eventId + - ", args.length=" + args.length + - ", paramNames.length=" + paramNames.length; - - out.marshallable(m -> { - - for (int i = 0; i < paramNames.length; i++) { - final ValueOut vo = m.write(paramNames[i]); - this.writeField(vo, args[i]); - } - - }); - - }; - } - @Override public int size() { return proxyReturnInt(size); @@ -127,7 +98,7 @@ class ClientWiredStatelessChronicleEntrySet extends MapStatelessClient extends MapStatelessClient EventId(P... params) { +

EntrySetEventId(P... params) { this.params = params; } diff --git a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java index e59be8082..f9681445d 100644 --- a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java @@ -448,33 +448,7 @@ class ClientWiredStatelessChronicleMap extends MapStatelessClient toParameters(@NotNull EventId eventId, Object... args) { - return out -> { - final MapWireHandler.Params[] paramNames = eventId.params(); - - if (paramNames.length == 1) { - writeField(out, args[0]); - return; - } - - assert args.length == paramNames.length : - "methodName=" + eventId + - ", args.length=" + args.length + - ", paramNames.length=" + paramNames.length; - - out.marshallable(m -> { - - for (int i = 0; i < paramNames.length; i++) { - final ValueOut vo = m.write(paramNames[i]); - this.writeField(vo, args[i]); - } - - }); - - }; - } } diff --git a/src/main/java/net/openhft/chronicle/map/MapStatelessClient.java b/src/main/java/net/openhft/chronicle/map/MapStatelessClient.java index 33604edaf..c982ea1f1 100644 --- a/src/main/java/net/openhft/chronicle/map/MapStatelessClient.java +++ b/src/main/java/net/openhft/chronicle/map/MapStatelessClient.java @@ -2,13 +2,12 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub; import net.openhft.chronicle.engine.client.ParameterizeWireKey; -import net.openhft.chronicle.wire.Marshallable; -import net.openhft.chronicle.wire.ValueIn; -import net.openhft.chronicle.wire.Wire; -import net.openhft.chronicle.wire.WireKey; +import net.openhft.chronicle.wire.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Consumer; + import static net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub.CoreFields.reply; /** @@ -160,4 +159,7 @@ public abstract class MapStatelessClient ex protected abstract boolean eventReturnsNull(@NotNull E methodName); + + + } diff --git a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java index a04f5a1ee..2a2814dca 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java @@ -28,6 +28,7 @@ import net.openhft.chronicle.engine.client.ParameterizeWireKey; import net.openhft.chronicle.hash.ChronicleHashInstanceBuilder; import net.openhft.chronicle.hash.impl.util.BuildVersion; import net.openhft.chronicle.hash.replication.ReplicationHub; +import net.openhft.chronicle.map.ClientWiredStatelessChronicleEntrySet.EntrySetEventId; import net.openhft.chronicle.network.WireHandler; import net.openhft.chronicle.network.event.EventGroup; import net.openhft.chronicle.network.event.WireHandlers; @@ -52,6 +53,7 @@ import static net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnect import static net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub.CoreFields.csp; import static net.openhft.chronicle.engine.client.ClientWiredStatelessTcpConnectionHub.CoreFields.reply; import static net.openhft.chronicle.engine.client.StringUtils.endsWith; +import static net.openhft.chronicle.map.AbstactStatelessClient.toParameters; import static net.openhft.chronicle.map.MapWireHandler.EventId.*; import static net.openhft.chronicle.map.MapWireHandler.Params.*; import static net.openhft.chronicle.wire.Wires.acquireStringBuilder; @@ -307,14 +309,30 @@ public class MapWireHandler implements WireHandler, Consumer // -- THESE METHODS ARE ONLY ENTRY SET METHODS if (endsWith(cspText, "#entrySet")) { - // not remove on the key-set returns a boolean and on the map returns the old - // value - if (remove.contentEquals(eventName)) { + // note : remove on the key-set returns a boolean and on the map returns the + // old value + if (EntrySetEventId.remove.contentEquals(eventName)) { write(b -> outWire.write(reply).bool( b.delegate.remove(toByteArray(valueIn)) != null)); return; } + // note : remove on the key-set returns a boolean and on the map returns the + // old value + if (EntrySetEventId.iterator.contentEquals(eventName)) { + write(b -> { + final ValueOut valueOut = outWire.writeEventName(() -> "entry"); + b.delegate.entrySet().forEach(e -> + valueOut.sequence(toParameters(put, + e.getKey(), + e.getValue()))); + } + + ); + return; + } + + throw new IllegalStateException("unsupported event=" + eventName); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java index a075907ad..bdd70c196 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java @@ -163,6 +163,7 @@ public class TCPSocketReplicationIntValueTest { assertEquals(map1, map2); } + @Test(timeout = 12000) public void testSoakTestWithRandomData() throws IOException, InterruptedException { final long start = System.currentTimeMillis();