final Runnable task = new Runnable() {
@Override
public void run() {
CONTROLLER_MANAGEMENT_LOGGER.serverRegistered(serverName, channel);
// Create the server mgmt handler
final ManagementChannelHandler handler = new ManagementChannelHandler(channel, executorService, new ServerHandlerFactory(serverName));
// Register the communication channel
inventory.serverCommunicationRegistered(serverName, handler);
// Send the response once the server is fully registered
safeWriteResponse(channel, header, null);
// Onto the next message
channel.receiveMessage(handler.getReceiver());
}
};
executorService.execute(task);
// Handle the server reconnect request
} else if(type == DomainServerProtocol.SERVER_RECONNECT_REQUEST) {
expectHeader(input, DomainServerProtocol.PARAM_SERVER_NAME);
final String serverName = input.readUTF();
final Runnable task = new Runnable() {
@Override
public void run() {
CONTROLLER_MANAGEMENT_LOGGER.serverRegistered(serverName, channel);
// Create the server mgmt handler
final ManagementChannelHandler handler = new ManagementChannelHandler(channel, executorService, new ServerHandlerFactory(serverName));
// Check if the server is still in sync with the domain model
final byte param;
if(inventory.serverReconnected(serverName, handler)) {
param = DomainServerProtocol.PARAM_OK;
} else {
param = DomainServerProtocol.PARAM_RESTART_REQUIRED;
}
// Notify the server whether configuration is still in sync or it requires a reload
safeWriteResponse(channel, header, param);
// Onto the next message
channel.receiveMessage(handler.getReceiver());
}
};
executorService.execute(task);
} else {
safeWriteResponse(channel, header, MESSAGES.unrecognizedType(type));