Package com.castlabs.utils
Class HandlerRunner
java.lang.Object
com.castlabs.utils.HandlerRunner
Helper class to execute
Callables on specific Handler-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHandlerRunner(Handler handler) CreatesHandlerRunnerinstance.HandlerRunner(Handler handler, long timeoutMs, boolean verifyThread) CreatesHandlerRunnerinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidRunsRunnableon theHandlerthread and waits for the completion.<T> TRunsCallableon theHandlerthread and waits for the result.<T> TrunOnNullable(Callable<T> callable, T valueOnError) RunsCallableon theHandlerthread and waits for the result.
-
Field Details
-
DEBUG
public static boolean DEBUGSet to true to get more logging
-
-
Constructor Details
-
HandlerRunner
CreatesHandlerRunnerinstance.- Parameters:
handler- The handler with the looper to execute the callable on
-
HandlerRunner
CreatesHandlerRunnerinstance.- Parameters:
handler- The handler with the looper to execute the callable ontimeoutMs- The timeout for the operation in millisecondsverifyThread- true if thread verification is enabled, false otherwise
-
-
Method Details
-
runOn
RunsCallableon theHandlerthread and waits for the result.- Type Parameters:
T- The callable result type.- Parameters:
callable- The callable to run.valueOnError- The value to return if execution fails or if the callable returnsnull. Must not benull.- Returns:
- The callable result if non-null, or
valueOnErrorotherwise.
-
runOnNullable
RunsCallableon theHandlerthread and waits for the result.- Type Parameters:
T- The result type returned by the callable.- Parameters:
callable-Callableto executevalueOnError- Value to return upon failure- Returns:
- The callable result, or
valueOnErrorif execution fails. May benull.
-
runOn
RunsRunnableon theHandlerthread and waits for the completion.- Parameters:
runnable-Runnableto execute
-