R- the type of the result produced by the asynchronous task for which this callback was registered. Types which do not produce any result should use the
public interface ILfnCallback<R>
Future.isDone()method), and to retrieve the result via a blocking call on the future (
ILfnCallback. A callback implementing this interface is therefore provided to the executor of the task.
where T is the type of the result produced by the asynchronous task. The callback is often allowed to be
Future<T> executeTask(Object aTaskParameter1, ..., ILfnCallback<T> aCallback);
null, if one is only interested in the future. Since callback methods may be invoked from any thread (asynchronously), implementations should take the necessary measures to ensure thread-safety. Especially updating the user interface directly from within these methods is not allowed, as user interface interactions should always be performed from within the Event Dispatch Thread.
The callback argument in asynchronous operations is usually the last parameter. This parameter may be
null, meaning the caller
is not interested in the asynchronous behavior. Asynchronous operations can easily be used in a synchronous workflow by using the Future's
blocking "get" family of methods instead of the callback. This paradigm is illustrated in the code snippet below:
T result = executeTask(taskParameter1, ..., null).get();
|Modifier and Type||Method and Description|
Called by the executor of the asynchronous task when the task has completed successfully.
Called by the executor of the asynchronous task when the task failed to complete normally due to an error, exception or cancellation of the task.
void completed(R aResult)
aResult- the result of the asynchronous task, or
nullfor tasks that do not produce any result
void threw(Throwable aThrowable)
Future.cancel()), a CancellationException will be reported on this method.
aThrowable- the error or exception causing the abortion of the task