Package io.opentelemetry.sdk.common
Class CompletableResultCode
- java.lang.Object
-
- io.opentelemetry.sdk.common.CompletableResultCode
-
public final class CompletableResultCode extends Object
This class models JDK 8's CompletableFuture to afford migration should Open Telemetry's SDK select JDK 8 or greater as a baseline, and also to offer familiarity to developers.The implementation of Export operations are often asynchronous in nature, hence the need to convey a result at a later time. CompletableResultCode facilitates this.
-
-
Constructor Summary
Constructors Constructor Description CompletableResultCode()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableResultCode
fail()
Complete thisCompletableResultCode
unsuccessfully if it is not already completed.boolean
isDone()
Returns whether thisCompletableResultCode
has completed.boolean
isSuccess()
Obtain the current state of completion.CompletableResultCode
join(long timeout, TimeUnit unit)
Waits up to the specified amount of time for thisCompletableResultCode
to complete.static CompletableResultCode
ofAll(Collection<CompletableResultCode> codes)
Returns aCompletableResultCode
that completes after all the providedCompletableResultCode
s complete.static CompletableResultCode
ofFailure()
Returns aCompletableResultCode
that has been completed unsuccessfully.static CompletableResultCode
ofSuccess()
Returns aCompletableResultCode
that has been completed successfully.CompletableResultCode
succeed()
Complete thisCompletableResultCode
successfully if it is not already completed.CompletableResultCode
whenComplete(Runnable action)
Perform an action on completion.
-
-
-
Method Detail
-
ofSuccess
public static CompletableResultCode ofSuccess()
Returns aCompletableResultCode
that has been completed successfully.
-
ofFailure
public static CompletableResultCode ofFailure()
Returns aCompletableResultCode
that has been completed unsuccessfully.
-
ofAll
public static CompletableResultCode ofAll(Collection<CompletableResultCode> codes)
Returns aCompletableResultCode
that completes after all the providedCompletableResultCode
s complete. If any of the results fail, the result will be failed.
-
succeed
public CompletableResultCode succeed()
Complete thisCompletableResultCode
successfully if it is not already completed.
-
fail
public CompletableResultCode fail()
Complete thisCompletableResultCode
unsuccessfully if it is not already completed.
-
isSuccess
public boolean isSuccess()
Obtain the current state of completion. Generally call once completion is achieved via the thenRun method.- Returns:
- the current state of completion
-
whenComplete
public CompletableResultCode whenComplete(Runnable action)
Perform an action on completion. Actions are guaranteed to be called only once.- Parameters:
action
- the action to perform- Returns:
- this completable result so that it may be further composed
-
isDone
public boolean isDone()
Returns whether thisCompletableResultCode
has completed.
-
join
public CompletableResultCode join(long timeout, TimeUnit unit)
Waits up to the specified amount of time for thisCompletableResultCode
to complete. Even after this method returns, the result may not be complete yet - you should always checkisSuccess()
orisDone()
after calling this method to determine the result.- Returns:
- this
CompletableResultCode
-
-