Package org.apache.mina.core.future
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 ofConnectFuture.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description DefaultConnectFuture()Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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()booleanisCanceled()booleanisConnected()static ConnectFuturenewFailedFuture(Throwable exception)Creates a new instance of a Connection Failure, with the associated cause.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 class org.apache.mina.core.future.DefaultIoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, getValue, isDone, join, join, setValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.mina.core.future.IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, isDone, join, join
-
-
-
-
Method Detail
-
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
ConnectFuturewhich is already marked as 'failed to connect'.
-
getSession
public IoSession getSession()
- Specified by:
getSessionin interfaceConnectFuture- Specified by:
getSessionin interfaceIoFuture- Overrides:
getSessionin classDefaultIoFuture- Returns:
- the
IoSessionwhich is associated with this future.
-
getException
public Throwable 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
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:
setSessionin interfaceConnectFuture- 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:
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
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:
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
public ConnectFuture 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
public 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 interfaceConnectFuture- Specified by:
addListenerin interfaceIoFuture- Overrides:
addListenerin classDefaultIoFuture- Parameters:
listener- The listener to add- Returns:
- the current IoFuture
-
removeListener
public ConnectFuture removeListener(IoFutureListener<?> listener)
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
-
-