Class IteratingCallback
- Direct Known Subclasses:
IteratingNestedCallback
A typical example is the write of a large content to a socket, divided in chunks. Chunk C1 is written by thread T1, which also invokes the callback, which writes chunk C2, which invokes the callback again, which writes chunk C3, and so forth.
The problem with the example above is that if the callback thread is the same that performs the I/O operation, then the process is recursive and may result in a stack overflow. To avoid the stack overflow, a thread dispatch must be performed, causing context switching and cache misses, affecting performance.
To avoid this issue, this callback atomically records whether the callback for an asynchronous sub-task has been called during the processing of the asynchronous sub-task, and if so then the processing of the large asynchronous task iterates rather than recursing.
Subclasses must implement method process()
where the
asynchronous sub-task is initiated and a suitable IteratingCallback.Action
is returned to this callback to indicate the overall progress of
the large asynchronous task.
This callback is passed to the asynchronous sub-task, and a call
to succeeded()
on this callback represents the successful
completion of the asynchronous sub-task, while a call to
failed(Throwable)
on this callback represents the
completion with a failure of the large asynchronous task.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback
Callback.Completable, Callback.Completing, Callback.Nested
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.InvocationType
-
Field Summary
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
Deprecated.Method to invoke when the asynchronous sub-task fails, or to fail the overall asynchronous task and therefore terminate the iteration.boolean
isClosed()
Deprecated.boolean
isFailed()
Deprecated.boolean
Deprecated.void
iterate()
Deprecated.This method must be invoked by applications to start the processing of asynchronous sub-tasks.boolean
reset()
Deprecated.Resets this callback.void
Deprecated.Method to invoke when the asynchronous sub-task succeeds.toString()
Deprecated.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.thread.Invocable
getInvocationType
-
Method Details
-
iterate
public void iterate()Deprecated.This method must be invoked by applications to start the processing of asynchronous sub-tasks.It can be called at any time by any thread, and its contract is that when called, then the
process()
method will be called during or soon after, either by the calling thread or by another thread, but in either case by one thread only. -
succeeded
public void succeeded()Deprecated.Method to invoke when the asynchronous sub-task succeeds.Subclasses that override this method must always remember to call
super.succeeded()
. -
failed
Deprecated.Method to invoke when the asynchronous sub-task fails, or to fail the overall asynchronous task and therefore terminate the iteration.Subclasses that override this method must always remember to call
super.failed(Throwable)
.Eventually,
onCompleteFailure(Throwable)
is called, either by the caller thread or by the processing thread. -
close
public void close()Deprecated.Method to invoke to forbid further invocations toiterate()
andreset()
.When this method is invoked during processing, it behaves like invoking
failed(Throwable)
.- See Also:
-
isClosed
public boolean isClosed()Deprecated.- Returns:
- whether this callback has been
closed
-
isFailed
public boolean isFailed()Deprecated.- Returns:
- whether this callback has been
failed
-
isSucceeded
public boolean isSucceeded()Deprecated.- Returns:
- whether this callback and the overall asynchronous task has been succeeded
- See Also:
-
reset
public boolean reset()Deprecated.Resets this callback.A callback can only be reset to the idle state from the
succeeded
orfailed
states or if it is already idle.- Returns:
- true if the reset was successful
-
toString
Deprecated.
-