Top Description Fields Constructors Methods
org.eclipse.jetty.util

public Class CountingCallback

extends Nested
Class Inheritance
Imports
java.util.concurrent.atomic.AtomicInteger

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);
}

Field Summary

Modifier and TypeField and Description
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
CountingCallback(Callback callback, int count)

Method Summary

Modifier and TypeMethod and Description
public void
failed(Throwable
the reason for the operation failure
failure
)

Overrides org.eclipse.jetty.util.Callback.Nested.failed.

Overrides default org.eclipse.jetty.util.Callback.Completing.failed.

Callback invoked when the operation fails.

public void
succeeded()

Overrides org.eclipse.jetty.util.Callback.Nested.succeeded.

Overrides default org.eclipse.jetty.util.Callback.Completing.succeeded.

Callback invoked when the operation completes.

public String
toString()

Overrides org.eclipse.jetty.util.Callback.Nested.toString.

Returns a string representation of the object.
Inherited from org.eclipse.jetty.util.Callback.Nested:
completedgetCallbackgetInvocationType

Field Detail

countback to summary
private final AtomicInteger count

Constructor Detail

CountingCallbackback to summary
public CountingCallback(Callback callback, int count)

Method Detail

failedback to summary
public void failed(Throwable failure)

Overrides org.eclipse.jetty.util.Callback.Nested.failed.

Overrides default org.eclipse.jetty.util.Callback.Completing.failed.

Doc from org.eclipse.jetty.util.Callback.failed.

Callback invoked when the operation fails.

Parameters
failure:Throwable

the reason for the operation failure

Annotations
@Override
succeededback to summary
public void succeeded()

Overrides org.eclipse.jetty.util.Callback.Nested.succeeded.

Overrides default org.eclipse.jetty.util.Callback.Completing.succeeded.

Doc from org.eclipse.jetty.util.Callback.succeeded.

Callback invoked when the operation completes.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.util.Callback.Nested.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override