org.apache.mina.common
Interface ReadFuture

All Superinterfaces:
IoFuture
All Known Implementing Classes:
DefaultReadFuture

public interface ReadFuture
extends IoFuture

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.await();
 try {
     Object message = future.getMessage();
 } catch (Exception e) {
     ...
 }
 

Version:
$Rev: 594477 $, $Date: 2007-11-13 11:42:03 +0100 (Tue, 13 Nov 2007) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Method Summary
 ReadFuture addListener(IoFutureListener<?> listener)
          Adds an event listener which is notified when the state of this future changes.
 ReadFuture await()
          Wait for the asynchronous operation to end.
 ReadFuture awaitUninterruptibly()
          Wait for the asynchronous operation to end uninterruptibly.
 Throwable getException()
          Returns the cause of the read failure if and only if the read operation has failed due to an Exception.
 Object getMessage()
          Returns the received message.
 boolean isClosed()
          Returns true if the IoSession associated with this future has been closed.
 boolean isRead()
          Returns true if a message was received successfully.
 ReadFuture removeListener(IoFutureListener<?> listener)
          Removes an existing event listener which is notified when the state of this future changes.
 void setClosed()
          Sets the associated IoSession 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.common.IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getSession, isReady, join, join
 

Method Detail

getMessage

Object getMessage()
Returns the received message. It returns null if this future is not ready or the associated IoSession has been closed.

Throws:
RuntimeException - if read or any relevant operation has failed.

isRead

boolean isRead()
Returns true if a message was received successfully.


isClosed

boolean isClosed()
Returns true if the IoSession 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.


setClosed

void setClosed()
Sets the associated IoSession 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.


await

ReadFuture await()
                 throws InterruptedException
Description copied from interface: IoFuture
Wait for the asynchronous operation to end.

Specified by:
await in interface IoFuture
Throws:
InterruptedException

awaitUninterruptibly

ReadFuture awaitUninterruptibly()
Description copied from interface: IoFuture
Wait for the asynchronous operation to end uninterruptibly.

Specified by:
awaitUninterruptibly in interface IoFuture

addListener

ReadFuture addListener(IoFutureListener<?> listener)
Description copied from interface: IoFuture
Adds an event listener which is notified when the state of this future changes.

Specified by:
addListener in interface IoFuture

removeListener

ReadFuture removeListener(IoFutureListener<?> listener)
Description copied from interface: IoFuture
Removes an existing event listener which is notified when the state of this future changes.

Specified by:
removeListener in interface IoFuture


Copyright © 2004-2009 Apache MINA Project. All Rights Reserved.