use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class HierarAlignerGcModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
Task newTask = new HierarAlignerGCTask(project, parameters);
tasks.add(newTask);
return ExitCode.OK;
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class SmoothingModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(SmoothingParameters.peakLists).getValue().getMatchingPeakLists();
for (final PeakList peakList : peakLists) {
Task newTask = new SmoothingTask(project, peakList, parameters);
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class DataPointProcessingController method execute.
/**
* This will execute the modules associated with the plot. It will start with the first one and
* execute the following ones afterwards automatically. This method is called by the public method
* execute(). The status listener in this method starts the next task recursively after the
* previous one has finished.
*
* @param dp
* @param module
* @param plot
*/
private void execute(DataPoint[] dp, MZmineProcessingStep<DataPointProcessingModule> step, SpectraPlot plot) {
if (queue == null || queue.isEmpty() || plot == null) {
logger.warning("execute called, without queue or plot being set.");
setStatus(ControllerStatus.FINISHED);
return;
}
if (getForcedStatus() == ForcedControllerStatus.CANCEL || getStatus() == ControllerStatus.CANCELED) {
setResults(ProcessedDataPoint.convert(dp));
logger.finest("Canceled controller, not starting new tasks. Results are set to latest array.");
setStatus(ControllerStatus.CANCELED);
return;
}
List<String> err = new ArrayList<>();
if (!step.getParameterSet().checkParameterValues(err)) {
setResults(ProcessedDataPoint.convert(dp));
setStatus(ControllerStatus.CANCELED);
logger.warning(step.getModule().getName() + " - Not all parameters set." + Arrays.toString(err.toArray(new String[0])));
return;
}
if (step.getModule() instanceof DataPointProcessingModule) {
DataPointProcessingModule inst = step.getModule();
ParameterSet parameters = step.getParameterSet();
Task t = ((DataPointProcessingModule) inst).createTask(dp, parameters, plot, this, new TaskStatusListener() {
@Override
public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
if (!(task instanceof DataPointProcessingTask)) {
// TODO: Throw exception?
logger.warning("This should have been a DataPointProcessingTask.");
return;
}
// logger.finest("Task status changed to " + newStatus.toString());
switch(newStatus) {
case FINISHED:
if (queue.hasNextStep(step)) {
if (DataPointProcessingManager.getInst().isRunning(((DataPointProcessingTask) task).getController())) {
MZmineProcessingStep<DataPointProcessingModule> next = queue.getNextStep(step);
// pass results to next task and start recursively
ProcessedDataPoint[] result = ((DataPointProcessingTask) task).getResults();
((DataPointProcessingTask) task).displayResults();
execute(result, next, plot);
} else {
logger.warning("This controller was already removed from the running list, although it " + "had not finished processing. Exiting");
break;
}
} else {
setResults(((DataPointProcessingTask) task).getResults());
((DataPointProcessingTask) task).displayResults();
setStatus(ControllerStatus.FINISHED);
}
break;
case PROCESSING:
setStatus(ControllerStatus.PROCESSING);
break;
case WAITING:
// should we even set to WAITING here?
break;
case ERROR:
setStatus(ControllerStatus.ERROR);
break;
case CANCELED:
setStatus(ControllerStatus.CANCELED);
break;
}
}
});
logger.finest("Start processing of " + t.getClass().getName());
MZmineCore.getTaskController().addTask(t);
// maybe we need this some time
setCurrentTask((DataPointProcessingTask) t);
setCurrentStep(step);
}
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class TaskQueue method getValueAt.
/**
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
public synchronized Object getValueAt(int row, int column) {
if (row < size) {
WrappedTask wrappedTask = queue[row];
Task actualTask = wrappedTask.getActualTask();
switch(column) {
case 0:
return actualTask.getTaskDescription();
case 1:
return wrappedTask.getPriority();
case 2:
return actualTask.getStatus();
case 3:
double finishedPercentage = actualTask.getFinishedPercentage();
LabeledProgressBar progressBar = progressBars.get(row);
if (progressBar == null) {
progressBar = new LabeledProgressBar(finishedPercentage);
progressBars.put(row, progressBar);
} else {
progressBar.setValue(finishedPercentage);
}
return progressBar;
}
}
return null;
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class WorkerThread method run.
/**
* @see java.lang.Runnable#run()
*/
public void run() {
Task actualTask = wrappedTask.getActualTask();
try {
// Log the start (INFO level events go to the Status bar, too)
logger.info("Starting processing of task " + actualTask.getTaskDescription());
// Process the actual task
actualTask.run();
// Check if task finished with an error
if (actualTask.getStatus() == TaskStatus.ERROR) {
String errorMsg = actualTask.getErrorMessage();
if (errorMsg == null)
errorMsg = "Unspecified error";
// Log the error
logger.severe("Error of task " + actualTask.getTaskDescription() + ": " + errorMsg);
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error of task " + actualTask.getTaskDescription(), errorMsg);
} else {
// Log the finish
logger.info("Processing of task " + actualTask.getTaskDescription() + " done, status " + actualTask.getStatus());
}
/*
* This is important to allow the garbage collector to remove the task, while keeping the task
* description in the "Tasks in progress" window
*/
wrappedTask.removeTaskReference();
} catch (Throwable e) {
/*
* This should never happen, it means the task did not handle its exception properly, or there
* was some severe error, like OutOfMemoryError
*/
logger.log(Level.SEVERE, "Unhandled exception " + e + " while processing task " + actualTask.getTaskDescription(), e);
e.printStackTrace();
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Unhandled exception in task " + actualTask.getTaskDescription() + ": " + ExceptionUtils.exceptionToString(e));
}
/*
* Mark this thread as finished
*/
finished = true;
}
Aggregations