public abstract class CompletableCallback extends Object implements Callback
A callback to be used by driver code that needs to know whether the callback has been succeeded or failed (that is, completed) just after the asynchronous operation or not, typically because further processing depends on the callback being completed. The driver code competes with the asynchronous operation to complete the callback.
If the callback is already completed, the driver code continues the
processing, otherwise it suspends it. If it is suspended, the callback will
be completed some time later, and resume() or
abort(Throwable) will be called to allow the application to resume
the processing.
CompletableCallback callback = new CompletableCallback()
{
@Override
public void resume()
{
// continue processing
}
@Override
public void abort(Throwable failure)
{
// abort processing
}
}
asyncOperation(callback);
boolean completed = callback.tryComplete();
if (completed)
// suspend processing, async operation not done yet
else
// continue processing, async operation already done
Callback.Completable, Callback.Nested, Callback.NonBlocking| 构造器和说明 |
|---|
CompletableCallback() |
| 限定符和类型 | 方法和说明 |
|---|---|
abstract void |
abort(Throwable failure)
Callback method invoked when this callback is failed.
|
void |
failed(Throwable x)
Callback invoked when the operation fails.
|
abstract void |
resume()
Callback method invoked when this callback is succeeded after a
first call to
tryComplete(). |
void |
succeeded()
Callback invoked when the operation completes.
|
boolean |
tryComplete()
Tries to complete this callback; driver code should call this method once
after the asynchronous operation to detect whether the
asynchronous operation has already completed or not.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfrom, from, isNonBlockingpublic void succeeded()
CallbackCallback invoked when the operation completes.
succeeded 在接口中 CallbackCallback.failed(Throwable)public void failed(Throwable x)
CallbackCallback invoked when the operation fails.
public abstract void resume()
tryComplete().public abstract void abort(Throwable failure)
failure - the throwable reprsenting the callback failurepublic boolean tryComplete()
Copyright © 2016. All rights reserved.