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 of WriteFuture.
  • Field Details

    • CLOSED

      private static final Object CLOSED
      A static object used when the session is closed
  • Constructor Details

    • DefaultReadFuture

      public DefaultReadFuture(IoSession session)
      Creates a new instance.
      Parameters:
      session - The associated session
  • Method Details

    • getMessage

      public Object getMessage()
      Get the read message.
      Specified by:
      getMessage in interface ReadFuture
      Returns:
      the received message. It returns null if this future is not ready or the associated IoSession has been closed.
    • isRead

      public boolean isRead()
      Specified by:
      isRead in interface ReadFuture
      Returns:
      true if a message was received successfully.
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface ReadFuture
      Returns:
      true if the IoSession associated with this future has been closed.
    • getException

      public Throwable getException()
      Specified by:
      getException in interface ReadFuture
      Returns:
      the cause of the read failure if and only if the read operation has failed due to an Exception. Otherwise, null is returned.
    • setClosed

      public void setClosed()
      Sets the associated IoSession is closed. This method is invoked by MINA internally. Please do not call this method directly.
      Specified by:
      setClosed in interface ReadFuture
    • 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:
      setRead in interface ReadFuture
      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:
      setException in interface ReadFuture
      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:
      await in interface IoFuture
      Specified by:
      await in interface ReadFuture
      Overrides:
      await in class DefaultIoFuture
      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:
      awaitUninterruptibly in interface IoFuture
      Specified by:
      awaitUninterruptibly in interface ReadFuture
      Overrides:
      awaitUninterruptibly in class DefaultIoFuture
      Returns:
      the current IoFuture
    • addListener

      public ReadFuture addListener(IoFutureListener<?> listener)
      Adds an event listener 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 interface IoFuture
      Specified by:
      addListener in interface ReadFuture
      Overrides:
      addListener in class DefaultIoFuture
      Parameters:
      listener - The listener to add
      Returns:
      the current IoFuture
    • removeListener

      public ReadFuture removeListener(IoFutureListener<?> listener)
      Removes an existing event listener so it won't be notified when the future is completed.
      Specified by:
      removeListener in interface IoFuture
      Specified by:
      removeListener in interface ReadFuture
      Overrides:
      removeListener in class DefaultIoFuture
      Parameters:
      listener - The listener to remove
      Returns:
      the current IoFuture