public class FunctionalInterfaces extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
FunctionalInterfaces.ConsumerThrows<T,E extends Exception> |
static interface |
FunctionalInterfaces.ConsumerTwoParam<T1,T2> |
static interface |
FunctionalInterfaces.FunctionThrows<T,R,E extends Exception> |
static interface |
FunctionalInterfaces.FunctionTwoParam<T1,T2,R> |
static interface |
FunctionalInterfaces.RunnableThrows<E extends Exception> |
static interface |
FunctionalInterfaces.SupplierThrows<R,E extends Exception> |
Constructor and Description |
---|
FunctionalInterfaces() |
Modifier and Type | Method and Description |
---|---|
static void |
retryMethodOnException(Runnable methodToRun)
Runs the given method.
In case exception occurred runs the method again either until succeed or until 10 seconds pass. |
static <R> R |
retryMethodOnException(Supplier<R> methodToRun)
Runs the given method.
In case exception occurred runs the method again either until succeed or until 10 seconds pass. |
static <R> R |
retryMethodOnResult(Supplier<R> methodToRun,
Function<R,Boolean> resultVerifier)
Runs the given method.
Verify the method result against the resultVerifier. If verification passed returns the result. If Verification failed keeps retrying until it passes or until 10 seconds pass. If Exception Occurred keeps retrying until it passes or until 10 seconds pass, If last retry result caused an exception - it is thrown. |
static <R> R |
retryMethodOnResult(Supplier<R> methodToRun,
Function<R,Boolean> resultVerifier,
long maxWaitMS,
long retryIntervalMS)
Runs the given method.
Verify the method result against the resultVerifier. If verification passed returns the result. If Verification failed keeps retrying until it passes or until maxWait pass. If Exception Occurred keeps retrying until it passes or until maxWait pass, If last retry result caused an exception - it is thrown. |
static void |
sleep(long millis)
Same as Thread.sleep but throws a FunctionalAttException
(RuntimeException) instead of InterruptedException.
|
static <E extends Exception> |
swallowException(FunctionalInterfaces.RunnableThrows<E> methodToRun)
Runs a method that declares throwing an Exception without return value.
|
static <R,E extends Exception> |
swallowException(FunctionalInterfaces.SupplierThrows<R,E> methodToRun)
Runs a method that declares throwing an Exception and has a return value.
|
public static <R,E extends Exception> R swallowException(FunctionalInterfaces.SupplierThrows<R,E> methodToRun)
methodToRun
- public static <E extends Exception> void swallowException(FunctionalInterfaces.RunnableThrows<E> methodToRun)
methodToRun
- public static <R> R retryMethodOnResult(Supplier<R> methodToRun, Function<R,Boolean> resultVerifier)
methodToRun
- given MethodresultVerifier
- verifier for the method resultpublic static <R> R retryMethodOnResult(Supplier<R> methodToRun, Function<R,Boolean> resultVerifier, long maxWaitMS, long retryIntervalMS)
methodToRun
- given MethodresultVerifier
- verifier for the method resultmaxWaitMS
- retryIntervalMS
- public static <R> R retryMethodOnException(Supplier<R> methodToRun)
methodToRun
- given methodpublic static void retryMethodOnException(Runnable methodToRun)
methodToRun
- given methodpublic static void sleep(long millis)
millis
- Copyright © 2017. All rights reserved.