private void initializeModeShapeEngine( final OperationContext context, final ModelNode operation, ModelNode model, final List<ServiceController<?>> newControllers) { ServiceTarget target = context.getServiceTarget(); final JBossLifeCycleListener shutdownListener = new JBossLifeCycleListener(); engine = buildModeShapeEngine(model); // Engine service ServiceBuilder<JcrEngine> engineBuilder = target.addService(ModeShapeServiceNames.ENGINE, engine); engineBuilder.setInitialMode(ServiceController.Mode.ACTIVE); ServiceController<JcrEngine> controller = engineBuilder.install(); controller.getServiceContainer().addTerminateListener(shutdownListener); newControllers.add(controller); // JNDI Binding final ReferenceFactoryService<JcrEngine> referenceFactoryService = new ReferenceFactoryService<JcrEngine>(); final ServiceName referenceFactoryServiceName = ModeShapeServiceNames.ENGINE.append("reference-factory"); // $NON-NLS-1$ final ServiceBuilder<?> referenceBuilder = target.addService(referenceFactoryServiceName, referenceFactoryService); referenceBuilder.addDependency( ModeShapeServiceNames.ENGINE, JcrEngine.class, referenceFactoryService.getInjector()); referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE); final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(ModeShapeJndiNames.JNDI_BASE_NAME); final BinderService binderService = new BinderService(bindInfo.getBindName()); final ServiceBuilder<?> binderBuilder = target.addService(bindInfo.getBinderServiceName(), binderService); binderBuilder.addDependency( ModeShapeServiceNames.ENGINE, JcrEngine.class, new ManagedReferenceInjector<JcrEngine>(binderService.getManagedObjectInjector())); binderBuilder.addDependency( bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()); binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE); Logger.getLogger(getClass()) .debug("Binding ModeShape to JNDI name '{0}'", bindInfo.getAbsoluteJndiName()); newControllers.add(referenceBuilder.install()); newControllers.add(binderBuilder.install()); }
/** * Unbind the entry from the injected context. * * @param context The stop context */ public synchronized void stop(StopContext context) { final ServiceBasedNamingStore namingStore = namingStoreValue.getValue(); namingStore.remove(context.getController().getName()); if (deploymentServiceName != null) { // remove the service name from the related deployment runtime bindings management service, final Set<ServiceName> duBindingReferences = (Set<ServiceName>) controller .getServiceContainer() .getService(JndiNamingDependencyProcessor.serviceName(deploymentServiceName)) .getValue(); if (duBindingReferences != null) { // the set is null if the binder service was stopped by the deployment unit undeploy duBindingReferences.remove(controller.getName()); } } }
/** * Bind the entry into the injected context. * * @param context The start context * @throws StartException If the entity can not be bound */ public synchronized void start(StartContext context) throws StartException { final ServiceBasedNamingStore namingStore = namingStoreValue.getValue(); ServiceController<?> controller = context.getController(); this.controller = controller; namingStore.add(controller.getName()); ROOT_LOGGER.tracef( "Bound resource %s into naming store %s (service name %s)", name, namingStore, controller.getName()); if (deploymentServiceName != null) { // add this controller service name to the related deployment runtime bindings management // service, which if stop will release this service too, thus removing the bind final Set<ServiceName> duBindingReferences = (Set<ServiceName>) controller .getServiceContainer() .getService(JndiNamingDependencyProcessor.serviceName(deploymentServiceName)) .getValue(); duBindingReferences.add(controller.getName()); } }
/** * Uninstall the Bundle associated with this deployment. * * @param context The stop context. */ public synchronized void stop(StopContext context) { log.tracef("Uninstalling deployment: %s", deployment); try { BundleManager bundleManager = injectedBundleManager.getValue(); bundleManager.uninstallBundle(deployment); ServiceController<?> controller = context.getController(); ServiceContainer serviceContainer = controller.getServiceContainer(); controller.setMode(Mode.REMOVE); // [JBAS-8801] Undeployment leaks root deployment service // [TODO] remove this workaround ServiceName serviceName = Services.deploymentUnitName(controller.getName().getSimpleName()); ServiceController<?> deploymentController = serviceContainer.getService(serviceName); if (deploymentController != null) { deploymentController.setMode(Mode.REMOVE); } } catch (Throwable t) { log.errorf(t, "Failed to uninstall deployment: %s", deployment); } }
public void start(final StartContext context) throws StartException { if (configurationPersister == null) { throw MESSAGES.persisterNotInjected(); } final ServiceController<?> serviceController = context.getController(); final ServiceContainer container = serviceController.getServiceContainer(); final ServiceTarget target = context.getChildTarget(); final ExecutorService executorService = injectedExecutorService.getOptionalValue(); ManagementResourceRegistration rootResourceRegistration = rootDescriptionProvider != null ? ManagementResourceRegistration.Factory.create(rootDescriptionProvider) : ManagementResourceRegistration.Factory.create(rootResourceDefinition); final ModelControllerImpl controller = new ModelControllerImpl( container, target, rootResourceRegistration, new ContainerStateMonitor(container), configurationPersister, processType, runningModeControl, prepareStep, processState, executorService, expressionResolver, authorizer, auditLogger); // Initialize the model initModel(controller.getRootResource(), controller.getRootRegistration()); this.controller = controller; final long bootStackSize = getBootStackSize(); final Thread bootThread = new Thread( null, new Runnable() { public void run() { try { try { boot( new BootContext() { public ServiceTarget getServiceTarget() { return target; } }); } finally { processState.setRunning(); } } catch (Throwable t) { container.shutdown(); if (t instanceof StackOverflowError) { ROOT_LOGGER.errorBootingContainer(t, bootStackSize, BOOT_STACK_SIZE_PROPERTY); } else { ROOT_LOGGER.errorBootingContainer(t); } } finally { bootThreadDone(); } } }, "Controller Boot Thread", bootStackSize); bootThread.start(); }
@Override public void start(StartContext context) throws StartException { processState.setStarting(); final ProductConfig config = environment.getProductConfig(); final String prettyVersion = config.getPrettyVersionString(); ServerLogger.AS_ROOT_LOGGER.serverStarting(prettyVersion); if (ServerLogger.CONFIG_LOGGER.isDebugEnabled()) { final Properties properties = System.getProperties(); final StringBuilder b = new StringBuilder(8192); b.append("Configured system properties:"); for (String property : new TreeSet<String>(properties.stringPropertyNames())) { b.append("\n\t") .append(property) .append(" = ") .append(properties.getProperty(property, "<undefined>")); } ServerLogger.CONFIG_LOGGER.debug(b); ServerLogger.CONFIG_LOGGER.debugf("VM Arguments: %s", getVMArguments()); if (ServerLogger.CONFIG_LOGGER.isTraceEnabled()) { b.setLength(0); final Map<String, String> env = System.getenv(); b.append("Configured system environment:"); for (String key : new TreeSet<String>(env.keySet())) { b.append("\n\t").append(key).append(" = ").append(env.get(key)); } ServerLogger.CONFIG_LOGGER.trace(b); } } final ServiceTarget serviceTarget = context.getChildTarget(); final ServiceController<?> myController = context.getController(); final ServiceContainer serviceContainer = myController.getServiceContainer(); futureContainer = new FutureServiceContainer(); long startTime = this.startTime; if (startTime == -1) { startTime = System.currentTimeMillis(); } else { this.startTime = -1; } final BootstrapListener bootstrapListener = new BootstrapListener( serviceContainer, startTime, serviceTarget, futureContainer, prettyVersion + " (Host Controller)"); bootstrapListener.getStabilityMonitor().addController(myController); // The first default services are registered before the bootstrap operations are executed. // Install the process controller client final ProcessControllerConnectionService processControllerClient = new ProcessControllerConnectionService(environment, authCode); serviceTarget .addService(ProcessControllerConnectionService.SERVICE_NAME, processControllerClient) .install(); // Executor Services final HostControllerExecutorService executorService = new HostControllerExecutorService(); serviceTarget .addService(HC_EXECUTOR_SERVICE_NAME, executorService) .addAliases( ManagementRemotingServices .SHUTDOWN_EXECUTOR_NAME) // Use this executor for mgmt shutdown for now .install(); // Install required path services. (Only install those identified as required) HostPathManagerService hostPathManagerService = new HostPathManagerService(); HostPathManagerService.addService(serviceTarget, hostPathManagerService, environment); HttpListenerRegistryService.install(serviceTarget); // Add product config service final Value<ProductConfig> productConfigValue = new ImmediateValue<ProductConfig>(config); serviceTarget .addService( Services.JBOSS_PRODUCT_CONFIG_SERVICE, new ValueService<ProductConfig>(productConfigValue)) .setInitialMode(ServiceController.Mode.ACTIVE) .install(); DomainModelControllerService.addService( serviceTarget, environment, runningModeControl, processState, bootstrapListener, hostPathManagerService); }
public void transition( final ServiceController<? extends Object> controller, final ServiceController.Transition transition) { switch (transition) { case STARTING_to_UP: { CommonDeployment deploymentMD = getDeploymentMetadata(controller); if (deploymentMD.getConnectionManagers() != null) { for (ConnectionManager cm : deploymentMD.getConnectionManagers()) { if (cm.getPool() != null) { StatisticsPlugin poolStats = cm.getPool().getStatistics(); poolStats.setEnabled(false); final ServiceController<?> bootstrapContextController = controller .getServiceContainer() .getService( ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootstrapCtx)); WorkManager wm = null; if (bootstrapContextController != null) { wm = (WorkManager) ((CloneableBootstrapContext) bootstrapContextController.getValue()) .getWorkManager(); } if ((wm != null && wm.getStatistics() != null) || poolStats.getNames().size() != 0) { PathElement pe = PathElement.pathElement( ModelDescriptionConstants.SUBSYSTEM, ResourceAdaptersExtension.SUBSYSTEM_NAME); PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, Constants.STATISTICS_NAME); PathElement peRa = PathElement.pathElement(Constants.RESOURCEADAPTER_NAME, raName); PathElement peWm = PathElement.pathElement(Constants.WORKMANAGER_NAME, wm.getName()); PathElement peDistributedWm = PathElement.pathElement(Constants.DISTRIBUTED_WORKMANAGER_NAME, wm.getName()); PathElement peCD = PathElement.pathElement( Constants.CONNECTIONDEFINITIONS_NAME, cm.getJndiName()); ManagementResourceRegistration overrideRegistration = registration; // when you are in deploy you have a registration pointing to deployment=* // when you are in re-deploy it points to specific deploymentUnit synchronized (this) { if (registration.isAllowsOverride()) { if (registration.getOverrideModel(deploymentUnitName) != null) { overrideRegistration = registration.getOverrideModel(deploymentUnitName); } else { overrideRegistration = registration.registerOverrideModel( deploymentUnitName, new OverrideDescriptionProvider() { @Override public Map<String, ModelNode> getAttributeOverrideDescriptions( Locale locale) { return Collections.emptyMap(); } @Override public Map<String, ModelNode> getChildTypeOverrideDescriptions( Locale locale) { return Collections.emptyMap(); } }); } } ManagementResourceRegistration subRegistration; try { ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create( pe, new StandardResourceDescriptionResolver( Constants.STATISTICS_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader())); subRegistration = overrideRegistration.registerSubModel(resourceBuilder.build()); } catch (IllegalArgumentException iae) { subRegistration = overrideRegistration.getSubModel(PathAddress.pathAddress(pe)); } Resource subsystemResource; if (!deploymentResource.hasChild(pe)) { subsystemResource = new IronJacamarResource.IronJacamarRuntimeResource(); deploymentResource.registerChild(pe, subsystemResource); } else { subsystemResource = deploymentResource.getChild(pe); } ManagementResourceRegistration statsRegistration; try { ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create( peStats, new StandardResourceDescriptionResolver( Constants.STATISTICS_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader())); statsRegistration = subRegistration.registerSubModel(resourceBuilder.build()); } catch (IllegalArgumentException iae) { statsRegistration = subRegistration.getSubModel(PathAddress.pathAddress(peStats)); } Resource statisticsResource; if (!subsystemResource.hasChild(peStats)) { statisticsResource = new IronJacamarResource.IronJacamarRuntimeResource(); subsystemResource.registerChild(peStats, statisticsResource); } else { statisticsResource = subsystemResource.getChild(peStats); } ManagementResourceRegistration raRegistration; try { ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create( peRa, new StandardResourceDescriptionResolver( Constants.STATISTICS_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader())); raRegistration = statsRegistration.registerSubModel(resourceBuilder.build()); } catch (IllegalArgumentException iae) { raRegistration = statsRegistration.getSubModel(PathAddress.pathAddress(peRa)); } Resource raResource; if (!statisticsResource.hasChild(peRa)) { raResource = new IronJacamarResource.IronJacamarRuntimeResource(); statisticsResource.registerChild(peRa, raResource); } else { raResource = statisticsResource.getChild(peRa); } if (deploymentMD.getConnector() != null && deploymentMD.getConnector().getResourceAdapter() != null && deploymentMD.getConnector().getResourceAdapter().getStatistics() != null) { StatisticsPlugin raStats = deploymentMD.getConnector().getResourceAdapter().getStatistics(); raStats.setEnabled(false); PoolMetrics.ParametrizedPoolMetricsHandler handler = new PoolMetrics.ParametrizedPoolMetricsHandler(raStats); for (AttributeDefinition attribute : StatisticsResourceDefinition.getAttributesFromPlugin(raStats)) { raRegistration.registerMetric(attribute, handler); } // adding enable/disable for pool stats OperationStepHandler readHandler = new PoolStatisticsRuntimeAttributeReadHandler(raStats); OperationStepHandler writeHandler = new PoolStatisticsRuntimeAttributeWriteHandler(raStats); raRegistration.registerReadWriteAttribute( org.jboss.as.connector.subsystems.common.pool.Constants .POOL_STATISTICS_ENABLED, readHandler, writeHandler); } if (poolStats.getNames().size() != 0 && raRegistration.getSubModel(PathAddress.pathAddress(peCD)) == null) { ManagementResourceRegistration cdSubRegistration = raRegistration.registerSubModel( new StatisticsResourceDefinition( peCD, CommonAttributes.RESOURCE_NAME, poolStats)); final Resource cdResource = new IronJacamarResource.IronJacamarRuntimeResource(); if (!raResource.hasChild(peCD)) raResource.registerChild(peCD, cdResource); } if (wm.getStatistics() != null) { if (wm instanceof DistributedWorkManager && ((DistributedWorkManager) wm).getDistributedStatistics() != null && raRegistration.getSubModel(PathAddress.pathAddress(peDistributedWm)) == null) { ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create( peDistributedWm, new StandardResourceDescriptionResolver( Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader())); ManagementResourceRegistration dwmSubRegistration = raRegistration.registerSubModel(resourceBuilder.build()); final Resource dwmResource = new IronJacamarResource.IronJacamarRuntimeResource(); if (!raResource.hasChild(peDistributedWm)) raResource.registerChild(peDistributedWm, dwmResource); OperationStepHandler metricsHandler = new WorkManagerRuntimeAttributeReadHandler( wm, ((DistributedWorkManager) wm).getDistributedStatistics(), false); for (SimpleAttributeDefinition metric : Constants.WORKMANAGER_METRICS) { dwmSubRegistration.registerMetric(metric, metricsHandler); } OperationStepHandler readHandler = new WorkManagerRuntimeAttributeReadHandler( wm, ((DistributedWorkManager) wm).getDistributedStatistics(), true); OperationStepHandler writeHandler = new WorkManagerRuntimeAttributeWriteHandler( wm, true, Constants.DISTRIBUTED_WORKMANAGER_RW_ATTRIBUTES); for (SimpleAttributeDefinition attribute : Constants.DISTRIBUTED_WORKMANAGER_RW_ATTRIBUTES) { dwmSubRegistration.registerReadWriteAttribute( attribute, readHandler, writeHandler); } dwmSubRegistration.registerOperationHandler( ClearWorkManagerStatisticsHandler.DEFINITION, new ClearWorkManagerStatisticsHandler(wm)); } if (raRegistration.getSubModel(PathAddress.pathAddress(peWm)) == null) { ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create( peWm, new StandardResourceDescriptionResolver( Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader())); ManagementResourceRegistration wmSubRegistration = raRegistration.registerSubModel(resourceBuilder.build()); final Resource wmResource = new IronJacamarResource.IronJacamarRuntimeResource(); if (!raResource.hasChild(peWm)) raResource.registerChild(peWm, wmResource); OperationStepHandler metricHandler = new WorkManagerRuntimeAttributeReadHandler( wm, wm.getStatistics(), false); for (SimpleAttributeDefinition metric : Constants.WORKMANAGER_METRICS) { wmSubRegistration.registerMetric(metric, metricHandler); } OperationStepHandler readHandler = new WorkManagerRuntimeAttributeReadHandler( wm, wm.getStatistics(), false); OperationStepHandler writeHandler = new WorkManagerRuntimeAttributeWriteHandler( wm, false, Constants.WORKMANAGER_RW_ATTRIBUTES); for (SimpleAttributeDefinition attribute : Constants.WORKMANAGER_RW_ATTRIBUTES) { wmSubRegistration.registerReadWriteAttribute( attribute, readHandler, writeHandler); } wmSubRegistration.registerOperationHandler( ClearWorkManagerStatisticsHandler.DEFINITION, new ClearWorkManagerStatisticsHandler(wm)); } } registerIronjacamar(controller, subRegistration, subsystemResource); } } } } } break; } case UP_to_STOP_REQUESTED: { PathElement pe = PathElement.pathElement( ModelDescriptionConstants.SUBSYSTEM, ResourceAdaptersExtension.SUBSYSTEM_NAME); PathElement ijPe = PathElement.pathElement(Constants.IRONJACAMAR_NAME, Constants.IRONJACAMAR_NAME); PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, Constants.STATISTICS_NAME); PathElement peCD = PathElement.pathElement(Constants.CONNECTIONDEFINITIONS_NAME); ManagementResourceRegistration overrideRegistration = registration; // when you are in deploy you have a registration pointing to deployment=* // when you are in re-deploy it points to specific deploymentUnit if (registration.isAllowsOverride() && registration.getOverrideModel(deploymentUnitName) != null) { overrideRegistration = registration.getOverrideModel(deploymentUnitName); } ManagementResourceRegistration subsystemReg = overrideRegistration.getSubModel(PathAddress.pathAddress(pe)); if (subsystemReg != null) { if (subsystemReg.getSubModel(PathAddress.pathAddress(ijPe)) != null) { subsystemReg.unregisterSubModel(ijPe); } ManagementResourceRegistration statsReg = subsystemReg.getSubModel(PathAddress.pathAddress(peStats)); if (statsReg != null) { if (statsReg.getSubModel(PathAddress.pathAddress(peCD)) != null) { statsReg.unregisterSubModel(peCD); } subsystemReg.unregisterSubModel(peStats); } overrideRegistration.unregisterSubModel(pe); } deploymentResource.removeChild(pe); } } }