Package io.pravega.common.function
Class Callbacks
- java.lang.Object
-
- io.pravega.common.function.Callbacks
-
public final class Callbacks extends java.lang.ObjectMisc methods that can be used as callbacks.
-
-
Constructor Summary
Constructors Constructor Description Callbacks()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voiddoNothing(T ignored)Empty consumer.static <T> Tidentity(T input)Identity Function.static voidinvokeSafely(RunnableWithException runnable, java.util.function.Consumer<java.lang.Throwable> failureHandler)Invokes the givenRunnableWithExceptionand catches any exceptions that it may throw.static <T1,T2>
voidinvokeSafely(java.util.function.BiConsumer<T1,T2> consumer, T1 argument1, T2 argument2, java.util.function.Consumer<java.lang.Throwable> failureHandler)Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.static <T> voidinvokeSafely(java.util.function.Consumer<T> consumer, T argument, java.util.function.Consumer<java.lang.Throwable> failureHandler)Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.
-
-
-
Method Detail
-
doNothing
public static <T> void doNothing(T ignored)
Empty consumer. Does nothing.- Type Parameters:
T- Return type. Ignored.- Parameters:
ignored- Ignored argument.
-
identity
public static <T> T identity(T input)
Identity Function.- Type Parameters:
T- Type of the input.- Parameters:
input- The input.- Returns:
- The input.
-
invokeSafely
public static <T> void invokeSafely(java.util.function.Consumer<T> consumer, T argument, java.util.function.Consumer<java.lang.Throwable> failureHandler)Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.- Type Parameters:
T- The type of the argument.- Parameters:
consumer- The consumer to invoke.argument- The argument to pass to the consumer.failureHandler- An optional callback to invoke if the consumer threw any exceptions.- Throws:
java.lang.NullPointerException- If the consumer is null.
-
invokeSafely
public static void invokeSafely(RunnableWithException runnable, java.util.function.Consumer<java.lang.Throwable> failureHandler)
Invokes the givenRunnableWithExceptionand catches any exceptions that it may throw.- Parameters:
runnable- TheRunnableWithExceptionto invoke.failureHandler- An optional callback to invoke if theRunnableWithExceptionthrew any exceptions.
-
invokeSafely
public static <T1,T2> void invokeSafely(java.util.function.BiConsumer<T1,T2> consumer, T1 argument1, T2 argument2, java.util.function.Consumer<java.lang.Throwable> failureHandler)Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.- Type Parameters:
T1- The type of the first argument.T2- The type of the second argument.- Parameters:
consumer- The consumer to invoke.argument1- The first argument to pass to the consumer.argument2- The second argument to pass to the consumer.failureHandler- An optional callback to invoke if the consumer threw any exceptions.- Throws:
java.lang.NullPointerException- If the consumer is null.
-
-