use of org.knime.core.util.MutableBoolean in project knime-core by knime.
the class CommandExecution method execute.
/**
* Executes the commands via the Runtime and streams the stdout as well as
* the stderr to the logger and notifies the registered observer if a msg
* occurs.
*
* @see Runtime#exec(String[], String[], File)
*
* @param exec The <code>ExecutionMonitor</code> to monitor the status of
* execution and to check for user cancellations.
*
* @return The exit value of the subprocess.
*
* @throws Exception If the execution terminates abnormally.
*/
public int execute(final ExecutionMonitor exec) throws Exception {
// execute the command
int exitVal;
try {
exec.setProgress("Starting command");
Runtime rt = Runtime.getRuntime();
LOGGER.debug("Launching command: '" + getCmdString() + "'");
exec.setProgress("External command is running...");
final Process proc;
if (m_cmds != null) {
assert m_cmd == null;
proc = rt.exec(m_cmds, m_envps, m_dir);
} else {
assert m_cmds == null;
proc = rt.exec(m_cmd, m_envps, m_dir);
}
// create a thread that periodically checks for user cancellation
final MutableBoolean procDone = new MutableBoolean(false);
ThreadUtils.threadWithContext(new CheckCanceledRunnable(proc, procDone, exec)).start();
// pick up the output to std err from the executable
Thread stdErrThread = ThreadUtils.threadWithContext(new StdErrCatchRunnable(proc, exec, m_extErrout));
stdErrThread.setName("ExtTool StdErr collector");
stdErrThread.start();
// pick up the output to std out from the executable
Thread stdOutThread = ThreadUtils.threadWithContext(new StdOutCatchRunnable(proc, exec, m_extOutput));
stdOutThread.setName("ExtTool StdOut collector");
stdOutThread.start();
// wait until the external process finishes.
exitVal = proc.waitFor();
synchronized (procDone) {
// this should terminate the check cancel thread
procDone.setValue(true);
}
exec.checkCanceled();
exec.setProgress("External command done.");
String message = "External commands terminated with exit code: " + exitVal;
if (exitVal == 0) {
LOGGER.debug(message);
} else {
LOGGER.info(message);
}
} catch (InterruptedException ie) {
throw ie;
} catch (Exception e) {
LOGGER.error("Execution failed (with exception): " + e.getMessage(), e);
throw e;
} catch (Throwable t) {
LOGGER.fatal("Execution failed (with error): " + t.getMessage(), t);
throw new Exception(t);
}
return exitVal;
}
use of org.knime.core.util.MutableBoolean in project knime-core by knime.
the class BatchExecutor method executeWorkflow.
/**
* Executes a workflow.
*
* @param wfm the workflow manager
* @param config the corresponding workflow configuration
* @return <code>true</code> if the workflow executed successfully, <code>false</code> otherwise
* @throws CanceledExecutionException if execution has been canceled by the user
* @throws BatchException may be thrown by subclass implementations; the real exception is available via the cause
* of the batch exception
* @since 2.7
*/
protected boolean executeWorkflow(final WorkflowManager wfm, final WorkflowConfiguration config) throws CanceledExecutionException, BatchException {
LOGGER.debug("Status of workflow before execution:");
LOGGER.debug("------------------------------------");
dumpWorkflowToDebugLog(wfm);
LOGGER.debug("------------------------------------");
boolean successful = true;
final MutableBoolean executionCanceled = new MutableBoolean(false);
if (!config.noExecute) {
// get workspace dir
File wsFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
// file to be checked for
final File cancelFile = new File(wsFile, ".cancel");
// create new timer task
TimerTask task = new TimerTask() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
if (cancelFile.exists()) {
// CANCEL workflow manager
wfm.cancelExecution();
// delete cancel file
cancelFile.delete();
executionCanceled.setValue(true);
// cancel this timer
this.cancel();
}
}
};
KNIMETimer.getInstance().schedule(task, 1000, 1000);
successful = wfm.executeAllAndWaitUntilDone();
task.cancel();
}
if (executionCanceled.booleanValue()) {
throw new CanceledExecutionException();
}
return successful;
}
use of org.knime.core.util.MutableBoolean in project knime-core by knime.
the class KNIMEApplication method checkForUpdates.
private boolean checkForUpdates() {
final IPreferenceStore prefStore = ProductPlugin.getDefault().getPreferenceStore();
if (prefStore.getBoolean(JUSTUPDATED)) {
prefStore.setValue(JUSTUPDATED, false);
return false;
}
final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
if (provUI.getRepositoryTracker() == null) {
LogHelper.log(new Status(IStatus.WARNING, ProductPlugin.getDefault().getBundle().getSymbolicName(), "Updating is not possible of KNIME is started from " + "within the IDE."));
return false;
}
final IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(ProductPlugin.getDefault().getBundle().getBundleContext(), IProvisioningAgent.SERVICE_NAME);
if (agent == null) {
LogHelper.log(new Status(IStatus.ERROR, ProductPlugin.getDefault().getBundle().getSymbolicName(), "No provisioning agent found. This application is " + "not set up for updates."));
}
final MutableBoolean restart = new MutableBoolean(false);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ProvisioningSession session = new ProvisioningSession(agent);
UpdateOperation operation = new UpdateOperation(session);
SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
IStatus status = operation.resolveModal(sub.newChild(100));
if (status.getSeverity() == IStatus.CANCEL) {
throw new OperationCanceledException();
} else if (status.getSeverity() != IStatus.ERROR) {
ProvisioningJob job = operation.getProvisioningJob(null);
status = job.runModal(sub.newChild(100));
if (status.getSeverity() == IStatus.CANCEL) {
throw new OperationCanceledException();
}
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
// ok, just proceed
LogHelper.log(new Status(IStatus.INFO, ProductPlugin.getDefault().getBundle().getSymbolicName(), "No updates found."));
} else if (status.getSeverity() != IStatus.ERROR) {
prefStore.setValue(JUSTUPDATED, true);
restart.setValue(true);
} else {
LogHelper.log(status);
}
} else {
LogHelper.log(status);
}
}
};
try {
new ProgressMonitorDialog(null).run(true, true, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
}
return restart.booleanValue();
}
Aggregations