public final class Callables
extends java.lang.Object
Callable interface.| Modifier | Constructor and Description |
|---|---|
private |
Callables() |
| Modifier and Type | Method and Description |
|---|---|
static <T> AsyncCallable<T> |
asAsyncCallable(java.util.concurrent.Callable<T> callable,
ListeningExecutorService listeningExecutorService)
Creates an
AsyncCallable from a Callable. |
static <T> java.util.concurrent.Callable<T> |
returning(T value)
Creates a
Callable which immediately returns a preset value each time it is called. |
(package private) static <T> java.util.concurrent.Callable<T> |
threadRenaming(java.util.concurrent.Callable<T> callable,
Supplier<java.lang.String> nameSupplier)
Wraps the given callable such that for the duration of
Callable.call() the thread that is
running will have the given name. |
(package private) static java.lang.Runnable |
threadRenaming(java.lang.Runnable task,
Supplier<java.lang.String> nameSupplier)
Wraps the given runnable such that for the duration of
Runnable.run() the thread that is
running with have the given name. |
private static boolean |
trySetName(java.lang.String threadName,
java.lang.Thread currentThread)
Tries to set name of the given
Thread, returns true if successful. |
public static <T> java.util.concurrent.Callable<T> returning(T value)
Callable which immediately returns a preset value each time it is called.public static <T> AsyncCallable<T> asAsyncCallable(java.util.concurrent.Callable<T> callable, ListeningExecutorService listeningExecutorService)
AsyncCallable from a Callable.
The AsyncCallable returns the ListenableFuture resulting from ListeningExecutorService.submit(Callable).
static <T> java.util.concurrent.Callable<T> threadRenaming(java.util.concurrent.Callable<T> callable,
Supplier<java.lang.String> nameSupplier)
Callable.call() the thread that is
running will have the given name.callable - The callable to wrapnameSupplier - The supplier of thread names, get will be called once
for each invocation of the wrapped callable.static java.lang.Runnable threadRenaming(java.lang.Runnable task,
Supplier<java.lang.String> nameSupplier)
Runnable.run() the thread that is
running with have the given name.task - The Runnable to wrapnameSupplier - The supplier of thread names, get will be called once
for each invocation of the wrapped callable.private static boolean trySetName(java.lang.String threadName,
java.lang.Thread currentThread)
Thread, returns true if successful.