Class DefaultConnectFuture

java.lang.Object
org.apache.mina.core.future.DefaultIoFuture
org.apache.mina.core.future.DefaultConnectFuture
All Implemented Interfaces:
ConnectFuture, IoFuture
Direct Known Subclasses:
AbstractPollingIoConnector.ConnectionRequest

public class DefaultConnectFuture extends DefaultIoFuture implements ConnectFuture
A default implementation of ConnectFuture.
  • Field Details

    • CANCELED

      private static final Object CANCELED
      A static object stored into the ConnectFuture when teh connection has been cancelled
  • Constructor Details

    • DefaultConnectFuture

      public DefaultConnectFuture()
      Creates a new instance.
  • Method Details

    • newFailedFuture

      public static ConnectFuture newFailedFuture(Throwable exception)
      Creates a new instance of a Connection Failure, with the associated cause.
      Parameters:
      exception - The exception that caused the failure
      Returns:
      a new ConnectFuture which is already marked as 'failed to connect'.
    • getSession

      public IoSession getSession()
      Specified by:
      getSession in interface ConnectFuture
      Specified by:
      getSession in interface IoFuture
      Overrides:
      getSession in class DefaultIoFuture
      Returns:
      the IoSession which is associated with this future.
    • getException

      public Throwable getException()
      Returns the cause of the connection failure.
      Specified by:
      getException in interface ConnectFuture
      Returns:
      null if the connect operation is not finished yet, or if the connection attempt is successful, otherwise returns the cause of the exception
    • isConnected

      public boolean isConnected()
      Specified by:
      isConnected in interface ConnectFuture
      Returns:
      true if the connect operation is finished successfully.
    • isCanceled

      public boolean isCanceled()
      Specified by:
      isCanceled in interface ConnectFuture
      Returns:
      true if the connect operation has been canceled by ConnectFuture.cancel() method.
    • setSession

      public void setSession(IoSession session)
      Sets the newly connected session and notifies all threads waiting for this future. This method is invoked by MINA internally. Please do not call this method directly.
      Specified by:
      setSession in interface ConnectFuture
      Parameters:
      session - The created session to store in the ConnectFuture insteance
    • setException

      public void setException(Throwable exception)
      Sets the exception caught due to connection 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 ConnectFuture
      Parameters:
      exception - The exception to store in the ConnectFuture instance
    • cancel

      public boolean cancel()
      Cancels the connection attempt and notifies all threads waiting for this future.
      Specified by:
      cancel in interface ConnectFuture
      Returns:
      true if the future has been cancelled by this call, false if the future was already cancelled.
    • await

      public ConnectFuture 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 ConnectFuture
      Specified by:
      await in interface IoFuture
      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 ConnectFuture 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 ConnectFuture
      Specified by:
      awaitUninterruptibly in interface IoFuture
      Overrides:
      awaitUninterruptibly in class DefaultIoFuture
      Returns:
      the current IoFuture
    • addListener

      public ConnectFuture 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 ConnectFuture
      Specified by:
      addListener in interface IoFuture
      Overrides:
      addListener in class DefaultIoFuture
      Parameters:
      listener - The listener to add
      Returns:
      the current IoFuture
    • removeListener

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