diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index b86f16cd1..1b895a7c1 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -1348,21 +1348,12 @@ class StatelessServerConnector { final ThreadLocalCopies local = keyValueSerializer.threadLocalCopies(); final K key = readKey(reader, local); - V value = using.getAndSet(null); - if (value == null) { - - //value = map.createValueInstance(); - - // todo replace this - value = map.acquireUsing(key, null); - } - - - + final V value = using.getAndSet(null); final Function o = (Function) reader.readObject(); - try (WriteContext wc = map.acquireUsingLocked(key, value)) { - Object result = o.apply(value); + try (WriteContext wc = map.lookupUsing(key, value, VanillaChronicleMap.LockType.WRITE_LOCK, + false)) { + Object result = o.apply(wc.value()); keyValueSerializer.writeObject(result, writer); } catch (RuntimeException e) { diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 400b55c2e..908ee3ccc 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -29,10 +29,7 @@ import net.openhft.lang.collection.DirectBitSet; import net.openhft.lang.collection.SingleThreadedDirectBitSet; import net.openhft.lang.io.*; import net.openhft.lang.io.serialization.JDKObjectSerializer; -import net.openhft.lang.io.serialization.impl.AllocateInstanceObjectFactory; import net.openhft.lang.io.serialization.impl.VanillaBytesMarshallerFactory; -import net.openhft.lang.model.Byteable; -import net.openhft.lang.model.DataValueClasses; import net.openhft.lang.model.constraints.Nullable; import net.openhft.lang.threadlocal.Provider; import net.openhft.lang.threadlocal.ThreadLocalCopies; @@ -353,30 +350,7 @@ class VanillaChronicleMap, } - V createValueInstance() { - if (vClass.isAssignableFrom(Byteable.class)) - return DataValueClasses.newDirectReference(vClass); - else { - - - try { - return vClass.newInstance(); - } catch (InstantiationException e) { - try { - return (V) (new AllocateInstanceObjectFactory(vClass)).create(); - } catch (Exception e1) { - LOG.error("", e); - return null; - } - } catch (IllegalAccessException e) { - LOG.error("", e); - return null; - } - - - } - } enum LockType {READ_LOCK, WRITE_LOCK} diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index d8e3558c1..4bec46de5 100755 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -1494,16 +1494,16 @@ public class ChronicleMapTest { @Test public void testOnheapAcquireUsingLockedStringBuilder() throws IOException { - try (final ChronicleMap map = ChronicleMapOnHeapUpdatableBuilder - .of(CharSequence.class, StringBuilder.class) + try (final ChronicleMap map = ChronicleMapOnHeapUpdatableBuilder + .of(CharSequence.class, CharSequence.class) .entries(1000) - - .entrySize(40).create()) { + .entrySize(40) + .defaultValue("") + .create()) { StringBuilder value = new StringBuilder(); - - try (WriteContext context = map.acquireUsingLocked("one", value)) { + try (WriteContext context = map.acquireUsingLocked("one", value)) { value.append("Hello World"); }