Package com.luciad.fusion.util
Interface ILfnCallback<R>
- Type Parameters:
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 theVoid
type.
- All Known Subinterfaces:
ILfnProgressCallback<R>
,ILfnReadCallback
public interface ILfnCallback<R>
Interface to be implemented by objects interested in the result of an (asynchronously) executed task.
Tasks which are executed asynchronously usually offer two mechanisms for accessing their results: a future-based
mechanism and a callback-based mechanism:
- The future-based mechanism allows to poll for the status of the task (using
the
Future.isDone()
method), and to retrieve the result via a blocking call on the future (Future.get()
). - The callback-based mechanism allows to get notified of the result via the callback methods of
ILfnCallback
. A callback implementing this interface is therefore provided to the executor of the task.
Future<T> executeTask(Object aTaskParameter1, ..., ILfnCallback<T> aCallback);
where T is the type of the result produced by the asynchronous task.
The callback is often allowed to be 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();
- Since:
- 2012.0
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Called by the executor of the asynchronous task when the task has completed successfully.void
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.
-
Method Details
-
completed
Called by the executor of the asynchronous task when the task has completed successfully.- Parameters:
aResult
- the result of the asynchronous task, ornull
for tasks that do not produce any result
-
threw
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. In case of cancellation of the task (typically by callingFuture.cancel()
), a CancellationException will be reported on this method.- Parameters:
aThrowable
- the error or exception causing the abortion of the task
-