*
* @return the connection
* @throws IOException
*/
public Connection connect() throws IOException {
Connection connection;
synchronized (this) {
if(shutdown) throw ProtocolMessages.MESSAGES.channelClosed();
connection = this.connection;
if(connection == null) {
connection = connectTask.connect();
if(connection == null) {
throw ProtocolMessages.MESSAGES.channelClosed();
}
boolean ok = false;
try {
// Connection opened notification
final ConnectionOpenHandler openHandler = connectTask.getConnectionOpenedHandler();
openHandler.connectionOpened(connection);
ok = true;
this.connection = connection;
connection.addCloseHandler(new CloseHandler<Connection>() {
@Override
public void handleClose(Connection closed, IOException exception) {
onConnectionClose(closed);
}
});