Package io.opentelemetry.sdk.common
Class CompletableResultCode
java.lang.Object
io.opentelemetry.sdk.common.CompletableResultCode
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 -
Method Summary
Modifier and TypeMethodDescriptionfail()Complete thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletonull.failExceptionally(Throwable throwable) Completes thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletothrowable.booleanisDone()Returns whether thisCompletableResultCodehas completed.booleanObtain the current state of completion.Waits up to the specified amount of time for thisCompletableResultCodeto complete.static CompletableResultCodeofAll(Collection<CompletableResultCode> codes) Returns aCompletableResultCodethat completes after all the providedCompletableResultCodes complete.static CompletableResultCodeofExceptionalFailure(Throwable throwable) Returns aCompletableResultCodethat has beenfailed exceptionally.static CompletableResultCodeReturns aCompletableResultCodethat has been completed unsuccessfully.static CompletableResultCodeReturns aCompletableResultCodethat has been completed successfully.succeed()Complete thisCompletableResultCodesuccessfully if it is not already completed.whenComplete(Runnable action) Perform an action on completion.
-
Constructor Details
-
CompletableResultCode
public CompletableResultCode()
-
-
Method Details
-
ofSuccess
Returns aCompletableResultCodethat has been completed successfully. -
ofFailure
Returns aCompletableResultCodethat has been completed unsuccessfully. -
ofExceptionalFailure
Returns aCompletableResultCodethat has beenfailed exceptionally.- Since:
- 1.41.0
-
ofAll
Returns aCompletableResultCodethat completes after all the providedCompletableResultCodes complete. If any of the results fail, the result will be failed. If anyfailed exceptionally, the result will be failed exceptionally with the firstThrowablefromcodes. -
succeed
Complete thisCompletableResultCodesuccessfully if it is not already completed. -
fail
Complete thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletonull. -
failExceptionally
Completes thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletothrowable.- Parameters:
throwable- theThrowablethat caused the failure, ornull- Since:
- 1.41.0
-
isSuccess
public boolean isSuccess()Obtain the current state of completion. Generally call once completion is achieved via thewhenComplete(Runnable)method.- Returns:
- the current state of completion
-
getFailureThrowable
ReturnsThrowableif thisCompletableResultCodewasfailed exceptionally. Generally call once completion is achieved via thewhenComplete(Runnable)method.- Returns:
- the throwable if failed exceptionally, or null if:
failed without exception,succeeded,failExceptionally(Throwable)with a nullthrowable, or not complete. - Since:
- 1.41.0
-
whenComplete
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 thisCompletableResultCodehas completed. -
join
Waits up to the specified amount of time for thisCompletableResultCodeto 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
-