From 44fede015653403fea549f0660694d250b48dd46 Mon Sep 17 00:00:00 2001 From: leventov Date: Wed, 31 Dec 2014 07:08:27 +0700 Subject: [PATCH] Removed ByteableIntValueMarshaller and ByteableLongValueMarshalller --- .../map/ByteableIntValueMarshaller.java | 75 ------------------ .../map/ByteableLongValueMarshaller.java | 76 ------------------- .../chronicle/map/IntValueMapTest.java | 3 +- .../map/TCPSocketReplicationIntValueTest.java | 5 +- 4 files changed, 2 insertions(+), 157 deletions(-) delete mode 100644 src/test/java/net/openhft/chronicle/map/ByteableIntValueMarshaller.java delete mode 100644 src/test/java/net/openhft/chronicle/map/ByteableLongValueMarshaller.java diff --git a/src/test/java/net/openhft/chronicle/map/ByteableIntValueMarshaller.java b/src/test/java/net/openhft/chronicle/map/ByteableIntValueMarshaller.java deleted file mode 100644 index 4acbae9ac..000000000 --- a/src/test/java/net/openhft/chronicle/map/ByteableIntValueMarshaller.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.map; - -import net.openhft.chronicle.hash.serialization.internal.ByteableMarshaller; -import net.openhft.lang.io.Bytes; -import net.openhft.lang.io.NativeBytes; -import net.openhft.lang.io.serialization.BytesMarshaller; -import net.openhft.lang.io.serialization.ObjectFactory; -import net.openhft.lang.model.Byteable; -import net.openhft.lang.model.DataValueClasses; -import net.openhft.lang.values.IntValue; -import org.jetbrains.annotations.Nullable; - -enum ByteableIntValueMarshaller implements BytesMarshaller { - INSTANCE; - - static final Class DIRECT = DataValueClasses.directClassFor(IntValue.class); - - @Override - public void write(Bytes bytes, IntValue intValue) { - Byteable biv = (Byteable) intValue; - bytes.write(biv.bytes(), biv.offset(), biv.maxSize()); - } - - @Nullable - @Override - public IntValue read(Bytes bytes) { - return read(bytes, null); - } - - @Nullable - @Override - public IntValue read(Bytes bytes, @Nullable IntValue intValue) { - try { - if (intValue == null) - intValue = (IntValue) NativeBytes.UNSAFE.allocateInstance(DIRECT); - Byteable biv = (Byteable) intValue; - ByteableMarshaller.setBytesAndOffset(biv, bytes); - bytes.skip(biv.maxSize()); - return intValue; - } catch (Exception e) { - throw new IllegalStateException(e); - } - } -} - -enum DirectIntValueFactory implements ObjectFactory { - INSTANCE; - - @Override - public IntValue create() { - try { - return (IntValue) NativeBytes.UNSAFE.allocateInstance(ByteableIntValueMarshaller.DIRECT); - } catch (InstantiationException e) { - throw new AssertionError(e); - } - } -} diff --git a/src/test/java/net/openhft/chronicle/map/ByteableLongValueMarshaller.java b/src/test/java/net/openhft/chronicle/map/ByteableLongValueMarshaller.java deleted file mode 100644 index 656610e67..000000000 --- a/src/test/java/net/openhft/chronicle/map/ByteableLongValueMarshaller.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.map; - -import net.openhft.chronicle.hash.serialization.internal.ByteableMarshaller; -import net.openhft.lang.io.Bytes; -import net.openhft.lang.io.NativeBytes; -import net.openhft.lang.io.serialization.BytesMarshaller; -import net.openhft.lang.io.serialization.ObjectFactory; -import net.openhft.lang.model.Byteable; -import net.openhft.lang.model.DataValueClasses; -import net.openhft.lang.values.LongValue; -import org.jetbrains.annotations.Nullable; - -enum ByteableLongValueMarshaller implements BytesMarshaller { - INSTANCE; - - static final Class DIRECT = DataValueClasses.directClassFor(LongValue.class); - - @Override - public void write(Bytes bytes, LongValue longValue) { - Byteable biv = (Byteable) longValue; - bytes.write(biv.bytes(), biv.offset(), biv.maxSize()); - } - - @Nullable - @Override - public LongValue read(Bytes bytes) { - return read(bytes, null); - } - - @Nullable - @Override - public LongValue read(Bytes bytes, @Nullable LongValue longValue) { - try { - if (longValue == null) - longValue = (LongValue) NativeBytes.UNSAFE.allocateInstance(DIRECT); - Byteable biv = (Byteable) longValue; - ByteableMarshaller.setBytesAndOffset(biv, bytes); - bytes.skip(biv.maxSize()); - return longValue; - } catch (Exception e) { - throw new IllegalStateException(e); - } - } -} - -enum DirectLongValueFactory implements ObjectFactory { - INSTANCE; - - @Override - public LongValue create() { - try { - return (LongValue) NativeBytes.UNSAFE.allocateInstance(ByteableLongValueMarshaller.DIRECT); - } catch (InstantiationException e) { - throw new AssertionError(e); - } - } -} - diff --git a/src/test/java/net/openhft/chronicle/map/IntValueMapTest.java b/src/test/java/net/openhft/chronicle/map/IntValueMapTest.java index 76e3ea92a..500262099 100644 --- a/src/test/java/net/openhft/chronicle/map/IntValueMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/IntValueMapTest.java @@ -38,8 +38,7 @@ public class IntValueMapTest { try (final ChronicleMap map = ChronicleMapBuilder .of(IntValue.class, CharSequence.class) - .entries(20000) - .keyMarshaller(ByteableIntValueMarshaller.INSTANCE).create()) { + .entries(20000).create()) { IntValue$$Native value = new IntValue$$Native(); value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0); diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java index 4905ff033..a075907ad 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationIntValueTest.java @@ -59,13 +59,10 @@ public class TCPSocketReplicationIntValueTest { ((Byteable) value).bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0); map1Builder = newTcpSocketShmBuilder(IntValue.class, CharSequence.class, (byte) 1, s_port, new InetSocketAddress("localhost", s_port + 1)); - map1Builder.keyMarshaller(ByteableIntValueMarshaller.INSTANCE); - map1 = map1Builder.keyMarshaller(ByteableIntValueMarshaller.INSTANCE) - .createPersistedTo(getPersistenceFile()); + map1 = map1Builder.createPersistedTo(getPersistenceFile()); map2 = newTcpSocketShmBuilder(IntValue.class, CharSequence.class, (byte) 2, s_port + 1) .entries(Builder.SIZE) - .keyMarshaller(ByteableIntValueMarshaller.INSTANCE) .create(); s_port += 2; }