}
// Read the domain model async, this will block until the registration process is complete
context.executeAsync(new ManagementRequestContext.AsyncTask<RegistrationContext>() {
@Override
public void execute(ManagementRequestContext<RegistrationContext> context) throws Exception {
final Channel channel = context.getChannel();
try {
// The domain model is going to be sent as part of the prepared notification
final OperationStepHandler handler = new HostRegistrationStepHandler(registration);
operationExecutor.execute(READ_DOMAIN_MODEL, OperationMessageHandler.logging, registration, OperationAttachments.EMPTY, handler);
} catch (Exception e) {
registration.failed(e);
return;
}
// Send a registered notification back
registration.sendCompletedMessage();
// Make sure that the host controller gets unregistered when the channel is closed
channel.addCloseHandler(new CloseHandler<Channel>() {
@Override
public void handleClose(Channel closed, IOException exception) {
if(domainController.isHostRegistered(hostName)) {
DOMAIN_LOGGER.lostConnectionToRemoteHost(hostName);
}