use of org.knime.core.node.workflow.InternalNodeContainerState.EXECUTING in project knime-core by knime.
the class WorkflowManager method waitWhileInExecution.
/**
* Causes the current thread to wait until the the workflow has reached a non-executing state unless a given timeout
* elapsed.
*
* @param mutex The lock to sleep on (m_workflowMutex of the nodes/wfm to be waited for)
* @param time the maximum time to wait (0 or negative for waiting infinitely)
* @param unit the time unit of the {@code time} argument
* @return {@code false} if the waiting time detectably elapsed before return from the method, else {@code true}. It
* returns {@code true} if the time argument is 0 or negative.
* @throws InterruptedException if the current thread is interrupted
*/
private static boolean waitWhileInExecution(final WorkflowLock workflowLock, final NodeContainerStateObservable[] ncs, final long time, final TimeUnit unit) throws InterruptedException {
final ReentrantLock lock = workflowLock.getReentrantLock();
final Condition whileInExecCondition = lock.newCondition();
NodeStateChangeListener listener = new NodeStateChangeListener() {
@Override
public void stateChanged(final NodeStateEvent stateEvent) {
lock.lock();
try {
if (!containsExecutingNode(ncs)) {
whileInExecCondition.signalAll();
}
} finally {
lock.unlock();
}
}
};
lock.lockInterruptibly();
Arrays.stream(ncs).filter(nc -> nc != null).forEach(nc -> nc.addNodeStateChangeListener(listener));
try {
if (!containsExecutingNode(ncs)) {
return true;
}
if (time > 0) {
return whileInExecCondition.await(time, unit);
} else {
whileInExecCondition.await();
return true;
}
} finally {
lock.unlock();
Arrays.stream(ncs).filter(nc -> nc != null).forEach(nc -> nc.removeNodeStateChangeListener(listener));
}
}
Aggregations