mirror of
https://github.com/ethauvin/rife2.git
synced 2025-05-01 19:08:12 -07:00
Workflow work waiting tweaks.
This commit is contained in:
parent
9d04473685
commit
2e127ddd93
1 changed files with 23 additions and 13 deletions
|
@ -58,7 +58,17 @@ public class Workflow {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new workflow instance with a provided executor.
|
* Creates a new workflow instance with a provided parent properties.
|
||||||
|
*
|
||||||
|
* @param properties the parent hierarchical properties
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
public Workflow(HierarchicalProperties properties) {
|
||||||
|
this(Executors.newCachedThreadPool(), properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new workflow instance.
|
||||||
*
|
*
|
||||||
* @param executor the executor to use for running the work
|
* @param executor the executor to use for running the work
|
||||||
* @param properties the parent hierarchical properties
|
* @param properties the parent hierarchical properties
|
||||||
|
@ -103,12 +113,12 @@ public class Workflow {
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public void start(final Class<? extends Work> klass) {
|
public void start(final Class<? extends Work> klass) {
|
||||||
|
activeWorkCount_.increment();
|
||||||
workExecutor_.submit(() -> {
|
workExecutor_.submit(() -> {
|
||||||
try {
|
try {
|
||||||
activeWorkCount_.increment();
|
|
||||||
runner_.start(klass);
|
runner_.start(klass);
|
||||||
activeWorkCount_.decrement();
|
|
||||||
|
|
||||||
|
activeWorkCount_.decrement();
|
||||||
signalWhenAllWorkFinished();
|
signalWhenAllWorkFinished();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -123,12 +133,12 @@ public class Workflow {
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public void start(Work work) {
|
public void start(Work work) {
|
||||||
|
activeWorkCount_.increment();
|
||||||
workExecutor_.submit(() -> {
|
workExecutor_.submit(() -> {
|
||||||
try {
|
try {
|
||||||
activeWorkCount_.increment();
|
|
||||||
runner_.start(work);
|
runner_.start(work);
|
||||||
activeWorkCount_.decrement();
|
|
||||||
|
|
||||||
|
activeWorkCount_.decrement();
|
||||||
signalWhenAllWorkFinished();
|
signalWhenAllWorkFinished();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -286,12 +296,12 @@ public class Workflow {
|
||||||
*/
|
*/
|
||||||
public void waitForPausedWork()
|
public void waitForPausedWork()
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
workLock_.lock();
|
|
||||||
try {
|
|
||||||
if (!eventsMapping_.isEmpty()) {
|
if (!eventsMapping_.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workLock_.lock();
|
||||||
|
try {
|
||||||
workPaused_.await();
|
workPaused_.await();
|
||||||
} finally {
|
} finally {
|
||||||
workLock_.unlock();
|
workLock_.unlock();
|
||||||
|
@ -306,12 +316,12 @@ public class Workflow {
|
||||||
*/
|
*/
|
||||||
public void waitForNoWork()
|
public void waitForNoWork()
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
workLock_.lock();
|
|
||||||
try {
|
|
||||||
if (activeWorkCount_.sum() == 0) {
|
if (activeWorkCount_.sum() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workLock_.lock();
|
||||||
|
try {
|
||||||
workFinished_.await();
|
workFinished_.await();
|
||||||
} finally {
|
} finally {
|
||||||
workLock_.unlock();
|
workLock_.unlock();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue