private void activateManagementCommunication(final ServiceActivatorContext serviceActivatorContext) {
final BatchBuilder batchBuilder = serviceActivatorContext.getBatchBuilder();
HostModel hostConfig = getHostModel();
final ManagementElement managementElement = hostConfig.getManagementElement();
if(managementElement == null) {
throw new IllegalStateException("null management configuration");
}
final Set<InterfaceElement> hostInterfaces = hostConfig.getInterfaces();
if(hostInterfaces != null) {
for(InterfaceElement interfaceElement : hostInterfaces) {
if(interfaceElement.getName().equals(managementElement.getInterfaceName())) {
interfaceElement.activate(serviceActivatorContext);
break;
}
}
}
// Add the executor
final ServiceName threadFactoryServiceName = SERVICE_NAME_BASE.append("thread-factory");
batchBuilder.addService(threadFactoryServiceName, new ThreadFactoryService());
final ServiceName executorServiceName = SERVICE_NAME_BASE.append("executor");
/**
* Replace below with fixed ScheduledThreadPoolService
*/
final InjectedValue<ThreadFactory> threadFactoryValue = new InjectedValue<ThreadFactory>();
batchBuilder.addService(executorServiceName, new Service<ScheduledExecutorService>() {
private ScheduledExecutorService executorService;
public synchronized void start(StartContext context) throws StartException {
executorService = Executors.newScheduledThreadPool(20, threadFactoryValue.getValue());
}
public synchronized void stop(StopContext context) {
executorService.shutdown();
}
public synchronized ScheduledExecutorService getValue() throws IllegalStateException {
return executorService;
}
}).addDependency(threadFactoryServiceName, ThreadFactory.class, threadFactoryValue);
// Add the management communication service
final ManagementCommunicationService managementCommunicationService = new ManagementCommunicationService();
batchBuilder.addService(ManagementCommunicationService.SERVICE_NAME, managementCommunicationService)
.addDependency(NetworkInterfaceService.JBOSS_NETWORK_INTERFACE.append(managementElement.getInterfaceName()), NetworkInterfaceBinding.class, managementCommunicationService.getInterfaceInjector())
.addInjection(managementCommunicationService.getPortInjector(), managementElement.getPort())
.addDependency(executorServiceName, ExecutorService.class, managementCommunicationService.getExecutorServiceInjector())
.addDependency(threadFactoryServiceName, ThreadFactory.class, managementCommunicationService.getThreadFactoryInjector())
.setInitialMode(ServiceController.Mode.ACTIVE);
// Add the DC to server manager operation handler