use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class FileUtil method copy.
/**
* Copies a file. The implementation uses a temporary buffer of 8kB. This
* method will report progress to the given execution monitor and will also
* check a canceled status. The copy process will report progress in the
* full range of the execution monitor. Consider to use a sub-execution
* monitor if the copy process is only a small part of the entire work.
*
* @param file The file to copy.
* @param destination The destination file, fully qualified (do not provide
* a directory).
* @param exec The execution monitor for progress information.
* @throws CanceledExecutionException If canceled. The destination file will
* be deleted.
* @throws IOException If that fail for any reason.
*/
public static void copy(final File file, final File destination, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
final long size = file.length();
byte[] cache = new byte[BUFF_SIZE];
CanceledExecutionException cee = null;
try (OutputStream copyOutStream = new FileOutputStream(destination);
InputStream copyInStream = new FileInputStream(file)) {
int read;
long processed = 0;
exec.setMessage("Copying \"" + file.getName() + "\"");
while ((read = copyInStream.read(cache, 0, cache.length)) > 0) {
copyOutStream.write(cache, 0, read);
processed += read;
exec.setProgress(processed / (double) size);
try {
exec.checkCanceled();
} catch (CanceledExecutionException c) {
cee = c;
break;
}
}
}
// delete destination file if canceled.
if (cee != null) {
if (!destination.delete()) {
LOGGER.warn("Unable to delete \"" + destination.getName() + "\" after copying has been canceled.");
}
throw cee;
}
}
use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.
the class NativeNodeContainer method performExecuteNode.
/**
* {@inheritDoc}
*/
@Override
public NodeContainerExecutionStatus performExecuteNode(final PortObject[] inObjects) {
ExecutionContext ec = createExecutionContext();
m_node.openFileStoreHandler(ec);
ExecutionEnvironment ev = getExecutionEnvironment();
boolean success;
try {
ec.checkCanceled();
success = true;
} catch (CanceledExecutionException e) {
String errorString = "Execution canceled";
LOGGER.warn(errorString);
setNodeMessage(new NodeMessage(NodeMessage.Type.WARNING, errorString));
success = false;
}
NodeContext.pushContext(this);
try {
// execute node outside any synchronization!
success = success && m_node.execute(inObjects, ev, ec);
} finally {
NodeContext.removeLastContext();
}
if (success) {
// output tables are made publicly available (for blobs)
putOutputTablesIntoGlobalRepository(ec);
} else {
// something went wrong: reset and configure node to reach
// a solid state again will be done by WorkflowManager (in
// doAfterExecute().
}
return success ? NodeContainerExecutionStatus.SUCCESS : NodeContainerExecutionStatus.FAILURE;
}
Aggregations