public class CountingCallback extends Callback.Nested
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); }
Callback.Completable, Callback.Completing, Callback.InvocableCallback, Callback.Nested
Invocable.InvocationType
__nonBlocking
Constructor and Description |
---|
CountingCallback(Callback callback,
int count) |
Modifier and Type | Method and Description |
---|---|
void |
failed(Throwable failure)
Callback invoked when the operation fails.
|
void |
succeeded()
Callback invoked when the operation completes.
|
String |
toString() |
getCallback, getInvocationType
completed
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
combine, from, from, from, from, from, from
combine, getInvocationType, invokeNonBlocking, isNonBlockingInvocation
public CountingCallback(Callback callback, int count)
public void succeeded()
Callback
Callback invoked when the operation completes.
succeeded
in interface Callback
succeeded
in class Callback.Nested
Callback.failed(Throwable)
public void failed(Throwable failure)
Callback
Callback invoked when the operation fails.
failed
in interface Callback
failed
in class Callback.Nested
failure
- the reason for the operation failureCopyright © 2010 - 2020 Adobe. All Rights Reserved