package jalview.api;
+import java.util.List;
+
+import jalview.datamodel.AlignmentAnnotation;
+
public interface AlignCalcManagerI
{
void workerCannotRun(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);
+ /**
* launch a new worker
* @param worker
*/
*/
boolean isWorking();
+
+ /**
+ * register a restartable worker
+ * @param worker
+ */
+ void registerWorker(AlignCalcWorkerI worker);
+
+ /**
+ * restart any registered workers
+ */
+ void restartWorkers();
+
+ /**
+ *
+ * @param alignmentAnnotation
+ * @return true if a currently registered and working worker indicates its involvement with the given alignmentAnnotation
+ */
+ boolean workingInvolvedWith(AlignmentAnnotation alignmentAnnotation);
+
+ /**
+ * kick any known instances of the given worker class to update their annotation
+ * @param workerClass
+ */
+ void updateAnnotationFor(Class workerClass);
+
+ /**
+ * return any registered workers of the given class
+ * @param workerClass
+ * @return null or one or more workers of the given class
+ */
+ List<AlignCalcWorkerI> getRegisteredWorkersOfClass(
+ Class workerClass);
+
+ /**
+ * start any workers of the given class
+ * @param workerClass
+ * @return false if no workers of given class were registered
+ * (note - blacklisted classes cannot be restarted, so this method will return true for blacklisted workers)
+ */
+ boolean startRegisteredWorkersOfClass(Class workerClass);
+
}
protected AlignCalcManagerI calculator=new AlignCalcManager();
- jalview.workers.ConsensusThread consensusThread;
-
- StrucConsensusThread strucConsensusThread;
-
-
- private ConservationThread conservationThread;
-
/**
* trigger update of conservation annotation
*/
{
return;
}
-
- calculator.startWorker(conservationThread=new jalview.workers.ConservationThread(this, ap));
+ if (!calculator.startRegisteredWorkersOfClass(jalview.workers.ConservationThread.class))
+ {
+ calculator.registerWorker(new jalview.workers.ConservationThread(this, ap));
+ }
}
/**
{
return;
}
- calculator.startWorker(consensusThread = new ConsensusThread(this, ap));
+ if (!calculator.startRegisteredWorkersOfClass(ConsensusThread.class))
+ {
+ calculator.registerWorker(new ConsensusThread(this, ap));
+ }
}
// --------START Structure Conservation
{
return;
}
- calculator.startWorker(strucConsensusThread = new StrucConsensusThread(this,ap));
+ if (!calculator.startRegisteredWorkersOfClass(StrucConsensusThread.class))
+ {
+ calculator.registerWorker(new StrucConsensusThread(this,ap));
+ }
}
public boolean isCalcInProgress()
{
if (!alignmentAnnotation.autoCalculated)
return false;
- if ((calculator.isWorking(consensusThread) && consensus==alignmentAnnotation)
- || (calculator.isWorking(conservationThread) && (conservation==alignmentAnnotation || quality==alignmentAnnotation))
- || (calculator.isWorking(strucConsensusThread) && strucConsensus==alignmentAnnotation)
- )
+ if (calculator.workingInvolvedWith(alignmentAnnotation))
{
+// System.err.println("grey out ("+alignmentAnnotation.label+")");
return true;
}
return false;
// TODO: decouple settings setting from calculation when refactoring
// annotation update method from alignframe to viewport
this.showSequenceLogo = showSequenceLogo;
- if (consensusThread != null)
- {
- consensusThread.updateAnnotation();
- }
- if (strucConsensusThread != null)
- {
- strucConsensusThread.updateAnnotation();
- }
+ calculator.updateAnnotationFor(ConsensusThread.class);
+ calculator.updateAnnotationFor(StrucConsensusThread.class);
}
this.showSequenceLogo = showSequenceLogo;
}
}
resetAllColourSchemes();
-
+ calculator.restartWorkers();
// alignment.adjustSequenceAnnotations();
}
package jalview.workers;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import jalview.api.AlignCalcManagerI;
import jalview.api.AlignCalcWorkerI;
+import jalview.datamodel.AlignmentAnnotation;
public class AlignCalcManager implements AlignCalcManagerI
{
+ private volatile List<AlignCalcWorkerI> restartable = new ArrayList<AlignCalcWorkerI>();
+
private List<Class> blackList = new ArrayList<Class>();
/**
updating.put(worker.getClass(),
upd = new ArrayList<AlignCalcWorkerI>());
}
- // upd.add(worker);
+ upd.add(worker);
}
@Override
- public synchronized boolean alreadyDoing(AlignCalcWorkerI worker)
+ public synchronized boolean alreadyDoing(AlignCalcWorkerI worker)
{
return inProgress.containsKey(worker.getClass());
}
return true;
}
+ private HashSet<AlignCalcWorkerI> canUpdate=new HashSet<AlignCalcWorkerI>();
@Override
public synchronized void workerComplete(AlignCalcWorkerI worker)
{
if (upd != null)
{
upd.remove(worker);
+ canUpdate.add(worker);
}
}
@Override
public synchronized boolean isWorking(AlignCalcWorkerI worker)
{
-// System.err.println("isWorking : worker "+(worker!=null ? worker.getClass():"null")+ " "+hashCode());
- return worker!=null && inProgress.get(worker.getClass()) == worker;
+ // System.err.println("isWorking : worker "+(worker!=null ?
+ // worker.getClass():"null")+ " "+hashCode());
+ return worker != null && inProgress.get(worker.getClass()) == worker;
}
+
@Override
public boolean isWorking()
{
-// System.err.println("isWorking "+hashCode());
- return inProgress.size()>0;
+ // System.err.println("isWorking "+hashCode());
+ return inProgress.size() > 0;
+ }
+
+ @Override
+ public void registerWorker(AlignCalcWorkerI worker)
+ {
+ if (!restartable.contains(worker))
+ {
+ restartable.add(worker);
+ }
+ startWorker(worker);
+ }
+
+ @Override
+ public void restartWorkers()
+ {
+ for (AlignCalcWorkerI worker : restartable)
+ {
+ startWorker(worker);
+ }
+ }
+
+ @Override
+ public boolean workingInvolvedWith(AlignmentAnnotation alignmentAnnotation)
+ {
+ if (isWorking())
+ {
+ for (List<AlignCalcWorkerI> workers: updating.values())
+ {
+ for (AlignCalcWorkerI worker:workers)
+ if (worker.involves(alignmentAnnotation))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void updateAnnotationFor(Class workerClass)
+ {
+ for (AlignCalcWorkerI worker:canUpdate.toArray(new AlignCalcWorkerI[1]))
+ {
+ if (workerClass.equals(worker.getClass()))
+ {
+ worker.updateAnnotation();
+ }
+ }
+ }
+
+ @Override
+ public List<AlignCalcWorkerI> getRegisteredWorkersOfClass(
+ Class workerClass)
+ {
+ List<AlignCalcWorkerI> workingClass=new ArrayList<AlignCalcWorkerI>();
+ for (AlignCalcWorkerI worker:canUpdate.toArray(new AlignCalcWorkerI[0]))
+ {
+ if (workerClass.equals(worker.getClass()))
+ {
+ workingClass.add(worker);
+ }
+ }
+ return (workingClass.size()==0) ? null : workingClass;
+ }
+
+ @Override
+ public boolean startRegisteredWorkersOfClass(Class workerClass)
+ {
+ List<AlignCalcWorkerI> workers=getRegisteredWorkersOfClass(workerClass);
+ if (workers==null)
+ {
+ return false;
+ }
+ for (AlignCalcWorkerI worker: workers) {
+ startWorker(worker);
+ }
+ return true;
+ }
+
+ @Override
+ public void workerMayRun(AlignCalcWorkerI worker)
+ {
+ if (blackList.contains(worker.getClass()))
+ {
+ blackList.remove(worker.getClass());
+ }
}
}
*/
package jalview.workers;
+import java.util.ArrayList;
+import java.util.List;
+
import jalview.analysis.Conservation;
import jalview.api.AlignCalcWorkerI;
import jalview.api.AlignmentViewPanel;
super(alignViewport, alignPanel);
ConsPercGaps = alignViewport.getConsPercGaps();
}
-
+
+ private Conservation cons;
+ AlignmentAnnotation conservation,quality;
+ int alWidth;
public void run()
{
try
if (alignViewport.isClosed()) {
abortAndDestroy();
}
-
+ List<AlignmentAnnotation>ourAnnot = new ArrayList<AlignmentAnnotation>();
AlignmentI alignment=alignViewport.getAlignment();
- AlignmentAnnotation conservation=alignViewport.getAlignmentConservationAnnotation();
- AlignmentAnnotation quality=alignViewport.getAlignmentQualityAnnot();
+ conservation=alignViewport.getAlignmentConservationAnnotation();
+ quality=alignViewport.getAlignmentQualityAnnot();
+ ourAnnot.add(conservation);
+ ourAnnot.add(quality);
+ ourAnnots = ourAnnot;
+
// AlignViewport.UPDATING_CONSERVATION = true;
-
- int alWidth;
if (alignment==null || (alWidth=alignment.getWidth())< 0)
{
return;
}
- Conservation cons = Conservation.calculateConservation("All",
+ cons = Conservation.calculateConservation("All",
jalview.schemes.ResidueProperties.propHash, 3,
alignment.getSequences(), 0, alWidth - 1, false, ConsPercGaps, quality!=null);
- cons.completeAnnotations(conservation,
- quality, 0, alWidth);
+ updateResultAnnotation(true);
} catch (OutOfMemoryError error)
{
ap.raiseOOMWarning("calculating conservation", error);
}
}
+
+ private void updateResultAnnotation(boolean b)
+ {
+ if (b || !calcMan.isWorking(this) && cons!=null && conservation!=null && quality!=null)
+ cons.completeAnnotations(conservation,
+ quality, 0, alWidth);
+ }
+ @Override
+ public void updateAnnotation()
+ {
+ updateResultAnnotation(false);
+
+ }
}
{
super(alignViewport, alignPanel);
}
+ AlignmentAnnotation strucConsensus;
+ Hashtable[] hStrucConsensus;
+
public void run()
{
try
calcMan.workerComplete(this);
return;
}
- AlignmentAnnotation strucConsensus=alignViewport.getAlignmentStrucConsensusAnnotation();
- Hashtable[] hStrucConsensus=alignViewport.getRnaStructureConsensusHash();
+ strucConsensus=alignViewport.getAlignmentStrucConsensusAnnotation();
+ hStrucConsensus=alignViewport.getRnaStructureConsensusHash();
strucConsensus.annotations = null;
strucConsensus.annotations = new Annotation[aWidth];
public void updateResultAnnotation(boolean immediate)
{
- AlignmentAnnotation strucConsensus = alignViewport
- .getAlignmentStrucConsensusAnnotation();
- Hashtable[] hStrucConsensus = alignViewport.getRnaStructureConsensusHash();
if (immediate || !calcMan.isWorking(this) && strucConsensus!=null && hStrucConsensus!=null)
{
StructureFrequency.completeConsensus(strucConsensus,