ss: History trees can define their own node types
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core / src / org / eclipse / tracecompass / internal / statesystem / core / backend / historytree / HT_IO.java
index c69c51b6e18e97f63f71f39f957021cce83d9a43..b26225b733b99ea620d8f30183963be6d81a635d 100644 (file)
@@ -23,12 +23,13 @@ import java.nio.channels.FileChannel;
 import java.util.logging.Logger;
 
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
 import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
 import org.eclipse.tracecompass.internal.statesystem.core.Activator;
+import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.IHistoryTree.IHTNodeFactory;
 
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
@@ -45,7 +46,7 @@ import com.google.common.cache.LoadingCache;
  *
  * @author Alexandre Montplaisir
  */
-class HT_IO {
+public class HT_IO {
 
     private static final Logger LOGGER = TraceCompassLog.getLogger(HT_IO.class);
 
@@ -100,7 +101,7 @@ class HT_IO {
 
                     synchronized (io) {
                         io.seekFCToNodePos(io.fFileChannelIn, seqNb);
-                        return HTNode.readNode(io.fConfig, io.fFileChannelIn);
+                        return HTNode.readNode(io.fConfig, io.fFileChannelIn, key.fStateHistory.fNodeFactory);
                     }
                 }
             }));
@@ -119,6 +120,8 @@ class HT_IO {
     private final FileChannel fFileChannelIn;
     private final FileChannel fFileChannelOut;
 
+    private final IHTNodeFactory fNodeFactory;
+
     // ------------------------------------------------------------------------
     // Methods
     // ------------------------------------------------------------------------
@@ -132,11 +135,13 @@ class HT_IO {
      *            The configuration object for the StateHistoryTree
      * @param newFile
      *            Flag indicating that the file must be created from scratch
+     * @param nodeFactory
+     *            The factory to create new nodes for this tree
      *
      * @throws IOException
      *             An exception can be thrown when file cannot be accessed
      */
-    public HT_IO(HTConfig config, boolean newFile) throws IOException {
+    public HT_IO(HTConfig config, boolean newFile, IHTNodeFactory nodeFactory) throws IOException {
         fConfig = config;
 
         File historyTreeFile = config.getStateFile();
@@ -164,6 +169,7 @@ class HT_IO {
         }
         fFileChannelIn = fFileInputStream.getChannel();
         fFileChannelOut = fFileOutputStream.getChannel();
+        fNodeFactory = nodeFactory;
     }
 
     /**
@@ -198,6 +204,12 @@ class HT_IO {
         }
     }
 
+    /**
+     * Write the given node to disk.
+     *
+     * @param node
+     *            The node to write.
+     */
     public void writeNode(HTNode node) {
         try {
             int seqNumber = node.getSequenceNumber();
@@ -217,10 +229,23 @@ class HT_IO {
         }
     }
 
+    /**
+     * Get the output file channel, used for writing.
+     *
+     * @return The output file channel
+     */
     public FileChannel getFcOut() {
         return fFileChannelOut;
     }
 
+    /**
+     * Retrieve the input stream with which to write the attribute tree.
+     *
+     * @param nodeOffset
+     *            The offset in the file, in number of nodes. This should be
+     *            after all the nodes.
+     * @return The correctly-seeked input stream
+     */
     public FileInputStream supplyATReader(int nodeOffset) {
         try {
             /*
@@ -234,6 +259,9 @@ class HT_IO {
         return fFileInputStream;
     }
 
+    /**
+     * Close all file channels and streams.
+     */
     public synchronized void closeFile() {
         try {
             fFileInputStream.close();
@@ -243,6 +271,9 @@ class HT_IO {
         }
     }
 
+    /**
+     * Delete the history tree file
+     */
     public synchronized void deleteFile() {
         closeFile();
 
This page took 0.026733 seconds and 5 git commands to generate.