Factor some redundant code in trace object construction
authorFrancois Chouinard <fchouinard@gmail.com>
Wed, 19 Oct 2011 17:03:07 +0000 (13:03 -0400)
committerFrancois Chouinard <fchouinard@gmail.com>
Wed, 19 Oct 2011 21:13:27 +0000 (17:13 -0400)
org.eclipse.linuxtools.lttng/src/org/eclipse/linuxtools/lttng/trace/LTTngTrace.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/component/TmfComponent.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/component/TmfDataProvider.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/component/TmfEventProvider.java
org.eclipse.linuxtools.tmf/src/org/eclipse/linuxtools/tmf/trace/TmfTrace.java

index 52fe78cc0e287350a6b8dd9f828108ed8d9c634f..5de8a6c85dd282cc67c4033b15220064beaa4ea1 100644 (file)
@@ -127,8 +127,7 @@ public class LTTngTrace extends TmfTrace<LttngEvent> {
         traceTypeNames = new Vector<Integer>();
         initialiseEventTypes(currentJniTrace);
 
-        // *** VERIFY ***
-        // Verify that all those "default constructor" are safe to use
+        // Build the re-used event structure
         eventTimestamp = new LttngTimestamp();
         eventSource = new LttngEventSource();
         this.eventType = new LttngEventType();
@@ -145,15 +144,6 @@ public class LTTngTrace extends TmfTrace<LttngEvent> {
         // Set the currentEvent to the eventContent
         eventContent.setEvent(currentLttngEvent);
 
-        // // Bypass indexing if asked
-        // if ( bypassIndexing == false ) {
-        // indexTrace(true);
-        // }
-        // else {
-        // Even if we don't have any index, set ONE checkpoint
-        // fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L) , new
-        // LttngLocation() ) );
-
         // Set the time range of the trace
         TmfContext context = seekLocation(null);
         LttngEvent event = getNextEvent(context);
@@ -215,74 +205,63 @@ public class LTTngTrace extends TmfTrace<LttngEvent> {
     public LTTngTrace(String path, String traceLibPath, boolean waitForCompletion, boolean bypassIndexing)
             throws Exception {
         super(path, LttngEvent.class, path, CHECKPOINT_PAGE_SIZE, false);
-        try {
-            currentJniTrace = JniTraceFactory.getJniTrace(path, traceLibPath, SHOW_LTT_DEBUG_DEFAULT);
-        } catch (Exception e) {
-            throw new FileNotFoundException(e.getMessage());
-        }
-
+        initTrace(path, LttngEvent.class, !bypassIndexing);
         this.traceLibPath = traceLibPath;
-        // Export all the event types from the JNI side
-        traceTypes = new HashMap<Integer, LttngEventType>();
-        traceTypeNames = new Vector<Integer>();
-        initialiseEventTypes(currentJniTrace);
-
-        // *** VERIFY ***
-        // Verify that all those "default constructor" are safe to use
-        eventTimestamp = new LttngTimestamp();
-        eventSource = new LttngEventSource();
-        eventType = new LttngEventType();
-        eventContent = new LttngEventContent(currentLttngEvent);
-        eventReference = new LttngEventReference(this.getName());
-
-        // Create the skeleton event
-        currentLttngEvent = new LttngEvent(this, eventTimestamp, eventSource, eventType, eventContent, eventReference,
-                null);
-
-        // Create a new current location
-        previousLocation = new LttngLocation();
-
-        // Set the currentEvent to the eventContent
-        eventContent.setEvent(currentLttngEvent);
-
-        // // Bypass indexing if asked
-        // if ( bypassIndexing == false ) {
-        // indexTrace(true);
-        // }
-        // else {
-        // Even if we don't have any index, set ONE checkpoint
-        // fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L) , new
-        // LttngLocation() ) );
-
-        // Set the time range of the trace
-        TmfContext context = seekLocation(null);
-        LttngEvent event = getNextEvent(context);
-        LttngTimestamp startTime = new LttngTimestamp(event.getTimestamp());
-        LttngTimestamp endTime = new LttngTimestamp(currentJniTrace.getEndTime().getTime());
 
-        setTimeRange(new TmfTimeRange(startTime, endTime));
+//        try {
+//            currentJniTrace = JniTraceFactory.getJniTrace(path, traceLibPath, SHOW_LTT_DEBUG_DEFAULT);
+//        } catch (Exception e) {
+//            throw new FileNotFoundException(e.getMessage());
+//        }
+//
+//        // Export all the event types from the JNI side
+//        traceTypes = new HashMap<Integer, LttngEventType>();
+//        traceTypeNames = new Vector<Integer>();
+//        initialiseEventTypes(currentJniTrace);
+//
+//        // *** VERIFY ***
+//        // Verify that all those "default constructor" are safe to use
+//        eventTimestamp = new LttngTimestamp();
+//        eventSource = new LttngEventSource();
+//        eventType = new LttngEventType();
+//        eventContent = new LttngEventContent(currentLttngEvent);
+//        eventReference = new LttngEventReference(this.getName());
+//
+//        // Create the skeleton event
+//        currentLttngEvent = new LttngEvent(this, eventTimestamp, eventSource, eventType, eventContent, eventReference,
+//                null);
+//
+//        // Create a new current location
+//        previousLocation = new LttngLocation();
+//
+//        // Set the currentEvent to the eventContent
+//        eventContent.setEvent(currentLttngEvent);
+//
+//        // // Bypass indexing if asked
+//        // if ( bypassIndexing == false ) {
+//        // indexTrace(true);
+//        // }
+//        // else {
+//        // Even if we don't have any index, set ONE checkpoint
+//        // fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L) , new
+//        // LttngLocation() ) );
+//
+//        // Set the time range of the trace
+//        TmfContext context = seekLocation(null);
+//        LttngEvent event = getNextEvent(context);
+//        LttngTimestamp startTime = new LttngTimestamp(event.getTimestamp());
+//        LttngTimestamp endTime = new LttngTimestamp(currentJniTrace.getEndTime().getTime());
+//
+//        setTimeRange(new TmfTimeRange(startTime, endTime));
     }
 
     /*
      * Copy constructor is forbidden for LttngEvenmStream
      */
-    public LTTngTrace(LTTngTrace oldTrace) throws Exception {
-        this(oldTrace.getPath(), oldTrace.getTraceLibPath(), false, true);
-
-        // *** VERIFY ***
-        // Is this safe?
-        this.fCheckpoints = oldTrace.fCheckpoints;
-
-        /*
-         * // This would only work if the index is already done this.fCheckpoints = new Vector<TmfCheckpoint>(
-         * oldTrace.fCheckpoints.size() ); for (int x = 0; x<oldTrace.fCheckpoints.size(); x++){ TmfCheckpoint
-         * tmpCheckPoint = oldTrace.fCheckpoints.get(x); this.fCheckpoints.add( new
-         * TmfCheckpoint(tmpCheckPoint.getTimestamp(), tmpCheckPoint.getLocation()) ); }
-         */
-
-        // Set the start time of the trace
-        setTimeRange(new TmfTimeRange(new LttngTimestamp(oldTrace.getStartTime()), new LttngTimestamp(
-                oldTrace.getEndTime())));
+    public LTTngTrace(LTTngTrace other) throws Exception {
+        this(other.getPath(), other.getTraceLibPath(), false, true);
+        this.fCheckpoints = other.fCheckpoints;
+        setTimeRange(new TmfTimeRange(new LttngTimestamp(other.getStartTime()), new LttngTimestamp(other.getEndTime())));
     }
 
     @Override
index f9aae1acf80dc02366f7b261afaab2b78b0efbf5..62d863fc703cd9aaba0caac06693c47099dd6124 100644 (file)
@@ -24,6 +24,10 @@ import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
  */
 public abstract class TmfComponent implements ITmfComponent {
 
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
        private String fName;
        
        // ------------------------------------------------------------------------
@@ -40,18 +44,17 @@ public abstract class TmfComponent implements ITmfComponent {
     }
 
        public TmfComponent(String name) {
-               fName = name;
-               TmfSignalManager.register(this);
+               init(name);
        }
        
-       public TmfComponent(TmfComponent oldComponent) {
-        fName = oldComponent.fName;
-        TmfSignalManager.register(this);
+       public TmfComponent(TmfComponent other) {
+        init(other.fName);
        }
        
-       /* (non-Javadoc)
-        * @see org.eclipse.linuxtools.tmf.component.ITmfComponent#getName()
-        */
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
        protected void setName(String name) {
                fName = name;
        }
@@ -60,26 +63,17 @@ public abstract class TmfComponent implements ITmfComponent {
        // ITmfComponent
        // ------------------------------------------------------------------------
 
-       /* (non-Javadoc)
-        * @see org.eclipse.linuxtools.tmf.component.ITmfComponent#getName()
-        */
        @Override
        public String getName() {
                return fName;
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.linuxtools.tmf.component.ITmfComponent#dispose()
-        */
        @Override
        public void dispose() {
                TmfSignalManager.deregister(this);
 //             if (Tracer.isComponentTraced()) Tracer.traceComponent(this, "terminated");
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.linuxtools.tmf.component.ITmfComponent#broadcast(org.eclipse.linuxtools.tmf.signal.TmfSignal)
-        */
        @Override
        public void broadcast(TmfSignal signal) {
                TmfSignalManager.dispatchSignal(signal);
index 30d1202c18288b9b26d1629dda206b6237ed8518..feb58322d9b35c20721c7e6f686637ccf47fd5e3 100644 (file)
@@ -48,6 +48,9 @@ public abstract class TmfDataProvider<T extends TmfData> extends TmfComponent im
     // Constants
     // ------------------------------------------------------------------------
 
+    public static final int DEFAULT_BLOCK_SIZE = 50000;
+    public static final int DEFAULT_QUEUE_SIZE = 1000;
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -56,10 +59,7 @@ public abstract class TmfDataProvider<T extends TmfData> extends TmfComponent im
     protected boolean fLogData;
     protected boolean fLogError;
 
-    public static final int DEFAULT_BLOCK_SIZE = 50000;
-    public static final int DEFAULT_QUEUE_SIZE = 1000;
-
-    protected int fQueueSize;
+    protected int fQueueSize = DEFAULT_QUEUE_SIZE;
     protected BlockingQueue<T> fDataQueue;
     protected TmfRequestExecutor fExecutor;
 
@@ -73,6 +73,7 @@ public abstract class TmfDataProvider<T extends TmfData> extends TmfComponent im
     // ------------------------------------------------------------------------
 
     public TmfDataProvider() {
+        super();
         fQueueSize = DEFAULT_QUEUE_SIZE;
         fDataQueue = new LinkedBlockingQueue<T>(fQueueSize);
         fExecutor = new TmfRequestExecutor();
@@ -81,7 +82,6 @@ public abstract class TmfDataProvider<T extends TmfData> extends TmfComponent im
     public void init(String name, Class<T> dataType) {
         super.init(name);
         fType = dataType;
-        fQueueSize = DEFAULT_QUEUE_SIZE;
         fDataQueue = (fQueueSize > 1) ? new LinkedBlockingQueue<T>(fQueueSize) : new SynchronousQueue<T>();
 
         fExecutor = new TmfRequestExecutor();
@@ -93,37 +93,19 @@ public abstract class TmfDataProvider<T extends TmfData> extends TmfComponent im
         TmfProviderManager.register(fType, this);
     }
 
-    public TmfDataProvider(String name, Class<T> type) {
-        this(name, type, DEFAULT_QUEUE_SIZE);
-    }
-
     protected TmfDataProvider(String name, Class<T> type, int queueSize) {
-        super(name);
-        fType = type;
+        this();
         fQueueSize = queueSize;
-        fDataQueue = (fQueueSize > 1) ? new LinkedBlockingQueue<T>(fQueueSize) : new SynchronousQueue<T>();
-
-        fExecutor = new TmfRequestExecutor();
-        fSignalDepth = 0;
-
-        fLogData = Tracer.isEventTraced();
-        fLogError = Tracer.isErrorTraced();
-
-        TmfProviderManager.register(fType, this);
-        // if (Tracer.isComponentTraced()) Tracer.traceComponent(this, "started");
+        init(name, type);
     }
 
     public TmfDataProvider(TmfDataProvider<T> other) {
-        super(other);
-        fType = other.fType;
-        fQueueSize = other.fQueueSize;
-        fDataQueue = (fQueueSize > 1) ? new LinkedBlockingQueue<T>(fQueueSize) : new SynchronousQueue<T>();
-
-        fExecutor = new TmfRequestExecutor();
-        fSignalDepth = 0;
+        this();
+        init(other.getName(), other.fType);
+    }
 
-        fLogData = Tracer.isEventTraced();
-        fLogError = Tracer.isErrorTraced();
+    public TmfDataProvider(String name, Class<T> type) {
+        this(name, type, DEFAULT_QUEUE_SIZE);
     }
 
     @Override
@@ -134,6 +116,10 @@ public abstract class TmfDataProvider<T extends TmfData> extends TmfComponent im
         // if (Tracer.isComponentTraced()) Tracer.traceComponent(this, "stopped");
     }
 
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
     public int getQueueSize() {
         return fQueueSize;
     }
index ef0b8b3888ecff00f840b48f1ea8703bfe6586f8..01417db1e6e128d2878abd087d1de6062b60916a 100644 (file)
@@ -24,11 +24,15 @@ import org.eclipse.linuxtools.tmf.request.TmfEventRequest;
 /**
  * <b><u>TmfEventProvider</u></b>
  * <p>
- * Implement me. Please.
  */
 public abstract class TmfEventProvider<T extends TmfEvent> extends TmfDataProvider<T> {
 
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
     public TmfEventProvider() {
+        super();
     }
 
     public void init(String name, Class<T> eventType) {
@@ -43,10 +47,14 @@ public abstract class TmfEventProvider<T extends TmfEvent> extends TmfDataProvid
         super(name, type, queueSize);
     }
 
-    public TmfEventProvider(TmfEventProvider<T> oldProvider) {
-        super(oldProvider);
+    public TmfEventProvider(TmfEventProvider<T> other) {
+        super(other);
     }
 
+    // ------------------------------------------------------------------------
+    // TmfDataProvider
+    // ------------------------------------------------------------------------
+
     @Override
     public boolean isCompleted(ITmfDataRequest<T> request, T data, int nbRead) {
         boolean requestCompleted = super.isCompleted(request, data, nbRead);
index f7e71b7f62d74b4a1d6515d8226f3f4b1c020f2d..1f1bc3acd24d0b938580e05177c1daf419a66fd3 100644 (file)
@@ -66,6 +66,9 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfEventProvider<T> i
     // The trace path
     private String fPath;
 
+    // The trace name
+    private String fName;
+
     // The cache page size AND checkpoints interval
     protected int fIndexPageSize = DEFAULT_INDEX_PAGE_SIZE;
 
@@ -84,6 +87,7 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfEventProvider<T> i
     // ------------------------------------------------------------------------
 
     public TmfTrace() {
+        super();
     }
 
     @Override
@@ -103,16 +107,16 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfEventProvider<T> i
 
     @Override
     public void initTrace(String path, Class<T> eventType, int cacheSize, boolean indexTrace) throws FileNotFoundException {
-        String simpleName = ""; //$NON-NLS-1$
         fPath = path;
-        if (path != null) {
-            int sep = path.lastIndexOf(File.separator);
-            simpleName = (sep >= 0) ? path.substring(sep + 1) : path;
+        if (fName == null) {
+            fName = ""; //$NON-NLS-1$
+            if (path != null) {
+                int sep = path.lastIndexOf(File.separator);
+                fName = (sep >= 0) ? path.substring(sep + 1) : path;
+            }
         }
-        super.init(simpleName, eventType);
-
+        super.init(fName, eventType);
         fIndexPageSize = (cacheSize > 0) ? cacheSize : DEFAULT_INDEX_PAGE_SIZE;
-
         if (indexTrace)
             indexTrace(false);
     }
@@ -156,22 +160,11 @@ public abstract class TmfTrace<T extends TmfEvent> extends TmfEventProvider<T> i
      * @throws FileNotFoundException
      */
     protected TmfTrace(String name, Class<T> type, String path, int cacheSize, boolean indexTrace) throws FileNotFoundException {
-        super(name, type);
-        if (path != null) {
-            int sep = path.lastIndexOf(File.separator);
-            String simpleName = (sep >= 0) ? path.substring(sep + 1) : path;
-            setName(simpleName);
-        }
-        fPath = path;
-        fIndexPageSize = (cacheSize > 0) ? cacheSize : DEFAULT_INDEX_PAGE_SIZE;
-        if (indexTrace) {
-            indexTrace(false);
-        }
+        super();
+        fName = name;
+        initTrace(path, type, cacheSize, indexTrace);
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#clone()
-     */
     @SuppressWarnings("unchecked")
     @Override
     public TmfTrace<T> clone() throws CloneNotSupportedException {
This page took 0.029982 seconds and 5 git commands to generate.