VmPipe entry = VmPipeAcceptor.boundHandlers.get(remoteAddress);
if (entry == null) {
return DefaultConnectFuture.newFailedFuture(new IOException("Endpoint unavailable: " + remoteAddress));
}
DefaultConnectFuture future = new DefaultConnectFuture();
// Assign the local address dynamically,
VmPipeAddress actualLocalAddress;
try {
actualLocalAddress = nextLocalAddress();
} catch (IOException e) {
return DefaultConnectFuture.newFailedFuture(e);
}
VmPipeSession localSession = new VmPipeSession(this, getListeners(), actualLocalAddress, getHandler(), entry);
initSession(localSession, future, sessionInitializer);
// and reclaim the local address when the connection is closed.
localSession.getCloseFuture().addListener(LOCAL_ADDRESS_RECLAIMER);
// initialize connector session
try {
IoFilterChain filterChain = localSession.getFilterChain();
this.getFilterChainBuilder().buildFilterChain(filterChain);
// The following sentences don't throw any exceptions.
getListeners().fireSessionCreated(localSession);
idleChecker.addSession(localSession);
} catch (Exception e) {
future.setException(e);
return future;
}
// initialize acceptor session
VmPipeSession remoteSession = localSession.getRemoteSession();