Class Task<T,​E extends java.lang.Throwable>

  • Direct Known Subclasses:
    SimpleTask

    public abstract class Task<T,​E extends java.lang.Throwable>
    extends java.lang.Object
    A class which encapsulates a task.
    Author:
    Fabrizio Giudici
    Status: experimental API
    • Constructor Summary

      Constructors 
      Constructor Description
      Task()
      Creates a new Task.
      Task​(java.lang.String name)
      Creates a new Task with the given name.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> Task<T,​java.lang.Exception> ofCallable​(java.util.concurrent.Callable<T> callable)
      Creates a Task from a Callable.
      static Task<java.lang.Void,​java.lang.Throwable> ofCallback​(Callback callback)
      Creates a Task from a Callback.
      static Task<java.lang.Void,​java.lang.RuntimeException> ofRunnable​(java.lang.Runnable runnable)
      Creates a Task from a Runnable.
      abstract T run()
      The method that must contain the body of the Task.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

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

      • Task

        public Task()
        Creates a new Task.
      • Task

        public Task​(@Nonnull
                    java.lang.String name)
        Creates a new Task with the given name.
        Parameters:
        name - the name
    • Method Detail

      • run

        public abstract T run()
                       throws E extends java.lang.Throwable
        The method that must contain the body of the Task.
        Returns:
        the computed value
        Throws:
        E - in case of error
        E extends java.lang.Throwable
      • toString

        @Nonnull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • ofRunnable

        @Nonnull
        public static Task<java.lang.Void,​java.lang.RuntimeException> ofRunnable​(@Nonnull
                                                                                       java.lang.Runnable runnable)
        Creates a Task from a Runnable.
        Parameters:
        runnable - the wrapped object
        Returns:
        the Task
        Since:
        3.2-ALPHA-1 (was previously on Task8
      • ofCallable

        @Nonnull
        public static <T> Task<T,​java.lang.Exception> ofCallable​(@Nonnull
                                                                       java.util.concurrent.Callable<T> callable)
        Creates a Task from a Callable.
        Type Parameters:
        T - the return type of the callable
        Parameters:
        callable - the wrapped object
        Returns:
        the Task
        Since:
        3.2-ALPHA-1 (was previously on Task8
      • ofCallback

        @Nonnull
        public static Task<java.lang.Void,​java.lang.Throwable> ofCallback​(@Nonnull
                                                                                Callback callback)
        Creates a Task from a Callback.
        Parameters:
        callback - the wrapped object
        Returns:
        the Task
        Since:
        3.2-ALPHA-1 (was previously on Task8