Cool I think I understand what its doing now :-D (sorry i was getting
frustrated with the code as i didnt understand what it was
doing...pressure from the project manager also doesnt help :-( )
On 1/12/07, Niklas Therning <[EMAIL PROTECTED]> wrote:
peter ellis wrote:
> Can anyone help explain to me how the ConnectFuture works!???
>
In MINA most IO operations are asynchronous. A call to
connector.connect(...) will start a connect operation in a separate
thread and the call will most likely return before the connect operation
has finished. The ConnectFuture returned by connect() can be used to
determine if the connect operation has finished and if it was successful
or not.
Calling future.join() will wait for the operation to finish (either
succeed or fail). Calling future.getSession() after the connect
operation has finished will get the MINA IoSession corresponding to the
established connection. If the connect operation failed getSession()
throws an exception.
You can also listen for completion events by adding a IoFutureListener
to the future object. This way you won't have to call future.join()
which blocks the current thread:
connector.connect(...).addListener(new IoFutureListener() {
public void operationComplete(IoFuture f) {
ConnectFuture future = (ConnectFuture) f;
if (future.isConnected()) {
// The connect operation succeeded
} else {
// The connect operation failed
}
}
});
You can read more about futures here: http://c2.com/cgi/wiki?FutureValue
HTH
--
Niklas Therning
www.spamdrain.net
--
Peter Ellis
Java Developer