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 ConnectFuture
addListener(IoFutureListener<?> listener)
Adds an eventlistener
which is notified when this future is completed.ConnectFuture
await()
Wait for the asynchronous operation to complete.ConnectFuture
awaitUninterruptibly()
Wait for the asynchronous operation to complete uninterruptibly.boolean
cancel()
Cancels the connection attempt and notifies all threads waiting for this future.Throwable
getException()
Returns the cause of the connection failure.IoSession
getSession()
boolean
isCanceled()
boolean
isConnected()
static ConnectFuture
newFailedFuture(Throwable exception)
Creates a new instance of a Connection Failure, with the associated cause.ConnectFuture
removeListener(IoFutureListener<?> listener)
Removes an existing eventlistener
so it won't be notified when the future is completed.void
setException(Throwable exception)
Sets the exception caught due to connection failure and notifies all threads waiting for this future.void
setSession(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
ConnectFuture
which is already marked as 'failed to connect'.
-
getSession
public IoSession getSession()
- Specified by:
getSession
in interfaceConnectFuture
- Specified by:
getSession
in interfaceIoFuture
- Overrides:
getSession
in classDefaultIoFuture
- Returns:
- the
IoSession
which is associated with this future.
-
getException
public Throwable getException()
Returns the cause of the connection failure.- Specified by:
getException
in interfaceConnectFuture
- 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
public boolean isConnected()
- Specified by:
isConnected
in interfaceConnectFuture
- Returns:
true
if the connect operation is finished successfully.
-
isCanceled
public boolean isCanceled()
- Specified by:
isCanceled
in interfaceConnectFuture
- Returns:
true
if 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:
setSession
in 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:
setException
in 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:
cancel
in interfaceConnectFuture
- Returns:
true
if the future has been cancelled by this call,false
if 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:
await
in interfaceConnectFuture
- Specified by:
await
in interfaceIoFuture
- Overrides:
await
in 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:
awaitUninterruptibly
in interfaceConnectFuture
- Specified by:
awaitUninterruptibly
in interfaceIoFuture
- Overrides:
awaitUninterruptibly
in classDefaultIoFuture
- Returns:
- the current IoFuture
-
addListener
public ConnectFuture addListener(IoFutureListener<?> listener)
Adds an eventlistener
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 interfaceConnectFuture
- Specified by:
addListener
in interfaceIoFuture
- Overrides:
addListener
in classDefaultIoFuture
- Parameters:
listener
- The listener to add- Returns:
- the current IoFuture
-
removeListener
public ConnectFuture removeListener(IoFutureListener<?> listener)
Removes an existing eventlistener
so it won't be notified when the future is completed.- Specified by:
removeListener
in interfaceConnectFuture
- Specified by:
removeListener
in interfaceIoFuture
- Overrides:
removeListener
in classDefaultIoFuture
- Parameters:
listener
- The listener to remove- Returns:
- the current IoFuture
-
-