Search in sources :

Example 1 with TaskStatus

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

Example 2 with TaskStatus

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);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Task(net.sf.mzmine.taskcontrol.Task) ArrayList(java.util.ArrayList) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) TaskStatusListener(net.sf.mzmine.taskcontrol.TaskStatusListener) MZmineProcessingStep(net.sf.mzmine.modules.MZmineProcessingStep)

Example 3 with TaskStatus

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

Example 4 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 5 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)

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