JAL-3878 Add serviceExecutor to AlignmentViewport.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 2 Mar 2022 17:26:24 +0000 (18:26 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 2 Mar 2022 17:29:26 +0000 (18:29 +0100)
The serviceExecutor is a ScheduledExecutorService which
(web)services can use to run jobs associated with the current viewport.

src/jalview/viewmodel/AlignmentViewport.java

index 1a08b1b..c9165d0 100644 (file)
@@ -74,6 +74,9 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
 
 /**
  * base class holding visualization and analysis attributes and common logic for
@@ -995,6 +998,20 @@ public abstract class AlignmentViewport
     return false;
   }
 
+  private ScheduledExecutorService serviceExecutor = Executors.newSingleThreadScheduledExecutor();
+
+  /**
+   * Get a default scheduled executor service which can be used by
+   * services and calculators to run parallel jobs associated with this
+   * viewport.
+   * 
+   * @return default service executor of that viewport
+   */
+  public ScheduledExecutorService getServiceExecutor()
+  {
+    return serviceExecutor;
+  }
+
   public void setAlignment(AlignmentI align)
   {
     this.alignment = align;
@@ -1024,6 +1041,8 @@ public abstract class AlignmentViewport
     gapcounts = null;
     calculator.shutdown();
     calculator = null;
+    serviceExecutor.shutdown();
+    serviceExecutor = null;
     residueShading = null; // may hold a reference to Consensus
     changeSupport = null;
     ranges = null;