From 4ac07c647a44617e63d296e4f77abbf56c52104d Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Mon, 16 Jun 2008 15:41:54 +0000 Subject: [PATCH] add: methods waitForStarted(), waitForFinished(), waitForCleanedUp() SVN: 6630 --- .../common/concurrent/TerminableCallable.java | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/common/source/java/ch/systemsx/cisd/common/concurrent/TerminableCallable.java b/common/source/java/ch/systemsx/cisd/common/concurrent/TerminableCallable.java index 3111f9aa5e8..233dcc36361 100644 --- a/common/source/java/ch/systemsx/cisd/common/concurrent/TerminableCallable.java +++ b/common/source/java/ch/systemsx/cisd/common/concurrent/TerminableCallable.java @@ -493,13 +493,24 @@ public final class TerminableCallable<V> implements Callable<V>, ITerminable * Returns <code>true</code>, if the callable has already started running. */ public boolean hasStarted() + { + return waitForStarted(NO_WAIT_MILLIS); + } + + /** + * Waits for the callable to start running. The method waits at most <var>timeoutMillis</var> + * milli-seconds. + * + * @return <code>true</code>, if the callable has started running when the method returns. + */ + public boolean waitForStarted(long timeoutMillis) throws StopException { try { - return started.await(0L, TimeUnit.MILLISECONDS); + return started.await(timeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { - return false; // Shouldn't happen. + throw new StopException(ex); } } @@ -507,13 +518,24 @@ public final class TerminableCallable<V> implements Callable<V>, ITerminable * Returns <code>true</code>, if the callable has already finished running. */ public boolean hasFinished() + { + return waitForFinished(NO_WAIT_MILLIS); + } + + /** + * Waits for the callable to finish running. The method waits at most <var>timeoutMillis</var> + * milli-seconds. + * + * @return <code>true</code>, if the callable has finished running when the method returns. + */ + public boolean waitForFinished(long timeoutMillis) throws StopException { try { - return finished.await(0L, TimeUnit.MILLISECONDS); + return finished.await(timeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { - return false; // Shouldn't happen. + throw new StopException(ex); } } @@ -523,13 +545,24 @@ public final class TerminableCallable<V> implements Callable<V>, ITerminable * method, if any. */ public boolean hasCleanedUp() + { + return waitForCleanedUp(NO_WAIT_MILLIS); + } + + /** + * Waits for the callable to finish cleaning up. The method waits at most <var>timeoutMillis</var> + * milli-seconds. + * + * @return <code>true</code>, if the callable has finished cleaning up when the method returns. + */ + public boolean waitForCleanedUp(long timeoutMillis) throws StopException { try { - return cleanedUp.await(0L, TimeUnit.MILLISECONDS); + return cleanedUp.await(timeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { - return false; // Shouldn't happen. + throw new StopException(ex); } } -- GitLab