this.exchange = exchange;
}
@Override
public void completed(final ClientConnection connection) {
final ServerConnection serverConnection = exchange.getConnection();
final SimpleProxyClient simpleProxyClient = new SimpleProxyClient(connection);
//we attach to the connection so it can be re-used
serverConnection.putAttachment(clientAttachmentKey, simpleProxyClient);
exchange.putAttachment(CLIENT, simpleProxyClient);
serverConnection.addCloseListener(new ServerConnection.CloseListener() {
@Override
public void closed(ServerConnection serverConnection) {
IoUtils.safeClose(connection);
}
});
connection.getCloseSetter().set(new ChannelListener<Channel>() {
@Override
public void handleEvent(Channel channel) {
serverConnection.removeAttachment(clientAttachmentKey);
}
});
exchange.dispatch(SameThreadExecutor.INSTANCE, next);
}