Search in sources :

Example 6 with TaskStatus

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();
}
Also used : TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus)

Example 7 with TaskStatus

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);
        }
    }
}
Also used : CSVExportTask(net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask) AdapMgfExportTask(net.sf.mzmine.modules.peaklistmethods.io.adap.mgfexport.AdapMgfExportTask) Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) ArrayList(java.util.ArrayList) AllTasksFinishedListener(net.sf.mzmine.taskcontrol.AllTasksFinishedListener) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) File(java.io.File) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException)

Example 8 with TaskStatus

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
                }
            }
        }
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) ExitCode(net.sf.mzmine.util.ExitCode) ArrayList(java.util.ArrayList) MZmineProcessingModule(net.sf.mzmine.modules.MZmineProcessingModule) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) PeakListsSelection(net.sf.mzmine.parameters.parametertypes.selectors.PeakListsSelection) PeakListsParameter(net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter) PeakList(net.sf.mzmine.datamodel.PeakList) RawDataFilesParameter(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)

Example 9 with TaskStatus

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);
        }
    }
}
Also used : CSVExportTask(net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask) Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) ArrayList(java.util.ArrayList) AllTasksFinishedListener(net.sf.mzmine.taskcontrol.AllTasksFinishedListener) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) File(java.io.File)

Example 10 with TaskStatus

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();
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus)

Aggregations

TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)10 Task (net.sf.mzmine.taskcontrol.Task)7 ArrayList (java.util.ArrayList)4 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)4 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)2 File (java.io.File)2 CSVExportTask (net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask)2 ParameterSet (net.sf.mzmine.parameters.ParameterSet)2 AllTasksFinishedListener (net.sf.mzmine.taskcontrol.AllTasksFinishedListener)2 TaskStatusListener (net.sf.mzmine.taskcontrol.TaskStatusListener)2 PeakList (net.sf.mzmine.datamodel.PeakList)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)1 MZmineProcessingStep (net.sf.mzmine.modules.MZmineProcessingStep)1 AdapMgfExportTask (net.sf.mzmine.modules.peaklistmethods.io.adap.mgfexport.AdapMgfExportTask)1 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)1 PeakListsSelection (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsSelection)1 RawDataFilesParameter (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)1 RawDataFilesSelection (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection)1 TaskControllerImpl (net.sf.mzmine.taskcontrol.impl.TaskControllerImpl)1