Package com.castlabs.utils
Class HandlerRunner
java.lang.Object
com.castlabs.utils.HandlerRunner
Helper class to execute
Callables on specific Handler-
Constructor Summary
ConstructorsConstructorDescriptionHandlerRunner(Handler handler, long timeoutMs, boolean verifyThread) CreatesHandlerRunnerinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoiddisable(boolean mayInterruptIfRunning) Cancels all posted tasks and do not post all future tasks untilenable()voidenable()Enables posted tasks executionvoidRunsRunnableon theHandlerthread.<T> TRunsCallableon theHandlerthread.<T> TrunOnNullable(Callable<T> callable, T valueOnError) RunsCallableon theHandlerthread.
-
Constructor Details
-
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
-
disable
public void disable(boolean mayInterruptIfRunning) Cancels all posted tasks and do not post all future tasks untilenable()- Parameters:
mayInterruptIfRunning- Attempts to cancel execution of a running task
-
enable
public void enable()Enables posted tasks execution -
runOn
RunsCallableon theHandlerthread.- 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.- 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.- Parameters:
runnable-Runnableto execute
-