Search in sources :

Example 81 with CanceledExecutionException

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;
    }
}
Also used : CanceledExecutionException(org.knime.core.node.CanceledExecutionException) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipOutputStream(java.util.zip.ZipOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 82 with CanceledExecutionException

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;
}
Also used : ExecutionContext(org.knime.core.node.ExecutionContext) CanceledExecutionException(org.knime.core.node.CanceledExecutionException)

Aggregations

CanceledExecutionException (org.knime.core.node.CanceledExecutionException)82 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)34 IOException (java.io.IOException)32 File (java.io.File)21 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)21 DataRow (org.knime.core.data.DataRow)20 DataTableSpec (org.knime.core.data.DataTableSpec)20 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 DataCell (org.knime.core.data.DataCell)19 ArrayList (java.util.ArrayList)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)10 LinkedHashMap (java.util.LinkedHashMap)9 ExecutionException (java.util.concurrent.ExecutionException)9 DefaultRow (org.knime.core.data.def.DefaultRow)9 RowKey (org.knime.core.data.RowKey)8 BufferedWriter (java.io.BufferedWriter)7 FileInputStream (java.io.FileInputStream)7 Map (java.util.Map)7 Future (java.util.concurrent.Future)7