Interface ReadFuture
- All Superinterfaces:
IoFuture
- All Known Implementing Classes:
DefaultReadFuture
An
IoFuture for asynchronous 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) {
...
}
-
Method Summary
Modifier and TypeMethodDescriptionaddListener(IoFutureListener<?> listener) Adds an eventlistenerwhich is notified when this future is completed.await()Wait for the asynchronous operation to complete.Wait for the asynchronous operation to complete uninterruptibly.Get the read message.booleanisClosed()booleanisRead()removeListener(IoFutureListener<?> listener) Removes an existing eventlistenerso it won't be notified when the future is completed.voidSets the associatedIoSessionis closed.voidsetException(Throwable cause) Sets the cause of the read failure, and notifies all threads waiting for this future.voidSets the message is written, and notifies all threads waiting for this future.Methods inherited from interface IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getSession, isDone, join, join
-
Method Details
-
getMessage
-
isRead
boolean isRead()- Returns:
trueif a message was received successfully.
-
isClosed
boolean isClosed()- Returns:
trueif theIoSessionassociated with this future has been closed.
-
getException
-
setRead
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 associatedIoSessionis closed. This method is invoked by MINA internally. Please do not call this method directly. -
setException
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
Wait for the asynchronous operation to complete. The attached listeners will be notified when the operation is completed.- Specified by:
awaitin 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:
awaitUninterruptiblyin interfaceIoFuture- Returns:
- the current IoFuture
-
addListener
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- Parameters:
listener- The listener to add- Returns:
- the current IoFuture
-
removeListener
Removes an existing eventlistenerso it won't be notified when the future is completed.- Specified by:
removeListenerin interfaceIoFuture- Parameters:
listener- The listener to remove- Returns:
- the current IoFuture
-