diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 230bbce37..5c4def7b3 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -767,6 +767,7 @@ final class TcpReplicator extends AbstractChannelReplicator implements Closeable serverChannel.socket().setReceiveBufferSize(BUFFER_SIZE); serverChannel.configureBlocking(false); + serverChannel.register(TcpReplicator.this.selector,0); ServerSocket serverSocket = null; try { diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 28a21ab88..75932373c 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -70,7 +70,8 @@ class VanillaChronicleMap, // private static final Logger LOG = LoggerFactory.getLogger(VanillaChronicleMap.class); /** - * Because DirectBitSet implementations couldn't find more than 64 continuous clear or set bits. + * Because DirectBitSet implementations couldn't find more than 64 continuous clear or set + * bits. */ static final int MAX_ENTRY_OVERSIZE_FACTOR = 64; private static final long serialVersionUID = 2L; @@ -659,8 +660,15 @@ class VanillaChronicleMap, static T newInstance(Class interfaceClass, boolean isKey) { - return isKey ? DataValueClasses.newInstance(interfaceClass) : - DataValueClasses.newDirectInstance(interfaceClass); + if (isKey) + return DataValueClasses.newInstance(interfaceClass); + else { + if (interfaceClass.equals(CharSequence.class)) { + return (T) new StringBuilder(); + } + + return DataValueClasses.newDirectInstance(interfaceClass); + } } private XStreamConverter xStreamConverter; @@ -1056,9 +1064,9 @@ class VanillaChronicleMap, } /** - * removes ( if there exists ) an entry from the map, if the {@param key} and {@param expectedValue} match that of a - * maps.entry. If the {@param expectedValue} equals null then ( if there exists ) an entry whose key equals {@param - * key} this is removed. + * removes ( if there exists ) an entry from the map, if the {@param key} and {@param + * expectedValue} match that of a maps.entry. If the {@param expectedValue} equals null then ( + * if there exists ) an entry whose key equals {@param key} this is removed. * * @param k the key of the entry to remove * @param expectedValue null if not required @@ -1190,8 +1198,8 @@ class VanillaChronicleMap, * replace the value in a map, only if the existing entry equals {@param expectedValue} * * @param key the key into the map - * @param expectedValue the expected existing value in the map ( could be null when we don't wish to do this check - * ) + * @param expectedValue the expected existing value in the map ( could be null when we don't + * wish to do this check ) * @param newValue the new value you wish to store in the map * @return the value that was replaced */ @@ -1593,6 +1601,7 @@ class VanillaChronicleMap, } long startWriteLock = 0; + final WriteLocked writeLock() { return writeLock(null, false); } @@ -1968,9 +1977,9 @@ class VanillaChronicleMap, } /** - * Returns value size, writes the entry (key, value, sizes) to the entry, after this method call entry - * positioned after value bytes written (i. e. at the end of entry), sets entry position (in segment) and value - * size position in the given segmentState + * Returns value size, writes the entry (key, value, sizes) to the entry, after this method + * call entry positioned after value bytes written (i. e. at the end of entry), sets entry + * position (in segment) and value size position in the given segmentState */ final , E, EW> long putEntry(SegmentState segmentState, @@ -2094,9 +2103,10 @@ class VanillaChronicleMap, } /** - * - if expectedValue is not null, returns Boolean.TRUE (removed) or Boolean.FALSE (entry not found), regardless - * the expectedValue object is Bytes instance (RPC call) or the value instance - if expectedValue is null: - if - * resultUnused is false, null or removed value is returned - if resultUnused is true, null is always returned + * - if expectedValue is not null, returns Boolean.TRUE (removed) or Boolean.FALSE (entry + * not found), regardless the expectedValue object is Bytes instance (RPC call) or the value + * instance - if expectedValue is null: - if resultUnused is false, null or removed value is + * returned - if resultUnused is true, null is always returned */ , RV, VB extends RV, VBI, MVBI extends MetaBytesInterop> @@ -2240,8 +2250,9 @@ class VanillaChronicleMap, } /** - * Replaces the specified value for the key with the given value. {@code newValue} is set only if the existing - * value corresponding to the specified key is equal to {@code expectedValue} or {@code expectedValue == null}. + * Replaces the specified value for the key with the given value. {@code newValue} is set + * only if the existing value corresponding to the specified key is equal to {@code + * expectedValue} or {@code expectedValue == null}. * * @param hash2 a hash code related to the {@code keyBytes} * @return the replaced value or {@code null} if the value was not replaced @@ -2339,15 +2350,17 @@ class VanillaChronicleMap, } /** - * Replaces value in existing entry. May cause entry relocation, because there may be not enough space for new - * value in location already allocated for this entry. + * Replaces value in existing entry. May cause entry relocation, because there may be not + * enough space for new value in location already allocated for this entry. * * @param pos index of the first block occupied by the entry - * @param offset relative offset of the entry in Segment bytes (before, i. e. including metaData) + * @param offset relative offset of the entry in Segment bytes (before, i. e. + * including metaData) * @param entry relative pointer in Segment bytes * @param valueSizePos relative position of value size in entry * @param entryEndAddr absolute address of the entry end - * @return relative offset of the entry in Segment bytes after putting value (that may cause entry relocation) + * @return relative offset of the entry in Segment bytes after putting value (that may cause + * entry relocation) */ final long putValue( long pos, long offset, MultiStoreBytes entry, long valueSizePos, long entryEndAddr, diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 9740ab0c3..cc608a757 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -143,6 +143,23 @@ public class CHMUseCasesTest { } } + @Test + public void testAcquireUsingWithCharSequence() { + try (ChronicleMap map = ChronicleMapBuilder + .of(CharSequence.class, CharSequence.class) + .create()) { + + CharSequence using = map.newValueInstance(); + + try (WriteContext wc = map.acquireUsingLocked("1", using)) { + assertTrue(using instanceof StringBuilder); + ((StringBuilder) using).append("Hello World"); + } + + assertEquals("Hello World", map.get("1")); + } + } + /** * StringValue represents any bean which contains a String Value */