From 9457126b91171b4f0a520afe53e8773a80349208 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Fri, 28 Nov 2014 12:07:30 +0000 Subject: [PATCH] HCOLL-219 removed import/export support for Native classes as its too hard to cover all the edge cases at the moment and its not currently a priority --- .../openhft/chronicle/map/ChronicleMap.java | 6 ++ .../chronicle/map/VanillaChronicleMap.java | 78 ++----------------- .../map/ChronicleMapImportExportTest.java | 21 +++-- 3 files changed, 21 insertions(+), 84 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java index 572198dd7..8059da9f1 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java @@ -282,6 +282,9 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { * differ. This method is not performant and as such we recommend it is not used in performance * sensitive code. * + * MAPS CONTAINING KEYS/VALUES GENERATED WITH OFF-HEAP INTERFACES ARE NOT CURRENTLY + * SUPPORTED, CURRENTLY ONLY KEYS/VALUES THAT IMPLEMENT SERIALIZABLE ARE SUPPORTED + * * @param toFile the file to store all the entries to, the entries will be stored in JSON * format * @throws IOException its not possible store the data to {@code toFile} @@ -296,6 +299,9 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { * entries are overwritten. A write lock is only held while each individual entry is inserted * into the map, not over all the entries in the {@link java.io.File} * + * MAPS CONTAINING KEYS/VALUES GENERATED WITH OFF-HEAP INTERFACES ARE NOT CURRENTLY + * SUPPORTED, CURRENTLY ONLY KEYS/VALUES THAT IMPLEMENT SERIALIZABLE ARE SUPPORTED + * * @param fromFile the file containing entries ( in JSON format ) which will be deserialized and * {@link java.util.Map#put(java.lang.Object, java.lang.Object)} into the map * @throws IOException its not possible read the {@code fromFile} diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 097b9e866..62c2bf8fb 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -47,8 +47,6 @@ import org.slf4j.LoggerFactory; import java.io.*; import java.lang.reflect.Array; -import java.nio.BufferOverflowException; -import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.FileChannel; import java.util.*; @@ -388,6 +386,7 @@ class VanillaChronicleMap, static abstract class ReadValueToBytes implements ReadValue { private SizeMarshaller valueSizeMarshaller; + abstract Bytes bytes(long valueSize); void valueSizeMarshaller(SizeMarshaller valueSizeMarshaller) { @@ -427,6 +426,7 @@ class VanillaChronicleMap, private static class ReadValueToLazyBytes extends ReadValueToBytes { DirectBytes lazyBytes; + @Override Bytes bytes(long valueSize) { if (lazyBytes != null) { @@ -701,7 +701,7 @@ class VanillaChronicleMap, * @return a lazily created XStreamConverter */ private synchronized XStreamConverter lazyXStreamConverter() { - if (xStreamConverter == null) + if (xStreamConverter != null) return xStreamConverter; final KeyValueSerializer serializers = new KeyValueSerializer(keyBuilder, @@ -731,53 +731,6 @@ class VanillaChronicleMap, this.keyValueSerializer = keyValueSerializer; } - - private synchronized Bytes toKeyBytes(K key) { - for (; ; ) { - - try { - keyValueSerializer.writeKey(key, buffer, threadLocalCopies); - return buffer; - } catch (BufferOverflowException e) { - ByteBuffer b = allocateDirect((int) buffer.capacity() + (int) entrySize) - .order(ByteOrder.nativeOrder()); - buffer = new ByteBufferBytes(allocateDirect((int) buffer.capacity() + (int) entrySize) - .order(ByteOrder.nativeOrder())); - } - } - } - - private synchronized Bytes toValueBytes(V value) { - for (; ; ) { - - try { - keyValueSerializer.writeValue(value, buffer, threadLocalCopies); - return buffer; - } catch (BufferOverflowException e) { - ByteBuffer b = allocateDirect((int) buffer.capacity() + (int) entrySize) - .order(ByteOrder.nativeOrder()); - buffer = new ByteBufferBytes(b); - } - } - } - - - private synchronized Bytes append(CharSequence value) { - for (; ; ) { - - try { - buffer.clear(); - buffer.append(value); - buffer.flip(); - return buffer; - } catch (BufferOverflowException e) { - ByteBuffer b = allocateDirect((int) buffer.capacity() + (int) entrySize) - .order(ByteOrder.nativeOrder()); - buffer = new ByteBufferBytes(b); - } - } - } - private void registerConverter(XStream xstream) { final Converter converter = new Converter() { @@ -807,25 +760,7 @@ class VanillaChronicleMap, buffer.clear(); - if (kClass.isAssignableFrom(o.getClass())) { - - Bytes bytes = (ByteBufferBytes) toKeyBytes((K) o); - - String hex = AbstractBytes.toHex(bytes); - hex.toString(); - - - String text = bytes.asString().toString(); - System.out.println("key=" + text); - // writer.setValue(text); - - // writer.startNode("key"); - writer.setValue(o.toString()); - // writer.endNode(); - } else if (vClass.isAssignableFrom(o.getClass())) { - writer.setValue(o.toString()); - } else if (WriteThroughEntry.class.isAssignableFrom - (o.getClass())) { + if (WriteThroughEntry.class.isAssignableFrom(o.getClass())) { final SimpleEntry e = (SimpleEntry) o; @@ -860,10 +795,7 @@ class VanillaChronicleMap, @Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) { - String value = reader.getValue(); - buffer.clear(); - append(value); - buffer.flip(); + final String nodeName = reader.getNodeName(); diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java index 6646305d1..e8eefc106 100644 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java @@ -11,6 +11,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static org.junit.Assert.assertEquals; + /** * @author Rob Austin. */ @@ -178,7 +180,7 @@ public class ChronicleMapImportExportTest { } - @Ignore("this tyep of off heap reference is not currently supported") + @Ignore("this type of off heap reference is not currently supported") @Test public void testWithLongValue() throws IOException, InterruptedException { @@ -190,18 +192,15 @@ public class ChronicleMapImportExportTest { .class) .create()) { - - - ChronicleMapBuilder builder = ChronicleMapBuilder - .of(CharSequence.class, LongValue.class) - .entries(1000) - .entrySize(16); - - LongValue value = new LongValue$$Native(); - - expected.put("hello", value); + // this will add the entry + try (WriteContext context = expected.acquireUsingLocked("one", value)) { + assertEquals(0, context.value().getValue()); + assert value == context.value(); + LongValue value1 = context.value(); + value1.addValue(1); + } expected.getAll(file);