Package org.apache.ignite.internal.util
Class GridCountDownCallback
- java.lang.Object
-
- org.apache.ignite.internal.util.GridCountDownCallback
-
public class GridCountDownCallback extends Object
Allows to execute callback when a set of operations will be completed. Also has an execution counter, which allows to block callback execution in case if it is below given threshold. By default, threshold is 0 and nothing blocks callback execution.Sample usage::
GridCountDownCallback countDownCb = new GridCountDownCallback( n, //internal counter is initiated with n () -> doSomething() //callback ); //each call of countDown() decrements internal counter //doSomething() will be executed after counter reaches 0 for (int i = 0; i < n; i++) new Thread(() -> countDownCb.countDown()).start();Usage with execution threshold::
GridCountDownCallback countDownCb = new GridCountDownCallback( n, //internal counter is initiated with n () -> doSomething(), //callback n/2 //execution threshold is initiated with n/2 ); //a half of calls of countDown() increase execution counter, so it reaches threshold and callback executes. //doSomething() will be executed after n threads will perform countDown() for (int i = 0; i < n; i++) new Thread(() -> countDownCb.countDown(n % 2 == 0)).start();
-
-
Constructor Summary
Constructors Constructor Description GridCountDownCallback(int initCnt, Runnable cb)Constructor.GridCountDownCallback(int initCnt, Runnable cb, int executionThreshold)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcountDown()Decrements the internal counter.voidcountDown(boolean doIncreaseExecutionCounter)Decrements the internal counter.
-
-
-
Constructor Detail
-
GridCountDownCallback
public GridCountDownCallback(int initCnt, Runnable cb, int executionThreshold)Constructor.- Parameters:
initCnt- count of invocations ofcountDown(boolean).cb- callback which will be executed afterinitialCountinvocations ofcountDown(boolean).executionThreshold- minimal count of really performed operations to execute callback.
-
GridCountDownCallback
public GridCountDownCallback(int initCnt, Runnable cb)Constructor. Execution threshold is set to 0.- Parameters:
initCnt- count of invocations ofcountDown(boolean).cb- callback which will be executed afterinitialCountinvocations ofcountDown(boolean).
-
-
Method Detail
-
countDown
public void countDown(boolean doIncreaseExecutionCounter)
Decrements the internal counter. If counter becomes 0, callback will be executed.- Parameters:
doIncreaseExecutionCounter- whether to increase execution counter
-
countDown
public void countDown()
Decrements the internal counter. If counter becomes 0, callback will be executed.
-
-