[Bug304438] Improvement on ITmfLocation
authorFrancois Chouinard <fchouinard@gmail.com>
Thu, 4 Mar 2010 19:14:55 +0000 (19:14 +0000)
committerFrancois Chouinard <fchouinard@gmail.com>
Thu, 4 Mar 2010 19:14:55 +0000 (19:14 +0000)
18 files changed:
org.eclipse.linuxtools.lttng.tests/src/org/eclipse/linuxtools/lttng/tests/trace/LTTngTextTraceTest.java
org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/LTTngTraceStub.java
org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/event/LttngLocation.java
org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/state/StateManager.java
org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTextTrace.java
org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfEventParserStub.java
org.eclipse.linuxtools.tmf.tests/stubs/org/eclipse/linuxtools/tmf/trace/TmfTraceStub.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/experiment/TmfExperiment.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/experiment/TmfExperimentContext.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/experiment/TmfExperimentLocation.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfContext.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfLocation.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/ITmfTrace.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfCheckpoint.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfContext.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfLocation.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java

index e2235a6f31f04da1f4d8424c9d3231cd8fd18df2..ae54f3486f2892451b2275cf053c2a3f23dd7346 100644 (file)
@@ -245,7 +245,7 @@ public class LTTngTextTraceTest extends TestCase {
                assertNotSame("tmpEvent is null after first event",null,tmpEvent );
                assertTrue("tmpEvent has wrong reference after first event",((String)tmpEvent.getReference().getReference()).contains(firstEventReference) );
                assertNotSame("tmpContext is null after first seekEvent()",null,testStream1.getCurrentLocation() );
-               assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent, ((TmfLocation<Long>) testStream1.getCurrentLocation()).getValue());
+               assertEquals("tmpContext has wrong timestamp after first seekEvent()",locationAfterFirstEvent, ((TmfLocation<Long>) testStream1.getCurrentLocation()).getLocation());
                // Test CPU number of the trace
                assertSame("getCpuNumber() return wrong number of cpu",traceCpuNumber ,testStream1.getCpuNumber() );
     }
index 9bcc8a1862af2de24fb43658ab57ead3783fad66..5cbf5919e2e07ee823bf54e7cd312d38a071af38 100644 (file)
@@ -82,12 +82,13 @@ public class LTTngTraceStub extends TmfTrace<LttngEvent> {
     /* (non-Javadoc)
      * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
      */
+       @Override
        @SuppressWarnings("unchecked")
-       public TmfContext seekLocation(ITmfLocation location) {
+       public TmfContext seekLocation(ITmfLocation<?> location) {
         TmfContext context = null;
                try {
                        synchronized(fTrace) {
-                       fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getValue() : 0);
+                       fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
                        context = new TmfContext(getCurrentLocation(), 0);
 //                     TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
 //                     TmfEvent event = parseEvent(context2);
@@ -104,7 +105,7 @@ public class LTTngTraceStub extends TmfTrace<LttngEvent> {
      * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
      */
     @Override
-       public ITmfLocation getCurrentLocation() {
+       public ITmfLocation<?> getCurrentLocation() {
                try {
                        return new TmfLocation<Long>(fTrace.getFilePointer());
                } catch (IOException e) {
index 592f56975cc21c65c6ec72edebb719b7a45c2e7f..840b0424fa133eca197b2d60536ad9912522e198 100644 (file)
@@ -3,7 +3,7 @@ package org.eclipse.linuxtools.lttng.event;
 import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
 
 
-public class LttngLocation implements ITmfLocation {
+public class LttngLocation implements ITmfLocation<Long[]> {
        
        private final static Long DEFAULT_LAST_TIME = -1L;
        private final static Long DEFAULT_CURR_TIME =  0L;
@@ -88,5 +88,18 @@ public class LttngLocation implements ITmfLocation {
        public String toString() {
                return "\tLttngLocation[ Last : " + lastReadTime + "  Current : " + currentTime + " ]";
        }
+
+       // ------------------------------------------------------------------------
+       // ITmfLocation
+       // ------------------------------------------------------------------------
+
+       public void setLocation(Long[] location) {
+               lastReadTime = ((Long[]) location)[0];
+               currentTime  = ((Long[]) location)[1];
+       }
+
+       public Long[] getLocation() {
+               return new Long[] {lastReadTime, currentTime };
+       }
        
 }
index 7060521a7bfd2ef2c65e7dcc02a06a6bb5e11f38..bb2c94de6c504b579f01fcac22686a4b422e2252 100644 (file)
@@ -339,7 +339,7 @@ public class StateManager extends Observable {
                }
 
                // Make sure eventCount stay consistent!
-               eventCount = location.getValue();
+               eventCount = location.getLocation();
 
                // Restore the stored traceState
                stateIn.setTraceStateModel(traceState);
index 86b9659aa4a53005c44e0a0f58b2f50453c797c9..d15e6aeaf935d8cda6bbf592c816b589c32f40a1 100644 (file)
@@ -136,7 +136,7 @@ public class LTTngTextTrace extends TmfTrace<LttngEvent> implements ITmfTrace {
     
     private void skipToPosition(TmfLocation<Long> skip) {
        try {
-                       long skipPosition = skip.getValue();
+                       long skipPosition = skip.getLocation();
                        if ( skipPosition < 0 ) {
                                skipPosition = 0L;
                        }
@@ -156,14 +156,15 @@ public class LTTngTextTrace extends TmfTrace<LttngEvent> implements ITmfTrace {
        }
     }
     
-    @SuppressWarnings("unchecked")
-       public TmfContext seekLocation(ITmfLocation location) {
+    @Override
+       @SuppressWarnings("unchecked")
+       public TmfContext seekLocation(ITmfLocation<?> location) {
 
        if (location == null) {
                location = new TmfLocation<Long>(0L);
        }
 
-       if (!((TmfLocation<Long>) location).getValue().equals(nbCharRead)) {
+       if (!((TmfLocation<Long>) location).getLocation().equals(nbCharRead)) {
                skipToPosition((TmfLocation<Long>) location);
        }
 
@@ -398,7 +399,7 @@ public class LTTngTextTrace extends TmfTrace<LttngEvent> implements ITmfTrace {
     }
     
     @Override
-    public ITmfLocation getCurrentLocation() {
+    public ITmfLocation<?> getCurrentLocation() {
        return new TmfLocation<Long>(nbCharRead);
     }
     
index 2295b2c4d3a16548b7e3c086b6820098e16c85e5..072ec315eceea11c612f5b9c3661546bc0a58252 100644 (file)
@@ -449,11 +449,12 @@ public class LTTngTrace extends TmfTrace<LttngEvent> {
     }
     
     @Override
-       public ITmfLocation getCurrentLocation() {
+       public ITmfLocation<?> getCurrentLocation() {
         return currentLocation;
     }
     
-    public synchronized TmfContext seekLocation(ITmfLocation location) {
+    @Override
+       public synchronized TmfContext seekLocation(ITmfLocation<?> location) {
        
        if ( joie == true ) {
                System.out.println("seekLocation(location) location -> " + location);
index ceb98993f036077d430586a32e76405be1fbd97f..259604aff472c1cd99fcee47fbd944fbc1ff1c22 100644 (file)
@@ -75,7 +75,7 @@ public class TmfEventParserStub implements ITmfEventParser {
         synchronized(stream) {
                long location = 0;
                if (context != null)
-                       location = ((TmfLocation<Long>) (context.getLocation())).getValue();
+                       location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
                stream.seek(location);
 
                try {
index 8aa0d3afeb3808510d82f5c277b91ed4e9c339d3..aa69bef1088a466e5a692265cd1a5a7bcdc8169c 100644 (file)
@@ -89,13 +89,14 @@ public class TmfTraceStub extends TmfTrace<TmfEvent> {
     // Operators
     // ------------------------------------------------------------------------
 
+       @Override
        @SuppressWarnings("unchecked")
-       public TmfContext seekLocation(ITmfLocation location) {
+       public TmfContext seekLocation(ITmfLocation<?> location) {
         try {
                synchronized(fTrace) {
                        // Position the trace at the requested location and
                        // returns the corresponding context
-                       long loc = (location != null) ? ((TmfLocation<Long>) location).getValue() : 0;
+                       long loc = (location != null) ? ((TmfLocation<Long>) location).getLocation() : 0;
                        if (loc != fTrace.getFilePointer()) {
                                fTrace.seek(loc);
                        }
index 52b1cd291ec481dafdb902563b8d7f989fd64110..e0396f5d7b0548bc2d9579cd20cb1734aa004bc9 100644 (file)
@@ -281,10 +281,10 @@ public class TmfExperiment<T extends TmfEvent> extends TmfProvider<T> implements
        // Returns a brand new context based on the location provided
        // Arms the event queues
        // NOTE: This is a fine example of pathological coupling...
-       public TmfExperimentContext seekLocation(ITmfLocation location) {
+       public TmfExperimentContext seekLocation(ITmfLocation<?> location) {
                if (location instanceof TmfExperimentLocation || location == null) {
-                       ITmfLocation[] oldloc = (location != null) ? ((TmfExperimentLocation) location).getLocations() : new TmfExperimentLocation[fTraces.length];
-                       ITmfLocation[] newloc = new ITmfLocation[fTraces.length];
+                       ITmfLocation<?>[] oldloc = (location != null) ? ((TmfExperimentLocation) location).getLocation() : new TmfExperimentLocation[fTraces.length];
+                       ITmfLocation<?>[] newloc = new ITmfLocation[fTraces.length];
                        TmfContext[] contexts = new TmfContext[fTraces.length];
 
                        TmfExperimentContext context = new TmfExperimentContext(fTraces, contexts);
@@ -321,7 +321,7 @@ public class TmfExperiment<T extends TmfEvent> extends TmfProvider<T> implements
         }
 
         // Position the experiment at the checkpoint
-        ITmfLocation location;
+        ITmfLocation<?> location;
         synchronized (fCheckpoints) {
                if (fCheckpoints.size() > 0) {
                        if (index >= fCheckpoints.size()) {
@@ -448,7 +448,7 @@ public class TmfExperiment<T extends TmfEvent> extends TmfProvider<T> implements
                        TmfContext trcloc = expContext.getContexts()[trace];
                        TmfEvent event = expContext.getTraces()[trace].parseEvent(trcloc);
                        TmfExperimentLocation exploc = (TmfExperimentLocation) expContext.getLocation();
-                       exploc.getLocations()[trace] = trcloc.getLocation().clone();
+                       exploc.getLocation()[trace] = trcloc.getLocation().clone();
                        expContext.updateRank(1);
                        expContext.getEvents()[trace] = expContext.getTraces()[trace].getNextEvent(trcloc);
                        return event;
index 128bc5412cda3c25321661395aa7b0d919a292e6..2f01d008c2b6965cec8fcbf0a7d7392cf936ef2b 100644 (file)
@@ -38,7 +38,7 @@ public class TmfExperimentContext extends TmfContext {
                fContexts = contexts;
                fEvents   = new TmfEvent[fTraces.length];
 
-               ITmfLocation[] locations = new ITmfLocation[fTraces.length];
+               ITmfLocation<?>[] locations = new ITmfLocation[fTraces.length];
                long rank = 0;
                for (int i = 0; i < fTraces.length; i++) {
                        if (contexts[i] != null) {
index 21b919c099109f0fe359db1f8f4d855c4b336ee6..d24d809cf72f1210aa4244ecdb3aa6255f155c45 100644 (file)
 package org.eclipse.linuxtools.tmf.experiment;
 
 import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.trace.TmfLocation;
 
 /**
  * <b><u>TmfExperimentLocation</u></b>
  * <p>
  * The experiment location is the set of its traces' locations.
  */
-public class TmfExperimentLocation implements ITmfLocation {
+public class TmfExperimentLocation extends TmfLocation<ITmfLocation<?>[]> {
 
-       private ITmfLocation[] fLocations;
-       
-       public TmfExperimentLocation(ITmfLocation[] locations) {
-               fLocations = locations;
-       }
-
-       public ITmfLocation[] getLocations() {
-               return fLocations;
+       public TmfExperimentLocation(ITmfLocation<?>[] locations) {
+               super(locations);
        }
 
        @Override
        public TmfExperimentLocation clone() {
-               ITmfLocation[] locations = new ITmfLocation[fLocations.length];
-               for (int i = 0; i < fLocations.length; i++) {
-                       locations[i] = fLocations[i].clone();
+               ITmfLocation<?>[] locations = (ITmfLocation<?>[]) getLocation();
+               ITmfLocation<?>[] clones = new ITmfLocation[locations.length];
+               for (int i = 0; i < locations.length; i++) {
+                       clones[i] = locations[i].clone();
                }
-               return new TmfExperimentLocation(locations);
+               return new TmfExperimentLocation(clones);
        }
 
 }
index 72e96072d7f15486d56a30454ca40b302074145c..880f8c6e9f69f7c2f83a022af9e2dada3add86fa 100644 (file)
@@ -19,11 +19,11 @@ package org.eclipse.linuxtools.tmf.trace;
  */
 public interface ITmfContext extends Cloneable {
 
-       public void setLocation(ITmfLocation location);
-       public ITmfLocation getLocation();
+       public void setLocation(ITmfLocation<?> location);
+       public ITmfLocation<?> getLocation();
 
-       public void setRank(long value);
+       public void setRank(long rank);
        public long getRank();
-       public void updateRank(int value);
+       public void updateRank(int rank);
 
 }
index bd3e816b6b38db0aa2456ef3545571a13dd6836a..20b20caf5e400be810c05df4bbf4591f513ba319 100644 (file)
@@ -15,10 +15,14 @@ package org.eclipse.linuxtools.tmf.trace;
 /**
  * <b><u>ITmfLocation</u></b>
  * <p>
- * This is a place-holder for the context objects.
+ * This is a place-holder for the location objects.
  */
-public interface ITmfLocation extends Cloneable {
-       
-       public ITmfLocation clone();
+public interface ITmfLocation<L> extends Cloneable {
+
+       public void setLocation(L location);
+
+       public L getLocation();
+
+       public ITmfLocation<L> clone();
 
 }
index 50536c3b59778d40b3f4a1e1240521cc4a092df4..f8038207307e6fdc82ea8a7c866a3439071f4d47 100644 (file)
@@ -54,7 +54,7 @@ public interface ITmfTrace {
      * @param data.index
      * @return a context object for subsequent reads
      */
-    public TmfContext seekLocation(ITmfLocation location);
+    public TmfContext seekLocation(ITmfLocation<?> location);
     public TmfContext seekEvent(TmfTimestamp timestamp);
     public TmfContext seekEvent(long rank);
 
index 264d637193b4c94bf1956f16bff4e08367e39a2c..f37cb28d57f2b4fc710a178918e0e222c52e3413 100644 (file)
@@ -26,7 +26,7 @@ public class TmfCheckpoint implements Comparable<TmfCheckpoint> {
     // ------------------------------------------------------------------------
     
     private final TmfTimestamp fTimestamp;
-    private final ITmfLocation fLocation;
+    private final ITmfLocation<?> fLocation;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -36,7 +36,7 @@ public class TmfCheckpoint implements Comparable<TmfCheckpoint> {
      * @param ts
      * @param location
      */
-    public TmfCheckpoint(TmfTimestamp ts, ITmfLocation location) {
+    public TmfCheckpoint(TmfTimestamp ts, ITmfLocation<?> location) {
         fTimestamp = ts;
         fLocation = location;
     }
@@ -55,7 +55,7 @@ public class TmfCheckpoint implements Comparable<TmfCheckpoint> {
     /**
      * @return the checkpoint event stream location
      */
-    public ITmfLocation getLocation() {
+    public ITmfLocation<?> getLocation() {
         return fLocation;
     }
 
index 2df122285b0723c6335f65d70adea73de5ffe329..871421b380144002bf101972c184616132c99151 100644 (file)
@@ -24,19 +24,19 @@ package org.eclipse.linuxtools.tmf.trace;
  */
 public class TmfContext implements ITmfContext, Cloneable {
 
-       private ITmfLocation fLocation;
+       private ITmfLocation<?> fLocation;
        private long fRank;
        
        // ------------------------------------------------------------------------
        // Constructors
        // ------------------------------------------------------------------------
 
-       public TmfContext(ITmfLocation loc, long rank) {
+       public TmfContext(ITmfLocation<?> loc, long rank) {
                fLocation = loc;
                fRank = rank;
        }
 
-       public TmfContext(ITmfLocation location) {
+       public TmfContext(ITmfLocation<?> location) {
                this(location, 0);
        }
 
@@ -66,24 +66,24 @@ public class TmfContext implements ITmfContext, Cloneable {
        // ITmfContext
        // ------------------------------------------------------------------------
 
-       public void setLocation(ITmfLocation loc) {
-               fLocation = loc;
+       public void setLocation(ITmfLocation<?> location) {
+               fLocation = location;
        }
 
-       public ITmfLocation getLocation() {
+       public ITmfLocation<?> getLocation() {
                return fLocation;
        }
 
-       public void setRank(long value) {
-               fRank = value;
+       public void setRank(long rank) {
+               fRank = rank;
        }
 
        public long getRank() {
                return fRank;
        }
 
-       public void updateRank(int value) {
-               fRank += value;
+       public void updateRank(int delta) {
+               fRank += delta;
        }
 
 }
index c1996c62654f2f62da8941901478a3cfa40a444f..6851d9e1be8f59d11f37921cff35c0c128bf4061 100644 (file)
@@ -15,32 +15,38 @@ package org.eclipse.linuxtools.tmf.trace;
 /**
  * <b><u>TmfLocation</u></b>
  * <p>
- * Implement me. Please.
+ * A generic implementation of ITmfLocation
  */
-public class TmfLocation<T> implements ITmfLocation {
+public class TmfLocation<L> implements ITmfLocation<L> {
 
-       private T fLocation;
+       private L fLocation;
        
-       public TmfLocation(T location) {
+       public TmfLocation(L location) {
                fLocation = location;
        }
 
-       public void setValue(T location) {
+       public void setLocation(L location) {
                fLocation = location;
        }
 
-       public T getValue() {
+       public L getLocation() {
                return fLocation;
        }
 
+       @Override
+       public String toString() {
+               return fLocation.toString();
+       }
+
        @Override
        @SuppressWarnings("unchecked")
-       public TmfLocation<T> clone() {
+       public TmfLocation<L> clone() {
                try {
-                       return (TmfLocation<T>) super.clone();
+                       return (TmfLocation<L>) super.clone();
                } catch (CloneNotSupportedException e) {
                        e.printStackTrace();
                }
                return null;
        }
+
 }
index fdc5893cf05fc66786eb312f791afb855ca688f5..55aafc84e85ddc0a4f652131f355539f34029792 100644 (file)
@@ -225,7 +225,7 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfProvider<T> implem
         }
 
         // Position the stream at the checkpoint
-        ITmfLocation location;
+        ITmfLocation<?> location;
         synchronized (fCheckpoints) {
                if (fCheckpoints.size() > 0) {
                        if (index >= fCheckpoints.size()) {
@@ -259,7 +259,7 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfProvider<T> implem
 
         // Position the stream at the previous checkpoint
         int index = (int) rank / fIndexPageSize;
-        ITmfLocation location;
+        ITmfLocation<?> location;
         synchronized (fCheckpoints) {
                if (fCheckpoints.size() > 0) {
                        if (index >= fCheckpoints.size()) {
@@ -312,7 +312,8 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfProvider<T> implem
     /**
      * To be implemented by the concrete class
      */
-       public abstract ITmfLocation getCurrentLocation();
+    public abstract TmfContext seekLocation(ITmfLocation<?> location);
+       public abstract ITmfLocation<?> getCurrentLocation();
     public abstract TmfEvent parseEvent(TmfContext context);
 
        // ------------------------------------------------------------------------
@@ -373,7 +374,6 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfProvider<T> implem
                /* (non-Javadoc)
                 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
                 */
-               @SuppressWarnings("rawtypes")
                @Override
                protected IStatus run(IProgressMonitor monitor) {
 
@@ -389,7 +389,7 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfProvider<T> implem
             try {
                // Position the trace at the beginning
                 TmfContext context = seekLocation(null);
-                TmfLocation location = (TmfLocation) context.getLocation();
+                ITmfLocation<?> location = context.getLocation();
 
                 // Get the first event
                        TmfEvent event = getNextEvent(context);
@@ -418,7 +418,7 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfProvider<T> implem
 
                     // We will need this location at the next iteration
                     if ((nbEvents % fIndexPageSize) == 0) {
-                        location = (TmfLocation) context.getLocation();
+                        location = context.getLocation();
                                }
 
                     event = getNextEvent(context);
This page took 0.038819 seconds and 5 git commands to generate.