public class BlockingCallback extends Object implements Callback<Integer>
To avoid late redundant calls to completed(Integer)
or failed(Integer, Throwable)
from
interfering with later reuses of this class, the callback context is used to hold pass a phase indicated
and only a single callback per phase is allowed.
A typical usage pattern is:
public class MyClass { BlockingCallback cb = new BlockingCallback(); public void blockingMethod(Object args) throws Exception { asyncMethod(args,cb.getPhase(),cb); cb.block(); } publicvoid asyncMethod(Object args, C context, Callback callback) { ... } }
Callback.Empty<C>
Constructor and Description |
---|
BlockingCallback() |
Modifier and Type | Method and Description |
---|---|
void |
block()
Block until the FutureCallback is done or cancelled and
after the return leave in the state as if a
#reset() had been
done. |
void |
completed(Integer phase)
Callback invoked when the operation completes.
|
void |
failed(Integer phase,
Throwable cause)
Callback invoked when the operation fails.
|
Integer |
getPhase() |
String |
toString() |
public void completed(Integer phase)
Callback
Callback invoked when the operation completes.
completed
in interface Callback<Integer>
phase
- the contextCallback.failed(Object, Throwable)
public void failed(Integer phase, Throwable cause)
Callback
Callback invoked when the operation fails.
public Integer getPhase()
public void block() throws InterruptedException, IOException, TimeoutException
#reset()
had been
done.
This is useful for code that wants to repeatable use a FutureCallback to convert
an asynchronous API to a blocking API.Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.