Search in sources :

Example 6 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class TableSorterWorker method doInBackground.

/**
 * {@inheritDoc}
 */
@Override
protected DataTable doInBackground() throws Exception {
    // passed to table sorter for progress
    long rowCount;
    if (m_inputTable instanceof BufferedDataTable) {
        rowCount = ((BufferedDataTable) m_inputTable).size();
    } else if (m_inputTable instanceof ContainerTable) {
        rowCount = ((ContainerTable) m_inputTable).size();
    } else {
        // unknown, no progress
        rowCount = -1;
    }
    publish(new NodeProgress(0.0, "Starting table sort..."));
    Collection<String> sortColNames = new ArrayList<String>(2);
    DataTableSpec spec = m_inputTable.getDataTableSpec();
    for (int i : m_sortOrder.getSortColumnIndices()) {
        String name;
        if (i < 0) {
            // row id
            name = DataTableSorter.ROWKEY_SORT_SPEC.getName();
        } else {
            name = spec.getColumnSpec(i).getName();
        }
        sortColNames.add(name);
    }
    long start = System.currentTimeMillis();
    LOGGER.debug("Starting interactive table sorting on column(s) " + sortColNames);
    boolean[] sortOrders = m_sortOrder.getSortColumnOrder();
    // it DOES NOT respect blobs -- they will be copied (expensive)
    DataTableSorter sorter = new DataTableSorter(m_inputTable, rowCount, sortColNames, sortOrders, false);
    NodeProgressListener progLis = new NodeProgressListener() {

        @Override
        public void progressChanged(final NodeProgressEvent pe) {
            publish(pe.getNodeProgress());
        }
    };
    m_nodeProgressMonitor = new DefaultNodeProgressMonitor();
    ExecutionMonitor exec = new ExecutionMonitor(m_nodeProgressMonitor);
    m_nodeProgressMonitor.addProgressListener(progLis);
    try {
        DataTable result = sorter.sort(exec);
        long elapsedMS = System.currentTimeMillis() - start;
        String time = StringFormat.formatElapsedTime(elapsedMS);
        LOGGER.debug("Interactive table sorting finished (" + time + ")");
        return result;
    } finally {
        m_nodeProgressMonitor.removeProgressListener(progLis);
    }
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) ArrayList(java.util.ArrayList) ContainerTable(org.knime.core.data.container.ContainerTable) NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) DataTableSorter(org.knime.core.data.sort.DataTableSorter) DefaultNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor) BufferedDataTable(org.knime.core.node.BufferedDataTable) ExecutionMonitor(org.knime.core.node.ExecutionMonitor)

Example 7 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class DefaultNodeProgressMonitor method fireProgressChanged.

private void fireProgressChanged() {
    m_changed = false;
    NodeProgress pe = new NodeProgress(getProgress(), createMessage(m_messageSupplier, m_appendSupplier));
    for (NodeProgressListener l : m_listeners) {
        try {
            // we can't provide a useful node id here
            // TODO replace by null argument (0 is certainly misleading)
            l.progressChanged(new NodeProgressEvent(new NodeID(0), pe));
        } catch (Throwable t) {
            LOGGER.error("Exception while notifying listeners", t);
        }
    }
}
Also used : NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) NodeID(org.knime.core.node.workflow.NodeID)

Example 8 with NodeProgress

use of org.knime.core.node.workflow.NodeProgress in project knime-core by knime.

the class DefaultNodeProgressMonitorTest method internalTestManySmallIncrements.

/**
 * Just a lot of incremental numeric progress updates.
 */
private void internalTestManySmallIncrements(final NodeProgressMonitor toMonitor, final NodeProgressMonitor toControl) throws Exception {
    final Pointer<NodeProgress> progressPointer = new Pointer<>();
    final Function<NodeProgress, Boolean> isLastEventFunction = p -> p.getProgress() >= 1.0 - PROG_EPSILON;
    NodeProgressListener l = createListener(progressPointer, isLastEventFunction);
    toMonitor.addProgressListener(l);
    try {
        int parts = 10000000;
        for (int i = 0; i < parts; i++) {
            toControl.setProgress((i + 1) / (double) parts);
        }
        synchronized (isLastEventFunction) {
            isLastEventFunction.wait(1000);
        }
        assertThat(progressPointer.get().getProgress(), is(closeTo(1.0, PROG_EPSILON)));
    } finally {
        toMonitor.removeProgressListener(l);
    }
}
Also used : Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) RowKey(org.knime.core.data.RowKey) Matchers.allOf(org.hamcrest.Matchers.allOf) Test(org.junit.Test) Function(java.util.function.Function) NodeProgressEvent(org.knime.core.node.workflow.NodeProgressEvent) Assert.assertThat(org.junit.Assert.assertThat) Matchers.closeTo(org.hamcrest.Matchers.closeTo) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.lessThan(org.hamcrest.Matchers.lessThan) Matchers.is(org.hamcrest.Matchers.is) Assert(org.junit.Assert) SubNodeProgressMonitor(org.knime.core.node.DefaultNodeProgressMonitor.SubNodeProgressMonitor) Pointer(org.knime.core.util.Pointer) NodeProgress(org.knime.core.node.workflow.NodeProgress) NodeProgressListener(org.knime.core.node.workflow.NodeProgressListener) NodeProgress(org.knime.core.node.workflow.NodeProgress) Pointer(org.knime.core.util.Pointer)

Aggregations

NodeProgress (org.knime.core.node.workflow.NodeProgress)8 NodeProgressEvent (org.knime.core.node.workflow.NodeProgressEvent)7 NodeProgressListener (org.knime.core.node.workflow.NodeProgressListener)6 Test (org.junit.Test)4 Function (java.util.function.Function)2 MutableLong (org.apache.commons.lang3.mutable.MutableLong)2 Matchers.allOf (org.hamcrest.Matchers.allOf)2 Matchers.closeTo (org.hamcrest.Matchers.closeTo)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)2 Matchers.is (org.hamcrest.Matchers.is)2 Matchers.lessThan (org.hamcrest.Matchers.lessThan)2 Assert (org.junit.Assert)2 Assert.assertThat (org.junit.Assert.assertThat)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 RowKey (org.knime.core.data.RowKey)2 SubNodeProgressMonitor (org.knime.core.node.DefaultNodeProgressMonitor.SubNodeProgressMonitor)2 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)2 NodeID (org.knime.core.node.workflow.NodeID)2 Pointer (org.knime.core.util.Pointer)2