diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java b/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java index d2f22eb88..ed02fcb18 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/impl/InstanceCreatingMarshaller.java @@ -21,6 +21,7 @@ import net.openhft.chronicle.hash.serialization.DataAccess; import net.openhft.chronicle.hash.serialization.SizedReader; import net.openhft.chronicle.map.ChronicleMapBuilder; +import java.io.Serializable; import java.lang.reflect.Constructor; /** @@ -29,7 +30,7 @@ import java.lang.reflect.Constructor; * * @param the type of objects deserialized */ -public abstract class InstanceCreatingMarshaller { +public abstract class InstanceCreatingMarshaller implements Serializable { /** * The class of objects deserialized. diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index 60e4d5201..2611b5c0a 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -36,8 +36,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -47,7 +45,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import static java.lang.Double.isNaN; import static java.lang.Math.round; import static net.openhft.chronicle.bytes.NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity; -import static net.openhft.chronicle.core.Maths.*; +import static net.openhft.chronicle.core.Maths.isPowerOf2; +import static net.openhft.chronicle.core.Maths.nextPower2; import static net.openhft.chronicle.hash.impl.CompactOffHeapLinearHashTable.*; import static net.openhft.chronicle.hash.impl.util.Objects.builderEquals; import static net.openhft.chronicle.map.DefaultSpi.mapEntryOperations; @@ -118,9 +117,6 @@ public final class ChronicleMapBuilder implements private static final double UNDEFINED_DOUBLE_CONFIG = Double.NaN; - private static final int XML_SERIALIZATION = 1; - private static final int BINARY_SERIALIZATION = 2; - private static boolean isDefined(double config) { return !isNaN(config); } @@ -1369,18 +1365,10 @@ public final class ChronicleMapBuilder implements try (FileInputStream fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis)) { Object m; - byte serialization = ois.readByte(); - if (serialization == XML_SERIALIZATION) { - m = deserializeHeaderViaXStream(ois); - } else if (serialization == BINARY_SERIALIZATION) { - try { - m = ois.readObject(); - } catch (ClassNotFoundException e) { - throw new AssertionError(e); - } - } else { - throw new IOException("Unknown map header serialization type: " + - serialization); + try { + m = ois.readObject(); + } catch (ClassNotFoundException e) { + throw new AssertionError(e); } @SuppressWarnings("unchecked") VanillaChronicleMap map = (VanillaChronicleMap) m; @@ -1421,10 +1409,7 @@ public final class ChronicleMapBuilder implements try (FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos)) { - if (!trySerializeHeaderViaXStream(map, oos)) { - oos.writeByte(BINARY_SERIALIZATION); - oos.writeObject(map); - } + oos.writeObject(map); oos.flush(); map.initBeforeMapping(fos.getChannel()); map.createMappedStoreAndSegments(file); @@ -1450,43 +1435,6 @@ public final class ChronicleMapBuilder implements } } - private static boolean trySerializeHeaderViaXStream( - VanillaChronicleMap map, ObjectOutputStream oos) - throws IOException { - Class xStreamClass; - try { - xStreamClass = - Class.forName("net.openhft.xstream.MapHeaderSerializationXStream"); - } catch (ClassNotFoundException | NoClassDefFoundError e) { - xStreamClass = null; - } - if (xStreamClass == null) { - LOG.info("xStream not found, use binary ChronicleMap header serialization"); - return false; - } - try { - oos.writeByte(XML_SERIALIZATION); - Method toXML = xStreamClass.getMethod("toXML", Object.class, OutputStream.class); - toXML.invoke(xStreamClass.newInstance(), map, oos); - return true; - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | - InstantiationException e) { - throw new AssertionError(e); - } - } - - private static Object deserializeHeaderViaXStream(ObjectInputStream ois) { - try { - Class xStreamClass = - Class.forName("net.openhft.xstream.MapHeaderSerializationXStream"); - Method fromXML = xStreamClass.getMethod("fromXML", InputStream.class); - return fromXML.invoke(xStreamClass.newInstance(), ois); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException | InstantiationException e) { - throw new AssertionError(e); - } - } - ChronicleMap createWithoutFile( SingleChronicleHashReplication singleHashReplication, ReplicationChannel channel) { replicated = singleHashReplication != null || channel != null; diff --git a/src/main/java/net/openhft/xstream/MapHeaderSerializationXStream.java b/src/main/java/net/openhft/xstream/MapHeaderSerializationXStream.java deleted file mode 100644 index 1df6db36c..000000000 --- a/src/main/java/net/openhft/xstream/MapHeaderSerializationXStream.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2015 higherfrequencytrading.com - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package net.openhft.xstream; - -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.reflection.SunLimitedUnsafeReflectionProvider; - -public class MapHeaderSerializationXStream extends XStream { - - public MapHeaderSerializationXStream() { - super(new SunLimitedUnsafeReflectionProvider()); - } -}