JAL - 3690 AlignCalc rebuilt - FutureTask-based manager
[jalview.git] / src / jalview / workers / ConsensusThread.java
index 32204b9..b97c4c5 100644 (file)
@@ -41,71 +41,33 @@ public class ConsensusThread extends AlignCalcWorker
   @Override
   public void run()
   {
-    if (calcMan.isPending(this))
+    AlignmentAnnotation consensus = getConsensusAnnotation();
+    AlignmentAnnotation gap = getGapAnnotation();
+    if ((consensus == null && gap == null))
     {
       return;
     }
-    calcMan.notifyStart(this);
-    // long started = System.currentTimeMillis();
-    try
+    if (alignViewport.isClosed())
     {
-      AlignmentAnnotation consensus = getConsensusAnnotation();
-      AlignmentAnnotation gap = getGapAnnotation();
-      if ((consensus == null && gap == null) || calcMan.isPending(this))
-      {
-        calcMan.workerComplete(this);
-        return;
-      }
-      while (!calcMan.notifyWorking(this))
-      {
-        // System.err.println("Thread
-        // (Consensus"+Thread.currentThread().getName()+") Waiting around.");
-        try
-        {
-          if (ap != null)
-          {
-            ap.paintAlignment(false, false);
-          }
-          Thread.sleep(200);
-        } catch (Exception ex)
-        {
-          ex.printStackTrace();
-        }
-      }
-      if (alignViewport.isClosed())
-      {
-        abortAndDestroy();
-        return;
-      }
-      AlignmentI alignment = alignViewport.getAlignment();
+      abortAndDestroy();
+      return;
+    }
+    AlignmentI alignment = alignViewport.getAlignment();
 
-      int aWidth = -1;
+    int aWidth = -1;
 
-      if (alignment == null || (aWidth = alignment.getWidth()) < 0)
-      {
-        calcMan.workerComplete(this);
-        return;
-      }
+    if (alignment == null || (aWidth = alignment.getWidth()) < 0)
+    {
+      return;
+    }
 
-      eraseConsensus(aWidth);
-      computeConsensus(alignment);
-      updateResultAnnotation(true);
+    eraseConsensus(aWidth);
+    computeConsensus(alignment);
+    updateResultAnnotation(true);
 
-      if (ap != null)
-      {
-        ap.paintAlignment(true, true);
-      }
-    } catch (OutOfMemoryError error)
-    {
-      calcMan.disableWorker(this);
-      ap.raiseOOMWarning("calculating consensus", error);
-    } finally
+    if (ap != null)
     {
-      /*
-       * e.g. ArrayIndexOutOfBoundsException can happen due to a race condition
-       * - alignment was edited at same time as calculation was running
-       */
-      calcMan.workerComplete(this);
+      ap.paintAlignment(true, true);
     }
   }