Package com.qfs.util
Interface ILatch
- All Known Implementing Classes:
Latch
public interface ILatch
Simple latch with dynamic increment/decrement.
The latch internal pending count is initialized to 'zero'. The activity associated with the latch can increment the count to register a sub task for instance, and decrement the count to signify the sub task is finished. A Latch to be registered as a quartet type to allow tracing.
- Author:
- ActiveViam
-
Method Summary
Modifier and TypeMethodDescriptionvoidWait until the latch is completed: when it is shutdown and the pending count reached zero.intDecrement the pending count (unregister a unit of activity).intReturns the pending count.intIncrement the pending count (register a unit of activity).booleanReturns true if the latch is completed (shutdown and pending count equal to zero).booleanReturns true if the latch is shutdown.voidsetCompletion(ICompletion completion) Set the completion method that should run when the latch is complete.
The completion must be set before the latch is shutdown.voidshutdown()Shut down the latch: the latch will not accept any additional increment and can only await its completion.
-
Method Details
-
getPending
int getPending()Returns the pending count.- Returns:
- the pending count
-
isShutdown
boolean isShutdown()Returns true if the latch is shutdown.- Returns:
- Whether the latch is shutdown
-
isCompleted
boolean isCompleted()Returns true if the latch is completed (shutdown and pending count equal to zero).- Returns:
- Whether the latch is completed
-
increment
int increment()Increment the pending count (register a unit of activity).- Returns:
- the incremented value
-
decrement
Decrement the pending count (unregister a unit of activity). If the latch is shut down and this decrement brings the pending count to zero, then the optional completion is executed. If an exception is thrown by the completion, it will propagate through the decrement method.- Returns:
- the decremented value
- Throws:
IllegalStateException- if the actual pending count before decrementing is 0
-
awaitCompletion
void awaitCompletion()Wait until the latch is completed: when it is shutdown and the pending count reached zero. -
setCompletion
Set the completion method that should run when the latch is complete.
The completion must be set before the latch is shutdown.- Parameters:
completion- the completion to set
-
shutdown
Shut down the latch: the latch will not accept any additional increment and can only await its completion. Following a shutdown the latch will be considered complete the pending count reaches zero.When the latch will be completed (later or right now) the (optional) completion continuation will be executed.
If the pending count is already zero when shutdown is called, then the completion is executed immediately, and if the completion throws an exception it is thrown through the shutdown method.
- Throws:
IllegalStateException- if trying to shutdown a terminated latch
-