final IoFuture<Connection> futureConnection = endpoint.connect(connectionURI, builder.getMap(), new AuthenticationCallbackHandler(username, password));
// wait for the connection to be established
final Connection connection = IoFutureHelper.get(futureConnection, 5000, TimeUnit.MILLISECONDS);
// create a remoting EJB receiver for this connection
final EJBReceiver receiver = new RemotingConnectionEJBReceiver(connection);
// associate it with the client context
EJBClientContext context = EJBClientContext.create();
context.registerEJBReceiver(receiver);
return EJBClientContext.setSelector(new ClosableContextSelector(context, endpoint, connection, receiver));
}