mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
CE-23 added ( the first version ) of the server side of entry set itterator
This commit is contained in:
@@ -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<K, V> extends MapStatelessClient<K, V, ClientWiredStatelessChronicleEntrySet.EventId>
|
||||
class ClientWiredStatelessChronicleEntrySet<K, V> extends MapStatelessClient<K, V, ClientWiredStatelessChronicleEntrySet.EntrySetEventId>
|
||||
implements Set<Map.Entry<K, V>> {
|
||||
|
||||
public ClientWiredStatelessChronicleEntrySet(@NotNull final String channelName,
|
||||
@@ -28,35 +28,6 @@ class ClientWiredStatelessChronicleEntrySet<K, V> extends MapStatelessClient<K,
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Consumer<ValueOut> 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<K, V> extends MapStatelessClient<K,
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean eventReturnsNull(@NotNull EventId methodName) {
|
||||
protected boolean eventReturnsNull(@NotNull EntrySetEventId methodName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -136,14 +107,15 @@ class ClientWiredStatelessChronicleEntrySet<K, V> extends MapStatelessClient<K,
|
||||
key
|
||||
}
|
||||
|
||||
enum EventId implements ParameterizeWireKey {
|
||||
enum EntrySetEventId implements ParameterizeWireKey {
|
||||
size,
|
||||
isEmpty,
|
||||
remove(key);
|
||||
remove(key),
|
||||
iterator;
|
||||
|
||||
private final WireKey[] params;
|
||||
|
||||
<P extends WireKey> EventId(P... params) {
|
||||
<P extends WireKey> EntrySetEventId(P... params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
|
||||
@@ -448,33 +448,7 @@ class ClientWiredStatelessChronicleMap<K, V> extends MapStatelessClient<K, V, Ev
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Consumer<ValueOut> 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]);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<K, V, E extends ParameterizeWireKey> ex
|
||||
protected abstract boolean eventReturnsNull(@NotNull E methodName);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<K, V> implements WireHandler, Consumer<WireHandlers>
|
||||
// -- 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user