T
- the type of result that this operation producespublic abstract class AbstractIoFuture<T> extends java.lang.Object implements IoFuture<T>
IoFuture
objects. Used to easily produce implementations.IoFuture.HandlingNotifier<T,A>, IoFuture.Notifier<T,A>, IoFuture.Status
Modifier | Constructor and Description |
---|---|
protected |
AbstractIoFuture()
Construct a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCancelHandler(Cancellable cancellable)
Add a cancellation handler.
|
<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,
java.util.concurrent.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,
java.util.concurrent.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.
|
java.io.IOException |
getException()
Get the failure reason.
|
T |
getInterruptibly()
Get the result of the operation.
|
protected java.util.concurrent.Executor |
getNotifierExecutor()
Get the executor used to run asynchronous notifiers.
|
IoFuture.Status |
getStatus()
Get the current status.
|
protected void |
runNotifier(java.lang.Runnable runnable)
Run a notifier.
|
protected boolean |
setCancelled()
Acknowledge the cancellation of this operation.
|
protected boolean |
setException(java.io.IOException exception)
Set the exception for this operation.
|
protected boolean |
setResult(T result)
Set the result for this operation.
|
public IoFuture.Status getStatus()
public IoFuture.Status await()
IoFuture.Status.WAITING
.public IoFuture.Status await(long time, java.util.concurrent.TimeUnit timeUnit)
IoFuture.Status.WAITING
,
or the given time elapses. If the time elapses before the operation is complete, IoFuture.Status.WAITING
is
returned.await
in interface IoFuture<T>
time
- the amount of time to waittimeUnit
- the time unitIoFuture.Status.WAITING
if the timeout expiredpublic IoFuture.Status awaitInterruptibly() throws java.lang.InterruptedException
IoFuture.Status.WAITING
,
or the current thread is interrupted.awaitInterruptibly
in interface IoFuture<T>
java.lang.InterruptedException
- if the operation is interruptedpublic IoFuture.Status awaitInterruptibly(long time, java.util.concurrent.TimeUnit timeUnit) throws java.lang.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.awaitInterruptibly
in interface IoFuture<T>
time
- the amount of time to waittimeUnit
- the time unitIoFuture.Status.WAITING
if the timeout expiredjava.lang.InterruptedException
- if the operation is interruptedpublic T get() throws java.io.IOException, java.util.concurrent.CancellationException
public T getInterruptibly() throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.CancellationException
getInterruptibly
in interface IoFuture<T>
java.io.IOException
- if the operation failedjava.lang.InterruptedException
- if the operation is interruptedjava.util.concurrent.CancellationException
- if the operation was cancelledpublic java.io.IOException getException() throws java.lang.IllegalStateException
getException
in interface IoFuture<T>
java.lang.IllegalStateException
- if the operation did not failpublic <A> IoFuture<T> addNotifier(IoFuture.Notifier<? super T,A> notifier, A attachment)
addNotifier
in interface IoFuture<T>
A
- the attachment typenotifier
- the notifier to be calledattachment
- the attachment to pass in to the notifierprotected boolean setException(java.io.IOException exception)
exception
- the exception to setfalse
if the operation was already completed, true
otherwiseprotected boolean setResult(T result)
result
- the result to setfalse
if the operation was already completed, true
otherwiseprotected boolean setCancelled()
false
if the operation was already completed, true
otherwisepublic IoFuture<T> cancel()
setCancelled()
method to indicate that the cancel was successful. The
default implementation calls any registered cancel handlers.cancel
in interface Cancellable
cancel
in interface IoFuture<T>
IoFuture
instanceprotected void addCancelHandler(Cancellable cancellable)
IoFuture
is cancelled. If
the IoFuture
is already cancelled when this method is called, the handler will be called directly.cancellable
- the cancel handlerprotected void runNotifier(java.lang.Runnable runnable)
Executor
retrieved via getNotifierExecutor()
.runnable
- the runnable taskprotected java.util.concurrent.Executor getNotifierExecutor()
Copyright © 2010 JBoss, a division of Red Hat, Inc.