tmf: Remove back-reference from HT-Node to HT-Tree
authorEtienne Bergeron <etienne.bergeron@gmail.com>
Tue, 10 Dec 2013 02:12:21 +0000 (21:12 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 12 Dec 2013 03:02:19 +0000 (22:02 -0500)
The HT-Node needs to know about the layout of the node (size, n-child)
but not about the tree in which it belongs to. Any back reference
is typically a bad design. It complicated unittests and maintenance.

  HT-Tree --->  HTNode--\
   \                     \
    \---------------------> HTConfig

This patch-set is one of multiples to refactor the HT-Tree API.
The API refactoring will lead us to a easier algorithmic refactoring.

Change-Id: Ifa11cec6a89b9b1c698e0a2b2b18ac5ec70a7db0
Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com>
Reviewed-on: https://git.eclipse.org/r/19555
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java

index 882d5e64892c91a6189ca6f86e6f0ec3eaa074bd..59f9aff29d8dd96cf2d3193324cecfd814f259e0 100644 (file)
@@ -19,7 +19,7 @@ import java.nio.ByteBuffer;
  *
  * It extends HTNode by adding support for child nodes, and also extensions.
  *
- * @author alexmont
+ * @author Alexandre Montplaisir
  *
  */
 class CoreNode extends HTNode {
@@ -45,8 +45,8 @@ class CoreNode extends HTNode {
     /**
      * Initial constructor. Use this to initialize a new EMPTY node.
      *
-     * @param tree
-     *            The HistoryTree to which this node belongs
+     * @param config
+     *            Configuration of the History Tree
      * @param seqNumber
      *            The (unique) sequence number assigned to this particular node
      * @param parentSeqNumber
@@ -54,11 +54,11 @@ class CoreNode extends HTNode {
      * @param start
      *            The earliest timestamp stored in this node
      */
-    CoreNode(HistoryTree tree, int seqNumber, int parentSeqNumber,
+    CoreNode(HTConfig config, int seqNumber, int parentSeqNumber,
             long start) {
-        super(tree, seqNumber, parentSeqNumber, start);
+        super(config, seqNumber, parentSeqNumber, start);
         this.nbChildren = 0;
-        int size = getTree().getConfig().getMaxChildren();
+        int size = config.getMaxChildren();
 
         /*
          * We instantiate the two following arrays at full size right away,
@@ -72,7 +72,7 @@ class CoreNode extends HTNode {
 
     @Override
     protected void readSpecificHeader(ByteBuffer buffer) {
-        int size = getTree().getConfig().getMaxChildren();
+        int size = getConfig().getMaxChildren();
 
         extension = buffer.getInt();
         nbChildren = buffer.getInt();
@@ -96,7 +96,7 @@ class CoreNode extends HTNode {
 
     @Override
     protected void writeSpecificHeader(ByteBuffer buffer) {
-        int size = getTree().getConfig().getMaxChildren();
+        int size = getConfig().getMaxChildren();
 
         buffer.putInt(extension);
         buffer.putInt(nbChildren);
@@ -149,7 +149,7 @@ class CoreNode extends HTNode {
      *            The SHTNode object of the new child
      */
     void linkNewChild(CoreNode childNode) {
-        assert (this.nbChildren < getTree().getConfig().getMaxChildren());
+        assert (this.nbChildren < getConfig().getMaxChildren());
 
         this.children[nbChildren] = childNode.getSequenceNumber();
         this.childStart[nbChildren] = childNode.getNodeStart();
@@ -163,7 +163,7 @@ class CoreNode extends HTNode {
 
     @Override
     protected int getTotalHeaderSize() {
-        int maxChildren = getTree().getConfig().getMaxChildren();
+        int maxChildren = getConfig().getMaxChildren();
         int specificSize =
                   SIZE_INT /* 1x int (extension node) */
                 + SIZE_INT /* 1x int (nbChildren) */
index f7b47e26bebcec091bee28c0cc7e0801304756c8..2a06d2d116800cf67f90ce632fb59aad2dd77169 100644 (file)
@@ -28,7 +28,7 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
 /**
  * The base class for all the types of nodes that go in the History Tree.
  *
- * @author alexmont
+ * @author Alexandre Montplaisir
  */
 abstract class HTNode {
 
@@ -42,8 +42,8 @@ abstract class HTNode {
      */
     protected static final int DATA_ENTRY_SIZE = 25;
 
-    /* Reference to the History Tree to whom this node belongs */
-    private final HistoryTree ownerTree;
+    /* Configuration of the History Tree to which belongs this node */
+    private final HTConfig config;
 
     /* Time range of this node */
     private final long nodeStart;
@@ -62,13 +62,13 @@ abstract class HTNode {
     /* Vector containing all the intervals contained in this node */
     private final List<HTInterval> intervals;
 
-    HTNode(HistoryTree tree, int seqNumber, int parentSeqNumber, long start) {
-        this.ownerTree = tree;
+    HTNode(HTConfig config, int seqNumber, int parentSeqNumber, long start) {
+        this.config = config;
         this.nodeStart = start;
         this.sequenceNumber = seqNumber;
         this.parentSequenceNumber = parentSeqNumber;
 
-        this.stringSectionOffset = ownerTree.getConfig().getBlockSize();
+        this.stringSectionOffset = config.getBlockSize();
         this.isDone = false;
         this.intervals = new ArrayList<HTInterval>();
     }
@@ -77,23 +77,23 @@ abstract class HTNode {
      * Reader factory constructor. Build a Node object (of the right type) by
      * reading a block in the file.
      *
-     * @param tree
-     *            Reference to the HT which will own this node
+     * @param config
+     *            Configuration of the History Tree
      * @param fc
      *            FileChannel to the history file, ALREADY SEEKED at the start
      *            of the node.
      * @throws IOException
      */
-    static final HTNode readNode(HistoryTree tree, FileChannel fc)
+    static final HTNode readNode(HTConfig config, FileChannel fc)
             throws IOException {
         HTNode newNode = null;
         int res, i;
 
-        ByteBuffer buffer = ByteBuffer.allocate(tree.getConfig().getBlockSize());
+        ByteBuffer buffer = ByteBuffer.allocate(config.getBlockSize());
         buffer.order(ByteOrder.LITTLE_ENDIAN);
         buffer.clear();
         res = fc.read(buffer);
-        assert (res == tree.getConfig().getBlockSize());
+        assert (res == config.getBlockSize());
         buffer.flip();
 
         /* Read the common header part */
@@ -110,7 +110,7 @@ abstract class HTNode {
         switch (type) {
         case 1:
             /* Core nodes */
-            newNode = new CoreNode(tree, seqNb, parentSeqNb, start);
+            newNode = new CoreNode(config, seqNb, parentSeqNb, start);
             newNode.readSpecificHeader(buffer);
             break;
 
@@ -146,7 +146,7 @@ abstract class HTNode {
     }
 
     final void writeSelf(FileChannel fc) throws IOException {
-        final int blockSize = ownerTree.getConfig().getBlockSize();
+        final int blockSize = config.getBlockSize();
         int curStringsEntryEndPos = blockSize;
 
         ByteBuffer buffer = ByteBuffer.allocate(blockSize);
@@ -201,8 +201,8 @@ abstract class HTNode {
     // Accessors
     // ------------------------------------------------------------------------
 
-    protected HistoryTree getTree() {
-        return ownerTree;
+    HTConfig getConfig() {
+        return config;
     }
 
     long getNodeStart() {
@@ -413,7 +413,7 @@ abstract class HTNode {
      * (used space / total usable space, which excludes the header)
      */
     long getNodeUsagePRC() {
-        final int blockSize = ownerTree.getConfig().getBlockSize();
+        final int blockSize = config.getBlockSize();
         float freePercent = (float) this.getNodeFreeSpace()
                 / (float) (blockSize - this.getTotalHeaderSize())
                 * 100F;
index 8250c05865ec49e6ddf22d3fcb02dedcdd377c4f..445e0dfc1515d338dc2bf29ebc769794ddf9f782 100644 (file)
@@ -25,7 +25,7 @@ import java.nio.channels.FileChannel;
  * tree-file on disk and all the caching mechanisms. Every HistoryTree should
  * contain 1 and only 1 HT_IO element.
  *
- * @author alexmont
+ * @author Alexandre Montplaisir
  *
  */
 class HT_IO {
@@ -130,7 +130,7 @@ class HT_IO {
         /* Lookup on disk */
         try {
             seekFCToNodePos(fcIn, seqNumber);
-            readNode = HTNode.readNode(tree, fcIn);
+            readNode = HTNode.readNode(tree.getConfig(), fcIn);
 
             /* Put the node in the cache. */
             fNodeCache[offset] = readNode;
index 12f14ced82ae3388d3aa9bbeb2498083b4fbe0ea..fc8c382e97845cfabdcf99cbf734f5958545edee 100644 (file)
@@ -31,7 +31,7 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
  * Meta-container for the History Tree. This structure contains all the
  * high-level data relevant to the tree.
  *
- * @author alexmont
+ * @author Alexandre Montplaisir
  *
  */
 class HistoryTree {
@@ -468,7 +468,7 @@ class HistoryTree {
      * @return The newly created node
      */
     private CoreNode initNewCoreNode(int parentSeqNumber, long startTime) {
-        CoreNode newNode = new CoreNode(this, this.nodeCount, parentSeqNumber,
+        CoreNode newNode = new CoreNode(config, this.nodeCount, parentSeqNumber,
                 startTime);
         this.nodeCount++;
 
This page took 0.030556 seconds and 5 git commands to generate.