Removed AgileBytesMarshaller

This commit is contained in:
leventov
2014-11-07 14:32:30 +03:00
parent f96d369cdd
commit fddacd1243
10 changed files with 64 additions and 56 deletions
@@ -1,22 +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.hash.serialization;
public interface AgileBytesMarshaller<E> extends BytesReader<E>, BytesInterop<E>, SizeMarshaller {
}
@@ -18,8 +18,10 @@
package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.BytesInterop;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.Hasher;
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;
@@ -28,7 +30,8 @@ import net.openhft.lang.io.serialization.impl.AllocateInstanceObjectFactory;
import net.openhft.lang.model.Byteable;
import org.jetbrains.annotations.NotNull;
public class ByteableMarshaller<E extends Byteable> implements AgileBytesMarshaller<E> {
public class ByteableMarshaller<E extends Byteable>
implements BytesInterop<E>, BytesReader<E>, SizeMarshaller {
private static final long serialVersionUID = 0L;
public static <E extends Byteable> ByteableMarshaller<E> of(@NotNull Class<E> eClass) {
@@ -18,13 +18,15 @@
package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.BytesInterop;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.lang.io.Bytes;
import static java.lang.Double.doubleToLongBits;
public enum DoubleMarshaller implements AgileBytesMarshaller<Double> {
public enum DoubleMarshaller implements BytesInterop<Double>, BytesReader<Double>, SizeMarshaller {
INSTANCE;
@Override
@@ -18,11 +18,11 @@
package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.chronicle.hash.serialization.*;
import net.openhft.lang.io.Bytes;
public enum IntegerMarshaller implements AgileBytesMarshaller<Integer> {
public enum IntegerMarshaller
implements BytesInterop<Integer>, BytesReader<Integer>, SizeMarshaller {
INSTANCE;
@Override
@@ -18,11 +18,14 @@
package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.BytesInterop;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.Hasher;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.lang.io.Bytes;
public enum LongMarshaller implements AgileBytesMarshaller<Long> {
public enum LongMarshaller
implements BytesInterop<Long>, BytesReader<Long>, SizeMarshaller {
INSTANCE;
@Override
@@ -18,10 +18,13 @@
package net.openhft.chronicle.hash.serialization.internal;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
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 VoidMarshaller implements AgileBytesMarshaller<Void> {
public enum VoidMarshaller
implements BytesInterop<Void>, BytesReader<Void>, SizeMarshaller {
INSTANCE;
@Override
@@ -17,7 +17,8 @@
package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.ChronicleHashBuilder;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.BytesWriter;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.serialization.BytesMarshallable;
import net.openhft.lang.io.serialization.BytesMarshaller;
@@ -223,9 +224,10 @@ public final class ChronicleMapBuilder<K, V>
return this;
}
public ChronicleMapBuilder<K, V> valueMarshaller(
@NotNull AgileBytesMarshaller<V> valueMarshaller) {
valueBuilder.agileMarshaller(valueMarshaller, null);
public ChronicleMapBuilder<K, V> valueMarshallers(
BytesWriter<V> valueWriter, BytesReader<V> valueReader) {
valueBuilder.writer(valueWriter);
valueBuilder.reader(valueReader, valueBuilder.factory());
return this;
}
}
@@ -83,18 +83,29 @@ final class SerializationBuilder<E> implements Cloneable {
NullObjectFactory.<E>of();
if (concreteClass(eClass) && Byteable.class.isAssignableFrom(eClass)) {
agileMarshaller(ByteableMarshaller.of((Class) eClass), factory);
ByteableMarshaller agileBytesMarshaller = ByteableMarshaller.of((Class) eClass);
sizeMarshaller(agileBytesMarshaller)
.reader(agileBytesMarshaller, factory)
.interop(agileBytesMarshaller);
} else if (eClass == CharSequence.class || eClass == String.class) {
reader((BytesReader<E>) CharSequenceReader.of(), factory);
writer((BytesWriter<E>) CharSequenceWriter.instance());
} else if (eClass == Void.class) {
agileMarshaller((AgileBytesMarshaller<E>) VoidMarshaller.INSTANCE, factory);
sizeMarshaller(VoidMarshaller.INSTANCE)
.reader((BytesReader<E>) VoidMarshaller.INSTANCE, factory)
.interop((BytesInterop<E>) VoidMarshaller.INSTANCE);
} else if (eClass == Long.class) {
agileMarshaller((AgileBytesMarshaller<E>) LongMarshaller.INSTANCE, factory);
sizeMarshaller(LongMarshaller.INSTANCE)
.reader((BytesReader<E>) LongMarshaller.INSTANCE, factory)
.interop((BytesInterop<E>) LongMarshaller.INSTANCE);
} else if (eClass == Double.class) {
agileMarshaller((AgileBytesMarshaller<E>) DoubleMarshaller.INSTANCE, factory);
sizeMarshaller(DoubleMarshaller.INSTANCE)
.reader((BytesReader<E>) DoubleMarshaller.INSTANCE, factory)
.interop((BytesInterop<E>) DoubleMarshaller.INSTANCE);
} else if (eClass == Integer.class) {
agileMarshaller((AgileBytesMarshaller<E>) IntegerMarshaller.INSTANCE, factory);
sizeMarshaller(IntegerMarshaller.INSTANCE)
.reader((BytesReader<E>) IntegerMarshaller.INSTANCE, factory)
.interop((BytesInterop<E>) IntegerMarshaller.INSTANCE);
} else if (eClass == byte[].class) {
reader((BytesReader<E>) ByteArrayMarshaller.INSTANCE, factory);
interop((BytesInterop<E>) ByteArrayMarshaller.INSTANCE);
@@ -125,14 +136,6 @@ final class SerializationBuilder<E> implements Cloneable {
return this;
}
public SerializationBuilder<E> agileMarshaller(AgileBytesMarshaller<E> agileBytesMarshaller,
ObjectFactory<E> factory) {
if (factory == null) factory = this.factory;
return sizeMarshaller(agileBytesMarshaller)
.reader(agileBytesMarshaller, factory)
.interop(agileBytesMarshaller);
}
public SerializationBuilder<E> interop(BytesInterop<E> interop) {
return copyingInterop(null)
.setInterop(interop)
@@ -142,6 +145,8 @@ final class SerializationBuilder<E> implements Cloneable {
}
public SerializationBuilder<E> writer(BytesWriter<E> writer) {
if (writer instanceof BytesInterop)
return interop((BytesInterop<E>) writer);
return copyingInterop(CopyingInterop.FROM_WRITER)
.setInterop(writer)
.metaInterop(CopyingMetaBytesInterop
@@ -287,10 +292,19 @@ final class SerializationBuilder<E> implements Cloneable {
" value don't use object factory");
} else if (interop instanceof ByteableMarshaller) {
if (factory instanceof AllocateInstanceObjectFactory) {
agileMarshaller(ByteableMarshaller.of((Class) eClass), factory);
ByteableMarshaller agileBytesMarshaller =
ByteableMarshaller.of((Class) eClass);
sizeMarshaller(agileBytesMarshaller)
.reader(agileBytesMarshaller, factory)
.interop(agileBytesMarshaller);
} else {
agileMarshaller(ByteableMarshaller.of((Class) eClass, (ObjectFactory) factory),
factory);
ByteableMarshaller agileBytesMarshaller =
ByteableMarshaller.of((Class) eClass, (ObjectFactory) factory);
ObjectFactory<E> factory1 = factory;
if (factory1 == null) factory1 = this.factory;
sizeMarshaller(agileBytesMarshaller)
.reader(agileBytesMarshaller, factory1)
.interop(agileBytesMarshaller);
}
} else if (interop instanceof BytesMarshallableMarshaller) {
if (factory instanceof AllocateInstanceObjectFactory) {
@@ -53,7 +53,7 @@ public class ChronicleSetBuilder<E>
ChronicleSetBuilder(Class<E> keyClass) {
chronicleMapBuilder = ChronicleMapBuilder.of(keyClass, DummyValue.class)
.valueMarshaller(DummyValueMarshaller.INSTANCE);
.valueMarshallers(DummyValueMarshaller.INSTANCE, DummyValueMarshaller.INSTANCE);
}
public static <K> ChronicleSetBuilder<K> of(Class<K> keyClass) {
@@ -18,12 +18,15 @@
package net.openhft.chronicle.set;
import net.openhft.chronicle.hash.serialization.AgileBytesMarshaller;
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;
import static net.openhft.chronicle.set.DummyValue.DUMMY_VALUE;
enum DummyValueMarshaller implements AgileBytesMarshaller<DummyValue> {
enum DummyValueMarshaller
implements BytesInterop<DummyValue>, BytesReader<DummyValue>, SizeMarshaller {
INSTANCE;
@Override