tmf: CtfTmfContext rename
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 29 Jan 2013 22:02:22 +0000 (17:02 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 6 Feb 2013 16:16:49 +0000 (11:16 -0500)
Renamed from CtfTmfLightweighContext (there are no heavyweight
contexts anymore) + fixed the clone() method.

After much experimentation, I gave up trying to not make those
extend TmfContext (sorry bug 387929). It seems the iterator
manager depends on CtfTmfContext.equals() to not be overriden.

Fixing this behavior (by making the manager track the locations
instead of the contexts, for example) works, but then reading
events becomes unbearably slow.

I think it's better to not touch this until a proper iterator
API comes to TMF, at which point we can use that directly.

Change-Id: I57cedac2702d0b70950687bdfa7a681ac7582be8
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/10194
Tested-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>

org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/AllTests.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfLightweightContextTest.java [deleted file]
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/headless/Benchmark.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfLightweightContext.java [deleted file]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfContext.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfContext.java

index 7af0b41aa8fa374823ddb101a4520c382ecce212..894f5450db00ba6acddb9893dc0b31f8b96e5e12 100644 (file)
@@ -29,7 +29,7 @@ import org.junit.runners.Suite;
     CtfIteratorTest.class,
     CtfLocationDataTest.class,
     CtfLocationTest.class,
-    CtfTmfLightweightContextTest.class,
+    CtfTmfContextTest.class,
     CtfTmfEventFieldTest.class,
     CtfTmfEventTest.class,
     CtfTmfEventTypeTest.class,
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfContextTest.java
new file mode 100644 (file)
index 0000000..d952173
--- /dev/null
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * 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
+ *
+ * Contributors:
+ *   Matthew Khouzam - Initial implementation
+ *   Alexandre Montplaisir
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
+
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfContext;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for the CtfTmfLightweightContext class
+ *
+ * @author Matthew Khouzam
+ * @version 1.1
+ */
+public class CtfTmfContextTest {
+
+    private static final String PATH = TestParams.getPath();
+    private static final long begin = 1332170682440133097L; /* Trace start time */
+    private static final long end = 1332170692664579801L; /* Trace end time */
+
+    private CtfTmfTrace trace;
+
+    private class SeekerThread extends Thread {
+        long val;
+
+        public void setVal(long val) {
+            this.val = val;
+        }
+    }
+
+    /**
+     * Pre-test initialization
+     *
+     * @throws TmfTraceException
+     *             If the trace couldn't be init'ed, which shouldn't happen.
+     */
+    @Before
+    public void setUp() throws TmfTraceException {
+        trace = new CtfTmfTrace();
+        trace.initTrace((IResource) null, PATH, CtfTmfEvent.class);
+    }
+
+    /**
+     * Index all the events in the test trace.
+     */
+    @Test
+    public void testIndexing() {
+        CtfTmfContext context = new CtfTmfContext(trace);
+        context.seek(0);
+
+        int count = 0;
+        while (trace.getNext(context) != null) {
+            count++;
+        }
+        assertTrue(count > 0);
+    }
+
+    /**
+     * Context fuzzer. Use an amount of contexts greater than the size of the
+     * iterator cache and have them access the trace in parallel.
+     *
+     * @throws InterruptedException
+     *             Would fail the test
+     */
+    @Test
+    public void testTooManyContexts() throws InterruptedException {
+        final int lwcCount = 101;
+        double increment = (end - begin) / lwcCount;
+        final ArrayList<Long> vals = new ArrayList<Long>();
+        final ArrayList<Thread> threads = new ArrayList<Thread>();
+        final ArrayList<CtfTmfContext> tooManyContexts = new ArrayList<CtfTmfContext>();
+
+        for (double i = begin; i < end; i += increment) {
+            SeekerThread thread = new SeekerThread() {
+                @Override
+                public void run() {
+                    CtfTmfContext lwc = new CtfTmfContext(trace);
+                    lwc.seek(val);
+                    trace.getNext(lwc);
+                    synchronized(trace){
+                        if (lwc.getCurrentEvent() != null) {
+                            vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
+                        }
+                        tooManyContexts.add(lwc);
+                    }
+                }
+            };
+            thread.setVal((long)i);
+            threads.add(thread);
+            thread.start();
+        }
+
+        for( Thread t: threads){
+            t.join();
+        }
+
+        for( Long val : vals){
+            assertTrue(val >= begin);
+            assertTrue(val <= end);
+        }
+    }
+
+    /**
+     * Test for clone method
+     */
+    @Test
+    public void testClone() {
+        CtfTmfContext fixture1 = new CtfTmfContext(trace);
+        CtfTmfContext fixture2 = fixture1.clone();
+        //assertTrue(fixture1.equals(fixture2)); FIXME no .equals() override!
+        assertNotSame(fixture1, fixture2);
+
+        /* Make sure clone() did its job */
+        assertSame(fixture1.getTrace(), fixture2.getTrace());
+        assertSame(fixture1.getLocation(), fixture2.getLocation());
+        assertSame(fixture1.getRank(), fixture2.getRank());
+    }
+}
diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfLightweightContextTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfLightweightContextTest.java
deleted file mode 100644 (file)
index c345509..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Ericsson
- *
- * 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
- *
- * Contributors:
- *   Matthew Khouzam - Initial implementation
- *   Alexandre Montplaisir
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfLightweightContext;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
-import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Tests for the CtfTmfLightweightContext class
- *
- * @author Matthew Khouzam
- * @version 1.1
- */
-public class CtfTmfLightweightContextTest {
-
-    private static final String PATH = TestParams.getPath();
-    private static final long begin = 1332170682440133097L; /* Trace start time */
-    private static final long end = 1332170692664579801L; /* Trace end time */
-
-    private CtfTmfTrace fixture;
-
-    private class SeekerThread extends Thread {
-        long val;
-
-        public void setVal(long val) {
-            this.val = val;
-        }
-    }
-
-    /**
-     * Pre-test initialization
-     *
-     * @throws TmfTraceException
-     *             If the trace couldn't be init'ed, which shouldn't happen.
-     */
-    @Before
-    public void setUp() throws TmfTraceException {
-        fixture = new CtfTmfTrace();
-        fixture.initTrace((IResource) null, PATH, CtfTmfEvent.class);
-    }
-
-    /**
-     * Index all the events in the test trace.
-     */
-    @Test
-    public void testIndexing() {
-        CtfTmfLightweightContext context = new CtfTmfLightweightContext(fixture);
-        context.seek(0);
-
-        int count = 0;
-        while (fixture.getNext(context) != null) {
-            count++;
-        }
-        assertTrue(count > 0);
-    }
-
-    /**
-     * Context fuzzer. Use an amount of contexts greater than the size of the
-     * iterator cache and have them access the trace in parallel.
-     *
-     * @throws InterruptedException
-     *             Would fail the test
-     */
-    @Test
-    public void testTooManyContexts() throws InterruptedException {
-        final int lwcCount = 101;
-        double increment = (end - begin) / lwcCount;
-        final ArrayList<Long> vals = new ArrayList<Long>();
-        final ArrayList<Thread> threads = new ArrayList<Thread>();
-        final ArrayList<CtfTmfLightweightContext> tooManyContexts = new ArrayList<CtfTmfLightweightContext>();
-
-        for (double i = begin; i < end; i += increment) {
-            SeekerThread thread = new SeekerThread() {
-                @Override
-                public void run() {
-                    CtfTmfLightweightContext lwc = new CtfTmfLightweightContext(fixture);
-                    lwc.seek(val);
-                    fixture.getNext(lwc);
-                    synchronized(fixture){
-                        if (lwc.getCurrentEvent() != null) {
-                            vals.add(lwc.getCurrentEvent().getTimestamp().getValue());
-                        }
-                        tooManyContexts.add(lwc);
-                    }
-                }
-            };
-            thread.setVal((long)i);
-            threads.add(thread);
-            thread.start();
-        }
-
-        for( Thread t: threads){
-            t.join();
-        }
-
-        for( Long val : vals){
-            assertTrue(val >= begin);
-            assertTrue(val <= end);
-        }
-    }
-}
index dca37167953f358e8f4f5a1ea7e02e8e6fd1d361..75a931463b76cc49b9cbe2dfe6f1d64c5bf01872 100644 (file)
@@ -15,7 +15,7 @@ package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor.headless;
 import java.util.Vector;
 
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfLightweightContext;
+import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfContext;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 
@@ -55,7 +55,7 @@ public class Benchmark {
 
             start = System.nanoTime();
             if (nbEvent != -1) {
-                final CtfTmfLightweightContext traceReader = (CtfTmfLightweightContext) trace.seekEvent(0);
+                final CtfTmfContext traceReader = (CtfTmfContext) trace.seekEvent(0);
 
                 start = System.nanoTime();
                 CtfTmfEvent current = traceReader.getCurrentEvent();
index 0ebacde13d7b3967d356d5e8706274153e0dfa7a..a97fca8b55ae9fa45e38444bd0d6fa57d9df1301 100644 (file)
@@ -25,7 +25,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
  * @author Matthew Khouzam
  */
 public class CtfIterator extends CTFTraceReader implements ITmfContext,
-        Comparable<CtfIterator>, Cloneable {
+        Comparable<CtfIterator> {
 
     private final CtfTmfTrace ctfTmfTrace;
 
index db14b396c201dc00b9b0d3998b6cc51da84343ab..1abf28b002f2f90ab758ab1e7b886d7c72730f6a 100644 (file)
@@ -65,9 +65,10 @@ public abstract class CtfIteratorManager {
      * @param ctx
      *            the context
      * @return the iterator
+     * @since 2.0
      */
     public static synchronized CtfIterator getIterator(final CtfTmfTrace trace,
-            final CtfTmfLightweightContext ctx) {
+            final CtfTmfContext ctx) {
         return map.get(trace).getIterator(ctx);
     }
 }
@@ -86,11 +87,11 @@ class CtfTraceManager {
     /*
      * The map of the cache.
      */
-    private final HashMap<CtfTmfLightweightContext, CtfIterator> fMap;
+    private final HashMap<CtfTmfContext, CtfIterator> fMap;
     /*
      * An array pointing to the same cache. this allows fast "random" accesses.
      */
-    private final ArrayList<CtfTmfLightweightContext> fRandomAccess;
+    private final ArrayList<CtfTmfContext> fRandomAccess;
     /*
      * The parent trace
      */
@@ -101,8 +102,8 @@ class CtfTraceManager {
     private final Random fRnd;
 
     public CtfTraceManager(CtfTmfTrace trace) {
-        fMap = new HashMap<CtfTmfLightweightContext, CtfIterator>();
-        fRandomAccess = new ArrayList<CtfTmfLightweightContext>();
+        fMap = new HashMap<CtfTmfContext, CtfIterator>();
+        fRandomAccess = new ArrayList<CtfTmfContext>();
         fRnd = new Random(System.nanoTime());
         fTrace = trace;
     }
@@ -122,7 +123,7 @@ class CtfTraceManager {
      *            the context to look up
      * @return the iterator refering to the context
      */
-    public CtfIterator getIterator(final CtfTmfLightweightContext context) {
+    public CtfIterator getIterator(final CtfTmfContext context) {
         /*
          * if the element is in the map, we don't need to do anything else.
          */
@@ -161,7 +162,7 @@ class CtfTraceManager {
      * @param elem
      *            the iterator
      */
-    private void addElement(final CtfTmfLightweightContext context,
+    private void addElement(final CtfTmfContext context,
             final CtfIterator elem) {
         fMap.put(context, elem);
         fRandomAccess.add(context);
@@ -175,7 +176,7 @@ class CtfTraceManager {
      * @return the iterator of the removed elements.
      */
     private CtfIterator replaceRandomElement(
-            final CtfTmfLightweightContext context) {
+            final CtfTmfContext context) {
         /*
          * This needs some explanation too: We need to select a random victim
          * and remove it. The order of the elements is not important, so instead
@@ -185,7 +186,7 @@ class CtfTraceManager {
          */
         final int size = fRandomAccess.size();
         final int pos = fRnd.nextInt(size);
-        final CtfTmfLightweightContext victim = fRandomAccess.get(pos);
+        final CtfTmfContext victim = fRandomAccess.get(pos);
         fRandomAccess.set(pos, context);
         final CtfIterator elem = fMap.remove(victim);
         fMap.put(context, elem);
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java
new file mode 100644 (file)
index 0000000..9f6e285
--- /dev/null
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson
+ *
+ * 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
+ *
+ * Contributors: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.ctfadaptor;
+
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+
+/**
+ * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
+ * a boxed Long, a long and an int.
+ *
+ * @author Matthew Khouzam
+ * @version 1.0
+ * @since 2.0
+ */
+public class CtfTmfContext implements ITmfContext {
+
+    // -------------------------------------------
+    // Fields
+    // -------------------------------------------
+
+    private CtfLocation curLocation;
+    private long curRank;
+
+    private final CtfTmfTrace fTrace;
+
+    // -------------------------------------------
+    // Constructor
+    // -------------------------------------------
+
+    /**
+     * Constructor
+     *
+     * @param ctfTmfTrace
+     *            the parent trace
+     * @since 1.1
+     */
+    public CtfTmfContext(CtfTmfTrace ctfTmfTrace) {
+        fTrace = ctfTmfTrace;
+        curLocation = new CtfLocation(new CtfLocationData(0, 0));
+    }
+
+    // -------------------------------------------
+    // TmfContext Overrides
+    // -------------------------------------------
+
+    @Override
+    public long getRank() {
+        return curRank;
+    }
+
+    @Override
+    public ITmfLocation getLocation() {
+        return curLocation;
+    }
+
+    @Override
+    public boolean hasValidRank() {
+        return curRank != CtfLocation.INVALID_LOCATION.getTimestamp();
+    }
+
+    @Override
+    public void setLocation(ITmfLocation location) {
+        curLocation = (CtfLocation) location;
+        if (curLocation != null) {
+            getIterator().seek(curLocation.getLocationInfo());
+        }
+    }
+
+    @Override
+    public void setRank(long rank) {
+        curRank = rank;
+
+    }
+
+    @Override
+    public void increaseRank() {
+        if (hasValidRank()) {
+            curRank++;
+        }
+    }
+
+    // -------------------------------------------
+    // CtfTmfTrace Helpers
+    // -------------------------------------------
+
+    /**
+     * Gets the trace of this context.
+     *
+     * @return The trace of this context
+     */
+    public CtfTmfTrace getTrace() {
+        return fTrace;
+    }
+
+    /**
+     * Gets the current event. Wrapper to help CtfTmfTrace
+     *
+     * @return The event or null
+     */
+    public synchronized CtfTmfEvent getCurrentEvent() {
+        return getIterator().getCurrentEvent();
+    }
+
+    /**
+     * Advances to a the next event. Wrapper to help CtfTmfTrace
+     *
+     * @return success or not
+     */
+    public synchronized boolean advance() {
+        final CtfLocationData curLocationData = this.curLocation.getLocationInfo();
+        boolean retVal = getIterator().advance();
+        CtfTmfEvent currentEvent = getIterator().getCurrentEvent();
+
+        if (currentEvent != null) {
+            final long timestampValue = currentEvent.getTimestamp().getValue();
+            if (curLocationData.getTimestamp() == timestampValue) {
+                curLocation = new CtfLocation(timestampValue, curLocationData.getIndex() + 1);
+            } else {
+                curLocation = new CtfLocation(timestampValue, 0L);
+            }
+        } else {
+            curLocation = new CtfLocation(CtfLocation.INVALID_LOCATION);
+        }
+
+        return retVal;
+    }
+
+    @Override
+    public void dispose() {
+        // do nothing
+    }
+
+    /**
+     * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
+     *
+     * @param timestamp
+     *            desired timestamp
+     * @return success or not
+     */
+    public synchronized boolean seek(final long timestamp) {
+        curLocation = new CtfLocation(timestamp, 0);
+        return getIterator().seek(timestamp);
+    }
+
+    /**
+     * Seeks to a given location. Wrapper to help CtfTmfTrace
+     * @param location
+     *              unique location to find the event.
+     *
+     * @return success or not
+     * @since 2.0
+     */
+    public synchronized boolean seek(final CtfLocationData location) {
+        curLocation = new CtfLocation(location);
+        return getIterator().seek(location);
+    }
+
+    @Override
+    public CtfTmfContext clone() {
+        CtfTmfContext ret = null;
+        try {
+            ret = (CtfTmfContext) super.clone();
+            /* Fields are immutable, no need to deep-copy them */
+        } catch (CloneNotSupportedException e) {
+            /* Should not happen, we're calling Object.clone() */
+        }
+        return ret;
+    }
+
+    // -------------------------------------------
+    // Private helpers
+    // -------------------------------------------
+
+    /**
+     * Get iterator, called every time to get an iterator, no local copy is
+     * stored so that there is no need to "update"
+     *
+     * @return an iterator
+     */
+    private CtfIterator getIterator() {
+        return CtfIteratorManager.getIterator(fTrace, this);
+    }
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfLightweightContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfLightweightContext.java
deleted file mode 100644 (file)
index f1162f8..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 Ericsson
- *
- * 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
- *
- * Contributors: Matthew Khouzam - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.tmf.core.ctfadaptor;
-
-import java.util.ArrayList;
-import java.util.ListIterator;
-
-import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-
-/**
- * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
- * a boxed Long, a long and an int.
- *
- * @version 1.0
- * @author Matthew Khouzam
- */
-public class CtfTmfLightweightContext implements ITmfContext {
-
-    // -------------------------------------------
-    // Fields
-    // -------------------------------------------
-    private CtfLocation curLocation;
-    private long curRank;
-
-    private final CtfTmfTrace fTrace;
-
-    // -------------------------------------------
-    // Constructor
-    // -------------------------------------------
-    /**
-     * Deprecated, use CtfTmfLightweightContext( CtfTmfTrace please )
-     *
-     * @param iters
-     *            the shared iterator pool.
-     * @param pos
-     *            the iterator position.
-     */
-    @Deprecated
-    public CtfTmfLightweightContext(ArrayList<CtfIterator> iters,
-            ListIterator<CtfIterator> pos) {
-        fTrace = iters.get(0).getCtfTmfTrace();
-        curLocation = new CtfLocation(new CtfLocationData(0, 0));
-    }
-
-    /**
-     *
-     * @param ctfTmfTrace
-     *            the parent trace
-     * @since 1.1
-     */
-    public CtfTmfLightweightContext(CtfTmfTrace ctfTmfTrace) {
-        fTrace = ctfTmfTrace;
-        curLocation = new CtfLocation(new CtfLocationData(0, 0));
-    }
-
-    // -------------------------------------------
-    // TmfContext Overrides
-    // -------------------------------------------
-
-    @Override
-    public long getRank() {
-        return curRank;
-    }
-
-    @Override
-    public ITmfLocation getLocation() {
-        return curLocation;
-    }
-
-    @Override
-    public boolean hasValidRank() {
-        return curRank != CtfLocation.INVALID_LOCATION.getTimestamp();
-    }
-
-    @Override
-    public void setLocation(ITmfLocation location) {
-        curLocation = (CtfLocation) location;
-        if (curLocation != null) {
-            getIterator().seek(curLocation.getLocationInfo());
-        }
-    }
-
-    @Override
-    public void setRank(long rank) {
-        curRank = rank;
-
-    }
-
-    @Override
-    public void increaseRank() {
-        if (hasValidRank()) {
-            curRank++;
-        }
-    }
-
-    // -------------------------------------------
-    // CtfTmfTrace Helpers
-    // -------------------------------------------
-
-    /**
-     * Gets the current event. Wrapper to help CtfTmfTrace
-     *
-     * @return The event or null
-     */
-    public synchronized CtfTmfEvent getCurrentEvent() {
-        return getIterator().getCurrentEvent();
-    }
-
-    /**
-     * Advances to a the next event. Wrapper to help CtfTmfTrace
-     *
-     * @return success or not
-     */
-    public synchronized boolean advance() {
-        final CtfLocationData curLocationData = this.curLocation.getLocationInfo();
-        boolean retVal = getIterator().advance();
-        CtfTmfEvent currentEvent = getIterator().getCurrentEvent();
-
-        if (currentEvent != null) {
-            final long timestampValue = currentEvent.getTimestamp().getValue();
-            if (curLocationData.getTimestamp() == timestampValue) {
-                curLocation = new CtfLocation(timestampValue, curLocationData.getIndex() + 1);
-            } else {
-                curLocation = new CtfLocation(timestampValue, 0L);
-            }
-        } else {
-            curLocation = new CtfLocation(CtfLocation.INVALID_LOCATION);
-        }
-
-        return retVal;
-    }
-
-    @Override
-    public void dispose() {
-        // do nothing
-    }
-
-    /**
-     * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
-     *
-     * @param timestamp
-     *            desired timestamp
-     * @return success or not
-     */
-    public synchronized boolean seek(final long timestamp) {
-        curLocation = new CtfLocation(timestamp, 0);
-        return getIterator().seek(timestamp);
-    }
-
-    /**
-     * Seeks to a given location. Wrapper to help CtfTmfTrace
-     * @param location
-     *              unique location to find the event.
-     *
-     * @return success or not
-     * @since 2.0
-     */
-    public synchronized boolean seek(final CtfLocationData location) {
-        curLocation = new CtfLocation(location);
-        return getIterator().seek(location);
-    }
-
-    /*
-     * (non-Javadoc)
-     *
-     * @see java.lang.Object#clone()
-     */
-    @Override
-    public CtfTmfLightweightContext clone() {
-        CtfTmfLightweightContext ret = new CtfTmfLightweightContext(fTrace);
-        ret.curLocation = curLocation.clone();
-        ret.curRank = curRank;
-        return ret;
-    }
-
-    // -------------------------------------------
-    // Private helpers
-    // -------------------------------------------
-    /**
-     * Get iterator, called every time to get an iterator, no local copy is
-     * stored so that there is no need to "update"
-     *
-     * @return an iterator
-     */
-    private CtfIterator getIterator() {
-        return CtfIteratorManager.getIterator(fTrace, this);
-    }
-}
index ef5852ae05d1d1dfe3799e9279f06544356fb6ca..7a78f092a42c1cae461de00faf74ad38614fa452 100644 (file)
@@ -80,9 +80,9 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
         try {
             this.fTrace = new CTFTrace(path);
             CtfIteratorManager.addTrace(this);
-            CtfTmfLightweightContext ctx;
+            CtfTmfContext ctx;
             /* Set the start and (current) end times for this trace */
-            ctx = (CtfTmfLightweightContext) seekEvent(0L);
+            ctx = (CtfTmfContext) seekEvent(0L);
             CtfTmfEvent event = getNext(ctx);
             if((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
                 /* Handle the case where the trace is empty */
@@ -151,7 +151,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
     @Override
     public double getLocationRatio(ITmfLocation location) {
         final CtfLocation curLocation = (CtfLocation) location;
-        final CtfTmfLightweightContext context = new CtfTmfLightweightContext(this);
+        final CtfTmfContext context = new CtfTmfContext(this);
         context.setLocation(curLocation);
         context.seek(curLocation.getLocationInfo());
         final CtfLocationData currentTime = ((CtfLocationData)context.getLocation().getLocationInfo());
@@ -169,7 +169,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
     @Override
     public synchronized ITmfContext seekEvent(final ITmfLocation location) {
         CtfLocation currentLocation = (CtfLocation) location;
-        CtfTmfLightweightContext context = new CtfTmfLightweightContext(this);
+        CtfTmfContext context = new CtfTmfContext(this);
         if (fTrace == null) {
             context.setLocation(null);
             context.setRank(ITmfContext.UNKNOWN_RANK);
@@ -203,7 +203,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
 
     @Override
     public synchronized ITmfContext seekEvent(double ratio) {
-        CtfTmfLightweightContext context = new CtfTmfLightweightContext(this);
+        CtfTmfContext context = new CtfTmfContext(this);
         if (fTrace == null) {
             context.setLocation(null);
             context.setRank(ITmfContext.UNKNOWN_RANK);
@@ -230,11 +230,11 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
             return null;
         }
         CtfTmfEvent event = null;
-        if (context instanceof CtfTmfLightweightContext) {
+        if (context instanceof CtfTmfContext) {
             if (context.getLocation() == null || CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) {
                 return null;
             }
-            CtfTmfLightweightContext ctfContext = (CtfTmfLightweightContext) context;
+            CtfTmfContext ctfContext = (CtfTmfContext) context;
             event = ctfContext.getCurrentEvent();
 
             if (event != null) {
@@ -311,8 +311,8 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
     @Override
     public CtfTmfEvent parseEvent(ITmfContext context) {
         CtfTmfEvent event = null;
-        if( context instanceof CtfTmfLightweightContext ){
-            CtfTmfLightweightContext itt = (CtfTmfLightweightContext) context.clone();
+        if( context instanceof CtfTmfContext ){
+            CtfTmfContext itt = (CtfTmfContext) context.clone();
             event = itt.getCurrentEvent();
         }
         return event;
@@ -329,7 +329,7 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
     //          Helpers
     //-------------------------------------------
 
-    private static CtfIterator getIterator(CtfTmfTrace trace,  CtfTmfLightweightContext context) {
+    private static CtfIterator getIterator(CtfTmfTrace trace,  CtfTmfContext context) {
         return CtfIteratorManager.getIterator(trace, context);
     }
 
index 3d6fa30cebd3ec05c1f72bcc2c92aacf381f0083..1c2cd13ba24aded0b3025a6ba2cdf97b9db7296c 100644 (file)
@@ -26,7 +26,7 @@ package org.eclipse.linuxtools.tmf.core.trace;
  *
  * @see ITmfLocation
  */
-public interface ITmfContext {
+public interface ITmfContext extends Cloneable {
 
     // ------------------------------------------------------------------------
     // Constants
index 6e08185653cdc76e5557b0f9b8dd333025c8d332..2555e7a6d086e1c57294418ec7a859d466ead791 100644 (file)
@@ -24,7 +24,7 @@ package org.eclipse.linuxtools.tmf.core.trace;
  *
  * @see ITmfLocation
  */
-public class TmfContext implements ITmfContext, Cloneable {
+public class TmfContext implements ITmfContext {
 
     // ------------------------------------------------------------------------
     // Attributes
This page took 0.037663 seconds and 5 git commands to generate.