Remove Xstream XML ChronicleMap header serialization (is going to be replaced with Wire serialization soon)

This commit is contained in:
leventov
2015-11-23 18:43:17 +03:00
parent f575218da9
commit beec07f9a9
3 changed files with 9 additions and 87 deletions
@@ -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 <T> the type of objects deserialized
*/
public abstract class InstanceCreatingMarshaller<T> {
public abstract class InstanceCreatingMarshaller<T> implements Serializable {
/**
* The class of objects deserialized.
@@ -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<K, V> 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<K, V> 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<K, V, ?> map = (VanillaChronicleMap<K, V, ?>) m;
@@ -1421,10 +1409,7 @@ public final class ChronicleMapBuilder<K, V> 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<K, V> implements
}
}
private static <K, V> boolean trySerializeHeaderViaXStream(
VanillaChronicleMap<K, V, ?> 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<K, V> createWithoutFile(
SingleChronicleHashReplication singleHashReplication, ReplicationChannel channel) {
replicated = singleHashReplication != null || channel != 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 <http://www.gnu.org/licenses/>.
*/
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());
}
}