java.lang.Object
org.xnio.AbstractIoFuture<T>
- Type Parameters:
T
- the type of result that this operation produces
- All Implemented Interfaces:
Cancellable
,IoFuture<T>
- Direct Known Subclasses:
FailedIoFuture
An abstract base class for
IoFuture
objects. Used to easily produce implementations.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.xnio.IoFuture
IoFuture.HandlingNotifier<T,
A>, IoFuture.Notifier<T, A>, IoFuture.Status -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCancelHandler
(Cancellable cancellable) Add a cancellation handler.addNotifier
(IoFuture.Notifier<? super T, A> notifier, A attachment) Add a notifier to be called when this operation is complete.await()
Wait for the operation to complete.Wait for the operation to complete, with a timeout.Wait for the operation to complete.awaitInterruptibly
(long time, TimeUnit timeUnit) Wait for the operation to complete, with a timeout.cancel()
Cancel an operation.get()
Get the result of the operation.Get the failure reason.Get the result of the operation.protected Executor
Get the executor used to run asynchronous notifiers.Get the current status.protected void
runNotifier
(Runnable runnable) Run a notifier.protected boolean
Acknowledge the cancellation of this operation.protected boolean
setException
(IOException exception) Set the exception for this operation.protected boolean
Set the result for this operation.
-
Constructor Details
-
AbstractIoFuture
protected AbstractIoFuture()Construct a new instance.
-
-
Method Details
-
getStatus
Get the current status. -
await
Wait for the operation to complete. This method will block until the status changes fromIoFuture.Status.WAITING
. -
await
Wait for the operation to complete, with a timeout. This method will block until the status changes fromIoFuture.Status.WAITING
, or the given time elapses. If the time elapses before the operation is complete,IoFuture.Status.WAITING
is returned.- Specified by:
await
in interfaceIoFuture<T>
- Parameters:
time
- the amount of time to waittimeUnit
- the time unit- Returns:
- the new status, or
IoFuture.Status.WAITING
if the timeout expired
-
awaitInterruptibly
Wait for the operation to complete. This method will block until the status changes fromIoFuture.Status.WAITING
, or the current thread is interrupted.- Specified by:
awaitInterruptibly
in interfaceIoFuture<T>
- Returns:
- the new status
- Throws:
InterruptedException
- if the operation is interrupted
-
awaitInterruptibly
Wait for the operation to complete, with a timeout. This method will block until the status changes fromIoFuture.Status.WAITING
, the given time elapses, or the current thread is interrupted. If the time elapses before the operation is complete,IoFuture.Status.WAITING
is returned.- Specified by:
awaitInterruptibly
in interfaceIoFuture<T>
- Parameters:
time
- the amount of time to waittimeUnit
- the time unit- Returns:
- the new status, or
IoFuture.Status.WAITING
if the timeout expired - Throws:
InterruptedException
- if the operation is interrupted
-
get
Get the result of the operation. If the operation is not complete, blocks until the operation completes. If the operation fails, or has already failed at the time this method is called, the failure reason is thrown.- Specified by:
get
in interfaceIoFuture<T>
- Returns:
- the result of the operation
- Throws:
IOException
- if the operation failedCancellationException
- if the operation was cancelled
-
getInterruptibly
Get the result of the operation. If the operation is not complete, blocks until the operation completes. If the operation fails, or has already failed at the time this method is called, the failure reason is thrown. If the current thread is interrupted while waiting, an exception is thrown.- Specified by:
getInterruptibly
in interfaceIoFuture<T>
- Returns:
- the result of the operation
- Throws:
IOException
- if the operation failedInterruptedException
- if the operation is interruptedCancellationException
- if the operation was cancelled
-
getException
Get the failure reason.- Specified by:
getException
in interfaceIoFuture<T>
- Returns:
- the failure reason
- Throws:
IllegalStateException
- if the operation did not fail
-
addNotifier
Add a notifier to be called when this operation is complete. If the operation is already complete, the notifier is called immediately, possibly in the caller's thread. The given attachment is provided to the notifier.- Specified by:
addNotifier
in interfaceIoFuture<T>
- Type Parameters:
A
- the attachment type- Parameters:
notifier
- the notifier to be calledattachment
- the attachment to pass in to the notifier- Returns:
- this instance
-
setException
Set the exception for this operation. Any threads blocking on this instance will be unblocked.- Parameters:
exception
- the exception to set- Returns:
false
if the operation was already completed,true
otherwise
-
setResult
Set the result for this operation. Any threads blocking on this instance will be unblocked.- Parameters:
result
- the result to set- Returns:
false
if the operation was already completed,true
otherwise
-
setCancelled
protected boolean setCancelled()Acknowledge the cancellation of this operation.- Returns:
false
if the operation was already completed,true
otherwise
-
cancel
Cancel an operation. The actual cancel may be synchronous or asynchronous. Implementers will use this method to initiate the cancel; use thesetCancelled()
method to indicate that the cancel was successful. The default implementation calls any registered cancel handlers.- Specified by:
cancel
in interfaceCancellable
- Specified by:
cancel
in interfaceIoFuture<T>
- Returns:
- this
IoFuture
instance
-
addCancelHandler
Add a cancellation handler. The argument will be cancelled whenever thisIoFuture
is cancelled. If theIoFuture
is already cancelled when this method is called, the handler will be called directly.- Parameters:
cancellable
- the cancel handler
-
runNotifier
Run a notifier. Implementors will run the notifier, preferably in another thread. The default implementation runs the notifier using theExecutor
retrieved viagetNotifierExecutor()
.- Parameters:
runnable
- the runnable task
-
getNotifierExecutor
Get the executor used to run asynchronous notifiers. By default, this implementation simply returns the direct executor.- Returns:
- the executor to use
-