Package org.apache.mina.core.future
Interface ReadFuture
-
- All Superinterfaces:
IoFuture
- All Known Implementing Classes:
DefaultReadFuture
public interface ReadFuture extends IoFuture
AnIoFuture
forasynchronous read requests
.Example
IoSession session = ...; // useReadOperation must be enabled to use read operation. session.getConfig().setUseReadOperation(true); ReadFuture future = session.read(); // Wait until a message is received. future.awaitUninterruptibly(); try { Object message = future.getMessage(); } catch (Exception e) { ... }
- Author:
- Apache MINA Project
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ReadFuture
addListener(IoFutureListener<?> listener)
Adds an eventlistener
which is notified when this future is completed.ReadFuture
await()
Wait for the asynchronous operation to complete.ReadFuture
awaitUninterruptibly()
Wait for the asynchronous operation to complete uninterruptibly.Throwable
getException()
Object
getMessage()
Get the read message.boolean
isClosed()
boolean
isRead()
ReadFuture
removeListener(IoFutureListener<?> listener)
Removes an existing eventlistener
so it won't be notified when the future is completed.void
setClosed()
Sets the associatedIoSession
is closed.void
setException(Throwable cause)
Sets the cause of the read failure, and notifies all threads waiting for this future.void
setRead(Object message)
Sets the message is written, and notifies all threads waiting for this future.-
Methods inherited from interface org.apache.mina.core.future.IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getSession, isDone, join, join
-
-
-
-
Method Detail
-
getMessage
Object getMessage()
Get the read message.- Returns:
- the received message. It returns
null
if this future is not ready or the associatedIoSession
has been closed.
-
isRead
boolean isRead()
- Returns:
true
if a message was received successfully.
-
isClosed
boolean isClosed()
- Returns:
true
if theIoSession
associated with this future has been closed.
-
getException
Throwable getException()
- Returns:
- the cause of the read failure if and only if the read
operation has failed due to an
Exception
. Otherwise,null
is returned.
-
setRead
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.- Parameters:
message
- The received message to store in this future
-
setClosed
void setClosed()
Sets the associatedIoSession
is closed. This method is invoked by MINA internally. Please do not call this method directly.
-
setException
void setException(Throwable cause)
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.- Parameters:
cause
- The exception to store in the Future instance
-
await
ReadFuture await() throws InterruptedException
Wait for the asynchronous operation to complete. The attached listeners will be notified when the operation is completed.- Specified by:
await
in interfaceIoFuture
- Returns:
- The instance of IoFuture that we are waiting for
- Throws:
InterruptedException
- If the thread is interrupted while waiting
-
awaitUninterruptibly
ReadFuture awaitUninterruptibly()
Wait for the asynchronous operation to complete uninterruptibly. The attached listeners will be notified when the operation is completed.- Specified by:
awaitUninterruptibly
in interfaceIoFuture
- Returns:
- the current IoFuture
-
addListener
ReadFuture addListener(IoFutureListener<?> listener)
Adds an eventlistener
which is notified when this future is completed. If the listener is added after the completion, the listener is directly notified.- Specified by:
addListener
in interfaceIoFuture
- Parameters:
listener
- The listener to add- Returns:
- the current IoFuture
-
removeListener
ReadFuture removeListener(IoFutureListener<?> listener)
Removes an existing eventlistener
so it won't be notified when the future is completed.- Specified by:
removeListener
in interfaceIoFuture
- Parameters:
listener
- The listener to remove- Returns:
- the current IoFuture
-
-