public ModelController createController(final ModelNode model, final Setup registration) throws InterruptedException { final ServiceController<?> existingController = serviceContainer.getService(ServiceName.of("ModelController")); if (existingController != null) { final CountDownLatch latch = new CountDownLatch(1); existingController.addListener( new AbstractServiceListener<Object>() { public void listenerAdded(ServiceController<?> serviceController) { serviceController.setMode(ServiceController.Mode.REMOVE); } public void transition( ServiceController<?> serviceController, ServiceController.Transition transition) { if (transition.equals(ServiceController.Transition.REMOVING_to_REMOVED)) { latch.countDown(); } } }); latch.await(); } ServiceTarget target = serviceContainer.subTarget(); ControlledProcessState processState = new ControlledProcessState(true); ModelControllerService svc = new ModelControllerService(processState, registration, model); ServiceBuilder<ModelController> builder = target.addService(ServiceName.of("ModelController"), svc); builder.install(); svc.latch.await(); ModelController controller = svc.getValue(); ModelNode setup = Util.getEmptyOperation("setup", new ModelNode()); controller.execute(setup, null, null, null); processState.setRunning(); return controller; }
/** * Create a new controller with the passed in operations. * * @param additionalInit Additional initialization that should be done to the parsers, controller * and service container before initializing our extension * @param bootOperations the operations */ protected KernelServices installInController( AdditionalInitialization additionalInit, List<ModelNode> bootOperations) throws Exception { if (additionalInit == null) { additionalInit = new AdditionalInitialization(); } ControllerInitializer controllerInitializer = additionalInit.createControllerInitializer(); additionalInit.setupController(controllerInitializer); // Initialize the controller ServiceContainer container = ServiceContainer.Factory.create("test" + counter.incrementAndGet()); ServiceTarget target = container.subTarget(); ControlledProcessState processState = new ControlledProcessState(true); List<ModelNode> extraOps = controllerInitializer.initializeBootOperations(); List<ModelNode> allOps = new ArrayList<ModelNode>(); if (extraOps != null) { allOps.addAll(extraOps); } allOps.addAll(bootOperations); StringConfigurationPersister persister = new StringConfigurationPersister(allOps, testParser); ModelControllerService svc = new ModelControllerService( additionalInit.getType(), mainExtension, controllerInitializer, additionalInit, processState, persister, additionalInit.isValidateOperations()); ServiceBuilder<ModelController> builder = target.addService(ServiceName.of("ModelController"), svc); builder.install(); additionalInit.addExtraServices(target); // sharedState = svc.state; svc.latch.await(); ModelController controller = svc.getValue(); ModelNode setup = Util.getEmptyOperation("setup", new ModelNode()); controller.execute(setup, null, null, null); processState.setRunning(); KernelServices kernelServices = new KernelServices( container, controller, persister, new OperationValidator(svc.rootRegistration)); this.kernelServices.add(kernelServices); if (svc.error != null) { throw svc.error; } return kernelServices; }
private LiveOakFactory( File configDir, File applicationsDir, Vertx vertx, String bindAddress, ServiceContainer serviceContainer) { this( configDir, applicationsDir, vertx, bindAddress, serviceContainer, serviceContainer.subTarget()); }
/** * Start the host controller services. * * @throws Exception */ public void bootstrap() throws Exception { final HostRunningModeControl runningModeControl = environment.getRunningModeControl(); final ControlledProcessState processState = new ControlledProcessState(true); shutdownHook.setControlledProcessState(processState); ServiceTarget target = serviceContainer.subTarget(); ControlledProcessStateService controlledProcessStateService = ControlledProcessStateService.addService(target, processState).getValue(); RunningStateJmx.registerMBean( controlledProcessStateService, null, runningModeControl, Type.from(environment.getProcessType().name())); final HostControllerService hcs = new HostControllerService(environment, runningModeControl, authCode, processState); target.addService(HostControllerService.HC_SERVICE_NAME, hcs).install(); }