Search in sources :

Example 1 with AllTasksFinishedListener

use of net.sf.mzmine.taskcontrol.AllTasksFinishedListener 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 2 with AllTasksFinishedListener

use of net.sf.mzmine.taskcontrol.AllTasksFinishedListener 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)

Aggregations

MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 CSVExportTask (net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask)2 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)2 AllTasksFinishedListener (net.sf.mzmine.taskcontrol.AllTasksFinishedListener)2 Task (net.sf.mzmine.taskcontrol.Task)2 TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)2 AdapMgfExportTask (net.sf.mzmine.modules.peaklistmethods.io.adap.mgfexport.AdapMgfExportTask)1