Class CountingTask<V>
java.lang.Object
java.util.concurrent.CompletableFuture<V>
eu.cloudnetservice.utils.base.concurrent.CountingTask<V>
- Type Parameters:
V- the generic type of the task.
- All Implemented Interfaces:
CompletionStage<V>, Future<V>
The counting task is a task that starts at a specified count and is capable of counting both up and down. The task is
not completed until the count is 0 or less. Once the task is completed it is not usable anymore.
- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from class CompletableFuture
CompletableFuture.AsynchronousCompletionTaskNested classes/interfaces inherited from interface Future
Future.State -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCountingTask(V resultValue, int initialCount) Constructs a new counting task with a starting count and a value to complete after counting to 0. -
Method Summary
Modifier and TypeMethodDescriptionintcount()Gets the current count of this task.voidDecrements the count of this task by one and publishes the count change.voidcountTo(int target) Sets the count of this counting task to the given one and publishes the count change.voidcountUp()Increments the count of this task by one and publishes the count change.protected voidChecks if the count of this task is 0 or less if that is the case this task is completed with its result value.Methods inherited from class CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, exceptionNow, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, resultNow, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, state, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
-
Field Details
-
resultValue
-
count
-
-
Constructor Details
-
CountingTask
-
-
Method Details
-
countUp
public void countUp()Increments the count of this task by one and publishes the count change. -
countDown
public void countDown()Decrements the count of this task by one and publishes the count change. If the count is 0 or less this task is completed with the given result value. -
countTo
public void countTo(int target) Sets the count of this counting task to the given one and publishes the count change.- Parameters:
target- the value to count to.
-
count
public int count()Gets the current count of this task.- Returns:
- the count of this task.
-
publishCountChange
protected void publishCountChange()Checks if the count of this task is 0 or less if that is the case this task is completed with its result value.
-