mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
CE-14 changed to use enums for the methodNames as well
This commit is contained in:
@@ -136,7 +136,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
if (key == null || value == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
return proxyReturnObject(PUT_IF_ABSENT, key, value, vClass);
|
||||
return proxyReturnObject(putIfAbsent, key, value, vClass);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@@ -145,7 +145,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
if (key == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
return value != null && proxyReturnBoolean(REMOVE_WITH_VALUE.toString(), (K) key, (V) value);
|
||||
return value != null && proxyReturnBoolean(removeWithValue.toString(), (K) key, (V) value);
|
||||
|
||||
}
|
||||
|
||||
@@ -153,14 +153,14 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
public boolean replace(K key, V oldValue, V newValue) {
|
||||
if (key == null || oldValue == null || newValue == null)
|
||||
throw new NullPointerException();
|
||||
return proxyReturnBoolean(REPLACE_WITH_OLD_AND_NEW_VALUE.toString(), key, oldValue, newValue);
|
||||
return proxyReturnBoolean(replaceWithOldAndNewValue.toString(), key, oldValue, newValue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public V replace(K key, V value) {
|
||||
if (key == null || value == null)
|
||||
throw new NullPointerException();
|
||||
return proxyReturnObject(REPLACE, key, value, vClass);
|
||||
return proxyReturnObject(replace, key, value, vClass);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
@@ -195,7 +195,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return proxyReturnInt(HASH_CODE.toString());
|
||||
return proxyReturnInt(hashCode.toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -205,15 +205,15 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
|
||||
@NotNull
|
||||
public String serverPersistedDataVersion() {
|
||||
return hub.proxyReturnString(PERSISTED_DATA_VERSION, channelID);
|
||||
return hub.proxyReturnString(persistedDataVersion, channelID);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return proxyReturnBoolean(IS_EMPTY.toString());
|
||||
return proxyReturnBoolean(isEmpty.toString());
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
return proxyReturnBooleanK(CONTAINS_KEY, (K) key);
|
||||
return proxyReturnBooleanK(containsKey, (K) key);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -222,11 +222,11 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
return proxyReturnBooleanV(CONTAINS_VALUE, (V) value);
|
||||
return proxyReturnBooleanV(containsValue, (V) value);
|
||||
}
|
||||
|
||||
public long longSize() {
|
||||
return proxyReturnLong(LONG_SIZE.toString());
|
||||
return proxyReturnLong(longSize.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,7 +235,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
}
|
||||
|
||||
public V get(Object key) {
|
||||
return proxyReturnObject(vClass, GET, (K) key);
|
||||
return proxyReturnObject(vClass, get, (K) key);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -258,14 +258,14 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
public V remove(Object key) {
|
||||
if (key == null)
|
||||
throw keyNotNullNPE();
|
||||
return proxyReturnObject(vClass, removeReturnsNull ? REMOVE_WITHOUT_ACC : REMOVE, (K) key);
|
||||
return proxyReturnObject(vClass, removeReturnsNull ? removeWithoutAcc : remove, (K) key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createChannel(short channelID) {
|
||||
proxyReturnVoid(
|
||||
() -> {
|
||||
hub.outWire().write(Fields.methodName).text(CREATE_CHANNEL.toString());
|
||||
hub.outWire().write(Fields.methodName).text(createChannel.toString());
|
||||
hub.outWire().write(Fields.arg1).int16(channelID);
|
||||
});
|
||||
}
|
||||
@@ -295,7 +295,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
wire.write(Fields.transactionId).int64(transactionId);
|
||||
wire.write(Fields.timeStamp).int64(startTime);
|
||||
wire.write(Fields.channelId).int16(channelID);
|
||||
hub.outWire().write(Fields.methodName).text(PUT_ALL.toString());
|
||||
hub.outWire().write(Fields.methodName).text(putAll.toString());
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
@@ -330,7 +330,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
public V put(K key, V value) {
|
||||
if (key == null || value == null)
|
||||
throw new NullPointerException();
|
||||
return proxyReturnObject(putReturnsNull ? PUT_WITHOUT_ACC : PUT, key, value, vClass);
|
||||
return proxyReturnObject(putReturnsNull ? putWithoutAcc : put, key, value, vClass);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -345,14 +345,14 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
proxyReturnVoid(() -> writeField(Fields.methodName, CLEAR.toString()));
|
||||
proxyReturnVoid(() -> writeField(Fields.methodName, clear.toString()));
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public Set<K> keySet() {
|
||||
final Set<K> usingCollection = new HashSet<K>();
|
||||
readChunked(kClass, KEY_SET, usingCollection);
|
||||
readChunked(kClass, keySet, usingCollection);
|
||||
return usingCollection;
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
@NotNull
|
||||
public Collection<V> values() {
|
||||
final List<V> usingCollection = new ArrayList<>();
|
||||
return readChunked(vClass, VALUES, usingCollection);
|
||||
return readChunked(vClass, values, usingCollection);
|
||||
}
|
||||
|
||||
private <E, A extends Collection<E>> Collection<E> readChunked(Class<E> vClass1, EventId values, A usingCollection) {
|
||||
@@ -406,7 +406,7 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
final Map<K, V> result = new HashMap<K, V>();
|
||||
final long startTime = System.currentTimeMillis();
|
||||
// send
|
||||
final long transactionId = proxySend(ENTRY_SET, startTime);
|
||||
final long transactionId = proxySend(entrySet, startTime);
|
||||
assert !hub.outBytesLock().isHeldByCurrentThread();
|
||||
final long timeoutTime = startTime + hub.timeoutMs;
|
||||
|
||||
@@ -821,9 +821,9 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
private boolean eventReturnsNull(@NotNull EventId methodName) {
|
||||
|
||||
switch (methodName) {
|
||||
case PUT_ALL_WITHOUT_ACC:
|
||||
case PUT_WITHOUT_ACC:
|
||||
case REMOVE_WITHOUT_ACC:
|
||||
case putAllWithoutAcc:
|
||||
case putWithoutAcc:
|
||||
case removeWithoutAcc:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -845,37 +845,37 @@ class ClientWiredStatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Clon
|
||||
|
||||
|
||||
/* static enum EventId {
|
||||
CREATE_CHANNEL,
|
||||
createChannel,
|
||||
HEARTBEAT,
|
||||
STATEFUL_UPDATE,
|
||||
LONG_SIZE,
|
||||
SIZE,
|
||||
IS_EMPTY,
|
||||
CONTAINS_KEY,
|
||||
CONTAINS_VALUE,
|
||||
GET,
|
||||
PUT,
|
||||
PUT_WITHOUT_ACC,
|
||||
REMOVE,
|
||||
REMOVE_WITHOUT_ACC,
|
||||
CLEAR,
|
||||
longSize,
|
||||
size,
|
||||
isEmpty,
|
||||
containsKey,
|
||||
containsValue,
|
||||
get,
|
||||
put,
|
||||
putWithoutAcc,
|
||||
remove,
|
||||
removeWithoutAcc,
|
||||
clear,
|
||||
KEY_SET,
|
||||
VALUES,
|
||||
ENTRY_SET,
|
||||
REPLACE,
|
||||
REPLACE_WITH_OLD_AND_NEW_VALUE,
|
||||
PUT_IF_ABSENT,
|
||||
REMOVE_WITH_VALUE,
|
||||
TO_STRING,
|
||||
APPLICATION_VERSION,
|
||||
PERSISTED_DATA_VERSION,
|
||||
PUT_ALL,
|
||||
PUT_ALL_WITHOUT_ACC,
|
||||
HASH_CODE,
|
||||
MAP_FOR_KEY,
|
||||
PUT_MAPPED,
|
||||
KEY_BUILDER,
|
||||
VALUE_BUILDER
|
||||
entrySet,
|
||||
replace,
|
||||
replaceWithOldAndNewValue,
|
||||
putIfAbsent,
|
||||
removeWithValue,
|
||||
toString,
|
||||
applicationVersion,
|
||||
persistedDataVersion,
|
||||
putAll,
|
||||
putAllWithoutAcc,
|
||||
hashCode,
|
||||
mapForKey,
|
||||
putMapped,
|
||||
keyBuilder,
|
||||
valueBuilder
|
||||
}*/
|
||||
|
||||
class Entry implements Map.Entry<K, V> {
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static net.openhft.chronicle.map.MapWireHandler.EventId.APPLICATION_VERSION;
|
||||
import static net.openhft.chronicle.map.MapWireHandler.EventId.applicationVersion;
|
||||
import static net.openhft.chronicle.map.MapWireHandler.SIZE_OF_SIZE;
|
||||
import static net.openhft.chronicle.map.MapWireHandlerBuilder.Fields.*;
|
||||
|
||||
@@ -234,7 +234,7 @@ public class ClientWiredStatelessTcpConnectionHub {
|
||||
@NotNull
|
||||
public String serverApplicationVersion(short channelID) {
|
||||
TextWire wire = new TextWire(Bytes.elasticByteBuffer());
|
||||
String result = proxyReturnString(APPLICATION_VERSION, channelID, wire);
|
||||
String result = proxyReturnString(applicationVersion, channelID, wire);
|
||||
return (result == null) ? "" : result;
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
}
|
||||
try {
|
||||
|
||||
if (PUT_WITHOUT_ACC.toString().contentEquals(methodName)) {
|
||||
if (putWithoutAcc.toString().contentEquals(methodName)) {
|
||||
writeVoid(bytesMap -> {
|
||||
final net.openhft.lang.io.Bytes reader = toReader(inWire, arg1, arg2);
|
||||
// todo bytesMap.put(reader, reader, timestamp, identifier());
|
||||
@@ -203,22 +203,22 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (KEY_SET.toString().contentEquals(methodName)) {
|
||||
if (keySet.toString().contentEquals(methodName)) {
|
||||
writeChunked(transactionId, map -> map.keySet().iterator(), writeElement);
|
||||
return;
|
||||
}
|
||||
|
||||
if (VALUES.toString().contentEquals(methodName)) {
|
||||
if (values.toString().contentEquals(methodName)) {
|
||||
writeChunked(transactionId, map -> map.delegate.values().iterator(), writeElement);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ENTRY_SET.toString().contentEquals(methodName)) {
|
||||
if (entrySet.toString().contentEquals(methodName)) {
|
||||
writeChunked(transactionId, m -> m.delegate.entrySet().iterator(), writeEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PUT_ALL.toString().contentEquals(methodName)) {
|
||||
if (putAll.toString().contentEquals(methodName)) {
|
||||
putAll(transactionId);
|
||||
return;
|
||||
}
|
||||
@@ -227,7 +227,7 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
outWire.write(Fields.transactionId).int64(transactionId);
|
||||
|
||||
|
||||
if (CREATE_CHANNEL.toString().contentEquals(methodName)) {
|
||||
if (createChannel.toString().contentEquals(methodName)) {
|
||||
writeVoid(() -> {
|
||||
short channelId1 = inWire.read(arg1).int16();
|
||||
chronicleHashInstanceBuilder.get().replicatedViaChannel(hub.createChannel(channelId1)).create();
|
||||
@@ -237,37 +237,37 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
}
|
||||
|
||||
|
||||
if (REMOTE_IDENTIFIER.toString().contentEquals(methodName)) {
|
||||
if (EventId.remoteIdentifier.toString().contentEquals(methodName)) {
|
||||
this.remoteIdentifier = inWire.read(result).int8();
|
||||
return;
|
||||
}
|
||||
|
||||
if (LONG_SIZE.toString().contentEquals(methodName)) {
|
||||
if (longSize.toString().contentEquals(methodName)) {
|
||||
write(b -> outWire.write(result).int64(b.longSize()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (IS_EMPTY.toString().contentEquals(methodName)) {
|
||||
if (isEmpty.toString().contentEquals(methodName)) {
|
||||
write(b -> outWire.write(result).bool(b.isEmpty()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (CONTAINS_KEY.toString().contentEquals(methodName)) {
|
||||
if (containsKey.toString().contentEquals(methodName)) {
|
||||
write(b -> outWire.write(result).bool(b.delegate.containsKey(toByteArray(inWire, arg1))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (CONTAINS_VALUE.toString().contentEquals(methodName)) {
|
||||
if (containsValue.toString().contentEquals(methodName)) {
|
||||
write(b -> outWire.write(result).bool(b.delegate.containsValue(toByteArray(inWire, arg1))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (GET.toString().contentEquals(methodName)) {
|
||||
if (get.toString().contentEquals(methodName)) {
|
||||
writeValueUsingDelegate(map -> map.get(toByteArray(inWire, arg1)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (PUT.toString().contentEquals(methodName)) {
|
||||
if (put.toString().contentEquals(methodName)) {
|
||||
writeValue(b -> {
|
||||
final net.openhft.lang.io.Bytes reader = MapWireHandler.this.toReader(inWire, arg1, arg2);
|
||||
|
||||
@@ -278,17 +278,17 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (REMOVE.toString().contentEquals(methodName)) {
|
||||
if (remove.toString().contentEquals(methodName)) {
|
||||
writeValue(b -> b.remove(toReader(inWire, arg1)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (CLEAR.toString().contentEquals(methodName)) {
|
||||
if (clear.toString().contentEquals(methodName)) {
|
||||
writeVoid(BytesChronicleMap::clear);
|
||||
return;
|
||||
}
|
||||
|
||||
if (REPLACE.toString().contentEquals(methodName)) {
|
||||
if (replace.toString().contentEquals(methodName)) {
|
||||
write(bytesMap -> {
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (REPLACE_WITH_OLD_AND_NEW_VALUE.toString().contentEquals(methodName)) {
|
||||
if (replaceWithOldAndNewValue.toString().contentEquals(methodName)) {
|
||||
|
||||
write(bytesMap -> {
|
||||
final net.openhft.lang.io.Bytes reader = toReader(inWire, arg1, arg2, arg3);
|
||||
@@ -324,7 +324,7 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PUT_IF_ABSENT.toString().contentEquals(methodName)) {
|
||||
if (putIfAbsent.toString().contentEquals(methodName)) {
|
||||
|
||||
|
||||
// todo call bytesMap.putIfAbsent(reader, reader, timestamp, identifier());
|
||||
@@ -338,7 +338,7 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (REMOVE_WITH_VALUE.toString().contentEquals(methodName)) {
|
||||
if (removeWithValue.toString().contentEquals(methodName)) {
|
||||
write(bytesMap -> {
|
||||
final net.openhft.lang.io.Bytes reader = toReader(inWire, arg1, arg2);
|
||||
// todo call outWire.write(result).bool(bytesMap.remove(reader, reader, timestamp, identifier()));
|
||||
@@ -348,18 +348,18 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
}
|
||||
|
||||
|
||||
if (APPLICATION_VERSION.toString().contentEquals(methodName)) {
|
||||
if (applicationVersion.toString().contentEquals(methodName)) {
|
||||
write(b -> outWire.write(result).text(applicationVersion()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (PERSISTED_DATA_VERSION.toString().contentEquals(methodName)) {
|
||||
if (persistedDataVersion.toString().contentEquals(methodName)) {
|
||||
write(b -> outWire.write(result).text(persistedDataVersion()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (HASH_CODE.toString().contentEquals(methodName)) {
|
||||
if (hashCode.toString().contentEquals(methodName)) {
|
||||
write(b -> outWire.write(result).int32(b.hashCode()));
|
||||
return;
|
||||
}
|
||||
@@ -772,38 +772,41 @@ class MapWireHandler<K, V> implements WireHandler, Consumer<WireHandlers> {
|
||||
}
|
||||
|
||||
static enum EventId {
|
||||
HEARTBEAT,
|
||||
STATEFUL_UPDATE,
|
||||
LONG_SIZE,
|
||||
SIZE,
|
||||
IS_EMPTY,
|
||||
CONTAINS_KEY,
|
||||
CONTAINS_VALUE,
|
||||
GET,
|
||||
PUT,
|
||||
PUT_WITHOUT_ACC,
|
||||
REMOVE,
|
||||
REMOVE_WITHOUT_ACC,
|
||||
CLEAR,
|
||||
KEY_SET,
|
||||
VALUES,
|
||||
ENTRY_SET,
|
||||
REPLACE,
|
||||
REPLACE_WITH_OLD_AND_NEW_VALUE,
|
||||
PUT_IF_ABSENT,
|
||||
REMOVE_WITH_VALUE,
|
||||
TO_STRING,
|
||||
APPLICATION_VERSION,
|
||||
PERSISTED_DATA_VERSION,
|
||||
PUT_ALL,
|
||||
PUT_ALL_WITHOUT_ACC,
|
||||
HASH_CODE,
|
||||
MAP_FOR_KEY,
|
||||
PUT_MAPPED,
|
||||
KEY_BUILDER,
|
||||
VALUE_BUILDER,
|
||||
CREATE_CHANNEL,
|
||||
REMOTE_IDENTIFIER
|
||||
|
||||
longSize,
|
||||
size,
|
||||
isEmpty,
|
||||
containsKey,
|
||||
containsValue,
|
||||
get,
|
||||
put,
|
||||
putWithoutAcc,
|
||||
remove,
|
||||
removeWithoutAcc,
|
||||
clear,
|
||||
keySet,
|
||||
values,
|
||||
entrySet,
|
||||
replace,
|
||||
replaceWithOldAndNewValue,
|
||||
putIfAbsent,
|
||||
removeWithValue,
|
||||
toString,
|
||||
applicationVersion,
|
||||
persistedDataVersion,
|
||||
putAll,
|
||||
putAllWithoutAcc,
|
||||
hashCode,
|
||||
mapForKey,
|
||||
putMapped,
|
||||
keyBuilder,
|
||||
valueBuilder,
|
||||
createChannel,
|
||||
remoteIdentifier;
|
||||
|
||||
public boolean contentEquals(CharSequence c) {
|
||||
return this.toString().contentEquals(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user