public abstract class IteratingCallback extends Object implements Callback
This specialised callback is used when breaking up an asynchronous task into smaller asynchronous tasks. A typical pattern is that a successful callback is used to schedule the next sub task, but if that task completes quickly and uses the calling thread to callback the success notification, this can result in a growing stack depth.
To avoid this issue, this callback uses an AtomicReference to note if the success callback has been called during the processing of a sub task, and if so then the processing iterates rather than recurses.
This callback is passed to the asynchronous handling of each sub
task and a call the succeeded() on this call back represents
completion of the subtask. Only once all the subtasks are completed is
the Callback.succeeded() method called on the Callback instance
passed the the IteratingCallback(Callback) constructor.
Callback.Adapter| Constructor and Description |
|---|
IteratingCallback(Callback callback) |
| Modifier and Type | Method and Description |
|---|---|
void |
failed(Throwable x)
Callback invoked when the operation fails.
|
void |
iterate()
This method is called initially to start processing and
is then called by subsequent sub task success to continue
processing.
|
protected abstract boolean |
process()
Process a subtask.
|
void |
succeeded()
Callback invoked when the operation completes.
|
public IteratingCallback(Callback callback)
protected abstract boolean process()
throws Exception
Called by iterate() to process a sub task of the overall task
succeeded() or failed(Throwable).Exceptionpublic void iterate()
public void succeeded()
CallbackCallback invoked when the operation completes.
succeeded in interface CallbackCallback.failed(Throwable)Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.