Class BambooCallables

java.lang.Object
com.atlassian.bamboo.utils.BambooCallables

public class BambooCallables extends Object
  • Method Details

    • callUnchecked

      public static <V> V callUnchecked(Callable<V> callable)
    • notThrowing

      public static <V> BambooCallables.NotThrowing<V> notThrowing(BambooCallables.ThrowingX<V,? extends Exception,? extends Exception,? extends Exception> callable)
      Returns a wrapped callable which does not throw checked exceptions. All checked exceptions thrown by the underlying callable are wrapped and re-thrown as runtime exceptions.
      Type Parameters:
      V - type of returned value
      Parameters:
      callable - throwing callable
      Returns:
      a decorated callable which does not throw checked exceptions
    • retryOnException

      public static <V, E extends Throwable> V retryOnException(BambooCallables.Throwing<V,E> callable, Class<E> exceptionClass) throws E
      Utility to re-attempt to execute a callable if it fails with a known exception.

      If the given callable fails with the provided exception class, this method will re-run the callable in attempt to obtain the result again. Subsequent failure will not be handled and the exception will be propagated.

      If the callable fails with a different exception than was expected, the actual exception will be re-thrown by this method.

      Throws:
      E extends Throwable
    • retryOnException

      public static <V, E extends Throwable> V retryOnException(BambooCallables.Throwing<V,E> callable, Class<E> exceptionClass, long howManyRetries) throws E
      Utility to re-attempt to execute a callable if it fails with a known exception.

      If the given callable fails with the provided exception class, this method will re-run the callable in an attempt to obtain the result again. The number of retries is controlled by the `howManyTimes` parameter.

      If the callable fails with a different exception than was expected, the actual exception will be re-thrown by this method.

      Type Parameters:
      V - the type of the result returned by the callable
      E - the type of the exception that can be thrown by the callable
      Parameters:
      callable - the callable to be executed
      exceptionClass - the class of the exception that should trigger a retry
      howManyRetries - the number of times to retry the callable if it fails with the specified exception
      Returns:
      the result of the callable
      Throws:
      E - if the callable fails with the specified exception more than the allowed number of retries
    • retryOnExceptions

      public static <V, E extends Throwable> V retryOnExceptions(BambooCallables.Throwing<V,E> callable, Class<? extends Throwable>... exceptionClass) throws E
      Utility to re-attempt to execute a callable if it fails with a known exceptions.

      If the given callable fails with the provided exception class, this method will re-run the callable in attempt to obtain the result again. Subsequent failure will not be handled and the exception will be propagated.

      If the callable fails with a different exception than was expected, the actual exception will be re-thrown by this method.

      Throws:
      E extends Throwable
    • retryOnException

      public static <V> V retryOnException(BambooCallables.NotThrowing<V> callable, Predicate<RuntimeException> exceptionPredicate)
      Utility to re-attempt to execute a callable if it fails with a known exception.

      If the given callable fails with an exception that matches the given predicate, this method will re-run the callable in attempt to obtain the result again. Subsequent failure will not be handled and the exception will be propagated.

      If the callable fails with a different exception than was expected, the actual exception will be re-thrown by this method.

    • retryOnException

      public static <V> V retryOnException(BambooCallables.NotThrowing<V> callable, Predicate<RuntimeException> exceptionPredicate, int maxRetryCount)
      Utility to re-attempt to execute a callable if it fails with a known exception up to maxRetryCount times.

      If the given callable fails with an exception that matches the given predicate, this method will re-run the callable in attempt to obtain the result again. Subsequent failure will not be handled and the exception will be propagated.

      If the callable fails with a different exception than was expected, the actual exception will be re-thrown by this method.