Package org.apache.mina.core.future
Interface ConnectFuture
-
- All Superinterfaces:
IoFuture
- All Known Implementing Classes:
AbstractPollingIoConnector.ConnectionRequest
,DefaultConnectFuture
public interface ConnectFuture extends IoFuture
AnIoFuture
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(...);
- Author:
- Apache MINA Project
-
-
Method Summary
All Methods Instance Methods Abstract 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()
ReturnsIoSession
which is the result of connect operation.boolean
isCanceled()
boolean
isConnected()
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 interface org.apache.mina.core.future.IoFuture
await, await, awaitUninterruptibly, awaitUninterruptibly, isDone, join, join
-
-
-
-
Method Detail
-
getSession
IoSession getSession()
ReturnsIoSession
which is the result of connect operation.- Specified by:
getSession
in interfaceIoFuture
- Returns:
- The {link IoSession} instance that has been associated with the connection,
if the connection was successful,
null
otherwise
-
getException
Throwable getException()
Returns the cause of the connection failure.- 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
boolean isConnected()
- Returns:
true
if the connect operation is finished successfully.
-
isCanceled
boolean isCanceled()
- Returns:
true
if 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:
true
if the future has been cancelled by this call,false
if 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:
await
in 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:
awaitUninterruptibly
in interfaceIoFuture
- Returns:
- the current IoFuture
-
addListener
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 interfaceIoFuture
- Parameters:
listener
- The listener to add- Returns:
- the current IoFuture
-
removeListener
ConnectFuture removeListener(IoFutureListener<?> listener)
Removes an existing eventlistener
so it won't be notified when the future is completed.- Specified by:
removeListener
in interfaceIoFuture
- Parameters:
listener
- The listener to remove- Returns:
- the current IoFuture
-
-