Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Montplaisir2013-05-29 18:22:08 +0000
committerAlexandre Montplaisir2013-05-29 20:33:34 +0000
commit4dd744d88e91a2c27fa8c3974548a4dc0a48cec6 (patch)
treeead32df8ea5ee4ad07470727c03bf416541d6974
parent6dae671ed85b843461e045dc362f82ed2d7e51ff (diff)
downloadorg.eclipse.linuxtools-4dd744d88e91a2c27fa8c3974548a4dc0a48cec6.tar.gz
org.eclipse.linuxtools-4dd744d88e91a2c27fa8c3974548a4dc0a48cec6.tar.xz
org.eclipse.linuxtools-4dd744d88e91a2c27fa8c3974548a4dc0a48cec6.zip
tmf: Fix some Sonar warnings in the state system code
Change-Id: I796bad9720a2fd6bc2be2b2d27bc8d52e70afbb0 Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Reviewed-on: https://git.eclipse.org/r/13357 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java37
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java14
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java12
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java12
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java5
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java72
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTConfig.java40
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java15
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java114
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java18
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java98
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTreeBackend.java10
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java22
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java22
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialStateSystem.java8
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/exceptions/StateSystemDisposedException.java19
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateProvider.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemFactory.java5
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java2
21 files changed, 277 insertions, 256 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java
index 73b2853280..85174cad25 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/Attribute.java
@@ -2,39 +2,40 @@
* Copyright (c) 2012 Ericsson
* Copyright (c) 2010, 2011 École Polytechnique de Montréal
* Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.core.statesystem;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
-import java.util.Vector;
+import java.util.Map;
/**
* An Attribute is a "node" in the Attribute Tree. It represents a smallest
* unit of the model which can be in a particular state at a given time.
- *
+ *
* It is abstract, as different implementations can provide different ways to
* access sub-attributes
- *
+ *
* @author alexmont
- *
+ *
*/
abstract class Attribute {
private final Attribute parent;
private final String name;
private final int quark;
- protected final Vector<Attribute> subAttributes;
+ protected final List<Attribute> subAttributes;
/**
* Constructor
@@ -43,7 +44,7 @@ abstract class Attribute {
this.parent = parent;
this.quark = quark;
this.name = name;
- this.subAttributes = new Vector<Attribute>();
+ this.subAttributes = new ArrayList<Attribute>();
}
/**
@@ -58,8 +59,8 @@ abstract class Attribute {
return parent;
}
- List<Attribute> getSubAttributesList() {
- return subAttributes;
+ List<Attribute> getSubAttributes() {
+ return Collections.unmodifiableList(subAttributes);
}
String getName() {
@@ -68,7 +69,7 @@ abstract class Attribute {
/**
* Get the matching quark for a given path-of-strings
- *
+ *
* @param path
* The path we are looking for, *relative to this node*.
* @return The matching quark, or -1 if that attribute does not exist.
@@ -82,7 +83,7 @@ abstract class Attribute {
* returning the matching quark we return the AttributeTreeNode object
* itself. It can then be used as new "root node" for faster queries on the
* tree.
- *
+ *
* @param path
* The target path, *relative to this node*
* @return The Node object matching the last element in the path, or "null"
@@ -113,7 +114,7 @@ abstract class Attribute {
/**
* Return a String array composed of the full (absolute) path representing
* this attribute
- *
+ *
* @return
*/
String[] getFullAttribute() {
@@ -134,7 +135,7 @@ abstract class Attribute {
/**
* Return the absolute path of this attribute, as a single slash-separated
* String.
- *
+ *
* @return
*/
String getFullAttributeName() {
@@ -162,7 +163,7 @@ abstract class Attribute {
writer.println(currentNode.getName() + " (" + currentNode.quark + ')'); //$NON-NLS-1$
curDepth++;
- for (Attribute nextNode : currentNode.getSubAttributesList()) {
+ for (Attribute nextNode : currentNode.getSubAttributes()) {
/* Skip printing 'null' entries */
if (nextNode == null) {
continue;
@@ -191,13 +192,13 @@ abstract class Attribute {
* This is the basic implementation, where sub-attributes names can be composed
* of any alphanumeric characters, and are stored as Strings. A HashMap is used
* to access them.
- *
+ *
* @author alexmont
- *
+ *
*/
final class AlphaNumAttribute extends Attribute {
- private HashMap<String, Integer> subAttributesMap;
+ private Map<String, Integer> subAttributesMap;
AlphaNumAttribute(Attribute parent, String name, int quark) {
super(parent, name, quark);
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java
index da525a96b8..e1f1c5b147 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/AttributeTree.java
@@ -31,10 +31,10 @@ import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
* @author alexmont
*
*/
-public class AttributeTree {
+public final class AttributeTree {
/* "Magic number" for attribute tree files or file sections */
- private final static int ATTRIB_TREE_MAGIC_NUMBER = 0x06EC3671;
+ private static final int ATTRIB_TREE_MAGIC_NUMBER = 0x06EC3671;
private final StateSystem ss;
private final List<Attribute> attributeList;
@@ -296,14 +296,14 @@ public class AttributeTree {
ss.modifyAttribute(ss.getStartTime(), TmfStateValue.nullValue(), newAttrib);
} catch (TimeRangeException e) {
/* Should not happen, we're inserting at ss's start time */
- throw new RuntimeException();
+ throw new IllegalStateException(e);
} catch (AttributeNotFoundException e) {
/* Should not happen, we just created this attribute! */
- throw new RuntimeException();
+ throw new IllegalStateException(e);
} catch (StateValueTypeException e) {
/* Should not happen, there is no existing state value, and the
* one we insert is a null value anyway. */
- throw new RuntimeException();
+ throw new IllegalStateException(e);
}
return newAttrib;
@@ -316,7 +316,7 @@ public class AttributeTree {
}
int getSubAttributesCount(int quark) {
- return attributeList.get(quark).getSubAttributesList().size();
+ return attributeList.get(quark).getSubAttributes().size();
}
/**
@@ -352,7 +352,7 @@ public class AttributeTree {
private void addSubAttributes(List<Integer> list, Attribute curAttribute,
boolean recursive) {
- for (Attribute childNode : curAttribute.getSubAttributesList()) {
+ for (Attribute childNode : curAttribute.getSubAttributes()) {
list.add(childNode.getQuark());
if (recursive) {
addSubAttributes(list, childNode, true);
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java
index d2f480a87a..e56f39a314 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java
@@ -74,7 +74,7 @@ public class HistoryBuilder extends TmfComponent {
}
if (stateProvider.getAssignedStateSystem() != ss) {
/* Logic check to make sure the provider is setup properly */
- throw new RuntimeException();
+ throw new IllegalArgumentException();
}
sp = stateProvider;
@@ -227,7 +227,7 @@ public class HistoryBuilder extends TmfComponent {
class StateSystemBuildRequest extends TmfEventRequest {
/** The amount of events queried at a time through the requests */
- private final static int chunkSize = 50000;
+ private static final int CHUNK_SIZE = 50000;
private final HistoryBuilder builder;
private final ITmfStateProvider sci;
@@ -237,7 +237,7 @@ class StateSystemBuildRequest extends TmfEventRequest {
super(builder.getStateProvider().getExpectedEventType(),
TmfTimeRange.ETERNITY,
TmfDataRequest.ALL_DATA,
- chunkSize,
+ CHUNK_SIZE,
ITmfDataRequest.ExecutionType.BACKGROUND);
this.builder = builder;
this.sci = builder.getStateProvider();
@@ -247,10 +247,8 @@ class StateSystemBuildRequest extends TmfEventRequest {
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
- if (event != null) {
- if (event.getTrace() == trace) {
- sci.processEvent(event);
- }
+ if (event != null && event.getTrace() == trace) {
+ sci.processEvent(event);
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
index 48693b2be5..e1b4a82794 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
@@ -272,7 +272,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
* If there was no wildcard, we'll only return the one matching
* attribute, if there is one.
*/
- if (split == false) {
+ if (!split) {
int quark;
try {
quark = getQuarkAbsolute(prefixStr);
@@ -345,7 +345,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
public void pushAttribute(long t, ITmfStateValue value, int attributeQuark)
throws TimeRangeException, AttributeNotFoundException,
StateValueTypeException {
- Integer stackDepth = 0;
+ Integer stackDepth;
int subAttributeQuark;
ITmfStateValue previousSV = transState.getOngoingStateValue(attributeQuark);
@@ -354,6 +354,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
* If the StateValue was null, this means this is the first time we
* use this attribute. Leave stackDepth at 0.
*/
+ stackDepth = 0;
} else if (previousSV.getType() == Type.INTEGER) {
/* Previous value was an integer, all is good, use it */
stackDepth = previousSV.unboxInt();
@@ -456,7 +457,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
* Will not happen since we're inserting null values only, but poor
* compiler has no way of knowing this...
*/
- e.printStackTrace();
+ throw new IllegalStateException(e);
}
}
@@ -530,7 +531,6 @@ public class StateSystem implements ITmfStateSystemBuilder {
*/
for (int i = 0; i < stateInfo.size(); i++) {
if (stateInfo.get(i) == null) {
- //logMissingInterval(i, t);
stateInfo.set(i, new TmfStateInterval(t, t, i, TmfStateValue.nullValue()));
}
}
@@ -557,7 +557,6 @@ public class StateSystem implements ITmfStateSystemBuilder {
* We do NOT want to return 'null' here.
*/
if (ret == null) {
- //logMissingInterval(attributeQuark, t);
return new TmfStateInterval(t, this.getCurrentEndTime(),
attributeQuark, TmfStateValue.nullValue());
}
@@ -582,8 +581,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
}
int subAttribQuark = getQuarkRelative(stackAttributeQuark, curStackDepth.toString());
- ITmfStateInterval ret = querySingleState(t, subAttribQuark);
- return ret;
+ return querySingleState(t, subAttribQuark);
}
@Override
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java
index ea1a63eaee..276446c80c 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java
@@ -296,7 +296,7 @@ class TransientState {
* This shouldn't happen, since we control where the interval's
* start time comes from
*/
- e.printStackTrace();
+ throw new IllegalStateException(e);
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java
index 3ff4038f35..cfd6841abe 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java
@@ -41,7 +41,7 @@ import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
*/
public class InMemoryBackend implements IStateHistoryBackend {
- private final static Comparator<ITmfStateInterval> endComparator =
+ private static final Comparator<ITmfStateInterval> END_COMPARATOR =
new TmfIntervalEndComparator();
private final List<ITmfStateInterval> intervals;
@@ -181,7 +181,7 @@ public class InMemoryBackend implements IStateHistoryBackend {
private static int binarySearchEndTime(List<ITmfStateInterval> list, long time) {
ITmfStateInterval dummyInterval = new TmfStateInterval(-1, time, -1, null);
- int mid = Collections.binarySearch(list, dummyInterval, endComparator);
+ int mid = Collections.binarySearch(list, dummyInterval, END_COMPARATOR);
/* The returned value is < 0 if the exact key was not found. */
if (mid < 0) {
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java
index 88c3cc9701..1526a32b3d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java
@@ -17,15 +17,14 @@ import java.io.FileInputStream;
import java.io.PrintWriter;
import java.util.List;
-import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
/**
* An implement of a state history back-end to simply discards *all* the
* intervals it receives. Obviously, no queries can be done on it. It is useful
- * for using with a {@link StateSystem} on which you will only want to do
- * "ongoing" requests.
+ * for using with a StateSystem on which you will only want to do "ongoing"
+ * requests.
*
* @author Alexandre Montplaisir
*/
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java
index dfd1d61afe..882d5e6489 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java
@@ -2,12 +2,12 @@
* Copyright (c) 2012, 2013 Ericsson
* Copyright (c) 2010, 2011 École Polytechnique de Montréal
* Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
*******************************************************************************/
package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree;
@@ -16,29 +16,35 @@ import java.nio.ByteBuffer;
/**
* A Core node is a first-level node of a History Tree which is not a leaf node.
- *
+ *
* It extends HTNode by adding support for child nodes, and also extensions.
- *
+ *
* @author alexmont
- *
+ *
*/
class CoreNode extends HTNode {
- /* Nb. of children this node has */
+ /** Number of bytes in a int */
+ private static final int SIZE_INT = 4;
+
+ /** Number of bytes in a long */
+ private static final int SIZE_LONG = 8;
+
+ /** Nb. of children this node has */
private int nbChildren;
- /* Seq. numbers of the children nodes (size = MAX_NB_CHILDREN) */
+ /** Seq. numbers of the children nodes (size = MAX_NB_CHILDREN) */
private int[] children;
- /* Start times of each of the children (size = MAX_NB_CHILDREN) */
+ /** Start times of each of the children (size = MAX_NB_CHILDREN) */
private long[] childStart;
- /* Seq number of this node's extension. -1 if none */
+ /** Seq number of this node's extension. -1 if none */
private int extension;
/**
* Initial constructor. Use this to initialize a new EMPTY node.
- *
+ *
* @param tree
* The HistoryTree to which this node belongs
* @param seqNumber
@@ -52,6 +58,7 @@ class CoreNode extends HTNode {
long start) {
super(tree, seqNumber, parentSeqNumber, start);
this.nbChildren = 0;
+ int size = getTree().getConfig().getMaxChildren();
/*
* We instantiate the two following arrays at full size right away,
@@ -59,54 +66,54 @@ class CoreNode extends HTNode {
* "this.nbChildren" will tell us how many relevant entries there are in
* those tables.
*/
- this.children = new int[ownerTree.config.maxChildren];
- this.childStart = new long[ownerTree.config.maxChildren];
+ this.children = new int[size];
+ this.childStart = new long[size];
}
@Override
protected void readSpecificHeader(ByteBuffer buffer) {
- int i;
+ int size = getTree().getConfig().getMaxChildren();
extension = buffer.getInt();
nbChildren = buffer.getInt();
- children = new int[ownerTree.config.maxChildren];
- for (i = 0; i < nbChildren; i++) {
+ children = new int[size];
+ for (int i = 0; i < nbChildren; i++) {
children[i] = buffer.getInt();
}
- for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+ for (int i = nbChildren; i < size; i++) {
buffer.getInt();
}
- this.childStart = new long[ownerTree.config.maxChildren];
- for (i = 0; i < nbChildren; i++) {
+ this.childStart = new long[size];
+ for (int i = 0; i < nbChildren; i++) {
childStart[i] = buffer.getLong();
}
- for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+ for (int i = nbChildren; i < size; i++) {
buffer.getLong();
}
}
@Override
protected void writeSpecificHeader(ByteBuffer buffer) {
- int i;
+ int size = getTree().getConfig().getMaxChildren();
buffer.putInt(extension);
buffer.putInt(nbChildren);
/* Write the "children's seq number" array */
- for (i = 0; i < nbChildren; i++) {
+ for (int i = 0; i < nbChildren; i++) {
buffer.putInt(children[i]);
}
- for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+ for (int i = nbChildren; i < size; i++) {
buffer.putInt(0);
}
/* Write the "children's start times" array */
- for (i = 0; i < nbChildren; i++) {
+ for (int i = 0; i < nbChildren; i++) {
buffer.putLong(childStart[i]);
}
- for (i = nbChildren; i < ownerTree.config.maxChildren; i++) {
+ for (int i = nbChildren; i < size; i++) {
buffer.putLong(0);
}
}
@@ -137,12 +144,12 @@ class CoreNode extends HTNode {
/**
* Tell this node that it has a new child (Congrats!)
- *
+ *
* @param childNode
* The SHTNode object of the new child
*/
void linkNewChild(CoreNode childNode) {
- assert (this.nbChildren < ownerTree.config.maxChildren);
+ assert (this.nbChildren < getTree().getConfig().getMaxChildren());
this.children[nbChildren] = childNode.getSequenceNumber();
this.childStart[nbChildren] = childNode.getNodeStart();
@@ -156,17 +163,18 @@ class CoreNode extends HTNode {
@Override
protected int getTotalHeaderSize() {
- int specificSize;
- specificSize = 4 /* 1x int (extension node) */
- + 4 /* 1x int (nbChildren) */
+ int maxChildren = getTree().getConfig().getMaxChildren();
+ int specificSize =
+ SIZE_INT /* 1x int (extension node) */
+ + SIZE_INT /* 1x int (nbChildren) */
/* MAX_NB * int ('children' table) */
- + 4 * ownerTree.config.maxChildren
+ + SIZE_INT * maxChildren
/* MAX_NB * Timevalue ('childStart' table) */
- + 8 * ownerTree.config.maxChildren;
+ + SIZE_LONG * maxChildren;
- return getCommonHeaderSize() + specificSize;
+ return COMMON_HEADER_SIZE + specificSize;
}
@Override
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTConfig.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTConfig.java
index 2316533371..28eb45f4bd 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTConfig.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTConfig.java
@@ -18,15 +18,17 @@ import java.io.File;
* Configuration object for a StateHistoryTree.
*
* @author alexmont
- *
*/
final class HTConfig {
- public final File stateFile;
- public final int blockSize;
- public final int maxChildren;
- public final int providerVersion;
- public final long treeStart;
+ private static final int DEFAULT_BLOCKSIZE = 64 * 1024;
+ private static final int DEFAULT_MAXCHILDREN = 50;
+
+ private final File stateFile;
+ private final int blockSize;
+ private final int maxChildren;
+ private final int providerVersion;
+ private final long treeStart;
HTConfig(File newStateFile, int blockSize, int maxChildren,
int providerVersion, long startTime) {
@@ -44,6 +46,30 @@ final class HTConfig {
* @param startTime
*/
HTConfig(File newStateFile, int providerVersion, long startTime) {
- this(newStateFile, 64 * 1024, 50, providerVersion, startTime);
+ this(newStateFile, DEFAULT_BLOCKSIZE, DEFAULT_MAXCHILDREN, providerVersion, startTime);
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters
+ // ------------------------------------------------------------------------
+
+ public File getStateFile() {
+ return stateFile;
+ }
+
+ public int getBlockSize() {
+ return blockSize;
+ }
+
+ public int getMaxChildren() {
+ return maxChildren;
+ }
+
+ public int getProviderVersion() {
+ return providerVersion;
+ }
+
+ public long getTreeStart() {
+ return treeStart;
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
index 49100da9b3..886640ea1e 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
@@ -296,7 +296,7 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
* @return
*/
int getIntervalSize() {
- return stringsEntrySize + HTNode.getDataEntrySize();
+ return stringsEntrySize + HTNode.DATA_ENTRY_SIZE;
}
private int computeStringsEntrySize() {
@@ -314,12 +314,12 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
return sv.unboxStr().getBytes().length + 2;
} catch (StateValueTypeException e) {
/* We're inside a switch/case for the string type, can't happen */
- throw new RuntimeException();
+ throw new IllegalStateException(e);
}
default:
/* It's very important that we know how to write the state value in
* the file!! */
- throw new RuntimeException();
+ throw new IllegalStateException();
}
}
@@ -340,10 +340,9 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
@Override
public boolean equals(Object other) {
- if (other instanceof HTInterval) {
- if (this.compareTo((HTInterval) other) == 0) {
- return true;
- }
+ if (other instanceof HTInterval &&
+ this.compareTo((HTInterval) other) == 0) {
+ return true;
}
return false;
}
@@ -388,7 +387,7 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
return TYPE_LONG;
default:
/* Should not happen if the switch is fully covered */
- throw new RuntimeException();
+ throw new IllegalStateException();
}
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java
index 8bc4058372..f7b47e26be 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java
@@ -29,12 +29,21 @@ 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
- *
*/
abstract class HTNode {
+ /**
+ * Size of an entry in the data section.
+ *
+ * 16 2 x Timevalue/long (interval start + end)
+ * + 4 int (key)
+ * + 1 byte (type)
+ * + 4 int (valueOffset)
+ */
+ protected static final int DATA_ENTRY_SIZE = 25;
+
/* Reference to the History Tree to whom this node belongs */
- protected final HistoryTree ownerTree;
+ private final HistoryTree ownerTree;
/* Time range of this node */
private final long nodeStart;
@@ -51,7 +60,7 @@ abstract class HTNode {
private boolean isDone;
/* Vector containing all the intervals contained in this node */
- private final ArrayList<HTInterval> intervals;
+ private final List<HTInterval> intervals;
HTNode(HistoryTree tree, int seqNumber, int parentSeqNumber, long start) {
this.ownerTree = tree;
@@ -59,7 +68,7 @@ abstract class HTNode {
this.sequenceNumber = seqNumber;
this.parentSequenceNumber = parentSeqNumber;
- this.stringSectionOffset = ownerTree.config.blockSize;
+ this.stringSectionOffset = ownerTree.getConfig().getBlockSize();
this.isDone = false;
this.intervals = new ArrayList<HTInterval>();
}
@@ -75,22 +84,16 @@ abstract class HTNode {
* of the node.
* @throws IOException
*/
- final static HTNode readNode(HistoryTree tree, FileChannel fc)
+ static final HTNode readNode(HistoryTree tree, FileChannel fc)
throws IOException {
HTNode newNode = null;
int res, i;
- ByteBuffer buffer = ByteBuffer.allocate(tree.config.blockSize);
+ ByteBuffer buffer = ByteBuffer.allocate(tree.getConfig().getBlockSize());
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.clear();
res = fc.read(buffer);
- assert (res == tree.config.blockSize);
- // This often breaks, so might as well keep this code not too far...
- // if ( res != tree.config.blockSize ) {
- // tree.debugPrintFullTree(new PrintWriter(System.out, true), null,
- // false);
- // assert ( false );
- // }
+ assert (res == tree.getConfig().getBlockSize());
buffer.flip();
/* Read the common header part */
@@ -115,13 +118,11 @@ abstract class HTNode {
// case 2:
// /* Leaf nodes */
//
- // break;
//
//
// case 3:
// /* "Claudette" (extended) nodes */
//
- // break;
default:
/* Unrecognized node type */
@@ -145,10 +146,10 @@ abstract class HTNode {
}
final void writeSelf(FileChannel fc) throws IOException {
- int res, size;
- int curStringsEntryEndPos = ownerTree.config.blockSize;
+ final int blockSize = ownerTree.getConfig().getBlockSize();
+ int curStringsEntryEndPos = blockSize;
- ByteBuffer buffer = ByteBuffer.allocate(ownerTree.config.blockSize);
+ ByteBuffer buffer = ByteBuffer.allocate(blockSize);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.clear();
@@ -167,7 +168,7 @@ abstract class HTNode {
/* Back to us, we write the intervals */
for (HTInterval interval : intervals) {
- size = interval.writeInterval(buffer, curStringsEntryEndPos);
+ int size = interval.writeInterval(buffer, curStringsEntryEndPos);
curStringsEntryEndPos -= size;
}
@@ -189,16 +190,21 @@ abstract class HTNode {
/* Finally, write everything in the Buffer to disk */
// if we don't do this, flip() will lose what's after.
- buffer.position(ownerTree.config.blockSize);
+ buffer.position(blockSize);
buffer.flip();
- res = fc.write(buffer);
- assert (res == ownerTree.config.blockSize);
+ int res = fc.write(buffer);
+ assert (res == blockSize);
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+
+ protected HistoryTree getTree() {
+ return ownerTree;
}
- /**
- * Accessors
- */
long getNodeStart() {
return nodeStart;
}
@@ -255,12 +261,6 @@ abstract class HTNode {
*/
void closeThisNode(long endtime) {
assert (endtime >= this.nodeStart);
- // /* This also breaks often too */
- // if ( endtime.getValue() <= this.nodeStart.getValue() ) {
- // ownerTree.debugPrintFullTree(new PrintWriter(System.out, true), null,
- // false);
- // assert ( false );
- // }
if (intervals.size() > 0) {
/*
@@ -389,14 +389,6 @@ abstract class HTNode {
&& intervals.get(index - 1).compareTo(intervals.get(index)) == 0) {
index--;
}
- // FIXME F*ck all this, just do our own binary search in a saner way...
-
- // //checks to make sure startIndex works how I think it does
- // if ( startIndex > 0 ) { assert ( intervals.get(startIndex-1).getEnd()
- // < t ); }
- // assert ( intervals.get(startIndex).getEnd() >= t );
- // if ( startIndex < intervals.size()-1 ) { assert (
- // intervals.get(startIndex+1).getEnd() >= t ); }
return index;
}
@@ -405,8 +397,7 @@ abstract class HTNode {
* @return The offset, within the node, where the Data section ends
*/
private int getDataSectionEndOffset() {
- return this.getTotalHeaderSize() + HTNode.getDataEntrySize()
- * intervals.size();
+ return this.getTotalHeaderSize() + HTNode.DATA_ENTRY_SIZE * intervals.size();
}
/**
@@ -422,28 +413,21 @@ abstract class HTNode {
* (used space / total usable space, which excludes the header)
*/
long getNodeUsagePRC() {
+ final int blockSize = ownerTree.getConfig().getBlockSize();
float freePercent = (float) this.getNodeFreeSpace()
- / (float) (ownerTree.config.blockSize - this.getTotalHeaderSize())
- * 100f;
+ / (float) (blockSize - this.getTotalHeaderSize())
+ * 100F;
return (long) (100L - freePercent);
}
- protected final static int getDataEntrySize() {
- return 16 /* 2 x Timevalue/long (interval start + end) */
- + 4 /* int (key) */
- + 1 /* byte (type) */
- + 4; /* int (valueOffset) */
- /* = 25 */
- }
-
- protected final static byte boolToByte(boolean thebool) {
+ protected static final byte boolToByte(boolean thebool) {
if (thebool) {
return (byte) 1;
}
return (byte) 0;
}
- final static boolean byteToBool(byte thebyte) {
+ static final boolean byteToBool(byte thebyte) {
return (thebyte == (byte) 1);
}
@@ -502,19 +486,17 @@ abstract class HTNode {
writer.println('\n');
}
- final static int getCommonHeaderSize() {
- /*
- * 1 - byte (type)
- *
- * 16 - 2x long (start time, end time)
- *
- * 16 - 4x int (seq number, parent seq number, intervalcount, strings
- * section pos.)
- *
- * 1 - byte (done or not)
- */
- return 34;
- }
+ /**
+ * 1 - byte (type)
+ *
+ * 16 - 2x long (start time, end time)
+ *
+ * 16 - 4x int (seq number, parent seq number, intervalcount, strings
+ * section pos.)
+ *
+ * 1 - byte (done or not)
+ */
+ protected static final int COMMON_HEADER_SIZE = 34;
// ------------------------------------------------------------------------
// Abstract methods
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java
index 7270bd8814..c8ff18e148 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java
@@ -50,15 +50,15 @@ class HT_IO {
*/
HT_IO(HistoryTree tree, boolean newFile) throws IOException {
this.tree = tree;
- historyTreeFile = tree.config.stateFile;
- boolean success1 = true, success2;
+ historyTreeFile = tree.getConfig().getStateFile();
+ boolean success1 = true;
if (newFile) {
/* Create a new empty History Tree file */
if (historyTreeFile.exists()) {
success1 = historyTreeFile.delete();
}
- success2 = historyTreeFile.createNewFile();
+ boolean success2 = historyTreeFile.createNewFile();
if (!(success1 && success2)) {
/* It seems we do not have permission to create the new file */
throw new IOException("Cannot create new file at " + //$NON-NLS-1$
@@ -97,7 +97,7 @@ class HT_IO {
}
private HTNode readNodeFromMemory(int seqNumber) {
- for (HTNode node : tree.latestBranch) {
+ for (HTNode node : tree.getLatestBranch()) {
if (node.getSequenceNumber() == seqNumber) {
return node;
}
@@ -159,12 +159,12 @@ class HT_IO {
}
File supplyATWriterFile() {
- return tree.config.stateFile;
+ return tree.getConfig().getStateFile();
}
long supplyATWriterFilePos() {
- return HistoryTree.getTreeHeaderSize()
- + ((long) tree.getNodeCount() * tree.config.blockSize);
+ return HistoryTree.TREE_HEADER_SIZE
+ + ((long) tree.getNodeCount() * tree.getConfig().getBlockSize());
}
synchronized void closeFile() {
@@ -194,8 +194,8 @@ class HT_IO {
*/
private void seekFCToNodePos(FileChannel fc, int seqNumber)
throws IOException {
- fc.position(HistoryTree.getTreeHeaderSize() + (long) seqNumber
- * tree.config.blockSize);
+ fc.position(HistoryTree.TREE_HEADER_SIZE + (long) seqNumber
+ * tree.getConfig().getBlockSize());
/*
* cast to (long) is needed to make sure the result is a long too and
* doesn't get truncated
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java
index bb08413770..f5284048c6 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java
@@ -20,7 +20,9 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
@@ -34,6 +36,13 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
*/
class HistoryTree {
+ /**
+ * Size of the "tree header" in the tree-file The nodes will use this offset
+ * to know where they should be in the file. This should always be a
+ * multiple of 4K.
+ */
+ public static final int TREE_HEADER_SIZE = 4096;
+
private static final int HISTORY_FILE_MAGIC_NUMBER = 0x05FFA900;
/** File format version. Increment when breaking compatibility. */
@@ -44,7 +53,7 @@ class HistoryTree {
// ------------------------------------------------------------------------
/** Container for all the configuration constants */
- protected final HTConfig config;
+ private final HTConfig config;
/** Reader/writer object */
private final HT_IO treeIO;
@@ -60,7 +69,7 @@ class HistoryTree {
private int nodeCount;
/** "Cache" to keep the active nodes in memory */
- protected Vector<CoreNode> latestBranch;
+ private List<CoreNode> latestBranch;
// ------------------------------------------------------------------------
// Constructors/"Destructors"
@@ -75,20 +84,20 @@ class HistoryTree {
* Simple check to make sure we have enough place in the 0th block
* for the tree configuration
*/
- if (conf.blockSize < getTreeHeaderSize()) {
+ if (conf.getBlockSize() < TREE_HEADER_SIZE) {
throw new IllegalArgumentException();
}
config = conf;
- treeEnd = conf.treeStart;
+ treeEnd = conf.getTreeStart();
nodeCount = 0;
- latestBranch = new Vector<CoreNode>();
+ latestBranch = new ArrayList<CoreNode>();
/* Prepare the IO object */
treeIO = new HT_IO(this, true);
/* Add the first node to the tree */
- CoreNode firstNode = initNewCoreNode(-1, conf.treeStart);
+ CoreNode firstNode = initNewCoreNode(-1, conf.getTreeStart());
latestBranch.add(firstNode);
}
@@ -120,7 +129,7 @@ class HistoryTree {
}
FileInputStream fis = new FileInputStream(existingStateFile);
- ByteBuffer buffer = ByteBuffer.allocate(getTreeHeaderSize());
+ ByteBuffer buffer = ByteBuffer.allocate(TREE_HEADER_SIZE);
FileChannel fc = fis.getChannel();
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.clear();
@@ -176,13 +185,13 @@ class HistoryTree {
this.treeIO = new HT_IO(this, false);
rebuildLatestBranch(rootNodeSeqNb);
- this.treeEnd = latestBranch.firstElement().getNodeEnd();
+ this.treeEnd = latestBranch.get(0).getNodeEnd();
/*
* Make sure the history start time we read previously is consistent
* with was is actually in the root node.
*/
- if (startTime != latestBranch.firstElement().getNodeStart()) {
+ if (startTime != latestBranch.get(0).getNodeStart()) {
fc.close();
fis.close();
throw new IOException("Inconsistent start times in the" + //$NON-NLS-1$
@@ -218,11 +227,8 @@ class HistoryTree {
treeIO.writeNode(latestBranch.get(i));
}
- /* Only use this for debugging purposes, it's VERY slow! */
- // this.checkIntegrity();
-
fc = treeIO.getFcOut();
- buffer = ByteBuffer.allocate(getTreeHeaderSize());
+ buffer = ByteBuffer.allocate(TREE_HEADER_SIZE);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.clear();
@@ -233,32 +239,30 @@ class HistoryTree {
buffer.putInt(HISTORY_FILE_MAGIC_NUMBER);
buffer.putInt(FILE_VERSION);
- buffer.putInt(config.providerVersion);
+ buffer.putInt(config.getProviderVersion());
- buffer.putInt(config.blockSize);
- buffer.putInt(config.maxChildren);
+ buffer.putInt(config.getBlockSize());
+ buffer.putInt(config.getMaxChildren());
buffer.putInt(nodeCount);
/* root node seq. nb */
- buffer.putInt(latestBranch.firstElement().getSequenceNumber());
+ buffer.putInt(latestBranch.get(0).getSequenceNumber());
/* start time of this history */
- buffer.putLong(latestBranch.firstElement().getNodeStart());
+ buffer.putLong(latestBranch.get(0).getNodeStart());
buffer.flip();
res = fc.write(buffer);
- assert (res <= getTreeHeaderSize());
+ assert (res <= TREE_HEADER_SIZE);
/* done writing the file header */
} catch (IOException e) {
/* We should not have any problems at this point... */
- e.printStackTrace();
} finally {
try {
fc.close();
} catch (IOException e) {
- e.printStackTrace();
}
}
return;
@@ -268,8 +272,12 @@ class HistoryTree {
// Accessors
// ------------------------------------------------------------------------
+ HTConfig getConfig() {
+ return config;
+ }
+
long getTreeStart() {
- return config.treeStart;
+ return config.getTreeStart();
}
long getTreeEnd() {
@@ -284,6 +292,10 @@ class HistoryTree {
return treeIO;
}
+ List<CoreNode> getLatestBranch() {
+ return Collections.unmodifiableList(latestBranch);
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@@ -301,12 +313,12 @@ class HistoryTree {
private void rebuildLatestBranch(int rootNodeSeqNb) throws ClosedChannelException {
HTNode nextChildNode;
- this.latestBranch = new Vector<CoreNode>();
+ this.latestBranch = new ArrayList<CoreNode>();
nextChildNode = treeIO.readNodeFromDisk(rootNodeSeqNb);
latestBranch.add((CoreNode) nextChildNode);
- while (latestBranch.lastElement().getNbChildren() > 0) {
- nextChildNode = treeIO.readNodeFromDisk(latestBranch.lastElement().getLatestChild());
+ while (latestBranch.get(latestBranch.size() - 1).getNbChildren() > 0) {
+ nextChildNode = treeIO.readNodeFromDisk(latestBranch.get(latestBranch.size() - 1).getLatestChild());
latestBranch.add((CoreNode) nextChildNode);
}
}
@@ -317,7 +329,7 @@ class HistoryTree {
* @param interval
*/
void insertInterval(HTInterval interval) throws TimeRangeException {
- if (interval.getStartTime() < config.treeStart) {
+ if (interval.getStartTime() < config.getTreeStart()) {
throw new TimeRangeException();
}
tryInsertAtNode(interval, latestBranch.size() - 1);
@@ -388,7 +400,7 @@ class HistoryTree {
}
/* Check if we can indeed add a child to the target parent */
- if (latestBranch.get(indexOfNode - 1).getNbChildren() == config.maxChildren) {
+ if (latestBranch.get(indexOfNode - 1).getNbChildren() == config.getMaxChildren()) {
/* If not, add a branch starting one level higher instead */
addSiblingNode(indexOfNode - 1);
return;
@@ -418,8 +430,8 @@ class HistoryTree {
CoreNode oldRootNode, newRootNode, newNode, prevNode;
long splitTime = this.treeEnd;
- oldRootNode = latestBranch.firstElement();
- newRootNode = initNewCoreNode(-1, config.treeStart);
+ oldRootNode = latestBranch.get(0);
+ newRootNode = initNewCoreNode(-1, config.getTreeStart());
/* Tell the old root node that it isn't root anymore */
oldRootNode.setParentSequenceNumber(newRootNode.getSequenceNumber());
@@ -435,7 +447,7 @@ class HistoryTree {
/* Rebuild a new latestBranch */
depth = latestBranch.size();
- latestBranch = new Vector<CoreNode>();
+ latestBranch = new ArrayList<CoreNode>();
latestBranch.add(newRootNode);
for (i = 1; i < depth + 1; i++) {
prevNode = latestBranch.get(i - 1);
@@ -506,17 +518,8 @@ class HistoryTree {
return treeIO.readNode(potentialNextSeqNb);
}
- /**
- * Helper function to get the size of the "tree header" in the tree-file The
- * nodes will use this offset to know where they should be in the file. This
- * should always be a multiple of 4K.
- */
- static int getTreeHeaderSize() {
- return 4096;
- }
-
long getFileSize() {
- return config.stateFile.length();
+ return config.getStateFile().length();
}
// ------------------------------------------------------------------------
@@ -600,7 +603,6 @@ class HistoryTree {
checkNodeIntegrity(treeIO.readNode(i));
}
} catch (ClosedChannelException e) {
- e.printStackTrace();
}
}
@@ -609,14 +611,14 @@ class HistoryTree {
@Override
public String toString() {
return "Information on the current tree:\n\n" + "Blocksize: "
- + config.blockSize + "\n" + "Max nb. of children per node: "
- + config.maxChildren + "\n" + "Number of nodes: " + nodeCount
+ + config.getBlockSize() + "\n" + "Max nb. of children per node: "
+ + config.getMaxChildren() + "\n" + "Number of nodes: " + nodeCount
+ "\n" + "Depth of the tree: " + latestBranch.size() + "\n"
+ "Size of the treefile: " + this.getFileSize() + "\n"
+ "Root node has sequence number: "
- + latestBranch.firstElement().getSequenceNumber() + "\n"
+ + latestBranch.get(0).getSequenceNumber() + "\n"
+ "'Latest leaf' has sequence number: "
- + latestBranch.lastElement().getSequenceNumber();
+ + latestBranch.get(latestBranch.size() - 1).getSequenceNumber();
}
private int curDepth;
@@ -667,12 +669,12 @@ class HistoryTree {
void debugPrintFullTree(PrintWriter writer, boolean printIntervals) {
/* Only used for debugging, shouldn't be externalized */
curDepth = 0;
- this.preOrderPrint(writer, false, latestBranch.firstElement());
+ this.preOrderPrint(writer, false, latestBranch.get(0));
if (printIntervals) {
writer.println("\nDetails of intervals:"); //$NON-NLS-1$
curDepth = 0;
- this.preOrderPrint(writer, true, latestBranch.firstElement());
+ this.preOrderPrint(writer, true, latestBranch.get(0));
}
writer.println('\n');
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTreeBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTreeBackend.java
index ce240aa05d..ea1c611498 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTreeBackend.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTreeBackend.java
@@ -185,7 +185,7 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
/* We start by reading the information in the root node */
// FIXME using CoreNode for now, we'll have to redo this part to handle
// different node types
- CoreNode currentNode = sht.latestBranch.firstElement();
+ CoreNode currentNode = sht.getLatestBranch().get(0);
currentNode.writeInfoFromNode(stateInfo, t);
/* Then we follow the branch down in the relevant children */
@@ -195,7 +195,7 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
currentNode.writeInfoFromNode(stateInfo, t);
}
} catch (ClosedChannelException e) {
- throw new StateSystemDisposedException();
+ throw new StateSystemDisposedException(e);
}
/*
@@ -232,7 +232,7 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
// FIXME using CoreNode for now, we'll have to redo this part to handle
// different node types
- CoreNode currentNode = sht.latestBranch.firstElement();
+ CoreNode currentNode = sht.getLatestBranch().get(0);
HTInterval interval = currentNode.getRelevantInterval(key, t);
try {
@@ -241,7 +241,7 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
interval = currentNode.getRelevantInterval(key, t);
}
} catch (ClosedChannelException e) {
- throw new StateSystemDisposedException();
+ throw new StateSystemDisposedException(e);
}
/*
* Since we should now have intervals at every attribute/timestamp
@@ -266,7 +266,7 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
* @return The tree depth
*/
public int getTreeDepth() {
- return sht.latestBranch.size();
+ return sht.getLatestBranch().size();
}
/**
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java
index 4e6ddb6faa..fd3e939cee 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java
@@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
@@ -32,12 +33,6 @@ import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
public final class ThreadedHistoryTreeBackend extends HistoryTreeBackend
implements Runnable {
- /*
- * From superclass:
- *
- * protected final StateHistoryTree sht;
- */
-
private BlockingQueue<HTInterval> intervalQueue;
private final Thread shtThread;
@@ -125,9 +120,7 @@ public final class ThreadedHistoryTreeBackend extends HistoryTreeBackend
try {
intervalQueue.put(interval);
} catch (InterruptedException e) {
- /* We should not get interrupted here */
- System.out.println("State system got interrupted!"); //$NON-NLS-1$
- e.printStackTrace();
+ Activator.logError("State system interrupted", e); //$NON-NLS-1$
}
}
@@ -171,16 +164,16 @@ public final class ThreadedHistoryTreeBackend extends HistoryTreeBackend
intervalQueue.put(pill);
shtThread.join();
} catch (TimeRangeException e) {
- e.printStackTrace();
+ Activator.logError("Error closing state system", e); //$NON-NLS-1$
} catch (InterruptedException e) {
- e.printStackTrace();
+ Activator.logError("State system interrupted", e); //$NON-NLS-1$
}
}
@Override
public void run() {
if (intervalQueue == null) {
- System.err.println("Cannot start the storage backend without its interval queue."); //$NON-NLS-1$
+ Activator.logError("Cannot start the storage backend without its interval queue."); //$NON-NLS-1$
return;
}
HTInterval currentInterval;
@@ -200,11 +193,10 @@ public final class ThreadedHistoryTreeBackend extends HistoryTreeBackend
return;
} catch (InterruptedException e) {
/* We've been interrupted abnormally */
- System.out.println("State History Tree interrupted!"); //$NON-NLS-1$
- e.printStackTrace();
+ Activator.logError("State History Tree interrupted!", e); //$NON-NLS-1$
} catch (TimeRangeException e) {
/* This also should not happen */
- e.printStackTrace();
+ Activator.logError("Error starting the state system", e); //$NON-NLS-1$
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java
index f731170b91..5568d9f2a3 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialHistoryBackend.java
@@ -33,6 +33,7 @@ import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -100,12 +101,10 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
*/
public PartialHistoryBackend(ITmfStateProvider partialInput, PartialStateSystem pss,
IStateHistoryBackend realBackend, long granularity) {
- if (granularity <= 0 || partialInput == null || pss == null) {
+ if (granularity <= 0 || partialInput == null || pss == null ||
+ partialInput.getAssignedStateSystem() != pss) {
throw new IllegalArgumentException();
}
- if (partialInput.getAssignedStateSystem() != pss) {
- throw new RuntimeException();
- }
final long startTime = realBackend.getStartTime();
@@ -218,8 +217,8 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
* caused by the event(s) happening exactly at 'checkpointTime',
* if any. We must not include those events in the query.
*/
- new TmfTimestamp(checkpointTime + 1, -9),
- new TmfTimestamp(t, -9));
+ new TmfTimestamp(checkpointTime + 1, ITmfTimestamp.NANOSECOND_SCALE),
+ new TmfTimestamp(t, ITmfTimestamp.NANOSECOND_SCALE));
ITmfEventRequest request = new PartialStateSystemRequest(partialInput, range);
partialInput.getTrace().sendRequest(request);
@@ -286,7 +285,7 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
private class CheckpointsRequest extends TmfEventRequest {
/** The amount of events queried at a time through the requests */
- private final static int chunkSize = 50000;
+ private static final int CHUNK_SIZE = 50000;
private final ITmfTrace trace;
private final Map<Long, Long> checkpts;
@@ -297,12 +296,13 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
super(input.getExpectedEventType(),
TmfTimeRange.ETERNITY,
TmfDataRequest.ALL_DATA,
- chunkSize,
+ CHUNK_SIZE,
ITmfDataRequest.ExecutionType.BACKGROUND);
checkpoints.clear();
this.trace = input.getTrace();
this.checkpts = checkpoints;
- eventCount = lastCheckpointAt = 0;
+ eventCount = 0;
+ lastCheckpointAt = 0;
/* Insert a checkpoint at the start of the trace */
checkpoints.put(input.getStartTime(), 0L);
@@ -331,7 +331,7 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
private class PartialStateSystemRequest extends TmfEventRequest {
- private final static int chunkSize = 50000;
+ private static final int CHUNK_SIZE = 50000;
private final ITmfStateProvider sci;
private final ITmfTrace trace;
@@ -339,7 +339,7 @@ public class PartialHistoryBackend implements IStateHistoryBackend {
super(sci.getExpectedEventType(),
range,
TmfDataRequest.ALL_DATA,
- chunkSize,
+ CHUNK_SIZE,
ITmfDataRequest.ExecutionType.BACKGROUND);
this.sci = sci;
this.trace = sci.getTrace();
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialStateSystem.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialStateSystem.java
index b232261680..1684a83834 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialStateSystem.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/partial/PartialStateSystem.java
@@ -34,7 +34,7 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
*/
public class PartialStateSystem extends StateSystem {
- private static final String errMsg = "Partial state system should not modify the attribute tree!"; //$NON-NLS-1$
+ private static final String ERR_MSG = "Partial state system should not modify the attribute tree!"; //$NON-NLS-1$
private final CountDownLatch ssAssignedLatch = new CountDownLatch(1);
private final Lock queryLock = new ReentrantLock();
@@ -119,7 +119,7 @@ public class PartialStateSystem extends StateSystem {
@Override
protected void addEmptyAttribute() {
- throw new RuntimeException(errMsg);
+ throw new RuntimeException(ERR_MSG);
}
@Override
@@ -128,7 +128,7 @@ public class PartialStateSystem extends StateSystem {
try {
return realStateSystem.getQuarkAbsolute(attribute);
} catch (AttributeNotFoundException e) {
- throw new RuntimeException(errMsg);
+ throw new RuntimeException(ERR_MSG);
}
}
@@ -138,7 +138,7 @@ public class PartialStateSystem extends StateSystem {
try {
return realStateSystem.getQuarkRelative(startingNodeQuark, subPath);
} catch (AttributeNotFoundException e) {
- throw new RuntimeException(errMsg);
+ throw new RuntimeException(ERR_MSG);
}
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/exceptions/StateSystemDisposedException.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/exceptions/StateSystemDisposedException.java
index 6697a5c350..3e68a72308 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/exceptions/StateSystemDisposedException.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/exceptions/StateSystemDisposedException.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
@@ -23,4 +23,21 @@ public class StateSystemDisposedException extends Exception {
private static final long serialVersionUID = 7896041701818620084L;
+ /**
+ * Create a new simple StateSystemDisposedException.
+ */
+ public StateSystemDisposedException() {
+ super();
+ }
+
+ /**
+ * Create a new StateSystemDisposedException based on a previous one.
+ *
+ * @param e
+ * The previous exception
+ */
+ public StateSystemDisposedException(Throwable e) {
+ super(e);
+ }
+
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateProvider.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateProvider.java
index 0d49fa2285..75342a6eda 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateProvider.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/ITmfStateProvider.java
@@ -33,7 +33,7 @@ public interface ITmfStateProvider {
* don't match.
* @since 2.0
*/
- public final static int IGNORE_PROVIDER_VERSION = -42;
+ static final int IGNORE_PROVIDER_VERSION = -42;
/**
* Event handler plugins should provide a version number. This is used to
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemFactory.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemFactory.java
index 5dfa164f66..ebcb251c33 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemFactory.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/TmfStateSystemFactory.java
@@ -40,7 +40,7 @@ public final class TmfStateSystemFactory extends TmfComponent {
private TmfStateSystemFactory() {}
/** Size of the blocking queue to use when building a state history */
- private final static int QUEUE_SIZE = 10000;
+ private static final int QUEUE_SIZE = 10000;
/**
* Load the history file matching the target trace. If the file already
@@ -82,8 +82,7 @@ public final class TmfStateSystemFactory extends TmfComponent {
stateProvider.getVersion();
try {
htBackend = new HistoryTreeBackend(htFile, version);
- ITmfStateSystem ss = HistoryBuilder.openExistingHistory(htBackend);
- return ss;
+ return HistoryBuilder.openExistingHistory(htBackend);
} catch (IOException e) {
/*
* There was an error opening the existing file. Perhaps it was
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
index c4398575e6..159aae5cea 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java
@@ -88,7 +88,7 @@ public abstract class TmfStateValue implements ITmfStateValue {
*
* @return A null value
*/
- public final static TmfStateValue nullValue() {
+ public static final TmfStateValue nullValue() {
return nullValue;
}

Back to the top