Package org.eclipse.jetty.util
Class CountingCallback
java.lang.Object
org.eclipse.jetty.util.Callback.Nested
org.eclipse.jetty.util.CountingCallback
- All Implemented Interfaces:
Callback
,Callback.Completing
,Invocable
A callback wrapper that succeeds the wrapped callback when the count is reached, or on first failure.
This callback is particularly useful when an async operation is split into multiple parts, for example when an original byte buffer that needs to be written, along with a callback, is split into multiple byte buffers, since it allows the original callback to be wrapped and notified only when the last part has been processed.
Example:
public void process(EndPoint endPoint, ByteBuffer buffer, Callback callback) { ByteBuffer[] buffers = split(buffer); CountCallback countCallback = new CountCallback(callback, buffers.length); endPoint.write(countCallback, buffers); }
-
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.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task
-
Field Summary
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
Constructor Summary
-
Method Summary
Methods inherited from class org.eclipse.jetty.util.Callback.Nested
completed, getCallback, getInvocationType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.Callback
completeWith
-
Constructor Details
-
CountingCallback
-
-
Method Details
-
succeeded
public void succeeded()Description copied from interface:Callback
Callback invoked when the operation completes.
- Specified by:
succeeded
in interfaceCallback
- Specified by:
succeeded
in interfaceCallback.Completing
- Overrides:
succeeded
in classCallback.Nested
- See Also:
-
failed
Description copied from interface:Callback
Callback invoked when the operation fails.
- Specified by:
failed
in interfaceCallback
- Specified by:
failed
in interfaceCallback.Completing
- Overrides:
failed
in classCallback.Nested
- Parameters:
failure
- the reason for the operation failure
-
toString
- Overrides:
toString
in classCallback.Nested
-