Package io.opentelemetry.sdk.common
Class CompletableResultCode
- java.lang.Object
-
- io.opentelemetry.sdk.common.CompletableResultCode
-
public final class CompletableResultCode extends java.lang.ObjectThis 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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.Runnable>completionActionsprivate static CompletableResultCodeFAILUREprivate java.lang.Objectlockprivate java.lang.Booleansucceededprivate static CompletableResultCodeSUCCESSprivate java.lang.Throwablethrowable
-
Constructor Summary
Constructors Constructor Description CompletableResultCode()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableResultCodefail()Complete thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletonull.CompletableResultCodefailExceptionally(java.lang.Throwable throwable)Completes thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletothrowable.private CompletableResultCodefailInternal(java.lang.Throwable throwable)java.lang.ThrowablegetFailureThrowable()booleanisDone()Returns whether thisCompletableResultCodehas completed.booleanisSuccess()Obtain the current state of completion.CompletableResultCodejoin(long timeout, java.util.concurrent.TimeUnit unit)Waits up to the specified amount of time for thisCompletableResultCodeto complete.static CompletableResultCodeofAll(java.util.Collection<CompletableResultCode> codes)Returns aCompletableResultCodethat completes after all the providedCompletableResultCodes complete.static CompletableResultCodeofExceptionalFailure(java.lang.Throwable throwable)Returns aCompletableResultCodethat has beenfailed exceptionally.static CompletableResultCodeofFailure()Returns aCompletableResultCodethat has been completed unsuccessfully.static CompletableResultCodeofSuccess()Returns aCompletableResultCodethat has been completed successfully.CompletableResultCodesucceed()Complete thisCompletableResultCodesuccessfully if it is not already completed.CompletableResultCodewhenComplete(java.lang.Runnable action)Perform an action on completion.
-
-
-
Field Detail
-
SUCCESS
private static final CompletableResultCode SUCCESS
-
FAILURE
private static final CompletableResultCode FAILURE
-
succeeded
@Nullable private java.lang.Boolean succeeded
-
throwable
@Nullable private java.lang.Throwable throwable
-
completionActions
private final java.util.List<java.lang.Runnable> completionActions
-
lock
private final java.lang.Object lock
-
-
Method Detail
-
ofSuccess
public static CompletableResultCode ofSuccess()
Returns aCompletableResultCodethat has been completed successfully.
-
ofFailure
public static CompletableResultCode ofFailure()
Returns aCompletableResultCodethat has been completed unsuccessfully.
-
ofExceptionalFailure
public static CompletableResultCode ofExceptionalFailure(java.lang.Throwable throwable)
Returns aCompletableResultCodethat has beenfailed exceptionally.- Since:
- 1.41.0
-
ofAll
public static CompletableResultCode ofAll(java.util.Collection<CompletableResultCode> codes)
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
public CompletableResultCode succeed()
Complete thisCompletableResultCodesuccessfully if it is not already completed.
-
fail
public CompletableResultCode fail()
Complete thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletonull.
-
failExceptionally
public CompletableResultCode failExceptionally(java.lang.Throwable throwable)
Completes thisCompletableResultCodeunsuccessfully if it is not already completed, setting thefailure throwabletothrowable.- Since:
- 1.41.0
-
failInternal
private CompletableResultCode failInternal(@Nullable java.lang.Throwable throwable)
-
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
@Nullable public java.lang.Throwable 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, or not complete.g - Since:
- 1.41.0
-
whenComplete
public CompletableResultCode whenComplete(java.lang.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 thisCompletableResultCodehas completed.
-
join
public CompletableResultCode join(long timeout, java.util.concurrent.TimeUnit unit)
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
-
-