Package org.apache.mina.core.future
Interface ConnectFuture
-
- All Superinterfaces:
IoFuture
- All Known Implementing Classes:
AbstractPollingIoConnector.ConnectionRequest,DefaultConnectFuture
public interface ConnectFuture extends IoFuture
AnIoFuturefor 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(...);
- Author:
- Apache MINA Project
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ConnectFutureaddListener(IoFutureListener<?> listener)Adds an eventlistenerwhich is notified when this future is completed.ConnectFutureawait()Wait for the asynchronous operation to complete.ConnectFutureawaitUninterruptibly()Wait for the asynchronous operation to complete uninterruptibly.booleancancel()Cancels the connection attempt and notifies all threads waiting for this future.ThrowablegetException()Returns the cause of the connection failure.IoSessiongetSession()ReturnsIoSessionwhich is the result of connect operation.booleanisCanceled()booleanisConnected()ConnectFutureremoveListener(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 org.apache.mina.core.future.IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, isDone, join, join
-
-
-
-
Method Detail
-
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
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:
trueif the future has been cancelled by this call,falseif the future was already cancelled.
-
await
ConnectFuture await() throws InterruptedException
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
ConnectFuture addListener(IoFutureListener<?> listener)
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
ConnectFuture removeListener(IoFutureListener<?> listener)
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
-
-