tmf: Allow any object to use TmfSignalThrottler
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Wed, 21 Sep 2016 22:19:32 +0000 (18:19 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 23 Sep 2016 16:19:26 +0000 (12:19 -0400)
Some classes override broadcast(), so we can continue
calling that for subclasses of ITmfComponent.

Change-Id: I2b270fe58349e6206d00c874b84304581c56dce0
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/81723
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/signal/TmfSignalThrottler.java

index 8de7176f9ee78fa6786cf986ff2b1d9c90aa16a7..4ef82e51c4bbdc5641a4f134711628bf1e1c6933 100644 (file)
@@ -15,8 +15,9 @@ package org.eclipse.tracecompass.tmf.core.signal;
 import java.util.Timer;
 import java.util.TimerTask;
 
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.tmf.core.component.ITmfComponent;
-import org.eclipse.tracecompass.tmf.core.component.TmfComponent;
 
 /**
  * "Buffer" between a TmfComponent and the signal manager. You can use this if
@@ -34,31 +35,40 @@ import org.eclipse.tracecompass.tmf.core.component.TmfComponent;
  *
  * @author Alexandre Montplaisir
  */
+@NonNullByDefault
 public class TmfSignalThrottler {
 
-    private final ITmfComponent fComponent;
+    private final @Nullable ITmfComponent fComponent;
     private final long fDelay;
     private final Timer fTimer;
+
     private TimerTask fCurrentTask;
 
     /**
      * Constructor
      *
      * @param component
-     *            The source component of the signals
+     *            The optional source component of the signals. If non-null, its
+     *            {@link ITmfComponent#broadcast} method will be used to finally
+     *            send the signal. If null, the generic
+     *            {@link TmfSignalManager#dispatchSignal} is used.
      * @param delay
      *            Time to wait before actually sending signals (in ms)
      */
-    public TmfSignalThrottler(ITmfComponent component, long delay) {
+    public TmfSignalThrottler(@Nullable ITmfComponent component, long delay) {
         this.fComponent = component;
         this.fDelay = delay;
         this.fTimer = new Timer();
 
         /*
          * Initialize currentTask to something, so we don't have to do a null
-         * check every time
+         * check every time.
          */
-        fCurrentTask = new TimerTask() { @Override public void run() {} };
+        fCurrentTask = new TimerTask() {
+            @Override
+            public void run() {
+            }
+        };
     }
 
     /**
@@ -66,7 +76,8 @@ public class TmfSignalThrottler {
      * signal handler if 'delay' elapses without another signal being sent
      * through this method.
      *
-     * You call this instead of calling {@link TmfComponent#broadcast}.
+     * You call this instead of {@link ITmfComponent#broadcast} or
+     * {@link TmfSignalManager#dispatchSignal}.
      *
      * @param signal
      *            The signal to queue for broadcasting
@@ -96,7 +107,12 @@ public class TmfSignalThrottler {
 
         @Override
         public void run() {
-            fComponent.broadcast(signal);
+            if (fComponent != null) {
+                fComponent.broadcast(signal);
+            } else {
+                TmfSignalManager.dispatchSignal(signal);
+            }
         }
     }
+
 }
This page took 0.025636 seconds and 5 git commands to generate.