public final class SQLRetrier extends Object implements Serializable
Modifier and Type | Method and Description |
---|---|
static <X,Y> X |
retry(Callable<X> callable,
Callable<Y> onException,
int numRetries)
Tries to run the given
Callable the predefined number of times
before throwing an IOException . |
static <X,Y> X |
retry(Callable<X> callable,
Callable<Y> onException,
int numRetries,
int sleep)
Tries to run the given
Callable the predefined number of times
before throwing an IOException . |
static <X> X |
retry(Callable<X> callable,
int numRetries)
Tries to run the given
Callable the predefined number of times
before throwing an IOException . |
static <X> X |
retry(Callable<X> callable,
int numRetries,
int sleep)
Tries to run the given
Callable the predefined number of times
before throwing an IOException . |
public static <X> X retry(Callable<X> callable, int numRetries) throws IOException
Callable
the predefined number of times
before throwing an IOException
. This method will only retries
calls ending in SQLException
. Other exceptions will cause a
RuntimeException
.callable
- The callable to be retried.numRetries
- Max number of retries before throwing an IOException
.IOException
- The wrapped SQLException
.public static <X> X retry(Callable<X> callable, int numRetries, int sleep) throws IOException
Callable
the predefined number of times
before throwing an IOException
. This method will only retries
calls ending in SQLException
. Other exceptions will cause a
RuntimeException
.callable
- The callable to be retried.numRetries
- Max number of retries before throwing an IOException
.sleep
- The retrier will wait a random number of msecs between 1 and
sleep.Callable.call()
.IOException
- The wrapped SQLException
.public static <X,Y> X retry(Callable<X> callable, Callable<Y> onException, int numRetries, int sleep) throws IOException
Callable
the predefined number of times
before throwing an IOException
. This method will only retries
calls ending in SQLException
. Other exceptions will cause a
RuntimeException
.
Additionally the user can supply a second callable which will be executed
every time the first callable throws a SQLException
.callable
- The callable to be retried.onException
- The callable to be executed when an SQLException
was
encountered. Exceptions thrown during this call are ignored.numRetries
- Max number of retries before throwing an IOException
.sleep
- The retrier will wait a random number of msecs between 1 and
sleep.Callable.call()
.IOException
- The wrapped SQLException
.public static <X,Y> X retry(Callable<X> callable, Callable<Y> onException, int numRetries) throws IOException
Callable
the predefined number of times
before throwing an IOException
. This method will only retries
calls ending in SQLException
. Other exceptions will cause a
RuntimeException
.
Additionally the user can supply a second callable which will be executed
every time the first callable throws a SQLException
.callable
- The callable to be retried.onException
- The callable to be executed when an SQLException
was
encountered. Exceptions thrown during this call are ignored.numRetries
- Max number of retries before throwing an IOException
.Callable.call()
.IOException
- The wrapped SQLException
.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.