Package org.apache.mina.core.future
Class DefaultReadFuture
- java.lang.Object
-
- org.apache.mina.core.future.DefaultIoFuture
-
- org.apache.mina.core.future.DefaultReadFuture
-
- All Implemented Interfaces:
IoFuture,ReadFuture
public class DefaultReadFuture extends DefaultIoFuture implements ReadFuture
A default implementation ofWriteFuture.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description DefaultReadFuture(IoSession session)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ReadFutureaddListener(IoFutureListener<?> listener)Adds an eventlistenerwhich is notified when this future is completed.ReadFutureawait()Wait for the asynchronous operation to complete.ReadFutureawaitUninterruptibly()Wait for the asynchronous operation to complete uninterruptibly.ThrowablegetException()ObjectgetMessage()Get the read message.booleanisClosed()booleanisRead()ReadFutureremoveListener(IoFutureListener<?> listener)Removes an existing eventlistenerso it won't be notified when the future is completed.voidsetClosed()Sets the associatedIoSessionis closed.voidsetException(Throwable exception)Sets the cause of the read failure, and notifies all threads waiting for this future.voidsetRead(Object message)Sets the message is written, and notifies all threads waiting for this future.-
Methods inherited from class org.apache.mina.core.future.DefaultIoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getSession, getValue, isDone, join, join, setValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.mina.core.future.IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getSession, isDone, join, join
-
-
-
-
Constructor Detail
-
DefaultReadFuture
public DefaultReadFuture(IoSession session)
Creates a new instance.- Parameters:
session- The associated session
-
-
Method Detail
-
getMessage
public Object getMessage()
Get the read message.- Specified by:
getMessagein interfaceReadFuture- Returns:
- the received message. It returns
nullif this future is not ready or the associatedIoSessionhas been closed.
-
isRead
public boolean isRead()
- Specified by:
isReadin interfaceReadFuture- Returns:
trueif a message was received successfully.
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceReadFuture- Returns:
trueif theIoSessionassociated with this future has been closed.
-
getException
public Throwable getException()
- Specified by:
getExceptionin interfaceReadFuture- Returns:
- the cause of the read failure if and only if the read
operation has failed due to an
Exception. Otherwise,nullis returned.
-
setClosed
public void setClosed()
Sets the associatedIoSessionis closed. This method is invoked by MINA internally. Please do not call this method directly.- Specified by:
setClosedin interfaceReadFuture
-
setRead
public void setRead(Object message)
Sets the message is written, and notifies all threads waiting for this future. This method is invoked by MINA internally. Please do not call this method directly.- Specified by:
setReadin interfaceReadFuture- Parameters:
message- The received message to store in this future
-
setException
public void setException(Throwable exception)
Sets the cause of the read failure, and notifies all threads waiting for this future. This method is invoked by MINA internally. Please do not call this method directly.- Specified by:
setExceptionin interfaceReadFuture- Parameters:
exception- The exception to store in the Future instance
-
await
public ReadFuture await() throws InterruptedException
Wait for the asynchronous operation to complete. The attached listeners will be notified when the operation is completed.- Specified by:
awaitin interfaceIoFuture- Specified by:
awaitin interfaceReadFuture- Overrides:
awaitin classDefaultIoFuture- Returns:
- The instance of IoFuture that we are waiting for
- Throws:
InterruptedException- If the thread is interrupted while waiting
-
awaitUninterruptibly
public ReadFuture awaitUninterruptibly()
Wait for the asynchronous operation to complete uninterruptibly. The attached listeners will be notified when the operation is completed.- Specified by:
awaitUninterruptiblyin interfaceIoFuture- Specified by:
awaitUninterruptiblyin interfaceReadFuture- Overrides:
awaitUninterruptiblyin classDefaultIoFuture- Returns:
- the current IoFuture
-
addListener
public ReadFuture addListener(IoFutureListener<?> listener)
Adds an eventlistenerwhich is notified when this future is completed. If the listener is added after the completion, the listener is directly notified.- Specified by:
addListenerin interfaceIoFuture- Specified by:
addListenerin interfaceReadFuture- Overrides:
addListenerin classDefaultIoFuture- Parameters:
listener- The listener to add- Returns:
- the current IoFuture
-
removeListener
public ReadFuture removeListener(IoFutureListener<?> listener)
Removes an existing eventlistenerso it won't be notified when the future is completed.- Specified by:
removeListenerin interfaceIoFuture- Specified by:
removeListenerin interfaceReadFuture- Overrides:
removeListenerin classDefaultIoFuture- Parameters:
listener- The listener to remove- Returns:
- the current IoFuture
-
-