Remove the complexity and API-transparency of implementing and supporting built-in serializability for marshallers and core implementation classes, as this is replaced with Wire Marshallable

This commit is contained in:
leventov
2016-01-14 16:07:22 +03:00
parent 92c0aec592
commit 28eeeb70e7
38 changed files with 36 additions and 199 deletions
@@ -21,15 +21,13 @@ import net.openhft.chronicle.bytes.ReadBytesMarshallable;
import net.openhft.chronicle.wire.Marshallable;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
/**
* External version on {@link ReadBytesMarshallable}.
*
* @param <T> type of objects deserialized
* @see BytesWriter
*/
public interface BytesReader<T> extends Serializable, Marshallable {
public interface BytesReader<T> extends Marshallable {
/**
* Reads and returns the object from {@link Bytes#readPosition()} (i. e. the current position)
@@ -21,15 +21,13 @@ import net.openhft.chronicle.bytes.WriteBytesMarshallable;
import net.openhft.chronicle.wire.Marshallable;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
/**
* External version of {@link WriteBytesMarshallable}.
*
* @param <T> the type of objects serialized
* @see BytesReader
*/
public interface BytesWriter<T> extends Serializable, Marshallable {
public interface BytesWriter<T> extends Marshallable {
/**
* Serializes the given object to the given {@code out}.
@@ -20,9 +20,7 @@ import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.wire.Marshallable;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
public interface DataAccess<T> extends StatefulCopyable<DataAccess<T>>, Serializable, Marshallable {
public interface DataAccess<T> extends StatefulCopyable<DataAccess<T>>, Marshallable {
Data<T> getData(@NotNull T instance);
@@ -22,8 +22,6 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
@@ -49,8 +47,7 @@ import static net.openhft.chronicle.hash.serialization.StatefulCopyable.copyIfNe
* @see ListMarshaller
* @see SetMarshaller
*/
public final class MapMarshaller<K, V>
implements BytesReader<Map<K, V>>, BytesWriter<Map<K, V>>,
public final class MapMarshaller<K, V> implements BytesReader<Map<K, V>>, BytesWriter<Map<K, V>>,
StatefulCopyable<MapMarshaller<K, V>> {
// Config fields
@@ -73,11 +70,6 @@ public final class MapMarshaller<K, V>
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
orderedKeys = new ArrayDeque<>();
orderedValues = new ArrayDeque<>();
@@ -22,9 +22,10 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.*;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.Set;
import static net.openhft.chronicle.hash.serialization.StatefulCopyable.copyIfNeeded;
@@ -83,11 +84,6 @@ public final class SetMarshaller<T>
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
orderedElements = new ArrayDeque<>();
}
@@ -21,8 +21,6 @@ import net.openhft.chronicle.hash.serialization.impl.ConstantSizeMarshaller;
import net.openhft.chronicle.hash.serialization.impl.StopBitSizeMarshaller;
import net.openhft.chronicle.wire.Marshallable;
import java.io.Serializable;
/**
* Strategy of storing numbers in bytes stores (usually sizes of the subsequent chunks in
* the same bytes store). Normal number storing (4 bytes for {@code int}, 8 bytes for {@code long}
@@ -37,7 +35,7 @@ import java.io.Serializable;
* value (it's constant size). If the marshaller is fed with the size it is not able store, it could
* throw an {@code IllegalArgumentException}.
*/
public interface SizeMarshaller extends Serializable, Marshallable {
public interface SizeMarshaller extends Marshallable {
static SizeMarshaller stopBit() {
return StopBitSizeMarshaller.INSTANCE;
@@ -22,8 +22,6 @@ import net.openhft.chronicle.wire.Marshallable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.Serializable;
/**
* Deserializer of objects from bytes, mirroring the {@link SizedWriter}, i. e. assuming the length
* of the serialized form isn't written in the beginning of the serialized form itself, but managed
@@ -72,7 +70,7 @@ import java.io.Serializable;
* @param <T> the type of the object deserialized
* @see SizedWriter
*/
public interface SizedReader<T> extends Serializable, Marshallable {
public interface SizedReader<T> extends Marshallable {
/**
* Reads and returns the object from {@link Bytes#readPosition()} (i. e. the current position)
@@ -21,8 +21,6 @@ import net.openhft.chronicle.hash.ChronicleHash;
import net.openhft.chronicle.wire.Marshallable;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
/**
* Serializer (object to bytes writer) which 1) knows the length of serialized
* form of any object before actual serialization 2) doesn't include that length in the serialized
@@ -59,7 +57,7 @@ import java.io.Serializable;
* @param <T> the type of the object marshalled
* @see SizedReader
*/
public interface SizedWriter<T> extends Serializable, Marshallable {
public interface SizedWriter<T> extends Marshallable {
/**
* Returns the length (in bytes) of the serialized form of the given object. Serialization form
@@ -26,9 +26,6 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
public class ByteArrayDataAccess extends AbstractData<byte[]> implements DataAccess<byte[]> {
/** Cache field */
@@ -41,11 +38,6 @@ public class ByteArrayDataAccess extends AbstractData<byte[]> implements DataAcc
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
bs = HeapBytesStore.uninitialized();
}
@@ -26,8 +26,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import sun.nio.ch.DirectBuffer;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.nio.ByteBuffer;
public class ByteBufferDataAccess extends AbstractData<ByteBuffer>
@@ -46,11 +44,6 @@ public class ByteBufferDataAccess extends AbstractData<ByteBuffer>
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
heapBytesStore = HeapBytesStore.uninitialized();
nativeBytesStore = NativeBytesStore.uninitialized();
@@ -20,8 +20,6 @@ import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -18,7 +18,6 @@ package net.openhft.chronicle.hash.serialization.impl;
import net.openhft.chronicle.bytes.Byteable;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.SizedReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,9 +25,6 @@ import net.openhft.chronicle.wire.WireIn;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
public class BytesMarshallableDataAccess<T extends BytesMarshallable>
extends InstanceCreatingMarshaller<T> implements DataAccess<T>, Data<T> {
@@ -48,11 +45,6 @@ public class BytesMarshallableDataAccess<T extends BytesMarshallable>
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
bytes = Bytes.allocateElasticDirect(1);
}
@@ -27,9 +27,6 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import static net.openhft.chronicle.hash.serialization.StatefulCopyable.copyIfNeeded;
public class ExternalBytesMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T>
@@ -53,11 +50,6 @@ public class ExternalBytesMarshallableDataAccess<T> extends InstanceCreatingMars
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
bytes = Bytes.allocateElasticDirect(1);
}
@@ -25,15 +25,13 @@ import net.openhft.chronicle.wire.WireIn;
import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
/**
* Holds new instance creation logic, common for many {@link DataAccess} and {@link SizedReader}
* implementations
*
* @param <T> the type of objects deserialized
*/
public abstract class InstanceCreatingMarshaller<T> implements Serializable, Marshallable {
public abstract class InstanceCreatingMarshaller<T> implements Marshallable {
private Class<T> tClass;
@@ -43,11 +43,6 @@ public class SerializableDataAccess<T extends Serializable> extends AbstractData
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
void initTransients() {
bytes = Bytes.allocateElasticDirect(1);
out = bytes.outputStream();
@@ -28,8 +28,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
public class SerializableReader<T extends Serializable>
implements SizedReader<T>, BytesReader<T> {
public class SerializableReader<T extends Serializable> implements SizedReader<T>, BytesReader<T> {
@NotNull
@Override
@@ -30,8 +30,7 @@ import java.nio.ByteBuffer;
import static net.openhft.chronicle.hash.serialization.SizeMarshaller.constant;
import static net.openhft.chronicle.hash.serialization.SizeMarshaller.stopBit;
public final class SerializationBuilder<T> implements Cloneable, Serializable {
private static final long serialVersionUID = 0L;
public final class SerializationBuilder<T> implements Cloneable {
private static boolean concreteClass(Class c) {
return !c.isInterface() && !Modifier.isAbstract(c.getModifiers());
@@ -124,25 +123,6 @@ public final class SerializationBuilder<T> implements Cloneable, Serializable {
}
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeBoolean(serializesGeneratedClasses);
if (serializesGeneratedClasses) {
out.writeObject(tClass);
}
out.defaultWriteObject();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
boolean generatedClassesSerialized = in.readBoolean();
if (generatedClassesSerialized) {
Class<?> eClass = (Class) in.readObject();
// This is needed because ValueDataAccess/ValueReader tries to serialize/deserialize
// generated classes, requires them to be generated beforehand
new SerializationBuilder<>(eClass);
}
in.defaultReadObject();
}
public void reader(SizedReader<T> reader) {
this.reader = reader;
}
@@ -27,9 +27,6 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import static net.openhft.chronicle.hash.serialization.StatefulCopyable.copyIfNeeded;
public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T>
@@ -61,11 +58,6 @@ public class SizedMarshallableDataAccess<T> extends InstanceCreatingMarshaller<T
return sizedWriter;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
bytes = Bytes.allocateElasticDirect(1);
}
@@ -26,9 +26,6 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
/**
* {@link BytesReader} implementation for String, for the primary ChronicleMap's key of value type
* {@link StringSizedReader} + {@link CharSequenceSizedWriter} are more efficient (because don't
@@ -37,8 +34,7 @@ import java.io.ObjectInputStream;
*
* @see CharSequenceBytesWriter
*/
public class StringBytesReader
implements BytesReader<String>, StatefulCopyable<StringBytesReader> {
public class StringBytesReader implements BytesReader<String>, StatefulCopyable<StringBytesReader> {
/** Cache field */
private transient StringBuilder sb;
@@ -47,11 +43,6 @@ public class StringBytesReader
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
sb = new StringBuilder();
}
@@ -25,9 +25,6 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
public class StringSizedReader implements SizedReader<String>, StatefulCopyable<StringSizedReader> {
/** Cache field */
@@ -37,11 +34,6 @@ public class StringSizedReader implements SizedReader<String>, StatefulCopyable<
initTransients();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
sb = new StringBuilder();
}
@@ -28,9 +28,6 @@ import net.openhft.chronicle.wire.WireOut;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import static net.openhft.chronicle.bytes.NativeBytesStore.nativeStoreWithFixedCapacity;
public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T> {
@@ -65,11 +62,6 @@ public class ValueDataAccess<T> extends AbstractData<T> implements DataAccess<T>
return heapClass;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
nativeInstance = (Byteable) Values.newNativeReference(valueType);
nativeInstanceAsCopyable = (Copyable) nativeInstance;
@@ -60,11 +60,6 @@ public class ValueReader<T>
return heapClass;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
initTransients();
}
private void initTransients() {
nativeClass = Values.nativeClassFor(valueType);
heapClass = Values.heapClassFor(valueType);