diff --git a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java index fc78a9607..0942bed63 100644 --- a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessChronicleMap.java @@ -136,7 +136,7 @@ class ClientWiredStatelessChronicleMap implements ChronicleMap, 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 implements ChronicleMap, 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 implements ChronicleMap, 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 implements ChronicleMap, Clon @Override public int hashCode() { - return proxyReturnInt(HASH_CODE.toString()); + return proxyReturnInt(hashCode.toString()); } @NotNull @@ -205,15 +205,15 @@ class ClientWiredStatelessChronicleMap implements ChronicleMap, 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 implements ChronicleMap, 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 implements ChronicleMap, 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 implements ChronicleMap, 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 implements ChronicleMap, 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 implements ChronicleMap, 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 implements ChronicleMap, Clon } public void clear() { - proxyReturnVoid(() -> writeField(Fields.methodName, CLEAR.toString())); + proxyReturnVoid(() -> writeField(Fields.methodName, clear.toString())); } @NotNull public Set keySet() { final Set usingCollection = new HashSet(); - readChunked(kClass, KEY_SET, usingCollection); + readChunked(kClass, keySet, usingCollection); return usingCollection; } @@ -360,7 +360,7 @@ class ClientWiredStatelessChronicleMap implements ChronicleMap, Clon @NotNull public Collection values() { final List usingCollection = new ArrayList<>(); - return readChunked(vClass, VALUES, usingCollection); + return readChunked(vClass, values, usingCollection); } private > Collection readChunked(Class vClass1, EventId values, A usingCollection) { @@ -406,7 +406,7 @@ class ClientWiredStatelessChronicleMap implements ChronicleMap, Clon final Map result = new HashMap(); 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 implements ChronicleMap, 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 implements ChronicleMap, 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 { diff --git a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessTcpConnectionHub.java b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessTcpConnectionHub.java index f5976c242..c06ce69e7 100644 --- a/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessTcpConnectionHub.java +++ b/src/main/java/net/openhft/chronicle/map/ClientWiredStatelessTcpConnectionHub.java @@ -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; } diff --git a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java index ba906c76d..b2f838016 100644 --- a/src/main/java/net/openhft/chronicle/map/MapWireHandler.java +++ b/src/main/java/net/openhft/chronicle/map/MapWireHandler.java @@ -194,7 +194,7 @@ class MapWireHandler implements WireHandler, Consumer { } 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 implements WireHandler, Consumer { 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 implements WireHandler, Consumer { 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 implements WireHandler, Consumer { } - 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 implements WireHandler, Consumer { 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 implements WireHandler, Consumer { 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 implements WireHandler, Consumer { 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 implements WireHandler, Consumer { 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 implements WireHandler, Consumer { } - 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 implements WireHandler, Consumer { } 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); + } } diff --git a/src/test/java/net/openhft/chronicle/map/ConcurrentMap8Test.java b/src/test/java/net/openhft/chronicle/map/ConcurrentMap8Test.java index fb7a3f2bb..2a9071919 100644 --- a/src/test/java/net/openhft/chronicle/map/ConcurrentMap8Test.java +++ b/src/test/java/net/openhft/chronicle/map/ConcurrentMap8Test.java @@ -134,7 +134,7 @@ public class ConcurrentMap8Test extends JSR166TestCase { static ConcurrentMap longMap() { if (longMap == null) { longMap = newLongMap(); - for (int i = 0; i < SIZE; ++i) + for (int i = 0; i < size; ++i) longMap.put(Long.valueOf(i), Long.valueOf(2 * i)); }