JAL-4199 Fix interactive jobs not being stopped
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 7 Jul 2023 14:47:08 +0000 (16:47 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 12 Jul 2023 14:25:05 +0000 (16:25 +0200)
src/jalview/api/AlignCalcWorkerI.java
src/jalview/workers/AlignCalcManager2.java
src/jalview/ws2/actions/annotation/AlignCalcWorkerAdapter.java
src/jalview/ws2/gui/WebServicesMenuManager.java

index b51b94e..89470e0 100644 (file)
@@ -65,4 +65,12 @@ public interface AlignCalcWorkerI
    * @return
    */
   boolean isDeletable();
+
+  /**
+   * Returns the name of this calculation.
+   */
+  public default String getCalcName()
+  {
+    return null;
+  }
 }
index 39111ae..582c84f 100644 (file)
@@ -302,10 +302,7 @@ public class AlignCalcManager2 implements AlignCalcManagerI2
   @Override
   public void removeWorker(AlignCalcWorkerI worker)
   {
-    if (worker.isDeletable())
-    {
-      registered.remove(worker);
-    }
+    registered.remove(worker);
   }
 
   @Override
index 994e3fc..7a58a89 100644 (file)
@@ -50,6 +50,12 @@ public class AlignCalcWorkerAdapter extends AlignCalcWorker implements PollableA
   }
 
   @Override
+  public String getCalcName()
+  {
+    return action.getWebService().getName();
+  }
+
+  @Override
   public void updateAnnotation()
   {
 
@@ -130,4 +136,10 @@ public class AlignCalcWorkerAdapter extends AlignCalcWorker implements PollableA
     if (currentTask != null)
       currentTask.removeTaskEventListener(listener);
   }
+
+  @Override
+  public String toString()
+  {
+    return "AlignCalcWorkerAdapter for " + getCalcName();
+  }
 }
index f081915..5fd4734 100644 (file)
@@ -445,18 +445,20 @@ public class WebServicesMenuManager
     if (action instanceof AnnotationAction)
     {
       var calcManager = viewport.getCalcManager();
-      var oldWorkers = calcManager.getWorkersOfClass(AlignCalcWorkerAdapter.class);
-      for (var worker : oldWorkers)
-      {
-        calcManager.cancelWorker(worker);
-        calcManager.removeWorker(worker);
-      }
 
       var _action = (AnnotationAction) action;
       var worker = new AlignCalcWorkerAdapter(viewport, frame.alignPanel,
           _action, args, credentials);
       var handler = new AnnotationServiceGuiHandler(_action, frame);
       worker.addTaskEventListener(handler);
+      for (var w : calcManager.getWorkers())
+      {
+        if (worker.getCalcName() != null && worker.getCalcName().equals(w.getCalcName()))
+        {
+          calcManager.cancelWorker(w);
+          calcManager.removeWorker(w);
+        }
+      }
       if (action.getWebService().isInteractive())
         calcManager.registerWorker(worker);
       else