GSS: Avoid doing time-range requests if one of the timestamps is invalid
authorAlexandre Montplaisir <alexandre.montplaisir@gmail.com>
Sun, 18 Mar 2012 02:11:58 +0000 (22:11 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Mon, 19 Mar 2012 21:44:06 +0000 (17:44 -0400)
Thanks to the unit-test benchmarking for letting me know of this
problem...

Also exposed checkValidTime() through the IHistoryBackend interface,
this can be useful, as we see here.

org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateHistorySystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/backend/historytree/HistoryTreeBackend.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/helpers/IStateHistoryBackend.java

index 3f77430564c880f8ec531f4ae0471c7aa7690d25..25dd0007fbd5beaf20a622aad428b80b27790d83 100644 (file)
@@ -228,11 +228,20 @@ public class StateHistorySystem extends StateSystem {
     public List<ITmfStateInterval> queryHistoryRange(int attributeQuark, long t1,
             long t2) throws TimeRangeException, AttributeNotFoundException {
 
-        List<ITmfStateInterval> intervals = new ArrayList<ITmfStateInterval>();
+        List<ITmfStateInterval> intervals;
         ITmfStateInterval currentInterval;
         long ts;
+        
+        if ( !(backend.checkValidTime(t1) && backend.checkValidTime(t2)) ) {
+            /* 
+             * One of the two timestamps is out of range, don't bother
+             * with the requests
+             */
+            throw new TimeRangeException();
+        }
 
         /* Get the initial state at time T1 */
+        intervals = new ArrayList<ITmfStateInterval>();
         currentInterval = querySingleState(t1, attributeQuark);
         intervals.add(currentInterval);
 
index dab8018dd1bd0bf409eff48d3566d8f57a150895..2469b3c190684961dff569e0f03b6beda8ed9fce 100644 (file)
@@ -80,8 +80,11 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
     /**
      * Existing history constructor. Use this to open an existing state-file.
      * 
-     * @param existingFileName Filename/location of the history we want to load
-     * @throws IOException If we can't read the file, if it doesn't exist or is not recognized
+     * @param existingFileName
+     *            Filename/location of the history we want to load
+     * @throws IOException
+     *             If we can't read the file, if it doesn't exist or is not
+     *             recognized
      */
     public HistoryTreeBackend(File existingStateFile) throws IOException {
         sht = new HistoryTree(existingStateFile);
@@ -161,15 +164,8 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
         return getRelevantInterval(t, attributeQuark);
     }
 
-    /**
-     * Simple check to make sure the requested timestamps are within the borders
-     * of this tree.
-     * 
-     * @param t
-     *            The queried timestamp
-     * @return True if it's within range, false if not.
-     */
-    private boolean checkValidTime(long t) {
+    @Override
+    public boolean checkValidTime(long t) {
         return (t >= sht.getTreeStart() && t <= sht.getTreeEnd());
     }
 
@@ -249,8 +245,8 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
     }
 
     /**
-     * The basic debugPrint method will print the tree structure, but not
-     * their contents.
+     * The basic debugPrint method will print the tree structure, but not their
+     * contents.
      * 
      * This method here print the contents (the intervals) as well.
      * 
index 26d32637834bc312823d7e9897b60b694257b3c8..1d7a163ecfa64f161250ab3fbaf63d1fb84815ef 100644 (file)
@@ -138,6 +138,18 @@ public interface IStateHistoryBackend {
      */
     public ITmfStateInterval doSingularQuery(long t, int attributeQuark)
             throws TimeRangeException, AttributeNotFoundException;
+    
+    /**
+     * Simple check to make sure the requested timestamps are within the borders
+     * of this state history. This is used internally, but could also be used
+     * by the request sender (to check before sending in a lot of requests for
+     * example).
+     * 
+     * @param t
+     *            The queried timestamp
+     * @return True if the timestamp is within range, false if not.
+     */
+    public boolean checkValidTime(long t);
 
     /**
      * Debug method to print the contents of the history backend.
This page took 0.0334 seconds and 5 git commands to generate.