mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Update to newer Core, Bytes & Wire dependency versions; make all enum marshallers ordinary classes with static INSTANCE fields, because of difficulties with Wire serialization of enums
This commit is contained in:
@@ -39,8 +39,10 @@ public interface HashSplitting extends Marshallable {
|
||||
int segmentIndex(long hash);
|
||||
long segmentHash(long hash);
|
||||
|
||||
enum ForSingleSegment implements HashSplitting, EnumMarshallable<ForSingleSegment> {
|
||||
INSTANCE;
|
||||
final class ForSingleSegment implements HashSplitting, EnumMarshallable<ForSingleSegment> {
|
||||
public static final ForSingleSegment INSTANCE = new ForSingleSegment();
|
||||
|
||||
private ForSingleSegment() {}
|
||||
|
||||
@Override
|
||||
public int segmentIndex(long hash) {
|
||||
|
||||
@@ -24,10 +24,12 @@ import net.openhft.chronicle.hash.serialization.SizedWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum BooleanMarshaller
|
||||
public final class BooleanMarshaller
|
||||
implements SizedReader<Boolean>, BytesReader<Boolean>,
|
||||
SizedWriter<Boolean>, BytesWriter<Boolean>, EnumMarshallable<BooleanMarshaller> {
|
||||
INSTANCE;
|
||||
public static final BooleanMarshaller INSTANCE = new BooleanMarshaller();
|
||||
|
||||
private BooleanMarshaller() {}
|
||||
|
||||
@Override
|
||||
public long size(@NotNull Boolean e) {
|
||||
|
||||
+4
-2
@@ -22,10 +22,12 @@ import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum ByteArraySizedReader
|
||||
public final class ByteArraySizedReader
|
||||
implements SizedReader<byte[]>, EnumMarshallable<ByteArraySizedReader> {
|
||||
|
||||
INSTANCE;
|
||||
public static final ByteArraySizedReader INSTANCE = new ByteArraySizedReader();
|
||||
|
||||
private ByteArraySizedReader() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+4
-2
@@ -23,9 +23,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public enum ByteBufferSizedReader
|
||||
public final class ByteBufferSizedReader
|
||||
implements SizedReader<ByteBuffer>, EnumMarshallable<ByteBufferSizedReader> {
|
||||
INSTANCE;
|
||||
public static final ByteBufferSizedReader INSTANCE = new ByteBufferSizedReader();
|
||||
|
||||
private ByteBufferSizedReader() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+4
-2
@@ -37,9 +37,11 @@ import java.io.ObjectInputStream;
|
||||
*
|
||||
* @see CharSequenceBytesWriter
|
||||
*/
|
||||
public enum CharSequenceBytesReader implements BytesReader<CharSequence>,
|
||||
public final class CharSequenceBytesReader implements BytesReader<CharSequence>,
|
||||
StatefulCopyable<CharSequenceBytesReader>, EnumMarshallable<CharSequenceBytesReader> {
|
||||
INSTANCE;
|
||||
public static final CharSequenceBytesReader INSTANCE = new CharSequenceBytesReader();
|
||||
|
||||
private CharSequenceBytesReader() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+4
-2
@@ -30,9 +30,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
*
|
||||
* @see StringBytesReader
|
||||
*/
|
||||
public enum CharSequenceBytesWriter
|
||||
public final class CharSequenceBytesWriter
|
||||
implements BytesWriter<CharSequence>, EnumMarshallable<CharSequenceBytesWriter> {
|
||||
INSTANCE;
|
||||
public static final CharSequenceBytesWriter INSTANCE = new CharSequenceBytesWriter();
|
||||
|
||||
private CharSequenceBytesWriter() {}
|
||||
|
||||
@Override
|
||||
public void write(Bytes out, @NotNull CharSequence toWrite) {
|
||||
|
||||
+5
-2
@@ -25,9 +25,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @deprecated use one of {@link AbstractCharSequenceUtf8DataAccess} subclasses instead
|
||||
*/
|
||||
@Deprecated
|
||||
public enum CharSequenceSizedWriter
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class CharSequenceSizedWriter
|
||||
implements SizedWriter<CharSequence>, EnumMarshallable<CharSequenceSizedWriter> {
|
||||
INSTANCE;
|
||||
public static final CharSequenceSizedWriter INSTANCE = new CharSequenceSizedWriter();
|
||||
|
||||
private CharSequenceSizedWriter() {}
|
||||
|
||||
@Override
|
||||
public long size(@NotNull CharSequence toWrite) {
|
||||
|
||||
@@ -26,10 +26,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
* deprecated in favor of {@link DoubleDataAccess}. As reader and element writer for {@link
|
||||
* ListMarshaller} and similar composite marshallers, {@code DoubleMarshaller} is not deprecated.
|
||||
*/
|
||||
public enum DoubleMarshaller
|
||||
public final class DoubleMarshaller
|
||||
implements SizedReader<Double>, BytesReader<Double>,
|
||||
SizedWriter<Double>, BytesWriter<Double>, EnumMarshallable<DoubleMarshaller> {
|
||||
INSTANCE;
|
||||
public static final DoubleMarshaller INSTANCE = new DoubleMarshaller();
|
||||
|
||||
private DoubleMarshaller() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,19 @@ import net.openhft.chronicle.wire.WireIn;
|
||||
import net.openhft.chronicle.wire.WireOut;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface EnumMarshallable<E extends Enum<E>> extends Marshallable, ReadResolvable<E> {
|
||||
/**
|
||||
* This interface safes many single-constant enum-like subclasses in the
|
||||
* {@link net.openhft.chronicle.hash.serialization.impl} package from implementing empty
|
||||
* {@link #readMarshallable} and {@link #writeMarshallable} methods, and forces them to implement
|
||||
* {@link ReadResolvable}. The name references "Enum" because formerly it allowed only {@code enum}
|
||||
* subclasses, to enforce a good practice of making enum-like classes actually Java {@code enum}s.
|
||||
* But changes in Chronicle-Wire, used to serialize/deserialize marshallers in Chronicle Map
|
||||
* headers, turned {@code enum}s from recommended form of marshaller implementations to impossible
|
||||
* one. So now there are no subclasses of this interface which are actually {@code enum}s.
|
||||
*
|
||||
* @param <E> the subclassing marshaller type
|
||||
*/
|
||||
public interface EnumMarshallable<E> extends Marshallable, ReadResolvable<E> {
|
||||
|
||||
@Override
|
||||
default void readMarshallable(@NotNull WireIn wireIn) {
|
||||
|
||||
@@ -26,10 +26,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
* is deprecated in favor of {@link IntegerDataAccess}. As reader and element writer for {@link
|
||||
* ListMarshaller} and similar composite marshallers, {@code IntegerMarshaller} is not deprecated.
|
||||
*/
|
||||
public enum IntegerMarshaller
|
||||
public final class IntegerMarshaller
|
||||
implements SizedReader<Integer>, BytesReader<Integer>,
|
||||
SizedWriter<Integer>, BytesWriter<Integer>, EnumMarshallable<IntegerMarshaller> {
|
||||
INSTANCE;
|
||||
public static final IntegerMarshaller INSTANCE = new IntegerMarshaller();
|
||||
|
||||
private IntegerMarshaller() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -26,10 +26,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
* deprecated in favor of {@link LongDataAccess}. As reader and element writer for {@link
|
||||
* ListMarshaller} and similar composite marshallers, {@code LongMarshaller} is not deprecated.
|
||||
*/
|
||||
public enum LongMarshaller
|
||||
public final class LongMarshaller
|
||||
implements SizedReader<Long>, BytesReader<Long>,
|
||||
SizedWriter<Long>, BytesWriter<Long>, EnumMarshallable<LongMarshaller> {
|
||||
INSTANCE;
|
||||
public static final LongMarshaller INSTANCE = new LongMarshaller();
|
||||
|
||||
private LongMarshaller() {}
|
||||
|
||||
@Override
|
||||
public long size(@NotNull Long toWrite) {
|
||||
|
||||
@@ -19,9 +19,11 @@ package net.openhft.chronicle.hash.serialization.impl;
|
||||
import net.openhft.chronicle.bytes.Byteable;
|
||||
import net.openhft.chronicle.bytes.BytesMarshallable;
|
||||
import net.openhft.chronicle.core.OS;
|
||||
import net.openhft.chronicle.core.util.ReadResolvable;
|
||||
import net.openhft.chronicle.hash.serialization.*;
|
||||
import net.openhft.chronicle.values.ValueModel;
|
||||
import net.openhft.chronicle.values.Values;
|
||||
import net.openhft.chronicle.wire.Marshallable;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Modifier;
|
||||
@@ -36,6 +38,17 @@ public final class SerializationBuilder<T> implements Cloneable {
|
||||
return !c.isInterface() && !Modifier.isAbstract(c.getModifiers());
|
||||
}
|
||||
|
||||
private static void checkNonMarshallableEnum(Class c) {
|
||||
if (Enum.class.isAssignableFrom(c) && (Marshallable.class.isAssignableFrom(c) ||
|
||||
ReadResolvable.class.isAssignableFrom(c))) {
|
||||
throw new IllegalArgumentException(c + ": since Chronicle Map 3.9.0, enum marshaller " +
|
||||
"shouldn't be a Java enum and implement " + Marshallable.class.getName() +
|
||||
" or " + ReadResolvable.class.getName() + ". There are problems with " +
|
||||
"serializing/deserializing them in Chronicle Map header. Emulate enums by " +
|
||||
"static final fields");
|
||||
}
|
||||
}
|
||||
|
||||
public final Class<T> tClass;
|
||||
private SizeMarshaller sizeMarshaller = stopBit();
|
||||
private SizedReader<T> reader;
|
||||
@@ -129,10 +142,12 @@ public final class SerializationBuilder<T> implements Cloneable {
|
||||
}
|
||||
|
||||
public void reader(SizedReader<T> reader) {
|
||||
checkNonMarshallableEnum(reader.getClass());
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public void reader(BytesReader<T> reader) {
|
||||
checkNonMarshallableEnum(reader.getClass());
|
||||
this.reader = new BytesAsSizedReader<>(reader);
|
||||
}
|
||||
|
||||
@@ -141,6 +156,7 @@ public final class SerializationBuilder<T> implements Cloneable {
|
||||
}
|
||||
|
||||
public void dataAccess(DataAccess<T> dataAccess) {
|
||||
checkNonMarshallableEnum(dataAccess.getClass());
|
||||
this.dataAccess = dataAccess;
|
||||
}
|
||||
|
||||
@@ -149,14 +165,17 @@ public final class SerializationBuilder<T> implements Cloneable {
|
||||
}
|
||||
|
||||
public void writer(SizedWriter<? super T> writer) {
|
||||
checkNonMarshallableEnum(writer.getClass());
|
||||
dataAccess(new SizedMarshallableDataAccess<>(tClass, reader, writer));
|
||||
}
|
||||
|
||||
private void notReusingWriter(SizedWriter<? super T> writer) {
|
||||
checkNonMarshallableEnum(writer.getClass());
|
||||
dataAccess(new NotReusingSizedMarshallableDataAccess<>(tClass, reader, writer));
|
||||
}
|
||||
|
||||
public void writer(BytesWriter<? super T> writer) {
|
||||
checkNonMarshallableEnum(writer.getClass());
|
||||
dataAccess(new ExternalBytesMarshallableDataAccess<>(tClass, reader, writer));
|
||||
}
|
||||
|
||||
@@ -212,6 +231,7 @@ public final class SerializationBuilder<T> implements Cloneable {
|
||||
}
|
||||
|
||||
public SerializationBuilder<T> sizeMarshaller(SizeMarshaller sizeMarshaller) {
|
||||
checkNonMarshallableEnum(sizeMarshaller.getClass());
|
||||
this.sizeMarshaller = sizeMarshaller;
|
||||
return this;
|
||||
}
|
||||
|
||||
+4
-2
@@ -23,9 +23,11 @@ import net.openhft.chronicle.hash.serialization.SizeMarshaller;
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
public enum StopBitSizeMarshaller
|
||||
public final class StopBitSizeMarshaller
|
||||
implements SizeMarshaller, EnumMarshallable<StopBitSizeMarshaller> {
|
||||
INSTANCE;
|
||||
public static final StopBitSizeMarshaller INSTANCE = new StopBitSizeMarshaller();
|
||||
|
||||
private StopBitSizeMarshaller() {}
|
||||
|
||||
private static final long MIN_ENCODABLE_SIZE = Long.MIN_VALUE;
|
||||
private static final long MAX_ENCODABLE_SIZE = Long.MAX_VALUE;
|
||||
|
||||
+4
-2
@@ -22,9 +22,11 @@ import net.openhft.chronicle.hash.serialization.SizedReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum StringBuilderSizedReader
|
||||
public final class StringBuilderSizedReader
|
||||
implements SizedReader<StringBuilder>, EnumMarshallable<StringBuilderSizedReader> {
|
||||
INSTANCE;
|
||||
public static final StringBuilderSizedReader INSTANCE = new StringBuilderSizedReader();
|
||||
|
||||
private StringBuilderSizedReader() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -24,9 +24,11 @@ import net.openhft.chronicle.hash.serialization.impl.EnumMarshallable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
enum DummyValueMarshaller implements DataAccess<DummyValue>, SizedReader<DummyValue>,
|
||||
final class DummyValueMarshaller implements DataAccess<DummyValue>, SizedReader<DummyValue>,
|
||||
EnumMarshallable<DummyValueMarshaller> {
|
||||
INSTANCE;
|
||||
public static final DummyValueMarshaller INSTANCE = new DummyValueMarshaller();
|
||||
|
||||
private DummyValueMarshaller() {}
|
||||
|
||||
@Override
|
||||
public Data<DummyValue> getData(@NotNull DummyValue instance) {
|
||||
|
||||
Reference in New Issue
Block a user