From 59add5e42f421c0ca8fb690f881e3e151d99f0d1 Mon Sep 17 00:00:00 2001 From: leventov Date: Sun, 21 Dec 2014 21:47:07 +0700 Subject: [PATCH] HCOLL-263 assume direct off-heap impls only used if fails to generate generic off-heap/on-heap readers/writers --- README.md | 15 ++++----------- .../chronicle/map/SerializationBuilder.java | 18 ++++++++++-------- .../OpenJDKAndHashMapExamplesTest.java | 2 +- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 92760ea63..ec1e29a4a 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ this for best performance. or value objects that are created through, a directClass interface, for example : ``` java ChronicleMap chm = ChronicleMapBuilder - .of(String.class, DataValueClasses.directClassFor(BondVOInterface.class)) + .of(String.class, ondVOInterface.class) .create(); ``` @@ -470,19 +470,12 @@ Below we show you how you can work directly with the off heap entries. ``` java ChronicleMap map = ChronicleMapBuilder - .of(String.class, DataValueClasses.directClassFor(BondVOInterface.class)) + .of(String.class, BondVOInterface.class) .keySize(10) .create(); ``` - -notice that the the builder is passed a wrapped value type - -``` java -.of(CharSequence.class, DataValueClasses.directClassFor(BondVOInterface.class)) -``` - -this is in order to tell the builder that we are going to work directly with the off heap -entries. +by default, builder assume that we are going to work directly with the off heap +entries (`DataValueClasses.directClassFor(BondVOInterface.class)`). The value class, in our case `BondVOInterface.class` is an `interface` rather than a `class`, now like before, we can diff --git a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java index cb32fd227..eef36ec81 100644 --- a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java @@ -29,10 +29,7 @@ import net.openhft.lang.io.serialization.BytesMarshaller; import net.openhft.lang.io.serialization.ObjectFactory; import net.openhft.lang.io.serialization.ObjectSerializer; import net.openhft.lang.io.serialization.impl.*; -import net.openhft.lang.model.Byteable; -import net.openhft.lang.model.DataValueGenerator; -import net.openhft.lang.model.DataValueModel; -import net.openhft.lang.model.DataValueModels; +import net.openhft.lang.model.*; import net.openhft.lang.threadlocal.Provider; import net.openhft.lang.threadlocal.ThreadLocalCopies; import org.jetbrains.annotations.NotNull; @@ -104,10 +101,6 @@ final class SerializationBuilder implements Cloneable, Serializable { private void configureByDefault(Class eClass, Role role) { instancesAreMutable = instancesAreMutable(eClass); - ObjectFactory factory = concreteClass(eClass) && marshallerUseFactory(eClass) ? - new NewInstanceObjectFactory(eClass) : - NullObjectFactory.of(); - if (eClass.isInterface()) { try { BytesReader reader = DataValueBytesMarshallers.acquireBytesReader(eClass); @@ -119,10 +112,19 @@ final class SerializationBuilder implements Cloneable, Serializable { sizeMarshaller(constant((long) size)); return; } catch (Exception e) { + try { + eClass = DataValueClasses.directClassFor(eClass); + } catch (Exception ex) { + // ignore, fall through + } // ignore, fall through } } + ObjectFactory factory = concreteClass(eClass) && marshallerUseFactory(eClass) ? + new NewInstanceObjectFactory(eClass) : + NullObjectFactory.of(); + if (concreteClass(eClass) && Byteable.class.isAssignableFrom(eClass)) { ByteableMarshaller byteableMarshaller = ByteableMarshaller.of((Class) eClass); sizeMarshaller(byteableMarshaller); diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/OpenJDKAndHashMapExamplesTest.java b/src/test/java/net/openhft/chronicle/map/fromdocs/OpenJDKAndHashMapExamplesTest.java index 7b0664a99..13cd3dc0f 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/OpenJDKAndHashMapExamplesTest.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/OpenJDKAndHashMapExamplesTest.java @@ -56,7 +56,7 @@ public class OpenJDKAndHashMapExamplesTest { file.deleteOnExit(); ChronicleMap chm = ChronicleMapBuilder - .of(String.class, DataValueClasses.directClassFor(BondVOInterface.class)) + .of(String.class, BondVOInterface.class) .keySize(10) .createPersistedTo(file);