diff --git a/src/main/java/net/openhft/chronicle/hash/StatelessClientConfig.java b/src/main/java/net/openhft/chronicle/hash/StatelessClientConfig.java index 38add9b6a..9f24fc72f 100644 --- a/src/main/java/net/openhft/chronicle/hash/StatelessClientConfig.java +++ b/src/main/java/net/openhft/chronicle/hash/StatelessClientConfig.java @@ -18,10 +18,8 @@ package net.openhft.chronicle.hash; import net.openhft.chronicle.map.ChronicleMap; import net.openhft.chronicle.set.ChronicleSet; -import org.jetbrains.annotations.NotNull; import java.io.IOException; -import java.net.InetSocketAddress; import java.util.concurrent.TimeUnit; /** diff --git a/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java b/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java index d9b71abd5..ac67cf2ea 100644 --- a/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java +++ b/src/main/java/net/openhft/chronicle/hash/hashing/Accesses.java @@ -19,7 +19,6 @@ package net.openhft.chronicle.hash.hashing; import net.openhft.lang.io.Bytes; import java.nio.ByteBuffer; -import java.nio.ByteOrder; /** * Static methods returning useful {@link Access} implementations. diff --git a/src/main/java/net/openhft/chronicle/hash/hashing/UnsafeAccess.java b/src/main/java/net/openhft/chronicle/hash/hashing/UnsafeAccess.java index 36d54a1cb..b135be6e9 100644 --- a/src/main/java/net/openhft/chronicle/hash/hashing/UnsafeAccess.java +++ b/src/main/java/net/openhft/chronicle/hash/hashing/UnsafeAccess.java @@ -21,9 +21,7 @@ import sun.misc.Unsafe; import java.lang.reflect.Field; import java.nio.ByteOrder; -import static net.openhft.chronicle.hash.hashing.Primitives.unsignedByte; -import static net.openhft.chronicle.hash.hashing.Primitives.unsignedInt; -import static net.openhft.chronicle.hash.hashing.Primitives.unsignedShort; +import static net.openhft.chronicle.hash.hashing.Primitives.*; enum UnsafeAccess implements Access { INSTANCE; diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java new file mode 100644 index 000000000..8bdb4412b --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BasicCopyingMetaBytesInterop.java @@ -0,0 +1,70 @@ +/* + * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.hash.serialization.internal; + +import net.openhft.chronicle.hash.hashing.Hasher; +import net.openhft.lang.io.Bytes; +import net.openhft.lang.threadlocal.Provider; +import net.openhft.lang.threadlocal.ThreadLocalCopies; + +public abstract class BasicCopyingMetaBytesInterop implements MetaBytesInterop { + private static final long serialVersionUID = 0L; + + static final Provider provider = + Provider.of(DirectBytesBuffer.class); + + static abstract class BasicCopyingMetaBytesInteropProvider> implements MetaProvider { + private static final long serialVersionUID = 0L; + + @Override + public ThreadLocalCopies getCopies(ThreadLocalCopies copies) { + return provider.getCopies(copies); + } + } + + final DirectBytesBuffer buffer; + transient long size; + transient long hash; + + protected BasicCopyingMetaBytesInterop(DirectBytesBuffer buffer) { + this.buffer = buffer; + } + + @Override + public long size(W writer, E e) { + return size; + } + + @Override + public boolean startsWith(W writer, Bytes bytes, E e) { + return bytes.startsWith(buffer.buffer); + } + + @Override + public long hash(W writer, E e) { + long h; + if ((h = hash) == 0L) + return hash = Hasher.hash(buffer.buffer); + return h; + } + + @Override + public void write(W writer, Bytes bytes, E e) { + bytes.write(buffer.buffer); + } +} diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteArrayMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteArrayMarshaller.java index d92787fbb..767df0abd 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteArrayMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteArrayMarshaller.java @@ -18,9 +18,9 @@ package net.openhft.chronicle.hash.serialization.internal; +import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.chronicle.hash.serialization.BytesInterop; import net.openhft.chronicle.hash.serialization.BytesReader; -import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.lang.io.Bytes; public enum ByteArrayMarshaller implements BytesInterop, BytesReader { diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteableMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteableMarshaller.java index 0f32d5c03..b6350cca5 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteableMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/ByteableMarshaller.java @@ -19,16 +19,18 @@ package net.openhft.chronicle.hash.serialization.internal; import net.openhft.chronicle.hash.hashing.Hasher; -import net.openhft.chronicle.hash.serialization.*; +import net.openhft.chronicle.hash.serialization.BytesInterop; +import net.openhft.chronicle.hash.serialization.DeserializationFactoryConfigurableBytesReader; +import net.openhft.chronicle.hash.serialization.SizeMarshaller; import net.openhft.lang.io.Bytes; import net.openhft.lang.io.MultiStoreBytes; import net.openhft.lang.io.NativeBytes; -import net.openhft.lang.io.serialization.*; +import net.openhft.lang.io.serialization.ObjectFactory; import net.openhft.lang.model.Byteable; import org.jetbrains.annotations.NotNull; public abstract class ByteableMarshaller - implements BytesInterop, + implements BytesInterop, MetaBytesInterop, DeserializationFactoryConfigurableBytesReader>, SizeMarshaller { private static final long serialVersionUID = 0L; @@ -160,6 +162,26 @@ public abstract class ByteableMarshaller return (E) NativeBytes.UNSAFE.allocateInstance(tClass); } + @Override + public boolean startsWith(Object interop, Bytes bytes, E e) { + return startsWith(bytes, e); + } + + @Override + public long hash(Object interop, E e) { + return hash(e); + } + + @Override + public long size(Object writer, E e) { + return size(e); + } + + @Override + public void write(Object writer, Bytes bytes, E e) { + write(bytes, e); + } + private static class Default extends ByteableMarshaller { private static final long serialVersionUID = 0L; diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java index c8cb5ea3d..6c5a59174 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/BytesBytesInterop.java @@ -16,8 +16,8 @@ package net.openhft.chronicle.hash.serialization.internal; -import net.openhft.chronicle.hash.serialization.BytesInterop; import net.openhft.chronicle.hash.hashing.Hasher; +import net.openhft.chronicle.hash.serialization.BytesInterop; import net.openhft.lang.io.Bytes; public enum BytesBytesInterop implements BytesInterop { diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CharArrayMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CharArrayMarshaller.java index 9e646beaf..bdcf3d220 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CharArrayMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CharArrayMarshaller.java @@ -18,9 +18,9 @@ package net.openhft.chronicle.hash.serialization.internal; +import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.chronicle.hash.serialization.BytesInterop; import net.openhft.chronicle.hash.serialization.BytesReader; -import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.lang.io.Bytes; public enum CharArrayMarshaller implements BytesInterop, BytesReader { diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java index fa631cd04..2b7022e84 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java @@ -19,23 +19,15 @@ package net.openhft.chronicle.hash.serialization.internal; import net.openhft.chronicle.hash.serialization.BytesWriter; -import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.lang.MemoryUnit; import net.openhft.lang.io.Bytes; -import net.openhft.lang.io.DirectBytes; -import net.openhft.lang.io.DirectStore; import net.openhft.lang.io.serialization.BytesMarshaller; -import net.openhft.lang.io.serialization.JDKObjectSerializer; -import net.openhft.lang.threadlocal.Provider; -import net.openhft.lang.threadlocal.StatefulCopyable; import net.openhft.lang.threadlocal.ThreadLocalCopies; -import java.io.IOException; -import java.io.ObjectInputStream; import java.io.Serializable; -public abstract class CopyingMetaBytesInterop implements MetaBytesInterop { - private static final long serialVersionUID = 0L; +public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaBytesInterop { + private static final long serialVersionUID = 1L; private static final long MAX_REASONABLE_SERIALIZED_SIZE = MemoryUnit.MEGABYTES.toBytes(512L); @@ -50,14 +42,11 @@ public abstract class CopyingMetaBytesInterop implements MetaBytesInterop< } } - final DirectBytesBuffer buffer; - transient long size; - transient long hash; transient W writer; transient E cur; - private CopyingMetaBytesInterop(DirectBytesBuffer buffer) { - this.buffer = buffer; + protected CopyingMetaBytesInterop(DirectBytesBuffer buffer) { + super(buffer); } void init(W writer, E e, boolean mutable, long maxSize) { @@ -82,29 +71,6 @@ public abstract class CopyingMetaBytesInterop implements MetaBytesInterop< abstract void innerWrite(W writer, Bytes bytes, E e); - @Override - public long size(W writer, E e) { - return size; - } - - @Override - public boolean startsWith(W writer, Bytes bytes, E e) { - return bytes.startsWith(buffer.buffer); - } - - @Override - public long hash(W writer, E e) { - long h; - if ((h = hash) == 0L) - return hash = Hasher.hash(buffer.buffer); - return h; - } - - @Override - public void write(W writer, Bytes bytes, E e) { - bytes.write(buffer.buffer); - } - DirectBytesBuffer buffer() { return buffer; } @@ -119,20 +85,6 @@ public abstract class CopyingMetaBytesInterop implements MetaBytesInterop< return new DirectBytesBuffer(bufferIdentity).forBytesWriter; } - private static final Provider provider = - Provider.of(DirectBytesBuffer.class); - - private static abstract class AbstractCopyingMetaBytesInteropProvider> - implements MetaProvider { - private static final long serialVersionUID = 0L; - - @Override - public ThreadLocalCopies getCopies(ThreadLocalCopies copies) { - return provider.getCopies(copies); - } - } - public static > MetaProvider> providerForBytesMarshaller(boolean mutable, long maxSize) { @@ -141,7 +93,7 @@ public abstract class CopyingMetaBytesInterop implements MetaBytesInterop< private static class BytesMarshallerCopyingMetaBytesInteropProvider> - extends AbstractCopyingMetaBytesInteropProvider> { + extends BasicCopyingMetaBytesInteropProvider> { private static final long serialVersionUID = 0L; private final boolean mutable; private final long maxSize; @@ -169,7 +121,7 @@ public abstract class CopyingMetaBytesInterop implements MetaBytesInterop< } private static class BytesWriterCopyingMetaBytesInteropProvider> - extends AbstractCopyingMetaBytesInteropProvider> { + extends BasicCopyingMetaBytesInteropProvider> { private static final long serialVersionUID = 0L; private final boolean mutable; private final long maxSize; @@ -189,83 +141,4 @@ public abstract class CopyingMetaBytesInterop implements MetaBytesInterop< return forBytesWriter; } } - - private static class DirectBytesBuffer - implements StatefulCopyable, Serializable { - private static final long serialVersionUID = 0L; - private final Serializable identity; - private transient DirectBytes buffer; - - private transient ForBytesMarshaller forBytesMarshaller; - private transient ForBytesWriter forBytesWriter; - - DirectBytesBuffer(Serializable identity) { - this.identity = identity; - initTransients(); - } - - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - initTransients(); - } - - private void initTransients() { - forBytesMarshaller = new ForBytesMarshaller(); - forBytesWriter = new ForBytesWriter(); - } - - Bytes obtain(long maxSize) { - DirectBytes buf; - if ((buf = buffer) != null) { - if (maxSize <= buf.capacity()) { - return buf.clear(); - } else { - DirectStore store = (DirectStore) buf.store(); - store.resize(maxSize, false); - return buffer = store.bytes(); - } - } else { - buffer = new DirectStore(JDKObjectSerializer.INSTANCE, maxSize, false).bytes(); - return buffer; - } - } - - @Override - public Object stateIdentity() { - return identity; - } - - @Override - public DirectBytesBuffer copy() { - return new DirectBytesBuffer(identity); - } - - private class ForBytesMarshaller> - extends CopyingMetaBytesInterop { - private static final long serialVersionUID = 0L; - - private ForBytesMarshaller() { - super(DirectBytesBuffer.this); - } - - @Override - void innerWrite(M writer, Bytes bytes, E e) { - writer.write(bytes, e); - } - } - - private class ForBytesWriter> - extends CopyingMetaBytesInterop { - private static final long serialVersionUID = 0L; - - private ForBytesWriter() { - super(DirectBytesBuffer.this); - } - - @Override - void innerWrite(W writer, Bytes bytes, E e) { - writer.write(bytes, e); - } - } - } } diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java new file mode 100644 index 000000000..3c4425869 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DataValueMetaBytesInterop.java @@ -0,0 +1,92 @@ +/* + * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.hash.serialization.internal; + +import net.openhft.chronicle.hash.serialization.BytesWriter; +import net.openhft.lang.io.Bytes; +import net.openhft.lang.model.*; +import net.openhft.lang.threadlocal.ThreadLocalCopies; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; + +public abstract class DataValueMetaBytesInterop + extends BasicCopyingMetaBytesInterop> { + private static final long serialVersionUID = 0L; + + protected DataValueMetaBytesInterop(DirectBytesBuffer buffer) { + super(buffer); + } + + void init(BytesWriter writer, E e, long size) { + Bytes buffer = this.buffer.obtain(size); + writer.write(buffer, e); + buffer.flip(); + this.size = size; + hash = 0L; + } + + public static MetaBytesInterop> forIdentity(Serializable bufferIdentity) { + return new DirectBytesBuffer(bufferIdentity).forDataValueWriter; + } + + public static MetaProvider, MetaBytesInterop>> + interopProvider(Class eClass) { + return new InteropProvider<>(eClass); + } + + private static class InteropProvider extends BasicCopyingMetaBytesInteropProvider< + E, BytesWriter, MetaBytesInterop>> { + private static final long serialVersionUID = 0L; + + private final Class eClass; + transient long size; + transient MetaBytesInterop metaByteableInterop; + + private InteropProvider(Class eClass) { + this.eClass = eClass; + initTransients(); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + initTransients(); + } + + private void initTransients() { + DataValueModel model = DataValueModels.acquireModel(eClass); + size = DataValueGenerator.computeNonScalarOffset(model, eClass); + // TODO make this pick up configured deserializationFactory somehow + metaByteableInterop = ByteableMarshaller.of( + (Class) DataValueClasses.directClassFor(eClass)); + } + + @Override + public MetaBytesInterop> get( + ThreadLocalCopies copies, MetaBytesInterop> originalMetaWriter, + BytesWriter writer, E e) { + if (e instanceof Byteable) + return metaByteableInterop; + DirectBytesBuffer.ForDataValueWriter forDataValueWriter = + provider.get(copies, ((DataValueMetaBytesInterop)originalMetaWriter).buffer) + .forDataValueWriter; + forDataValueWriter.init(writer, e, size); + return forDataValueWriter; + } + } +} diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DirectBytesBuffer.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DirectBytesBuffer.java new file mode 100644 index 000000000..5a78d6dfa --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DirectBytesBuffer.java @@ -0,0 +1,117 @@ +/* + * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.hash.serialization.internal; + +import net.openhft.chronicle.hash.serialization.BytesWriter; +import net.openhft.lang.io.Bytes; +import net.openhft.lang.io.DirectBytes; +import net.openhft.lang.io.DirectStore; +import net.openhft.lang.io.serialization.BytesMarshaller; +import net.openhft.lang.io.serialization.JDKObjectSerializer; +import net.openhft.lang.threadlocal.StatefulCopyable; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; + +class DirectBytesBuffer + implements StatefulCopyable, Serializable { + private static final long serialVersionUID = 0L; + private final Serializable identity; + transient DirectBytes buffer; + + transient ForBytesMarshaller forBytesMarshaller; + transient ForBytesWriter forBytesWriter; + transient ForDataValueWriter forDataValueWriter; + + DirectBytesBuffer(Serializable identity) { + this.identity = identity; + initTransients(); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + initTransients(); + } + + private void initTransients() { + forBytesMarshaller = new ForBytesMarshaller(); + forBytesWriter = new ForBytesWriter(); + forDataValueWriter = new ForDataValueWriter(); + } + + Bytes obtain(long maxSize) { + DirectBytes buf; + if ((buf = buffer) != null) { + if (maxSize <= buf.capacity()) { + return buf.clear(); + } else { + DirectStore store = (DirectStore) buf.store(); + store.resize(maxSize, false); + return buffer = store.bytes(); + } + } else { + buffer = new DirectStore(JDKObjectSerializer.INSTANCE, maxSize, false).bytes(); + return buffer; + } + } + + @Override + public Object stateIdentity() { + return identity; + } + + @Override + public DirectBytesBuffer copy() { + return new DirectBytesBuffer(identity); + } + + class ForBytesMarshaller> + extends CopyingMetaBytesInterop { + private static final long serialVersionUID = 0L; + + private ForBytesMarshaller() { + super(DirectBytesBuffer.this); + } + + @Override + void innerWrite(M writer, Bytes bytes, E e) { + writer.write(bytes, e); + } + } + + class ForBytesWriter> + extends CopyingMetaBytesInterop { + private static final long serialVersionUID = 0L; + + private ForBytesWriter() { + super(DirectBytesBuffer.this); + } + + @Override + void innerWrite(W writer, Bytes bytes, E e) { + writer.write(bytes, e); + } + } + + class ForDataValueWriter extends DataValueMetaBytesInterop { + + private ForDataValueWriter() { + super(DirectBytesBuffer.this); + } + } +} diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java index 20fb35773..6df3b6c79 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/DoubleMarshaller.java @@ -18,9 +18,9 @@ package net.openhft.chronicle.hash.serialization.internal; +import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.chronicle.hash.serialization.BytesInterop; import net.openhft.chronicle.hash.serialization.BytesReader; -import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.chronicle.hash.serialization.SizeMarshaller; import net.openhft.lang.io.Bytes; diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/IntegerMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/IntegerMarshaller.java index eb0f05da5..759c9608c 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/IntegerMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/IntegerMarshaller.java @@ -19,7 +19,9 @@ package net.openhft.chronicle.hash.serialization.internal; import net.openhft.chronicle.hash.hashing.Hasher; -import net.openhft.chronicle.hash.serialization.*; +import net.openhft.chronicle.hash.serialization.BytesInterop; +import net.openhft.chronicle.hash.serialization.BytesReader; +import net.openhft.chronicle.hash.serialization.SizeMarshaller; import net.openhft.lang.io.Bytes; public enum IntegerMarshaller diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/LongMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/LongMarshaller.java index c3dde401a..635028206 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/LongMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/LongMarshaller.java @@ -18,9 +18,9 @@ package net.openhft.chronicle.hash.serialization.internal; +import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.chronicle.hash.serialization.BytesInterop; import net.openhft.chronicle.hash.serialization.BytesReader; -import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.chronicle.hash.serialization.SizeMarshaller; import net.openhft.lang.io.Bytes; diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/VoidMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/VoidMarshaller.java index e7b19b335..7d75f8e1d 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/VoidMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/VoidMarshaller.java @@ -18,7 +18,6 @@ package net.openhft.chronicle.hash.serialization.internal; -import net.openhft.chronicle.hash.hashing.Hasher; import net.openhft.chronicle.hash.serialization.BytesInterop; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.SizeMarshaller; diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index 81d845abf..f5a51af34 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -43,7 +43,10 @@ import org.slf4j.LoggerFactory; import java.io.*; import java.lang.reflect.Constructor; import java.net.InetSocketAddress; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java b/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java index 49fcaf1ba..5e3349f54 100644 --- a/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java +++ b/src/main/java/net/openhft/chronicle/map/MultiMapFactory.java @@ -24,9 +24,7 @@ import net.openhft.lang.io.DirectStore; import net.openhft.lang.io.NativeBytes; import static net.openhft.lang.Maths.isPowerOf2; -import static net.openhft.lang.MemoryUnit.BITS; -import static net.openhft.lang.MemoryUnit.BYTES; -import static net.openhft.lang.MemoryUnit.LONGS; +import static net.openhft.lang.MemoryUnit.*; /** * Created by peter on 09/11/14. diff --git a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java index 77ba08d36..ac1f597b5 100644 --- a/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/SerializationBuilder.java @@ -21,7 +21,6 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.hash.serialization.*; import net.openhft.chronicle.hash.serialization.internal.*; import net.openhft.chronicle.hash.serialization.internal.ByteBufferMarshaller; -import net.openhft.lang.MemoryUnit; import net.openhft.lang.io.ByteBufferBytes; import net.openhft.lang.io.Bytes; import net.openhft.lang.io.serialization.BytesMarshallable; @@ -108,7 +107,10 @@ final class SerializationBuilder implements Cloneable, Serializable { DataValueModel model = DataValueModels.acquireModel(eClass); int size = DataValueGenerator.computeNonScalarOffset(model, eClass); reader(reader); - writer(writer); + copyingInterop(null); + setInterop(writer); + metaInterop((MetaBytesInterop) DataValueMetaBytesInterop.forIdentity(role)); + metaInteropProvider(DataValueMetaBytesInterop.interopProvider(eClass)); sizeMarshaller(constant((long) size)); return; } catch (Exception e) { diff --git a/src/test/java/eg/BigData.java b/src/test/java/eg/BigData.java index 8c8fe917f..177b1059f 100644 --- a/src/test/java/eg/BigData.java +++ b/src/test/java/eg/BigData.java @@ -20,7 +20,6 @@ package eg; import net.openhft.affinity.AffinitySupport; import net.openhft.chronicle.map.ChronicleMapBuilder; -import net.openhft.chronicle.map.ChronicleMapBuilder; import net.openhft.lang.io.Bytes; import java.io.*; diff --git a/src/test/java/eg/TestMain.java b/src/test/java/eg/TestMain.java index 00beb1945..1f92e89c4 100644 --- a/src/test/java/eg/TestMain.java +++ b/src/test/java/eg/TestMain.java @@ -1,7 +1,5 @@ package eg; -import com.sun.tools.internal.xjc.generator.bean.BeanGenerator; - import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java index ba8742488..ddde2e047 100644 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java @@ -4,10 +4,8 @@ import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; import net.openhft.chronicle.map.fromdocs.BondVOInterface; -import net.openhft.lang.model.DataValueClasses; import net.openhft.lang.values.LongValue; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import java.io.File; diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index ebc5872be..6f5501629 100755 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -1613,7 +1613,7 @@ public class ChronicleMapTest { } - @Test(expected = IllegalStateException.class) + @Test public void testPutLongValue() throws IOException { final ChronicleMapBuilder builder = ChronicleMapBuilder .of(CharSequence.class, LongValue.class) @@ -1623,7 +1623,14 @@ public class ChronicleMapTest { final ChronicleMap map = builder.create(); LongValue value = nativeLongValue(); - map.put("x", value); + try { + map.put("x", value); + } catch (IllegalStateException | NullPointerException e) { + // ok + return; + } + throw new AssertionError("Should throw either IllegalStateException or " + + "NullPointerException, but succeed"); } @Test diff --git a/src/test/java/net/openhft/chronicle/map/ConstantSizeBySampleTest.java b/src/test/java/net/openhft/chronicle/map/ConstantSizeBySampleTest.java index a570ecd07..8cd0a1357 100644 --- a/src/test/java/net/openhft/chronicle/map/ConstantSizeBySampleTest.java +++ b/src/test/java/net/openhft/chronicle/map/ConstantSizeBySampleTest.java @@ -19,7 +19,6 @@ package net.openhft.chronicle.map; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import java.io.*; diff --git a/src/test/java/net/openhft/chronicle/map/Issue42Test.java b/src/test/java/net/openhft/chronicle/map/Issue42Test.java index 494b7b1b6..89aa015f6 100755 --- a/src/test/java/net/openhft/chronicle/map/Issue42Test.java +++ b/src/test/java/net/openhft/chronicle/map/Issue42Test.java @@ -18,8 +18,8 @@ package net.openhft.chronicle.map; - import org.junit.Assert; import net.openhft.lang.Jvm; +import org.junit.Assert; import org.junit.Test; import java.io.IOException; diff --git a/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java index cc33273d2..e8194356e 100644 --- a/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/NoTcpReplicationSoakTest.java @@ -5,12 +5,17 @@ import net.openhft.lang.io.ByteBufferBytes; import net.openhft.lang.model.Byteable; import net.openhft.lang.model.DataValueClasses; import net.openhft.lang.values.IntValue; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import java.io.Closeable; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.*; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java index 216903eb2..e7fc7872d 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpTimeBasedReplicationSoakTest.java @@ -6,7 +6,10 @@ import net.openhft.lang.io.ByteBufferBytes; import net.openhft.lang.model.Byteable; import net.openhft.lang.model.DataValueClasses; import net.openhft.lang.values.IntValue; -import org.junit.*; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; import org.mockito.Mockito; import java.io.Closeable; diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Heap.java b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Heap.java index 3db5fc71a..b3d97d526 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Heap.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$$Heap.java @@ -16,14 +16,13 @@ package net.openhft.chronicle.map.fromdocs; -import static net.openhft.lang.Compare.*; -import java.io.IOException; -import net.openhft.chronicle.map.fromdocs.BondVOInterface; -import net.openhft.chronicle.map.fromdocs.BondVOInterface.MarketPx; import net.openhft.lang.io.Bytes; import net.openhft.lang.io.serialization.BytesMarshallable; import net.openhft.lang.model.Copyable; +import static net.openhft.lang.Compare.calcLongHashCode; +import static net.openhft.lang.Compare.isEqual; + public class BondVOInterface$$Heap implements BondVOInterface, BytesMarshallable, Copyable { private double _coupon; private long _issueDate; diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Heap.java b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Heap.java index cd7839302..38c81c894 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Heap.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/BondVOInterface$MarketPx$$Heap.java @@ -16,13 +16,14 @@ package net.openhft.chronicle.map.fromdocs; -import static net.openhft.lang.Compare.*; -import java.io.IOException; import net.openhft.chronicle.map.fromdocs.BondVOInterface.MarketPx; import net.openhft.lang.io.Bytes; import net.openhft.lang.io.serialization.BytesMarshallable; import net.openhft.lang.model.Copyable; +import static net.openhft.lang.Compare.calcLongHashCode; +import static net.openhft.lang.Compare.isEqual; + public class BondVOInterface$MarketPx$$Heap implements MarketPx, BytesMarshallable, Copyable { private double _askPx; private double _bidPx;