Class Callback.Combination

java.lang.Object
org.eclipse.jetty.util.Callback.Combination
All Implemented Interfaces:
AutoCloseable
Enclosing interface:
Callback

public static class Callback.Combination extends Object implements AutoCloseable
A combination of multiple Callbacks, that must all be completed before a specific callback is completed. For example:

   void sendToAll(String message, Collection<Channel> channels, Callback callback)
   {
       try (Callback.Combination combination = new Callback.Combination(callback))
       {
           for (Channel channel : channels)
               channel.send(message, combination.newCallback());
       }
   }
 
  • Constructor Details

    • Combination

      public Combination(Callback andThen)
      Create a new empty combined callback.
      Parameters:
      andThen - The Callback to complete once all Callbacks in the combination are complete and this combination is closed.
    • Combination

      public Combination(Callback andThen, Throwable failure)
      Create a new empty combined callback with a forced failure and invocation type.
      Parameters:
      andThen - The Callback to complete once all Callbacks in the combination are complete and this combination is closed.
      failure - If not null, force a failure, so that the Callback.failed(Throwable) method will always be called on the Callback passed to the constructor, once all the combined callbacks are completed and the Combination is closed.
  • Method Details

    • newCallback

      public Callback newCallback()
      Create a new Callback as part of this combination.
      Returns:
      A Callback that must be completed before the callback passed to the constructor is completed.
      Throws:
      IllegalStateException - if the combination has already been completed.
    • close

      public void close() throws IllegalStateException
      Called to indicate that no more calls to newCallback() will happen. If the combination is already complete, then it will be completed in the scope of this call.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IllegalStateException - if this method has already been called.