T - the type of result that this operation producespublic interface IoFuture<T> extends Cancellable
IoFuture instances, you
use a wildcard to express the return type. This enables you to take advantage of covariance to retrofit
more specific types later on without breaking anything.
For example, if you have a method which returns a future InputStream, you might be tempted to declare it like
this:
IoFuture<InputStream> getFutureInputStream();Now if you later decide that what you really need is a
DataInputStream (which extends InputStream),
you're in trouble because you have written IoFuture<InputStream> everywhere, which cannot be assigned to or from
an IoFuture<DataInputStream>.
On the other hand, if you declare it like this:
IoFuture<? extends InputStream> getFutureInputStream();Now you can change it at any time to
IoFuture<? extends DataInputStream> without breaking the contract, since
it will be assignable to variables of type IoFuture<? extends InputStream>.| Modifier and Type | Interface and Description |
|---|---|
static class |
IoFuture.HandlingNotifier<T,A>
A base notifier class that calls the designated handler method on notification.
|
static interface |
IoFuture.Notifier<T,A>
A notifier that handles changes in the status of an
IoFuture. |
static class |
IoFuture.Status
The current status of an asynchronous operation.
|
| Modifier and Type | Method and Description |
|---|---|
<A> IoFuture<T> |
addNotifier(IoFuture.Notifier<? super T,A> notifier,
A attachment)
Add a notifier to be called when this operation is complete.
|
IoFuture.Status |
await()
Wait for the operation to complete.
|
IoFuture.Status |
await(long time,
TimeUnit timeUnit)
Wait for the operation to complete, with a timeout.
|
IoFuture.Status |
awaitInterruptibly()
Wait for the operation to complete.
|
IoFuture.Status |
awaitInterruptibly(long time,
TimeUnit timeUnit)
Wait for the operation to complete, with a timeout.
|
IoFuture<T> |
cancel()
Cancel an operation.
|
T |
get()
Get the result of the operation.
|
IOException |
getException()
Get the failure reason.
|
T |
getInterruptibly()
Get the result of the operation.
|
IoFuture.Status |
getStatus()
Get the current status.
|
IoFuture<T> cancel()
cancel in interface CancellableIoFuture.Status getStatus()
IoFuture.Status await()
IoFuture.Status.WAITING.IoFuture.Status await(long time, TimeUnit timeUnit)
IoFuture.Status.WAITING,
or the given time elapses. If the time elapses before the operation is complete, IoFuture.Status.WAITING is
returned.time - the amount of time to waittimeUnit - the time unitIoFuture.Status.WAITING if the timeout expiredIoFuture.Status awaitInterruptibly() throws InterruptedException
IoFuture.Status.WAITING,
or the current thread is interrupted.InterruptedException - if the operation is interruptedIoFuture.Status awaitInterruptibly(long time, TimeUnit timeUnit) throws InterruptedException
IoFuture.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.time - the amount of time to waittimeUnit - the time unitIoFuture.Status.WAITING if the timeout expiredInterruptedException - if the operation is interruptedT get() throws IOException, CancellationException
IOException - if the operation failedCancellationException - if the operation was cancelledT getInterruptibly() throws IOException, InterruptedException, CancellationException
IOException - if the operation failedInterruptedException - if the operation is interruptedCancellationException - if the operation was cancelledIOException getException() throws IllegalStateException
IllegalStateException - if the operation did not fail<A> IoFuture<T> addNotifier(IoFuture.Notifier<? super T,A> notifier, A attachment)
A - the attachment typenotifier - the notifier to be calledattachment - the attachment to pass in to the notifierCopyright © 2018 JBoss by Red Hat. All rights reserved.