Interface ConnectFuture
- All Superinterfaces:
IoFuture
- All Known Implementing Classes:
AbstractPollingIoConnector.ConnectionRequest, DefaultConnectFuture
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 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.booleancancel()Cancels the connection attempt and notifies all threads waiting for this future.Returns the cause of the connection failure.ReturnsIoSessionwhich is the result of connect operation.booleanbooleanremoveListener(IoFutureListener<?> listener) Removes an existing eventlistenerso it won't be notified when the future is completed.voidsetException(Throwable exception) Sets the exception caught due to connection failure and notifies all threads waiting for this future.voidsetSession(IoSession session) Sets the newly connected session and notifies all threads waiting for this future.Methods inherited from interface IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, isDone, join, join
-
Method Details
-
getSession
IoSession getSession()ReturnsIoSessionwhich is the result of connect operation.- Specified by:
getSessionin interfaceIoFuture- Returns:
- The {link IoSession} instance that has been associated with the connection,
if the connection was successful,
nullotherwise
-
getException
Throwable getException()Returns the cause of the connection failure.- Returns:
nullif 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:
trueif the connect operation is finished successfully.
-
isCanceled
boolean isCanceled()- Returns:
trueif the connect operation has been canceled bycancel()method.
-
setSession
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
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:
trueif the future has been cancelled by this call,falseif 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:
awaitin interfaceIoFuture- 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:
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
-