Class Callables


  • @GwtCompatible(emulated=true)
    public final class Callables
    extends java.lang.Object
    Static utility methods pertaining to the Callable 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 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 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.
      (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.
      private static boolean trySetName​(java.lang.String threadName, java.lang.Thread currentThread)
      Tries to set name of the given Thread, returns true if successful.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Callables

        private Callables()
    • Method Detail

      • returning

        public static <T> java.util.concurrent.Callable<T> returning​(T value)
        Creates a Callable which immediately returns a preset value each time it is called.
      • 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 of Callable.call() the thread that is running will have the given name.
        Parameters:
        callable - The callable to wrap
        nameSupplier - 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 of Runnable.run() the thread that is running with have the given name.
        Parameters:
        task - The Runnable to wrap
        nameSupplier - 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 given Thread, returns true if successful.