Class CountingCallback

  • All Implemented Interfaces:
    Callback, Invocable

    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);
     }
     
    • Constructor Detail

      • CountingCallback

        public CountingCallback​(Callback callback,
                                int count)
    • Method Detail

      • failed

        public void failed​(java.lang.Throwable failure)
        Description copied from interface: Callback

        Callback invoked when the operation fails.

        Specified by:
        failed in interface Callback
        Overrides:
        failed in class Callback.Nested
        Parameters:
        failure - the reason for the operation failure
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object