diff --git a/README.md b/README.md index 6c5b08040..7385846ad 100644 --- a/README.md +++ b/README.md @@ -310,14 +310,14 @@ the ChronicleMapBuilder can also be used to return the ChronicleMap, see the exa ChronicleMap map = ChronicleMapBuilder.of(Integer.class, CharSequence.class).create(); ``` -One way to achieve good performance is to focus on unnecessary object creation as this reduces +One way to achieve good performance is to focus on unnecessary object creation, as this reduces the amount of work that has to be carried out by the Garbage Collector. As such ChronicleMap supports the following methods : - [`V getUsing(K key, V value);`](http://openhft.github.io/Chronicle-Map/apidocs/net/openhft/chronicle/map/ChronicleMap.html#getUsing-K-V-) - [`V acquireUsing(K key, V value);`](http://openhft.github.io/Chronicle-Map/apidocs/net/openhft/chronicle/map/ChronicleMap.html#acquireUsing-K-V-) - - ReadContext getUsingLocked(@NotNull K key, @NotNull V usingValue); - - WriteContext acquireUsingLocked(@NotNull K key, @NotNull V usingValue); + - [`ReadContext getUsingLocked(@NotNull K key, @NotNull V usingValue);`] (https://github.com/OpenHFT/Chronicle-Map#off-heap-storage-and-how-using-a-proxy-object-can-improve-performance) + - [`WriteContext acquireUsingLocked(@NotNull K key, @NotNull V usingValue);`] (https://github.com/OpenHFT/Chronicle-Map#acquireusinglocked) These methods let you provide the object which the data will be written to, even if the object is @@ -364,7 +364,6 @@ that entry has to be deserialised onto the java heap so that you can use its val ``` java for(int i=1;i<=10;i++) { Value v = get(key) - } ``` this would create 10 separate instances of the value. As each time get() is called the map has to diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java index 92d42a2b6..432b64bfc 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java @@ -136,7 +136,7 @@ public abstract class AbstractChronicleMapBuilder> eventListener = MapEventListeners.nop(); private V defaultValue = null; - private DefaultValueProvider defaultValueProvider = NullValueProvider.INSTANCE; + private DefaultValueProvider defaultValueProvider = null; private PrepareValueBytes prepareValueBytes = null; private SingleChronicleHashReplication singleHashReplication = null; diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 465aa0b88..5b9be429b 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -237,12 +237,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { if (closeables != null) closeables.closeQuietly(); closeables = null; - try { - // give time to close - Thread.sleep(100); - } catch (InterruptedException e) { - // - } + } /** @@ -399,7 +394,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable { } - public synchronized V acquireUsing(@NotNull K key, V usingValue) { + public synchronized V acquireUsing(@NotNull K key, V usingValue) { throw new UnsupportedOperationException("acquireUsing() is not supported for stateless " + "clients"); } diff --git a/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java index 886420120..c85c8f86f 100755 --- a/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/DemoChronicleMapTest.java @@ -17,7 +17,6 @@ public class DemoChronicleMapTest { File file = File.createTempFile("DummyOrders", ".test"); file.deleteOnExit(); int maxEntries = 1000; -// ChronicleMap map = ChronicleMapBuilder ChronicleMap map = OffHeapUpdatableChronicleMapBuilder .of(IntValue.class, DemoOrderVOInterface.class) .putReturnsNull(true) @@ -37,7 +36,6 @@ public class DemoChronicleMapTest { map.acquireUsing(key, value); - // TODO Shouldn't throw an NPE, because acquire should set the value. value.setSymbol("IBM-" + i); value.addAtomicOrderQty(1000); @@ -61,7 +59,6 @@ public class DemoChronicleMapTest { File file = File.createTempFile("DummyOrders", ".test"); file.deleteOnExit(); int maxEntries = 1000; -// ChronicleMap map = ChronicleMapBuilder ChronicleMap map = OffHeapUpdatableChronicleMapBuilder .of(IntValue.class, DemoOrderVOInterface.class) .putReturnsNull(true) @@ -80,7 +77,6 @@ public class DemoChronicleMapTest { key.setValue(i); try (WriteContext wc = map.acquireUsingLocked(key, value)) { - // TODO Shouldn't throw an NPE, because acquire should set the value. value.setSymbol("IBM-" + i); value.addAtomicOrderQty(1000); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java index 9a4dcee0a..11d741f60 100755 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3VoidValueTest.java @@ -82,12 +82,12 @@ public class TCPSocketReplication3VoidValueTest { assertEquals(null, map1.put(2, null)); assertEquals(null, map2.put(5, null)); - assertEquals(null, map2.put(6,null)); + assertEquals(null, map2.put(6, null)); map1.remove(2); map2.remove(3); map1.remove(3); - map2.put(5,null); + map2.put(5, null); // allow time for the recompilation to resolve assertTrue(waitTillEqual(5000)); @@ -102,7 +102,7 @@ public class TCPSocketReplication3VoidValueTest { public void testClear() throws IOException, InterruptedException { assertEquals(null, map1.put(1, null)); - assertEquals(null, map1.put(2,null)); + assertEquals(null, map1.put(2, null)); assertEquals(null, map2.put(5, null)); assertEquals(null, map2.put(6, null)); @@ -123,7 +123,8 @@ public class TCPSocketReplication3VoidValueTest { int t = 0; for (; t < timeOutMs; t++) { if (map1.equals(map2) && - map1.equals(map3)) + map1.equals(map3) && + map2.equals(map3)) return true; Thread.sleep(1); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java index 02b00f377..3af0a9cc2 100755 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayPutReturnsNullTest.java @@ -145,7 +145,8 @@ public class TCPSocketReplication3wayPutReturnsNullTest { int t = 0; for (; t < timeOutMs; t++) { if (map1.equals(map2) && - map1.equals(map3)) + map1.equals(map3) + && map2.equals(map3)) break; Thread.sleep(1); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java index 7c359968b..bd5f058b1 100755 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplication3wayTest.java @@ -154,7 +154,8 @@ public class TCPSocketReplication3wayTest { int t = 0; for (; t < timeOutMs; t++) { if (map1.equals(map2) && - map1.equals(map3)) + map1.equals(map3) + && map2.equals(map3)) break; Thread.sleep(1); } diff --git a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java index 98b75f4dd..98f889388 100644 --- a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java +++ b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java @@ -148,7 +148,8 @@ public class SetForTCPSocketReplication3wayTest { int t = 0; for (; t < timeOutMs; t++) { if (set1.equals(set2) && - set1.equals(set3)) + set1.equals(set3) && + set2.equals(set3)) break; Thread.sleep(1); }