public final class CancellationSignal extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
CancellationSignal.OnCancelListener
Listens for cancellation.
|
Constructor and Description |
---|
CancellationSignal()
Creates a cancellation signal, initially not canceled.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancels the operation and signals the cancellation listener.
|
static ICancellationSignal |
createTransport()
Creates a transport that can be returned back to the caller of
a Binder function and subsequently used to dispatch a cancellation signal.
|
static CancellationSignal |
fromTransport(ICancellationSignal transport)
Given a locally created transport, returns its associated cancellation signal.
|
boolean |
isCanceled()
Returns true if the operation has been canceled.
|
void |
setOnCancelListener(CancellationSignal.OnCancelListener listener)
Sets the cancellation listener to be called when canceled.
|
void |
setRemote(ICancellationSignal remote)
Sets the remote transport.
|
void |
throwIfCanceled()
Throws
OperationCanceledException if the operation has been canceled. |
public CancellationSignal()
public boolean isCanceled()
public void throwIfCanceled()
OperationCanceledException
if the operation has been canceled.OperationCanceledException
- if the operation has been canceled.public void cancel()
public void setOnCancelListener(CancellationSignal.OnCancelListener listener)
cancel()
has already been called, then the provided
listener is invoked immediately.
This method is guaranteed that the listener will not be called after it
has been removed.listener
- The cancellation listener, or null to remove the current listener.public void setRemote(ICancellationSignal remote)
cancel()
has already been called, then the provided
remote transport is canceled immediately.
This method is guaranteed that the remote transport will not be called after it
has been removed.remote
- The remote transport, or null to remove.public static ICancellationSignal createTransport()
public static CancellationSignal fromTransport(ICancellationSignal transport)
transport
- The locally created transport, or null if none.