Interface ConnectFuture

All Superinterfaces:
IoFuture
All Known Implementing Classes:
AbstractPollingIoConnector.ConnectionRequest, DefaultConnectFuture

public interface ConnectFuture extends IoFuture
An IoFuture for asynchronous connect requests.

Example

IoConnector connector = ...;
ConnectFuture future = connector.connect(...);
future.awaitUninterruptibly(); // Wait until the connection attempt is finished.
IoSession session = future.getSession();
session.write(...);
  • Method Details

    • getSession

      IoSession getSession()
      Returns IoSession which is the result of connect operation.
      Specified by:
      getSession in interface IoFuture
      Returns:
      The {link IoSession} instance that has been associated with the connection, if the connection was successful, null otherwise
    • getException

      Throwable getException()
      Returns the cause of the connection failure.
      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

      boolean isConnected()
      Returns:
      true if the connect operation is finished successfully.
    • isCanceled

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

      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.
      Parameters:
      session - The created session to store in the ConnectFuture insteance
    • setException

      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.
      Parameters:
      exception - The exception to store in the ConnectFuture instance
    • cancel

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

      Wait for the asynchronous operation to complete. The attached listeners will be notified when the operation is completed.
      Specified by:
      await in interface IoFuture
      Returns:
      The instance of IoFuture that we are waiting for
      Throws:
      InterruptedException - If the thread is interrupted while waiting
    • awaitUninterruptibly

      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 IoFuture
      Returns:
      the current IoFuture
    • addListener

      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 IoFuture
      Parameters:
      listener - The listener to add
      Returns:
      the current IoFuture
    • removeListener

      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 IoFuture
      Parameters:
      listener - The listener to remove
      Returns:
      the current IoFuture