Class Callback.Combination
java.lang.Object
org.eclipse.jetty.util.Callback.Combination
- All Implemented Interfaces:
AutoCloseable
- Enclosing interface:
Callback
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 Summary
ConstructorsConstructorDescriptionCombination
(Callback andThen) Create a new empty combined callback.Combination
(Callback andThen, Throwable failure) Create a new empty combined callback with a forced failure and invocation type. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Called to indicate that no more calls tonewCallback()
will happen.Create a newCallback
as part of this combination.
-
Constructor Details
-
Combination
-
Combination
Create a new empty combined callback with a forced failure and invocation type.- Parameters:
andThen
- TheCallback
to complete once allCallbacks
in the combination are complete and this combination isclosed
.failure
- If notnull
, force a failure, so that theCallback.failed(Throwable)
method will always be called on theCallback
passed to the constructor, once all the combined callbacks are completed and theCombination
isclosed
.
-
-
Method Details
-
newCallback
Create a newCallback
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
Called to indicate that no more calls tonewCallback()
will happen. If the combination is already complete, then it will be completed in the scope of this call.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IllegalStateException
- if this method has already been called.
-