public abstract class AbstractIoFuture<V> extends Object implements IoFuture<V>
IoFuture
. Owners of this future must implement cancelOwner(boolean)
to
receive notifications of when the future should be canceled.
Concrete implementations of this abstract class should consider overriding the two methods
scheduleResult(org.apache.mina.api.IoFutureListener, Object)
and
scheduleException(org.apache.mina.api.IoFutureListener, Throwable)
so that listeners are called in a
separate thread. The default implementations may end up calling the listener in the same thread that is registering
the listener, before the registration has completed.
Constructor and Description |
---|
AbstractIoFuture() |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
protected abstract boolean |
cancelOwner(boolean mayInterruptIfRunning)
Notify the owner of this future that a client is attempting to cancel.
|
V |
get() |
V |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
IoFuture<V> |
register(IoFutureListener<V> listener)
Register a listener to asynchronously receive the results of the
future computation.
|
protected void |
scheduleException(IoFutureListener<V> listener,
Throwable throwable)
Default implementation to call a listener's
IoFutureListener.exception(Throwable) method. |
protected void |
scheduleResult(IoFutureListener<V> listener,
V result)
Default implementation to call a listener's
IoFutureListener.completed(Object) method. |
protected void |
setException(Throwable t)
Set the future result as a
Throwable , indicating that a throwable was thrown while executing the task. |
protected void |
setResult(V value)
Set the future result of the executing task.
|
public IoFuture<V> register(IoFutureListener<V> listener)
public boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled
in interface Future<V>
public V get() throws InterruptedException, ExecutionException
get
in interface Future<V>
InterruptedException
ExecutionException
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get
in interface Future<V>
InterruptedException
ExecutionException
TimeoutException
protected abstract boolean cancelOwner(boolean mayInterruptIfRunning)
After this method returns, subsequent calls to isDone()
will always return true. Subsequent calls
to isCancelled()
will always return true if this method returned true.
mayInterruptIfRunning
- true if the owner executing this task should be interrupted; otherwise,
in-progress tasks are allowed to completeprotected void scheduleResult(IoFutureListener<V> listener, V result)
IoFutureListener.completed(Object)
method. Owners may
override this method so that the listener is called from a thread pool.listener
- the listener to callresult
- the result to pass to the listenerprotected void scheduleException(IoFutureListener<V> listener, Throwable throwable)
IoFutureListener.exception(Throwable)
method. Owners may
override this method so that the listener is called from a thread pool.listener
- the listener to callthrowable
- the exception to pass to the listenerprotected final void setResult(V value)
IoFutureListener
s are notified of thevalue
- the value returned by the executing task.protected final void setException(Throwable t)
Throwable
, indicating that a throwable was thrown while executing the task.
This value is usually set by the future result owner.
Any IoFutureListener
s are notified of the exception.t
- the throwable that was thrown while executing the task.Copyright © 2009–2013 Apache MINA Project. All rights reserved.