Class CallbackUtils


  • public class CallbackUtils
    extends java.lang.Object
    Utilities for working with Callback.
    • 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 a Callback that handles common tasks like updating metrics via a AsyncOperationTracker and handling errors that may occur in the callback body.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CallbackUtils

        public CallbackUtils()
    • 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 a Callback that handles common tasks like updating metrics via a AsyncOperationTracker 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 - the AsyncOperationTracker 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 the successAction 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 the failureCallback will be called.
        Returns:
        the managed Callback.