Class DynamicTask<T,​P,​R>

  • Type Parameters:
    T - The type of the params.
    P - The type of the progress.
    R - The type of the result.
    All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    ContextTask, FileDeleteTask

    public abstract class DynamicTask<T,​P,​R>
    extends DynamicRunnable<T,​P,​R>
    Base class to represent Runnable according to the DynamicRunnable.
    • Constructor Detail

      • DynamicTask

        public DynamicTask()
        Constructor to initialize an object of this class.
      • DynamicTask

        public DynamicTask​(@NonNull
                           Looper looper)
        Constructor to initialize an object of this class.
        Parameters:
        looper - The looper to be used.
    • Method Detail

      • getHandler

        @NonNull
        public DynamicHandler<P,​R> getHandler()
        Returns the thread handler used by this task.
        Returns:
        The thread handler used by this task.
      • getBooleanResult

        public boolean getBooleanResult​(@Nullable
                                        DynamicResult<R> result)
        Returns the unboxed boolean value from the Boolean result.
        Parameters:
        result - The Boolean result to be unboxed.
        Returns:
        The unboxed boolean value from the Boolean result.
      • getStatus

        @NonNull
        public final DynamicStatus getStatus()
        Returns the current status of this task.
        Returns:
        The current status of this task.
      • get

        @Nullable
        public final DynamicResult<R> get()
                                   throws java.lang.InterruptedException,
                                          java.util.concurrent.ExecutionException
        Waits if necessary for the computation to complete, and then retrieves its result.
        Returns:
        The computed result.
        Throws:
        java.util.concurrent.CancellationException - If the computation was cancelled.
        java.util.concurrent.ExecutionException - If the computation threw an exception.
        java.lang.InterruptedException - If the current thread was interrupted while waiting.
      • get

        @Nullable
        public final DynamicResult<R> get​(long timeout,
                                          java.util.concurrent.TimeUnit unit)
                                   throws java.lang.InterruptedException,
                                          java.util.concurrent.ExecutionException,
                                          java.util.concurrent.TimeoutException
        Waits if necessary for at most the given time for the computation to complete, and then retrieves its result.
        Parameters:
        timeout - Time to wait before cancelling the operation.
        unit - The time unit for the timeout.
        Returns:
        The computed result.
        Throws:
        java.util.concurrent.CancellationException - If the computation was cancelled.
        java.util.concurrent.ExecutionException - If the computation threw an exception.
        java.lang.InterruptedException - If the current thread was interrupted while waiting.
        java.util.concurrent.TimeoutException - If the wait timed out.
      • run

        public void run()
      • finish

        public void finish​(@Nullable
                           DynamicResult<R> result)
        Description copied from class: DynamicRunnable
        This method will be called to handle the result returned by the task.
        Specified by:
        finish in class DynamicRunnable<T,​P,​R>
        Parameters:
        result - The result returned by the work.
      • executeOnExecutor

        @MainThread
        @NonNull
        public final DynamicTask<T,​P,​R> executeOnExecutor​(@NonNull
                                                                      java.util.concurrent.Executor executor,
                                                                      @Nullable
                                                                      T params)
        Executes the task on the supplied executor.
        Parameters:
        executor - The executor to execute the task.
        params - The optional parameters for the task.
        Returns:
        The instance of the executed task.
      • executeOnExecutor

        @MainThread
        @NonNull
        public final DynamicTask<T,​P,​R> executeOnExecutor​(@NonNull
                                                                      java.util.concurrent.Executor executor)
        Executes the task on the supplied executor.
        Parameters:
        executor - The executor to execute the task.
        Returns:
        The instance of the executed task.