super.stop(context);
}
@Override
public Channel.Key startReceiving(final Channel channel) {
final ManagementChannelHandler handler = new ManagementChannelHandler(ManagementClientChannelStrategy.create(channel), getExecutor());
// Assemble the request handlers for the domain channel
handler.addHandlerFactory(new HostControllerRegistrationHandler(handler, domainController, operationExecutor, slaveRequestExecutor));
handler.addHandlerFactory(new ModelControllerClientOperationHandler(getController(), handler));
handler.addHandlerFactory(new MasterDomainControllerOperationHandlerImpl(domainController, slaveRequestExecutor));
handler.addHandlerFactory(pongRequestHandler);
final Channel.Key key = channel.addCloseHandler(new CloseHandler<Channel>() {
@Override
public void handleClose(Channel closed, IOException exception) {
handler.shutdown();
boolean interrupted = false;
try {
if (!handler.awaitCompletion(CHANNEL_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS)) {
ROOT_LOGGER.gracefulManagementChannelHandlerShutdownTimedOut(CHANNEL_SHUTDOWN_TIMEOUT);
}
} catch (InterruptedException e) {
interrupted = true;
ROOT_LOGGER.serviceShutdownIncomplete(e);
} catch (Exception e) {
ROOT_LOGGER.serviceShutdownIncomplete(e);
} finally {
handler.shutdownNow();
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
});
channel.receiveMessage(handler.getReceiver());
return key;
}