tmf: Cleanup TmfEventProvider
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 23 Jan 2014 20:50:59 +0000 (15:50 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 27 Jan 2014 19:37:23 +0000 (14:37 -0500)
* Move the fDataQueue, as well as the whole concept of queue size, to
  the test stub. it was only used by that.
* Make some protected fields private.
* Change the ArrayList of pending requests to a linked list. We never
  access a specific index directly, and insertions are faster in a
  linked list.
* Remove fireRequest() from the interface, it should only be used
  internally.
* Remove queueBackgroundRequest(), it's not used anymore (this also
  removes the need for the dispatchRequest() method).

Change-Id: Ie9d2706f90d0afec1b01a35f2684c00eb83217fe
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/20911
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>

org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/component/TmfSyntheticEventProviderStub.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/ITmfEventProvider.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/component/TmfEventProvider.java

index 339956aff1b82911b17cb38893806933a9eabad0..d79c8218e1330cb6c68fa82db0f8986de181815a 100644 (file)
@@ -90,7 +90,6 @@ public class CtfTmfTraceTest {
         assertEquals(0L, result.getNbEvents());
         assertEquals(0L, result.getStreamingInterval());
         assertNull(result.getResource());
-        assertEquals(1000, result.getQueueSize());
         assertNull(result.getType());
     }
 
index ecf96aec5a4d46acad54aadfacd08ff141987d98..9b67737203063ddfce79442a906ac265297eb897 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.eclipse.linuxtools.tmf.tests.stubs.component;
 
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfProviderManager;
@@ -36,6 +38,8 @@ public class TmfSyntheticEventProviderStub extends TmfEventProvider {
 
     public static final int NB_EVENTS  = 1000;
 
+    private final BlockingQueue<ITmfEvent> fDataQueue = new LinkedBlockingQueue<>(1000);
+
     public TmfSyntheticEventProviderStub() {
         super("TmfSyntheticEventProviderStub", TmfSyntheticEventStub.class);
     }
index 4508b4c3c9ab85b6997aa2f1979884c711bc5bc9..ab0a6f593e04e5c7ee0666d2ab43b3bb5b0d83a6 100644 (file)
@@ -34,11 +34,6 @@ public interface ITmfEventProvider extends ITmfComponent {
      */
     void sendRequest(ITmfEventRequest request);
 
-    /**
-     * Queue the coalesced requests.
-     */
-    void fireRequest();
-
     /**
      * Increments/decrements the pending requests counters and fires the request
      * if necessary (counter == 0). Used for coalescing requests across multiple
index 932999f94da2df4b79d439258d9a56630ee5ff3b..d3986e7ec3954f11bc69045d1b55ca6b2830398f 100644 (file)
 
 package org.eclipse.linuxtools.tmf.core.component;
 
-import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.SynchronousQueue;
 
 import org.eclipse.linuxtools.internal.tmf.core.TmfCoreTracer;
 import org.eclipse.linuxtools.internal.tmf.core.component.TmfEventThread;
@@ -58,10 +55,6 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
      * @since 3.0 */
     public static final int DEFAULT_BLOCK_SIZE = 50000;
 
-    /** Default size of the queue
-     * @since 3.0 */
-    public static final int DEFAULT_QUEUE_SIZE = 1000;
-
     /** Delay for coalescing background requests (in milli-seconds) */
     private static final long DELAY = 1000;
 
@@ -69,21 +62,11 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
     // Attributes
     // ------------------------------------------------------------------------
 
-    /** List of coalesced requests
-     * @since 3.0*/
-    protected final List<TmfCoalescedEventRequest> fPendingCoalescedRequests = new ArrayList<>();
-
-    /** The type of event handled by this provider
-     * @since 3.0*/
-    protected Class<? extends ITmfEvent> fType;
-
-    /** Queue of events
-     * @since 3.0*/
-    protected BlockingQueue<ITmfEvent> fDataQueue;
+    /** List of coalesced requests */
+    private final List<TmfCoalescedEventRequest> fPendingCoalescedRequests = new LinkedList<>();
 
-    /** Size of the fDataQueue
-     * @since 3.0*/
-    protected int fQueueSize = DEFAULT_QUEUE_SIZE;
+    /** The type of event handled by this provider */
+    private Class<? extends ITmfEvent> fType;
 
     private final TmfRequestExecutor fExecutor;
 
@@ -106,69 +89,38 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
      */
     public TmfEventProvider() {
         super();
-        fQueueSize = DEFAULT_QUEUE_SIZE;
-        fDataQueue = new LinkedBlockingQueue<>(fQueueSize);
         fExecutor = new TmfRequestExecutor();
         fTimer = new Timer();
     }
 
     /**
-     * Initialize this data provider
+     * Standard constructor. Instantiate and initialize at the same time.
      *
      * @param name
      *            Name of the provider
      * @param type
      *            The type of events that will be handled
      */
-    public void init(String name, Class<? extends ITmfEvent> type) {
-        super.init(name);
-        fType = type;
-        fDataQueue = (fQueueSize > 1) ? new LinkedBlockingQueue<ITmfEvent>(fQueueSize) : new SynchronousQueue<ITmfEvent>();
-
-        fExecutor.init();
-
-        fSignalDepth = 0;
-
-        TmfProviderManager.register(fType, this);
-    }
-
-    /**
-     * Constructor specifying the event type and the queue size.
-     *
-     * @param name
-     *            Name of the provider
-     * @param type
-     *            Type of event that will be handled
-     * @param queueSize
-     *            Size of the event queue
-     */
-    protected TmfEventProvider(String name, Class<? extends ITmfEvent> type, int queueSize) {
+    public TmfEventProvider(String name, Class<? extends ITmfEvent> type) {
         this();
-        fQueueSize = queueSize;
         init(name, type);
     }
 
     /**
-     * Copy constructor
-     *
-     * @param other
-     *            The other object to copy
-     */
-    public TmfEventProvider(TmfEventProvider other) {
-        this();
-        init(other.getName(), other.fType);
-    }
-
-    /**
-     * Standard constructor. Instantiate and initialize at the same time.
+     * Initialize this data provider
      *
      * @param name
      *            Name of the provider
      * @param type
      *            The type of events that will be handled
      */
-    public TmfEventProvider(String name, Class<? extends ITmfEvent> type) {
-        this(name, type, DEFAULT_QUEUE_SIZE);
+    public void init(String name, Class<? extends ITmfEvent> type) {
+        super.init(name);
+        fType = type;
+        fExecutor.init();
+
+        fSignalDepth = 0;
+        TmfProviderManager.register(fType, this);
     }
 
     @Override
@@ -182,15 +134,6 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
     // Accessors
     // ------------------------------------------------------------------------
 
-    /**
-     * Get the queue size of this provider
-     *
-     * @return The size of the queue
-     */
-    public int getQueueSize() {
-        return fQueueSize;
-    }
-
     /**
      * Get the event type this provider handles
      *
@@ -214,7 +157,7 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
                 if ((fSignalDepth > 0) || (fRequestPendingCounter > 0)) {
                     coalesceEventRequest(request);
                 } else {
-                    dispatchRequest(request);
+                    queueRequest(request);
                 }
                 return;
             }
@@ -241,8 +184,7 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
         }
     }
 
-    @Override
-    public void fireRequest() {
+    private void fireRequest() {
         synchronized (fLock) {
             if (fRequestPendingCounter > 0) {
                 return;
@@ -254,7 +196,7 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
                     ExecutionType type = (fIsTimeout ? ExecutionType.BACKGROUND : ExecutionType.FOREGROUND);
                     ITmfEventRequest request = iter.next();
                     if (type == request.getExecType()) {
-                        dispatchRequest(request);
+                        queueRequest(request);
                         iter.remove();
                     }
                 }
@@ -362,14 +304,6 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
     // Request processing
     // ------------------------------------------------------------------------
 
-    private void dispatchRequest(final ITmfEventRequest request) {
-        if (request.getExecType() == ExecutionType.FOREGROUND) {
-            queueRequest(request);
-        } else {
-            queueBackgroundRequest(request, true);
-        }
-    }
-
     /**
      * Queue a request.
      *
@@ -393,19 +327,6 @@ public abstract class TmfEventProvider extends TmfComponent implements ITmfEvent
         fExecutor.execute(thread);
     }
 
-    /**
-     * Queue a background request
-     *
-     * @param request
-     *            The request
-     * @param indexing
-     *            Should we index the chunks
-     * @since 3.0
-     */
-    protected void queueBackgroundRequest(final ITmfEventRequest request, final boolean indexing) {
-        queueRequest(request);
-    }
-
     /**
      * Initialize the provider based on the request. The context is provider
      * specific and will be updated by getNext().
This page took 0.032896 seconds and 5 git commands to generate.