}
// 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();
final ModelNode result;
try {
// The domain model is going to be sent as part of the prepared notification
result = controller.execute(READ_DOMAIN_MODEL, OperationMessageHandler.logging, registration, OperationAttachments.EMPTY);
} catch (Exception e) {
registration.failed(SlaveRegistrationException.ErrorCode.UNKNOWN, e.getClass().getName() + ":" + e.getMessage());
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);
}