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
A default implementation of
ConnectFuture.-
Field Summary
Fields -
Constructor Summary
Constructors -
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.booleanbooleanstatic ConnectFuturenewFailedFuture(Throwable exception) Creates a new instance of a Connection Failure, with the associated cause.removeListener(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 class DefaultIoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getValue, isDone, join, join, setValueMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, isDone, join, join
-
Field Details
-
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
Creates a new instance of a Connection Failure, with the associated cause.- Parameters:
exception- The exception that caused the failure- Returns:
- a new
ConnectFuturewhich is already marked as 'failed to connect'.
-
getSession
- Specified by:
getSessionin interfaceConnectFuture- Specified by:
getSessionin interfaceIoFuture- Overrides:
getSessionin classDefaultIoFuture- Returns:
- the
IoSessionwhich is associated with this future.
-
getException
Returns the cause of the connection failure.- Specified by:
getExceptionin interfaceConnectFuture- Returns:
nullif 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:
isConnectedin interfaceConnectFuture- Returns:
trueif the connect operation is finished successfully.
-
isCanceled
public boolean isCanceled()- Specified by:
isCanceledin interfaceConnectFuture- Returns:
trueif the connect operation has been canceled byConnectFuture.cancel()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.- Specified by:
setSessionin interfaceConnectFuture- 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.- Specified by:
setExceptionin interfaceConnectFuture- 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:
cancelin interfaceConnectFuture- 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 interfaceConnectFuture- Specified by:
awaitin interfaceIoFuture- Overrides:
awaitin classDefaultIoFuture- Returns:
- The instance of IoFuture that we are waiting for
- Throws:
InterruptedException- If the thread is interrupted while waiting
-
awaitUninterruptibly
Wait for the asynchronous operation to complete uninterruptibly. The attached listeners will be notified when the operation is completed.- Specified by:
awaitUninterruptiblyin interfaceConnectFuture- Specified by:
awaitUninterruptiblyin interfaceIoFuture- Overrides:
awaitUninterruptiblyin classDefaultIoFuture- 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 interfaceConnectFuture- Specified by:
addListenerin interfaceIoFuture- Overrides:
addListenerin classDefaultIoFuture- 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 interfaceConnectFuture- Specified by:
removeListenerin interfaceIoFuture- Overrides:
removeListenerin classDefaultIoFuture- Parameters:
listener- The listener to remove- Returns:
- the current IoFuture
-