*
* @param worker
*/
- void workerCannotRun(AlignCalcWorkerI worker);
+ void disableWorker(AlignCalcWorkerI worker);
/**
* indicate that a worker like this may be run on the platform.
* @param worker
* of class to be removed from the execution blacklist
*/
- void workerMayRun(AlignCalcWorkerI worker);
+ void enableWorker(AlignCalcWorkerI worker);
/**
* launch a new worker
*/
void removeRegisteredWorkersOfClass(Class typeToRemove);
+ /**
+ * Removes the worker that produces the given annotation, provided it is
+ * marked as 'deletable'. Some workers may need to continue to run as the
+ * results of their calculations are needed elsewhere e.g. for colour schemes.
+ *
+ * @param ann
+ */
+ void removeWorkerForAnnotation(AlignmentAnnotation ann);
}
* @param annot
* @return
*/
- public boolean involves(AlignmentAnnotation annot);
+ boolean involves(AlignmentAnnotation annot);
/**
* Updates the display of calculated annotation values (does not recalculate
- * the values). This allows for quick redraw of annotations when display
- * settings are changed.
+ * the values). This allows ßquick redraw of annotations when display settings
+ * are changed.
*/
- public void updateAnnotation();
+ void updateAnnotation();
/**
- * Removes any annotation managed by this worker from the alignment
+ * Removes any annotation(s) managed by this worker from the alignment
*/
void removeAnnotation();
+
+ /**
+ * Answers true if the worker should be deleted entirely when its annotation
+ * is deleted from the display, or false if it should continue to run. Some
+ * workers are required to run for their side-effects.
+ *
+ * @return
+ */
+ boolean isDeletable();
}
else if (evt.getActionCommand().equals(DELETE))
{
ap.av.getAlignment().deleteAnnotation(aa[selectedRow]);
+ ap.av.getCalcManager().removeWorkerForAnnotation(aa[selectedRow]);
}
else if (evt.getActionCommand().equals(SHOWALL))
{
}
}
}
- if (!evt.isPopupTrigger())
- {
- return;
- }
+ // if (!evt.isPopupTrigger())
+ // {
+ // return;
+ // }
JPopupMenu pop = new JPopupMenu(
MessageManager.getString("label.annotations"));
private volatile List<AlignCalcWorkerI> restartable = Collections
.synchronizedList(new ArrayList<AlignCalcWorkerI>());
- private volatile List<Class> blackList = Collections
- .synchronizedList(new ArrayList<Class>());
+ private volatile List<AlignCalcWorkerI> blackList = Collections
+ .synchronizedList(new ArrayList<AlignCalcWorkerI>());
/**
* global record of calculations in progress
}
@Override
- public void workerCannotRun(AlignCalcWorkerI worker)
+ public void disableWorker(AlignCalcWorkerI worker)
{
synchronized (blackList)
{
- blackList.add(worker.getClass());
+ blackList.add(worker);
}
}
- public boolean isBlackListed(Class workerType)
+ public boolean isBlackListed(AlignCalcWorkerI worker)
{
synchronized (blackList)
{
- return blackList.contains(workerType);
+ return blackList.contains(worker);
}
}
@Override
public void startWorker(AlignCalcWorkerI worker)
{
- // System.err.println("Starting "+worker.getClass());
- // new Exception("").printStackTrace();
- Thread tw = new Thread(worker);
- tw.setName(worker.getClass().toString());
- tw.start();
+ if (!isBlackListed(worker))
+ {
+ Thread tw = new Thread(worker);
+ tw.setName(worker.getClass().toString());
+ tw.start();
+ }
}
@Override
}
@Override
- public void workerMayRun(AlignCalcWorkerI worker)
+ public void enableWorker(AlignCalcWorkerI worker)
{
synchronized (blackList)
{
- if (blackList.contains(worker.getClass()))
- {
- blackList.remove(worker.getClass());
- }
+ blackList.remove(worker);
}
}
* else { System.err.println("Pending exists for " + workerClass); } }
*/
}
+
+ /**
+ * Deletes the worker that update the given annotation, provided it is marked
+ * as deletable.
+ */
+ @Override
+ public void removeWorkerForAnnotation(AlignmentAnnotation ann)
+ {
+ /*
+ * first just find those to remove (to avoid
+ * ConcurrentModificationException)
+ */
+ List<AlignCalcWorkerI> toRemove = new ArrayList<AlignCalcWorkerI>();
+ for (AlignCalcWorkerI worker : restartable)
+ {
+ if (worker.involves(ann))
+ {
+ if (worker.isDeletable())
+ {
+ toRemove.add(worker);
+ }
+ }
+ }
+
+ /*
+ * remove all references to the workers
+ */
+ for (AlignCalcWorkerI worker : toRemove)
+ {
+ restartable.remove(worker);
+ blackList.remove(worker);
+ }
+ }
}
// TODO: allow GUI to query workers associated with annotation to add items to
// annotation label panel popup menu
+ @Override
+ public boolean isDeletable()
+ {
+ return false;
+ }
+
}
/**
* A class to create and update one or more alignment annotations, given a
- * 'calculator'.
- *
+ * 'calculator'. Intended to support a 'plug-in' annotation worker which
+ * implements the AnnotationProviderI interface.
*/
class AnnotationWorker extends AlignCalcWorker
{
} catch (OutOfMemoryError error)
{
ap.raiseOOMWarning("calculating annotations", error);
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
} finally
{
calcMan.workerComplete(this);
{
// do nothing
}
+
+ /**
+ * Answers true to indicate that if this worker's annotation is deleted from
+ * the display, the worker should also be removed. This prevents it running
+ * and recreating the annotation when the alignment changes.
+ */
+ @Override
+ public boolean isDeletable()
+ {
+ return true;
+ }
}
} catch (OutOfMemoryError error)
{
ap.raiseOOMWarning("calculating feature counts", error);
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
} finally
{
calcMan.workerComplete(this);
{
// do nothing
}
+
+ /**
+ * Answers true to indicate that if this worker's annotation is deleted from
+ * the display, the worker should also be removed. This prevents it running
+ * and recreating the annotation when the alignment changes.
+ */
+ @Override
+ public boolean isDeletable()
+ {
+ return true;
+ }
}
}
} catch (OutOfMemoryError error)
{
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
ap.raiseOOMWarning("calculating consensus", error);
} finally
{
} catch (OutOfMemoryError error)
{
ap.raiseOOMWarning("calculating conservation", error);
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
// alignViewport.conservation = null;
// this.alignViewport.quality = null;
updateResultAnnotation(true);
} catch (OutOfMemoryError error)
{
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
// consensus = null;
// hconsensus = null;
System.err.println("submission error with " + getServiceActionText()
+ " :");
x.printStackTrace();
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
} catch (ResultNotAvailableException x)
{
System.err.println("collection error:\nJob ID: " + rslt);
x.printStackTrace();
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
} catch (OutOfMemoryError error)
{
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
// consensus = null;
// hconsensus = null;
ap.raiseOOMWarning(getServiceActionText(), error);
} catch (Exception x)
{
- calcMan.workerCannotRun(this);
+ calcMan.disableWorker(this);
// consensus = null;
// hconsensus = null;
}
// reinstate worker if it was blacklisted (might have happened due to
// invalid parameters)
- alignFrame.getViewport().getCalcManager().workerMayRun(worker);
+ alignFrame.getViewport().getCalcManager().enableWorker(worker);
worker.updateParameters(this.preset, paramset);
}
}