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);
}
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicInteger |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | failed(Throwable
the reason for the operation failure failure)Overrides org. Overrides default org. Callback invoked when the operation fails. |
| public void | succeeded()
Overrides org. Overrides default org. Callback invoked when the operation completes. |
| public String | toString()
Returns a string representation of the object.
|
| count | back to summary |
|---|---|
| private final AtomicInteger count | |
| CountingCallback | back to summary |
|---|---|
| public CountingCallback(Callback callback, int count) | |
| failed | back to summary |
|---|---|
| public void failed(Throwable failure) Overrides org. Overrides default org. Doc from org. Callback invoked when the operation fails. | |
| succeeded | back to summary |
|---|---|
| public void succeeded() Overrides org. Overrides default org. Doc from org. Callback invoked when the operation completes.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Doc from java. Returns a string representation of the object. | |