mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Formatting -- 100 columns max
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class BytesChronicleMap implements AbstractChronicleMap<Bytes, Bytes> {
|
public class BytesChronicleMap implements AbstractChronicleMap<Bytes, Bytes> {
|
||||||
|
|
||||||
final VanillaChronicleMap<?, ?, ?, ?, ?, ?> delegate;
|
final VanillaChronicleMap<?, ?, ?, ?, ?, ?> delegate;
|
||||||
TcpReplicator.TcpSocketChannelEntryWriter output;
|
TcpReplicator.TcpSocketChannelEntryWriter output;
|
||||||
|
|
||||||
public BytesChronicleMap(VanillaChronicleMap<?, ?, ?, ?, ?, ?> delegate) {
|
public BytesChronicleMap(VanillaChronicleMap<?, ?, ?, ?, ?, ?> delegate) {
|
||||||
|
|||||||
+11
-17
@@ -22,14 +22,14 @@ import net.openhft.chronicle.hash.ChronicleHashStatelessClientBuilder;
|
|||||||
import net.openhft.lang.MemoryUnit;
|
import net.openhft.lang.MemoryUnit;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.Class;import java.lang.IllegalStateException;import java.lang.Override;import java.lang.String;import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Austin.
|
* @author Rob Austin.
|
||||||
*/
|
*/
|
||||||
public final class ClientWiredChronicleMapStatelessBuilder<K, V> implements
|
public final class ClientWiredChronicleMapStatelessBuilder<K, V> implements
|
||||||
ChronicleHashStatelessClientBuilder<ClientWiredChronicleMapStatelessBuilder<K, V>,
|
ChronicleHashStatelessClientBuilder<ClientWiredChronicleMapStatelessBuilder<K, V>,
|
||||||
ChronicleMap<K, V>>,
|
ChronicleMap<K, V>>,
|
||||||
MapBuilder<ClientWiredChronicleMapStatelessBuilder<K, V>> {
|
MapBuilder<ClientWiredChronicleMapStatelessBuilder<K, V>> {
|
||||||
@@ -41,28 +41,23 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
private short channelID;
|
private short channelID;
|
||||||
private boolean doHandShaking;
|
private boolean doHandShaking;
|
||||||
|
|
||||||
public ClientWiredChronicleMapStatelessBuilder(InetSocketAddress remoteAddress, Class keyClass, Class valueClass, short channelID) {
|
public ClientWiredChronicleMapStatelessBuilder(
|
||||||
|
InetSocketAddress remoteAddress, Class keyClass, Class valueClass, short channelID) {
|
||||||
this.keyClass = keyClass;
|
this.keyClass = keyClass;
|
||||||
this.valueClass = valueClass;
|
this.valueClass = valueClass;
|
||||||
this.remoteAddress = remoteAddress;
|
this.remoteAddress = remoteAddress;
|
||||||
this.channelID = channelID;
|
this.channelID = channelID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientWiredChronicleMapStatelessBuilder(ClientWiredStatelessTcpConnectionHub hub, Class keyClass, Class valueClass, short channelID) {
|
public ClientWiredChronicleMapStatelessBuilder(
|
||||||
|
ClientWiredStatelessTcpConnectionHub hub, Class keyClass, Class valueClass,
|
||||||
|
short channelID) {
|
||||||
this.keyClass = keyClass;
|
this.keyClass = keyClass;
|
||||||
this.valueClass = valueClass;
|
this.valueClass = valueClass;
|
||||||
this.hub = hub;
|
this.hub = hub;
|
||||||
this.channelID = channelID;
|
this.channelID = channelID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method is meaningful, despite you could call of().create(), because Java 7 doesn't
|
|
||||||
// infer type parameters if case of chained calls, like this; and then you couldn't omit class
|
|
||||||
// name. Then it is
|
|
||||||
// ChronicleMapStatelessClientBuilder.<Integer, Integer>.of(addr).create()
|
|
||||||
// vs
|
|
||||||
// createClientOf(addr) // static import
|
|
||||||
// -- the second is really shorter.
|
|
||||||
|
|
||||||
|
|
||||||
private InetSocketAddress remoteAddress;
|
private InetSocketAddress remoteAddress;
|
||||||
private boolean putReturnsNull = false;
|
private boolean putReturnsNull = false;
|
||||||
@@ -89,7 +84,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientWiredChronicleMapStatelessBuilder<K, V> removeReturnsNull(boolean removeReturnsNull) {
|
public ClientWiredChronicleMapStatelessBuilder<K, V> removeReturnsNull(
|
||||||
|
boolean removeReturnsNull) {
|
||||||
this.removeReturnsNull = removeReturnsNull;
|
this.removeReturnsNull = removeReturnsNull;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -136,7 +132,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
hub = new ClientWiredStatelessTcpConnectionHub(this, localIdentifier, doHandShaking);
|
hub = new ClientWiredStatelessTcpConnectionHub(this, localIdentifier, doHandShaking);
|
||||||
|
|
||||||
if (!used.getAndSet(true)) {
|
if (!used.getAndSet(true)) {
|
||||||
return new ClientWiredStatelessChronicleMap<K, V>(this, keyClass, valueClass, channelID);
|
return new ClientWiredStatelessChronicleMap<K, V>(
|
||||||
|
this, keyClass, valueClass, channelID);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
@@ -158,7 +155,4 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
public ClientWiredStatelessTcpConnectionHub hub() {
|
public ClientWiredStatelessTcpConnectionHub hub() {
|
||||||
return hub;
|
return hub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ import static net.openhft.chronicle.map.ClientWiredStatelessChronicleMap.EventId
|
|||||||
/**
|
/**
|
||||||
* @author Rob Austin.
|
* @author Rob Austin.
|
||||||
*/
|
*/
|
||||||
class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Cloneable, ChannelFactory {
|
class ClientWiredStatelessChronicleMap<K, V>
|
||||||
|
implements ChronicleMap<K, V>, Cloneable, ChannelFactory {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ClientWiredStatelessChronicleMap.class);
|
private static final Logger LOG =
|
||||||
|
LoggerFactory.getLogger(ClientWiredStatelessChronicleMap.class);
|
||||||
|
|
||||||
private final ClientWiredStatelessTcpConnectionHub hub;
|
private final ClientWiredStatelessTcpConnectionHub hub;
|
||||||
|
|
||||||
@@ -53,10 +55,9 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
private boolean removeReturnsNull;
|
private boolean removeReturnsNull;
|
||||||
private short channelID;
|
private short channelID;
|
||||||
|
|
||||||
public ClientWiredStatelessChronicleMap(@NotNull final ClientWiredChronicleMapStatelessBuilder config,
|
public ClientWiredStatelessChronicleMap(
|
||||||
@NotNull final Class kClass,
|
@NotNull final ClientWiredChronicleMapStatelessBuilder config,
|
||||||
@NotNull final Class vClass,
|
@NotNull final Class kClass, @NotNull final Class vClass, short channelID) {
|
||||||
short channelID) {
|
|
||||||
this.channelID = channelID;
|
this.channelID = channelID;
|
||||||
hub = config.hub;
|
hub = config.hub;
|
||||||
this.putReturnsNull = config.putReturnsNull();
|
this.putReturnsNull = config.putReturnsNull();
|
||||||
@@ -140,19 +141,19 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
|
|
||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings("NullableProblems")
|
||||||
public boolean remove(Object key, Object value) {
|
public boolean remove(Object key, Object value) {
|
||||||
|
|
||||||
if (key == null)
|
if (key == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
|
|
||||||
return value != null && proxyReturnBoolean(REMOVE_WITH_VALUE.toString(), (K) key, (V) value);
|
return value != null &&
|
||||||
|
proxyReturnBoolean(REMOVE_WITH_VALUE.toString(), (K) key, (V) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings("NullableProblems")
|
||||||
public boolean replace(K key, V oldValue, V newValue) {
|
public boolean replace(K key, V oldValue, V newValue) {
|
||||||
if (key == null || oldValue == null || newValue == null)
|
if (key == null || oldValue == null || newValue == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
return proxyReturnBoolean(REPLACE_WITH_OLD_AND_NEW_VALUE.toString(), key, oldValue, newValue);
|
return proxyReturnBoolean(
|
||||||
|
REPLACE_WITH_OLD_AND_NEW_VALUE.toString(), key, oldValue, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings("NullableProblems")
|
||||||
@@ -257,7 +258,8 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
public V remove(Object key) {
|
public V remove(Object key) {
|
||||||
if (key == null)
|
if (key == null)
|
||||||
throw keyNotNullNPE();
|
throw keyNotNullNPE();
|
||||||
return proxyReturnObject(vClass, removeReturnsNull ? REMOVE_WITHOUT_ACC.toString() : REMOVE.toString(), (K) key);
|
return proxyReturnObject(vClass,
|
||||||
|
removeReturnsNull ? REMOVE_WITHOUT_ACC.toString() : REMOVE.toString(), (K) key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -326,7 +328,8 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
public V put(K key, V value) {
|
public V put(K key, V value) {
|
||||||
if (key == null || value == null)
|
if (key == null || value == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
return proxyReturnObject(putReturnsNull ? PUT_WITHOUT_ACC.toString() : PUT.toString(), key, value, vClass);
|
return proxyReturnObject(putReturnsNull ? PUT_WITHOUT_ACC.toString() : PUT.toString(),
|
||||||
|
key, value, vClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -359,7 +362,8 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
return readChunked(vClass, "VALUES", usingCollection);
|
return readChunked(vClass, "VALUES", usingCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <E, A extends Collection<E>> Collection<E> readChunked(Class<E> vClass1, String values, A usingCollection) {
|
private <E, A extends Collection<E>> Collection<E> readChunked(
|
||||||
|
Class<E> vClass1, String values, A usingCollection) {
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// send
|
// send
|
||||||
@@ -484,7 +488,8 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
} else if (value instanceof Marshallable) {
|
} else if (value instanceof Marshallable) {
|
||||||
wire.write(fieldName).marshallable((Marshallable) value);
|
wire.write(fieldName).marshallable((Marshallable) value);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("type=" + value.getClass() + " is unsupported, it must either be of type Marshallable or CharSequence");
|
throw new IllegalStateException("type=" + value.getClass() +
|
||||||
|
" is unsupported, it must either be of type Marshallable or CharSequence");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,7 +633,8 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("SameParameterValue")
|
@SuppressWarnings("SameParameterValue")
|
||||||
private boolean proxyReturnBoolean(@NotNull final String methodName, K key, V value1, V value2) {
|
private boolean proxyReturnBoolean(
|
||||||
|
@NotNull final String methodName, K key, V value1, V value2) {
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
long transactionId;
|
long transactionId;
|
||||||
@@ -737,7 +743,8 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private <R> R proxyReturnObject(@NotNull final String methodName, K key, V value, Class<V> resultType) {
|
private <R> R proxyReturnObject(
|
||||||
|
@NotNull final String methodName, K key, V value, Class<V> resultType) {
|
||||||
|
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
long transactionId;
|
long transactionId;
|
||||||
@@ -764,8 +771,8 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
|||||||
return (R) readValue(Fields.RESULT, transactionId, startTime, null);
|
return (R) readValue(Fields.RESULT, transactionId, startTime, null);
|
||||||
|
|
||||||
else
|
else
|
||||||
throw new UnsupportedOperationException("class of type class=" + resultType + " is not " +
|
throw new UnsupportedOperationException("class of type class=" + resultType +
|
||||||
"supported");
|
" is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -84,7 +84,9 @@ public class ClientWiredStatelessTcpConnectionHub {
|
|||||||
private boolean doHandShaking;
|
private boolean doHandShaking;
|
||||||
|
|
||||||
|
|
||||||
public ClientWiredStatelessTcpConnectionHub(ClientWiredChronicleMapStatelessBuilder config, byte localIdentifier, boolean doHandShaking) {
|
public ClientWiredStatelessTcpConnectionHub(
|
||||||
|
ClientWiredChronicleMapStatelessBuilder config, byte localIdentifier,
|
||||||
|
boolean doHandShaking) {
|
||||||
this.localIdentifier = localIdentifier;
|
this.localIdentifier = localIdentifier;
|
||||||
this.doHandShaking = doHandShaking;
|
this.doHandShaking = doHandShaking;
|
||||||
this.remoteAddress = config.remoteAddress();
|
this.remoteAddress = config.remoteAddress();
|
||||||
@@ -132,7 +134,8 @@ public class ClientWiredStatelessTcpConnectionHub {
|
|||||||
LOG.warn("DIFFERENT CHRONICLE-MAP VERSIONS: The Chronicle-Map-Server and " +
|
LOG.warn("DIFFERENT CHRONICLE-MAP VERSIONS: The Chronicle-Map-Server and " +
|
||||||
"Stateless-Client are on different " +
|
"Stateless-Client are on different " +
|
||||||
"versions, " +
|
"versions, " +
|
||||||
" we suggest that you use the same version, server=" + serverApplicationVersion(channelID) + ", " +
|
" we suggest that you use the same version, server=" +
|
||||||
|
serverApplicationVersion(channelID) + ", " +
|
||||||
"client=" + clientVersion);
|
"client=" + clientVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,7 +271,8 @@ public class ClientWiredStatelessTcpConnectionHub {
|
|||||||
writeSocket(wire, timeoutTime);
|
writeSocket(wire, timeoutTime);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (@NotNull java.nio.channels.ClosedChannelException | ClosedConnectionException e) {
|
} catch (@NotNull java.nio.channels.ClosedChannelException |
|
||||||
|
ClosedConnectionException e) {
|
||||||
checkTimeout(timeoutTime);
|
checkTimeout(timeoutTime);
|
||||||
lazyConnect(timeoutMs, remoteAddress);
|
lazyConnect(timeoutMs, remoteAddress);
|
||||||
}
|
}
|
||||||
@@ -347,8 +351,8 @@ public class ClientWiredStatelessTcpConnectionHub {
|
|||||||
// reads just the size
|
// reads just the size
|
||||||
readSocket(SIZE_OF_SIZE, timeoutTime);
|
readSocket(SIZE_OF_SIZE, timeoutTime);
|
||||||
|
|
||||||
final int messageSize = intWire.bytes().readUnsignedShort(intWire.bytes().position());
|
final int messageSize =
|
||||||
|
intWire.bytes().readUnsignedShort(intWire.bytes().position());
|
||||||
|
|
||||||
assert messageSize > 0 : "Invalid message size " + messageSize;
|
assert messageSize > 0 : "Invalid message size " + messageSize;
|
||||||
assert messageSize < 16 << 20 : "Invalid message size " + messageSize;
|
assert messageSize < 16 << 20 : "Invalid message size " + messageSize;
|
||||||
@@ -487,8 +491,8 @@ public class ClientWiredStatelessTcpConnectionHub {
|
|||||||
long outBytesPosition = outWire.bytes().position();
|
long outBytesPosition = outWire.bytes().position();
|
||||||
|
|
||||||
|
|
||||||
// if we have other threads waiting to send and the buffer is not full, let the other threads
|
// if we have other threads waiting to send and the buffer is not full,
|
||||||
// write to the buffer
|
// let the other threads write to the buffer
|
||||||
if (outBytesLock().hasQueuedThreads() &&
|
if (outBytesLock().hasQueuedThreads() &&
|
||||||
outBytesPosition + largestChunkSoFar <= tcpBufferSize) {
|
outBytesPosition + largestChunkSoFar <= tcpBufferSize) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
|
|
||||||
private final StringBuilder methodName = new StringBuilder();
|
private final StringBuilder methodName = new StringBuilder();
|
||||||
private final Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> chronicleHashInstanceBuilder;
|
private final Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> mapFactory;
|
||||||
private Wire inWire = null;
|
private Wire inWire = null;
|
||||||
private Wire outWire = null;
|
private Wire outWire = null;
|
||||||
private final Consumer writeElement = new Consumer<Iterator<byte[]>>() {
|
private final Consumer writeElement = new Consumer<Iterator<byte[]>>() {
|
||||||
@@ -102,24 +102,24 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
private byte localIdentifier;
|
private byte localIdentifier;
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
private short channelId;
|
private short channelId;
|
||||||
private List<Replica> channelList;
|
private List<Replica> channels;
|
||||||
private ReplicationHub hub;
|
private ReplicationHub hub;
|
||||||
private byte remoteIdentifier;
|
private byte remoteIdentifier;
|
||||||
|
|
||||||
|
|
||||||
public MapWireHandler(@NotNull final Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> chronicleHashInstanceBuilder,
|
public MapWireHandler(
|
||||||
@NotNull final ReplicationHub hub,
|
@NotNull Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> mapFactory,
|
||||||
byte localIdentifier,
|
@NotNull ReplicationHub hub, byte localIdentifier, @NotNull List<Replica> channels) {
|
||||||
@NotNull final List<Replica> channelList) {
|
this(mapFactory, hub);
|
||||||
this(chronicleHashInstanceBuilder, hub);
|
this.channels = channels;
|
||||||
this.channelList = channelList;
|
|
||||||
this.localIdentifier = localIdentifier;
|
this.localIdentifier = localIdentifier;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapWireHandler(Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> chronicleHashInstanceBuilder, ReplicationHub hub) {
|
public MapWireHandler(Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> mapFactory,
|
||||||
this.chronicleHashInstanceBuilder = chronicleHashInstanceBuilder;
|
ReplicationHub hub) {
|
||||||
|
this.mapFactory = mapFactory;
|
||||||
this.hub = hub;
|
this.hub = hub;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,8 +136,9 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void writeChunked(long transactionId, @NotNull final Function<BytesChronicleMap, Iterator> function,
|
private void writeChunked(
|
||||||
@NotNull final Consumer<Iterator> c) throws StreamCorruptedException {
|
long transactionId, @NotNull final Function<BytesChronicleMap, Iterator> function,
|
||||||
|
@NotNull final Consumer<Iterator> c) throws StreamCorruptedException {
|
||||||
|
|
||||||
final BytesChronicleMap m = bytesMap(channelId);
|
final BytesChronicleMap m = bytesMap(channelId);
|
||||||
final Iterator<byte[]> iterator = function.apply(m);
|
final Iterator<byte[]> iterator = function.apply(m);
|
||||||
@@ -258,7 +259,7 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
if ("CREATE_CHANNEL".contentEquals(methodName)) {
|
if ("CREATE_CHANNEL".contentEquals(methodName)) {
|
||||||
writeVoid(() -> {
|
writeVoid(() -> {
|
||||||
short channelId1 = inWire.read(ARG_1).int16();
|
short channelId1 = inWire.read(ARG_1).int16();
|
||||||
chronicleHashInstanceBuilder.get().replicatedViaChannel(hub.createChannel(channelId1)).create();
|
mapFactory.get().replicatedViaChannel(hub.createChannel(channelId1)).create();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@@ -281,12 +282,14 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("CONTAINS_KEY".contentEquals(methodName)) {
|
if ("CONTAINS_KEY".contentEquals(methodName)) {
|
||||||
write(b -> outWire.write(RESULT).bool(b.delegate.containsKey(toByteArray(inWire, ARG_1))));
|
write(b -> outWire.write(RESULT).bool(
|
||||||
|
b.delegate.containsKey(toByteArray(inWire, ARG_1))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("CONTAINS_VALUE".contentEquals(methodName)) {
|
if ("CONTAINS_VALUE".contentEquals(methodName)) {
|
||||||
write(b -> outWire.write(RESULT).bool(b.delegate.containsValue(toByteArray(inWire, ARG_1))));
|
write(b -> outWire.write(RESULT).bool(
|
||||||
|
b.delegate.containsValue(toByteArray(inWire, ARG_1))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +300,8 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
|
|
||||||
if ("PUT".contentEquals(methodName)) {
|
if ("PUT".contentEquals(methodName)) {
|
||||||
writeValue(b -> {
|
writeValue(b -> {
|
||||||
final net.openhft.lang.io.Bytes reader = MapWireHandler.this.toReader(inWire, ARG_1, ARG_2);
|
final net.openhft.lang.io.Bytes reader =
|
||||||
|
MapWireHandler.this.toReader(inWire, ARG_1, ARG_2);
|
||||||
|
|
||||||
// todo call return b.put(reader, reader, timestamp, identifier());
|
// todo call return b.put(reader, reader, timestamp, identifier());
|
||||||
return b.put(reader, reader);
|
return b.put(reader, reader);
|
||||||
@@ -364,7 +368,8 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
if ("REMOVE_WITH_VALUE".contentEquals(methodName)) {
|
if ("REMOVE_WITH_VALUE".contentEquals(methodName)) {
|
||||||
write(bytesMap -> {
|
write(bytesMap -> {
|
||||||
final net.openhft.lang.io.Bytes reader = toReader(inWire, ARG_1, ARG_2);
|
final net.openhft.lang.io.Bytes reader = toReader(inWire, ARG_1, ARG_2);
|
||||||
// todo call outWire.write(RESULT).bool(bytesMap.remove(reader, reader, timestamp, identifier()));
|
// todo call outWire.write(RESULT)
|
||||||
|
// .bool(bytesMap.remove(reader, reader, timestamp, identifier()));
|
||||||
outWire.write(RESULT).bool(bytesMap.remove(reader, reader));
|
outWire.write(RESULT).bool(bytesMap.remove(reader, reader));
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@@ -394,7 +399,8 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
// if (len > 4)
|
// if (len > 4)
|
||||||
if (EventGroup.IS_DEBUG) {
|
if (EventGroup.IS_DEBUG) {
|
||||||
long len = outWire.bytes().position() - SIZE_OF_SIZE;
|
long len = outWire.bytes().position() - SIZE_OF_SIZE;
|
||||||
System.out.println("--------------------------------------------\nserver wrote:\n\n" + Bytes.toDebugString(outWire.bytes(), SIZE_OF_SIZE, len));
|
System.out.println("--------------------------------------------\nserver wrote:\n\n"
|
||||||
|
+ Bytes.toDebugString(outWire.bytes(), SIZE_OF_SIZE, len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +492,8 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte identifier() {
|
private byte identifier() {
|
||||||
// if the client provides a remote identifier then we will use that otherwise we will use the local identifier
|
// if the client provides a remote identifier then we will use that otherwise we will use
|
||||||
|
// the local identifier
|
||||||
return remoteIdentifier == 0 ? localIdentifier : remoteIdentifier;
|
return remoteIdentifier == 0 ? localIdentifier : remoteIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,11 +604,11 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
private ReplicatedChronicleMap map(short channelId) {
|
private ReplicatedChronicleMap map(short channelId) {
|
||||||
|
|
||||||
// todo this cast is a bit of a hack, improve later
|
// todo this cast is a bit of a hack, improve later
|
||||||
final ReplicatedChronicleMap replicas =
|
final ReplicatedChronicleMap map =
|
||||||
(ReplicatedChronicleMap) channelList.get(channelId);
|
(ReplicatedChronicleMap) channels.get(channelId);
|
||||||
|
|
||||||
if (replicas != null)
|
if (map != null)
|
||||||
return replicas;
|
return map;
|
||||||
|
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
@@ -736,7 +743,8 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
private void showOutWire() {
|
private void showOutWire() {
|
||||||
System.out.println("pos=" + outWire.bytes().position() + ",bytes=" + Bytes.toDebugString(outWire.bytes(), 0, outWire.bytes().position()));
|
System.out.println("pos=" + outWire.bytes().position() + ",bytes=" +
|
||||||
|
Bytes.toDebugString(outWire.bytes(), 0, outWire.bytes().position()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
|
|||||||
@@ -34,11 +34,9 @@ import java.util.function.Supplier;
|
|||||||
public class MapWireHandlerBuilder {
|
public class MapWireHandlerBuilder {
|
||||||
|
|
||||||
public static <K, V> WireHandler of(
|
public static <K, V> WireHandler of(
|
||||||
@NotNull final Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> chronicleHashInstanceBuilder,
|
@NotNull Supplier<ChronicleHashInstanceBuilder<ChronicleMap<K, V>>> mapFactory,
|
||||||
@NotNull final ReplicationHub hub,
|
@NotNull ReplicationHub hub, byte localIdentifier, @NotNull List<Replica> channels) {
|
||||||
byte localIdentifier,
|
return new MapWireHandler<>(mapFactory, hub, localIdentifier, channels);
|
||||||
@NotNull final List<Replica> channelList) {
|
|
||||||
return new MapWireHandler<K, V>(chronicleHashInstanceBuilder, hub, localIdentifier, channelList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Fields implements WireKey {
|
public static enum Fields implements WireKey {
|
||||||
|
|||||||
Reference in New Issue
Block a user