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);
}
}
}
use of net.sf.mzmine.taskcontrol.TaskStatus in project mzmine2 by mzmine.
the class BatchTask method processQueueStep.
private void processQueueStep(int stepNumber) {
logger.info("Starting step # " + (stepNumber + 1));
// Run next step of the batch
MZmineProcessingStep<?> currentStep = queue.get(stepNumber);
MZmineProcessingModule method = (MZmineProcessingModule) currentStep.getModule();
ParameterSet batchStepParameters = currentStep.getParameterSet();
// the ones from the previous step
if (createdDataFiles.isEmpty())
createdDataFiles.addAll(previousCreatedDataFiles);
if (createdPeakLists.isEmpty())
createdPeakLists.addAll(previousCreatedPeakLists);
// state of the batch
for (Parameter<?> p : batchStepParameters.getParameters()) {
if (p instanceof RawDataFilesParameter) {
RawDataFilesParameter rdp = (RawDataFilesParameter) p;
RawDataFile[] createdFiles = createdDataFiles.toArray(new RawDataFile[0]);
final RawDataFilesSelection selectedFiles = rdp.getValue();
if (selectedFiles == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Invalid parameter settings for module " + method.getName() + ": " + "Missing parameter value for " + p.getName());
return;
}
selectedFiles.setBatchLastFiles(createdFiles);
}
}
// state of the batch
for (Parameter<?> p : batchStepParameters.getParameters()) {
if (p instanceof PeakListsParameter) {
PeakListsParameter rdp = (PeakListsParameter) p;
PeakList[] createdPls = createdPeakLists.toArray(new PeakList[0]);
final PeakListsSelection selectedPeakLists = rdp.getValue();
if (selectedPeakLists == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Invalid parameter settings for module " + method.getName() + ": " + "Missing parameter value for " + p.getName());
return;
}
selectedPeakLists.setBatchLastPeakLists(createdPls);
}
}
// Clear the saved data files and feature lists. Save them to the
// "previous" lists, in case the next step does not produce any new data
previousCreatedDataFiles.clear();
previousCreatedDataFiles.addAll(createdDataFiles);
previousCreatedPeakLists.clear();
previousCreatedPeakLists.addAll(createdPeakLists);
createdDataFiles.clear();
createdPeakLists.clear();
// Check if the parameter settings are valid
ArrayList<String> messages = new ArrayList<String>();
boolean paramsCheck = batchStepParameters.checkParameterValues(messages);
if (!paramsCheck) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Invalid parameter settings for module " + method.getName() + ": " + Arrays.toString(messages.toArray()));
}
ArrayList<Task> currentStepTasks = new ArrayList<Task>();
ExitCode exitCode = method.runModule(project, batchStepParameters, currentStepTasks);
if (exitCode != ExitCode.OK) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not start batch step " + method.getName());
return;
}
// If current step didn't produce any tasks, continue with next step
if (currentStepTasks.isEmpty())
return;
boolean allTasksFinished = false;
// Submit the tasks to the task controller for processing
MZmineCore.getTaskController().addTasks(currentStepTasks.toArray(new Task[0]));
while (!allTasksFinished) {
// If we canceled the batch, cancel all running tasks
if (isCanceled()) {
for (Task stepTask : currentStepTasks) stepTask.cancel();
return;
}
// First set to true, then check all tasks
allTasksFinished = true;
for (Task stepTask : currentStepTasks) {
TaskStatus stepStatus = stepTask.getStatus();
// If any of them is not finished, keep checking
if (stepStatus != TaskStatus.FINISHED)
allTasksFinished = false;
// If there was an error, we have to stop the whole batch
if (stepStatus == TaskStatus.ERROR) {
setStatus(TaskStatus.ERROR);
setErrorMessage(stepTask.getTaskDescription() + ": " + stepTask.getErrorMessage());
return;
}
// whole batch
if (stepStatus == TaskStatus.CANCELED) {
setStatus(TaskStatus.CANCELED);
for (Task t : currentStepTasks) t.cancel();
return;
}
}
// Wait 1s before checking the tasks again
if (!allTasksFinished) {
synchronized (this) {
try {
this.wait(1000);
} catch (InterruptedException e) {
// ignore
}
}
}
}
}
use of net.sf.mzmine.taskcontrol.TaskStatus in project mzmine2 by mzmine.
the class GnpsFbmnExportAndSubmitTask method run.
@Override
public void run() {
final AbstractTask thistask = this;
setStatus(TaskStatus.PROCESSING);
boolean openFolder = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.OPEN_FOLDER).getValue();
boolean submit = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.SUBMIT).getValue();
File file = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).getValue();
file = FileAndPathUtil.eraseFormat(file);
parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).setValue(file);
List<AbstractTask> list = new ArrayList<>(3);
GnpsFbmnMgfExportTask task = new GnpsFbmnMgfExportTask(parameters);
list.add(task);
// 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) {
GnpsFbmnSubmitParameters param = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.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 submit was not started due too errors while file export");
thistask.setStatus(TaskStatus.ERROR);
throw new MSDKRuntimeException("GNPS 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 export/submit task", e);
}
}
}
use of net.sf.mzmine.taskcontrol.TaskStatus in project mzmine2 by mzmine.
the class TICVisualizerWindow method dispose.
@Override
public void dispose() {
// If the window is closed, we want to cancel all running tasks of the
// data sets
Task[] tasks = this.ticDataSets.values().toArray(new Task[0]);
for (Task task : tasks) {
TaskStatus status = task.getStatus();
if ((status == TaskStatus.WAITING) || (status == TaskStatus.PROCESSING)) {
task.cancel();
}
}
super.dispose();
}
Aggregations