From 4b3620a647526b557c384548d8cbbe83346b5b32 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 27 Nov 2014 12:39:28 +0000 Subject: [PATCH] HCOLL-219 support the importing and exporting of entries to a human readable file format like JSON --- .../openhft/chronicle/map/ChronicleMap.java | 33 +++++++++++++++++++ .../chronicle/map/VanillaChronicleMap.java | 1 - .../map/ChronicleMapImportExportTest.java | 3 ++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java index 0b80b6b9b..6e2fde929 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMap.java @@ -26,6 +26,8 @@ import net.openhft.lang.model.Byteable; import org.jetbrains.annotations.NotNull; import java.io.Closeable; +import java.io.File; +import java.io.IOException; import java.util.Map; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Future; @@ -269,5 +271,36 @@ public interface ChronicleMap extends ConcurrentMap, ChronicleHash { */ Future removeLater(@NotNull K key); + /** + * exports all the entries to a {@Link java.io.File} storing them in JSON format, an attempt is + * made where possible to use standard java serialisation and keep the data human readable, data + * serialized using the custom serialises are converted to a binary format which is not human + * readable but this is only done if the Keys or Values are not {@Link java.io.Serializable}. + * This method can be used in conjunction with {@link ChronicleMap#putAll(java.io.File)} and is + * especially useful if you wish to import/export entries from one chronicle map into another. + * This import and export of the entries can be performed even when the versions of ChronicleMap + * differ. This method is not performant and as such we recommend it is not used in performance + * sensitive code. + * + * @param toFile the file to store all the entries to, the enties will be stored in JSON format + * @throws IOException its not possible store the data to {@code toFile} + * @see ChronicleMap#putAll(java.io.File) + */ + void getAll(File toFile) throws IOException; + + /** + * imports all the entries from a {@Link java.io.File}, the {@code fromFile} must be created + * using or the same format as {@Link net.openhft.chronicle.map.ChronicleMap#getAll(java.io + *.File)}, this method behaves simualar to {@Link java.util.Map#put(java.lang.Object, java + *.lang.Object)} where existing entries are overwritten + * + * @param fromFile the file to store all the entries to, the enties will be stored in JSON + * format + * @throws IOException its not possible read the{@code fromFile} + * @see ChronicleMap#getAll(java.io.File) + */ + void putAll(File fromFile) throws IOException; + + } diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 106f6f537..b1c0f99f3 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -63,7 +63,6 @@ import static java.lang.Thread.currentThread; import static java.nio.ByteBuffer.allocateDirect; import static net.openhft.lang.MemoryUnit.*; - class VanillaChronicleMap, V, VW, MVW extends MetaBytesWriter> extends AbstractMap implements ChronicleMap, Serializable { diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java index a45a2e8d6..8bf8d2289 100644 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapImportExportTest.java @@ -44,4 +44,7 @@ public class ChronicleMapImportExportTest { } + + + }