use of net.sf.mzmine.taskcontrol.TaskStatus in project mzmine2 by mzmine.
the class TaskProgressTable method actionPerformed.
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent event) {
TaskControllerImpl taskController = (TaskControllerImpl) MZmineCore.getTaskController();
WrappedTask[] currentQueue = taskController.getTaskQueue().getQueueSnapshot();
Task selectedTask = null;
int selectedRow = taskTable.getSelectedRow();
if ((selectedRow < currentQueue.length) && (selectedRow >= 0))
selectedTask = currentQueue[selectedRow].getActualTask();
Object src = event.getSource();
if (src == cancelTaskMenuItem) {
if (selectedTask == null)
return;
TaskStatus status = selectedTask.getStatus();
if ((status == TaskStatus.WAITING) || (status == TaskStatus.PROCESSING)) {
selectedTask.cancel();
}
}
if (src == cancelAllMenuItem) {
for (WrappedTask wrappedTask : currentQueue) {
Task task = wrappedTask.getActualTask();
TaskStatus status = task.getStatus();
if ((status == TaskStatus.WAITING) || (status == TaskStatus.PROCESSING)) {
task.cancel();
}
}
}
if (src == highPriorityMenuItem) {
if (selectedTask == null)
return;
taskController.setTaskPriority(selectedTask, TaskPriority.HIGH);
}
if (src == normalPriorityMenuItem) {
if (selectedTask == null)
return;
taskController.setTaskPriority(selectedTask, TaskPriority.NORMAL);
}
}
use of net.sf.mzmine.taskcontrol.TaskStatus 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.TaskStatus in project mzmine2 by mzmine.
the class MultiThreadPeakFinderMainTask method run.
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running multithreaded gap filler on " + peakList);
// Create new results feature list
processedPeakList = createResultsPeakList();
progress = 0.5;
// split raw data files into groups for each thread (task)
// Obtain the settings of max concurrent threads
// as this task uses one thread
int maxRunningThreads = getMaxThreads();
// raw files
int raw = peakList.getNumberOfRawDataFiles();
// create consumer of resultpeaklist
SubTaskFinishListener listener = new SubTaskFinishListener(project, parameters, peakList, removeOriginal, maxRunningThreads);
// Submit the tasks to the task controller for processing
Task[] tasks = createSubTasks(raw, maxRunningThreads, listener);
// listener for status change: Cancel / error
TaskStatusListener list = new TaskStatusListener() {
@Override
public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
if (newStatus.equals(TaskStatus.CANCELED) || newStatus.equals(TaskStatus.ERROR)) {
// if one is cancelled, stop all
synchronized (this) {
// cancel all
for (Task t : tasks) {
if (t instanceof AbstractTask)
((AbstractTask) t).removeTaskStatusListener(this);
t.cancel();
}
}
}
}
};
// add listener to all sub tasks
for (Task t : tasks) {
if (t instanceof AbstractTask)
((AbstractTask) t).addTaskStatusListener(list);
// add to batchMode collection
if (batchTasks != null)
batchTasks.add(t);
}
// start
MZmineCore.getTaskController().addTasks(tasks);
// listener will take care of adding the final list
progress = 1;
// end
logger.info("All sub tasks started for multithreaded gap-filling on " + peakList);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.taskcontrol.TaskStatus in project mzmine2 by mzmine.
the class ResultWindow method dispose.
public void dispose() {
// Cancel the search task if it is still running
TaskStatus searchStatus = searchTask.getStatus();
if ((searchStatus == TaskStatus.WAITING) || (searchStatus == TaskStatus.PROCESSING))
searchTask.cancel();
super.dispose();
}
use of net.sf.mzmine.taskcontrol.TaskStatus in project mzmine2 by mzmine.
the class GnpsGcExportAndSubmitTask method run.
@Override
public void run() {
final AbstractTask thistask = this;
setStatus(TaskStatus.PROCESSING);
List<AbstractTask> list = new ArrayList<>(3);
// add mgf export task
list.add(addAdapMgfTask(parameters));
// add csv quant table
list.add(addQuantTableTask(parameters, null));
// finish listener to submit
final File fileName = file;
final File folder = file.getParentFile();
new AllTasksFinishedListener(list, true, // succeed
l -> {
try {
LOG.info("succeed" + thistask.getStatus().toString());
if (submit) {
GnpsGcSubmitParameters param = parameters.getParameter(GnpsGcExportAndSubmitParameters.SUBMIT).getEmbeddedParameters();
submit(fileName, param);
}
// open folder
try {
if (openFolder && Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(folder);
}
} catch (Exception ex) {
}
} finally {
// finish task
if (thistask.getStatus() == TaskStatus.PROCESSING)
thistask.setStatus(TaskStatus.FINISHED);
}
}, lerror -> {
setErrorMessage("GNPS-GC submit was not started due too errors while file export");
thistask.setStatus(TaskStatus.ERROR);
throw new MSDKRuntimeException("GNPS-GC submit was not started due too errors while file export");
}, // cancel if one was cancelled
listCancelled -> cancel()) {
@Override
public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
super.taskStatusChanged(task, newStatus, oldStatus);
// show progress
progress.getAndSet(getProgress());
}
};
MZmineCore.getTaskController().addTasks(list.toArray(new AbstractTask[list.size()]));
// wait till finish
while (!(isCanceled() || isFinished())) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.log(Level.SEVERE, "Error in GNPS-GC export/submit task", e);
}
}
}
Aggregations