Class Callables
- java.lang.Object
-
- com.google.common.util.concurrent.Callables
-
@GwtCompatible(emulated=true) public final class Callables extends java.lang.Object
Static utility methods pertaining to theCallable
interface.- Since:
- 1.0
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Callables()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> AsyncCallable<T>
asAsyncCallable(java.util.concurrent.Callable<T> callable, ListeningExecutorService listeningExecutorService)
Creates anAsyncCallable
from aCallable
.static <T> java.util.concurrent.Callable<T>
returning(T value)
Creates aCallable
which immediately returns a preset value each time it is called.(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 ofRunnable.run()
the thread that is running with have the given name.(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 ofCallable.call()
the thread that is running will have the given name.private static boolean
trySetName(java.lang.String threadName, java.lang.Thread currentThread)
Tries to set name of the givenThread
, returns true if successful.
-
-
-
Method Detail
-
returning
public static <T> java.util.concurrent.Callable<T> returning(@Nullable T value)
Creates aCallable
which immediately returns a preset value each time it is called.
-
asAsyncCallable
@Beta @GwtIncompatible public static <T> AsyncCallable<T> asAsyncCallable(java.util.concurrent.Callable<T> callable, ListeningExecutorService listeningExecutorService)
Creates anAsyncCallable
from aCallable
.The
AsyncCallable
returns theListenableFuture
resulting fromListeningExecutorService.submit(Callable)
.- Since:
- 20.0
-
threadRenaming
@GwtIncompatible 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 ofCallable.call()
the thread that is running will have the given name.- Parameters:
callable
- The callable to wrapnameSupplier
- The supplier of thread names,get
will be called once for each invocation of the wrapped callable.
-
threadRenaming
@GwtIncompatible static java.lang.Runnable threadRenaming(java.lang.Runnable task, Supplier<java.lang.String> nameSupplier)
Wraps the given runnable such that for the duration ofRunnable.run()
the thread that is running with have the given name.- Parameters:
task
- The Runnable to wrapnameSupplier
- The supplier of thread names,get
will be called once for each invocation of the wrapped callable.
-
trySetName
@GwtIncompatible private static boolean trySetName(java.lang.String threadName, java.lang.Thread currentThread)
Tries to set name of the givenThread
, returns true if successful.
-
-