[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / provisional / tmf / ui / views / timegraph2 / swtjfx / LatestJobExecutor.java
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/provisional/tmf/ui/views/timegraph2/swtjfx/LatestJobExecutor.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/provisional/tmf/ui/views/timegraph2/swtjfx/LatestJobExecutor.java
new file mode 100644 (file)
index 0000000..1ff199c
--- /dev/null
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swtjfx;
+
+import java.lang.ref.WeakReference;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.annotation.Nullable;
+
+public class LatestJobExecutor {
+
+    /**
+     * The latest job that was schedule in this queue.
+     */
+    private WeakReference<@Nullable Job> fLatestJob = new WeakReference<>(null);
+
+    public LatestJobExecutor() {
+    }
+
+    public synchronized void schedule(Job newJob) {
+        Job latestJob = fLatestJob.get();
+        if (latestJob != null) {
+            /*
+             * Cancel the existing job. Here's hoping it cooperates and ends
+             * quickly!
+             */
+            latestJob.cancel();
+        }
+
+        /* Start the new job */
+        fLatestJob = new WeakReference<>(newJob);
+        newJob.schedule();
+    }
+
+}
This page took 0.023281 seconds and 5 git commands to generate.