Package com.github.ambry.router
Class CallbackUtils
- java.lang.Object
-
- com.github.ambry.router.CallbackUtils
-
public class CallbackUtils extends java.lang.Object
Utilities for working withCallback
.
-
-
Constructor Summary
Constructors Constructor Description CallbackUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Callback<T>
chainCallback(com.github.ambry.utils.AsyncOperationTracker asyncOperationTracker, Callback<?> failureCallback, com.github.ambry.utils.ThrowingConsumer<? super T> successAction)
Create aCallback
that handles common tasks like updating metrics via aAsyncOperationTracker
and handling errors that may occur in the callback body.
-
-
-
Method Detail
-
chainCallback
public static <T> Callback<T> chainCallback(com.github.ambry.utils.AsyncOperationTracker asyncOperationTracker, Callback<?> failureCallback, com.github.ambry.utils.ThrowingConsumer<? super T> successAction)
Create aCallback
that handles common tasks like updating metrics via aAsyncOperationTracker
and handling errors that may occur in the callback body. It is meant to be a part of multi-step callback chain and handle intermediate failures in a consistent way.- Type Parameters:
T
- the result type that the callback accepts.- Parameters:
asyncOperationTracker
- theAsyncOperationTracker
to use to update metrics for an async call. The operation is marked as started right before the callback is constructed.failureCallback
- the callback to call if this callback was called with an exception or if thesuccessAction
call throws an exception.successAction
- the action to take when the callback is called successfully. The result of the callback is provided to this consumer. This consumer is allowed to throw an exception, in which case thefailureCallback
will be called.- Returns:
- the managed
Callback
.
-
-