RequestTask<TResult,TCallback>

Overview

The RequestTask is the essential task in the asynchronous work of RemoteDataAdapter. It has several inheritors but they differ only in the type of return value (if any). All other configuration methods are in this task.

Additional getters and getters for several properties are available:

  • state - holds an optional object, that can be additionally provided by your code, then accessed in callback method.
  • executor - holds the executor that will be used on task's execute() call. It is often assigned by the RemoteDataAdapter by default (from its taskExecutor property), though you may replace it if you want.
  • callbackExecutor -holds the executor that will be used to invoke callback after task's work completion. It doesn't assigned by default which means that callback will be executed in the same thread where all task work has been performed. However, you may change it providing your own Executor (i.e. to invoke callback in main/UI thread).

The instances of its inheritors are created internally in adapter's async methods and preconfigured for execution. All you need after getting the task's instance is to call its execute method to invoke the request. Here is the simple async request, though with some additional configuration:

FillRequestTask fillTask = fDataModule.getDataAdapter().fillAsync(table, new FillRequestTask.Callback() {
    @Override
    public void completed(FillRequestTask aTask, Object aState) {
        if (aTask.isFailed()) {
          // do something on failure

        } else if (aTask.isCancelled()) {
            // do something on cancellation

        } else {
            // do something on success
        }
    }
});
fillTask.setState(probablySomeTagObject);
fillTask.execute();

If you don't need additional configuration you can run call execute() on the go (callback is ommited for simplicity):

FillRequestTask fillTask = fDataModule.getDataAdapter().fillAsync(table, callback).execute();

You can even ommit callback assignment by calling async method with NULL callback parameter.

Location


 

constructor (Callable<TResult>, TCallback)  protected

 

constructor(aCallable: Callable<TResult>; aCallback: TCallback)

 

RequestTask<TResult,TCallback>(Callable<TResult> aCallable, TCallback aCallback)

Parameters:

  • aCallable:
  • aCallback:

constructor (Runnable, TResult, TCallback)  protected

 

constructor(aRunnable: Runnable; aResult: TResult; aCallback: TCallback)

 

RequestTask<TResult,TCallback>(Runnable aRunnable, TResult aResult, TCallback aCallback)

Parameters:

  • aRunnable:
  • aResult:
  • aCallback:

CallbackExecutor

 

property CallbackExecutor: Executor read write;

 

Executor CallbackExecutor { __get; __set; }

cancel

Attempts to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

 

method cancel(mayInterruptIfRunning: Boolean): Boolean

 

Boolean cancel(Boolean mayInterruptIfRunning)

Parameters:

  • mayInterruptIfRunning: TRUE if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete

execute

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.


Executor

 

property Executor: Executor read write;

 

Executor Executor { __get; __set; }

FailureCause

 

property FailureCause: Throwable read write;

 

Throwable FailureCause { __get; __set; }

get

Waits if necessary for the computation to complete, and then retrieves its result.

 

method get: TResult

 

TResult get()

get (Long, TimeUnit): TResult

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

 

method get(aTimeout: Long; aUnit: TimeUnit): TResult

 

TResult get(Long aTimeout, TimeUnit aUnit)

Parameters:

  • aTimeout: the maximum time to wait
  • aUnit: the time unit of the timeout argument

isCancelled

Returns TRUE if this task was cancelled before it completed normally.

 

method isCancelled: Boolean

 

Boolean isCancelled()

isFailed

Returns TRUE if an exception was thrown during task execution. Call getFailureCause to get the exception.

 

method isFailed: Boolean

 

Boolean isFailed()

onFutureDone  protected

 

method onFutureDone

 

void onFutureDone()

setCallback  protected

Sets the callback to invoke on task completion. NULL is possible.

 

method setCallback(aCallback: TCallback)

 

void setCallback(TCallback aCallback)

Parameters:

  • aCallback: the callback instance to invoke.

State

 

property State: Object read write;

 

Object State { __get; __set; }

Status

 

property Status: Status read;

 

Status Status { __get; }

 

CallbackExecutor

 

property CallbackExecutor: Executor read write;

 

Executor CallbackExecutor { __get; __set; }

Executor

 

property Executor: Executor read write;

 

Executor Executor { __get; __set; }

FailureCause

 

property FailureCause: Throwable read write;

 

Throwable FailureCause { __get; __set; }

State

 

property State: Object read write;

 

Object State { __get; __set; }

Status

 

property Status: Status read;

 

Status Status { __get; }

 

constructor (Callable<TResult>, TCallback)  protected

 

constructor(aCallable: Callable<TResult>; aCallback: TCallback)

 

RequestTask<TResult,TCallback>(Callable<TResult> aCallable, TCallback aCallback)

Parameters:

  • aCallable:
  • aCallback:

constructor (Runnable, TResult, TCallback)  protected

 

constructor(aRunnable: Runnable; aResult: TResult; aCallback: TCallback)

 

RequestTask<TResult,TCallback>(Runnable aRunnable, TResult aResult, TCallback aCallback)

Parameters:

  • aRunnable:
  • aResult:
  • aCallback:

cancel

Attempts to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

 

method cancel(mayInterruptIfRunning: Boolean): Boolean

 

Boolean cancel(Boolean mayInterruptIfRunning)

Parameters:

  • mayInterruptIfRunning: TRUE if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete

execute

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.


get

Waits if necessary for the computation to complete, and then retrieves its result.

 

method get: TResult

 

TResult get()

get (Long, TimeUnit): TResult

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

 

method get(aTimeout: Long; aUnit: TimeUnit): TResult

 

TResult get(Long aTimeout, TimeUnit aUnit)

Parameters:

  • aTimeout: the maximum time to wait
  • aUnit: the time unit of the timeout argument

isCancelled

Returns TRUE if this task was cancelled before it completed normally.

 

method isCancelled: Boolean

 

Boolean isCancelled()

isFailed

Returns TRUE if an exception was thrown during task execution. Call getFailureCause to get the exception.

 

method isFailed: Boolean

 

Boolean isFailed()

onFutureDone  protected

 

method onFutureDone

 

void onFutureDone()

setCallback  protected

Sets the callback to invoke on task completion. NULL is possible.

 

method setCallback(aCallback: TCallback)

 

void setCallback(TCallback aCallback)

Parameters:

  • aCallback: the callback instance to invoke.