static MBeanServer getMBeanServer(OperationContext context) { final ServiceRegistry serviceRegistry = context.getServiceRegistry(false); final ServiceController<?> serviceController = serviceRegistry.getService(MBEAN_SERVER_SERVICE_NAME); if (serviceController == null) { throw TransactionLogger.ROOT_LOGGER.jmxSubsystemNotInstalled(); } return (MBeanServer) serviceController.getValue(); }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ModelNode result = new ModelNode(); CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.CCM_SERVICE).getValue(); ModelNode txResult = new ModelNode().set(ccm.getNumberOfConnections()); ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.NON_TX_CCM_SERVICE).getValue(); ModelNode nonTxResult = new ModelNode().set(ccm.getNumberOfConnections()); result.get(Constants.TX).set(txResult); result.get(Constants.NON_TX).set(nonTxResult); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME);
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final String driverName = model.get(DRIVER_NAME.getName()).asString(); final ServiceRegistry registry = context.getServiceRegistry(true); ServiceName jdbcServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_")); ServiceController<?> jdbcServiceController = registry.getService(jdbcServiceName); context.removeService(jdbcServiceController); }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final String jndiName = address.getLastElement().getValue(); final String attributeName = operation.require(NAME).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { try { final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue(); final ModelNode result = context.getResult(); List<StatisticsPlugin> stats = getMatchingStats(jndiName, repository); for (StatisticsPlugin stat : stats) { result.set("" + stat.getValue(attributeName)); } } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } } }, OperationContext.Stage.RUNTIME);
final String moduleName = moduleDescription.getModuleName(); final ModelNode moduleNode = modulesNode.get(moduleDescription.getModuleName()); final ServiceController<?> moduleContextController = serviceRegistry.getService(moduleContextName); if (moduleContextController != null) { final NamingStore moduleStore = NamingStore.class.cast(moduleContextController.getValue()); try { context.addEntries(moduleNode.get("java:module"), new NamingContext(moduleStore, null)); } catch (NamingException e) { throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:module", appName, moduleName))); final String componentName = componentDescription.getComponentName(); final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(appName, moduleName, componentName); final ServiceController<?> compContextController = serviceRegistry.getService(compContextServiceName); if (compContextController != null) { final ModelNode componentNode = moduleNode.get("components").get(componentName); final NamingStore compStore = NamingStore.class.cast(compContextController.getValue()); try { context.addEntries(componentNode.get("java:comp"), new NamingContext(compStore, null));
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(NAME).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { try { setModelValue(context.getResult(), attributeName); } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } } }, OperationContext.Stage.RUNTIME);
@Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException { ServiceController<?> controller = context.getServiceRegistry(false).getService(UndertowService.UNDERTOW); if (controller != null) { UndertowService service = (UndertowService) controller.getService(); if (service != null) { service.setStatisticsEnabled(resolvedValue.asBoolean()); } } return false; }
public ManagedReference getReference(final Object instance) { if (component == null) { synchronized (this) { if (component == null) { component = (ServiceController<Component>) serviceRegistry.getService(serviceName); } } } if (component == null) { return null; } return new ComponentManagedReference(component.getValue().createInstance(instance)); }
registration = baseRegistration.getSubModel(PathAddress.pathAddress(PathElement.pathElement("subdeployment"))); } else { registration = baseRegistration; final ServiceController<?> raService = phaseContext.getServiceRegistry().getService( ConnectorServices.RESOURCEADAPTERS_SERVICE); if (raService != null) raxmls = ((ResourceAdaptersService.ModifiableResourceAdaptors) raService.getValue());
private void addConfigSourcesFromServices(ConfigBuilder builder, ServiceRegistry serviceRegistry, ClassLoader classloader) { List<ServiceName> serviceNames = serviceRegistry.getServiceNames(); for (ServiceName serviceName: serviceNames) { if (ServiceNames.CONFIG_SOURCE.isParentOf(serviceName)) { ServiceController<?> service = serviceRegistry.getService(serviceName); ConfigSource configSource = ConfigSource.class.cast(service.getValue()); builder.withSources(configSource); } else if (ServiceNames.CONFIG_SOURCE_PROVIDER.isParentOf(serviceName)) { ServiceController<?> service = serviceRegistry.getService(serviceName); ConfigSourceProvider configSourceProvider = ConfigSourceProvider.class.cast(service.getValue()); for (ConfigSource configSource : configSourceProvider.getConfigSources(classloader)) { builder.withSources(configSource); } } } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = CONNECTION_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String jndiName = path.getElement(path.size() - 2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = DataSourceConfigService.SERVICE_NAME_BASE.append(jndiName).append("connection-properties").append(configPropertyName); final ServiceRegistry registry = context.getServiceRegistry(true); final ServiceName dataSourceConfigServiceName = DataSourceConfigService.SERVICE_NAME_BASE .append(jndiName); final ServiceController<?> dataSourceConfigController = registry .getService(dataSourceConfigServiceName); if (dataSourceConfigController == null || !((DataSource) dataSourceConfigController.getValue()).isEnabled()) { final ServiceTarget serviceTarget = context.getServiceTarget(); final ConnectionPropertiesService service = new ConnectionPropertiesService(configPropertyName, configPropertyValue); serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.NEVER) .install(); } else { context.reloadRequired(); } }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { ModelNode result = new ModelNode(); CachedConnectionManager ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.CCM_SERVICE).getValue(); Map<String, String> map = ccm.listConnections(); ModelNode txResult = new ModelNode(); for (Map.Entry<String, String> entry : map.entrySet()) { txResult.add(entry.getKey(), entry.getValue()); } ccm = (CachedConnectionManager) context.getServiceRegistry(false).getService(ConnectorServices.NON_TX_CCM_SERVICE).getValue(); map= ccm.listConnections(); ModelNode nonTxResult = new ModelNode(); for (Map.Entry<String, String> entry : map.entrySet()) { nonTxResult.add(entry.getKey(), entry.getValue()); } result.get(Constants.TX).set(txResult); result.get(Constants.NON_TX).set(nonTxResult); context.getResult().set(result); } }, OperationContext.Stage.RUNTIME);
private void applyModelToRuntime(OperationContext context, final ModelNode model) throws OperationFailedException { final ServiceRegistry serviceRegistry = context.getServiceRegistry(true); ServiceController<IIOPSettingsService> controller = (ServiceController<IIOPSettingsService>) serviceRegistry.getService(IIOPSettingsService.SERVICE_NAME); if (controller != null) { IIOPSettingsService service = controller.getValue(); applySetting(service, context, model); } }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(NAME).asString(); final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService( ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE); if (managementRepoService != null) { try { setModelValue(context.getResult(), attributeName); } catch (Exception e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToGetMetrics(e.getLocalizedMessage())); } } } }, OperationContext.Stage.RUNTIME);
@Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Void handback) throws OperationFailedException { ServiceController<?> controller = context.getServiceRegistry(false).getService(UndertowService.UNDERTOW); if (controller != null) { UndertowService service = (UndertowService) controller.getService(); if (service != null) { service.setStatisticsEnabled(valueToRestore.asBoolean()); } } } });
private CallbackHandler getCallbackHandler(final ServiceRegistry serviceRegistry, final String userName, final String securityRealmName) { if (securityRealmName != null && ! securityRealmName.trim().isEmpty()) { final ServiceName securityRealmServiceName = SecurityRealm.ServiceUtil.createServiceName(securityRealmName); final ServiceController<SecurityRealm> securityRealmController = (ServiceController<SecurityRealm>) serviceRegistry.getService(securityRealmServiceName); if (securityRealmController != null) { final SecurityRealm securityRealm = securityRealmController.getValue(); final CallbackHandlerFactory cbhFactory; if (securityRealm != null && (cbhFactory = securityRealm.getSecretCallbackHandlerFactory()) != null && userName != null) { return cbhFactory.getCallbackHandler(userName); } } } return null; }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode recoveryEnvModel) throws OperationFailedException { final String configPropertyValue = XADATASOURCE_PROPERTY_VALUE.resolveModelAttribute(context, recoveryEnvModel).asString(); final ModelNode address = operation.require(OP_ADDR); PathAddress path = PathAddress.pathAddress(address); final String dsName = path.getElement(path.size() - 2).getValue(); final String configPropertyName = PathAddress.pathAddress(address).getLastElement().getValue(); ServiceName serviceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName).append("xa-datasource-properties").append(configPropertyName); final ServiceRegistry registry = context.getServiceRegistry(true); final ServiceName dataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE .append(dsName); final ServiceController<?> dataSourceConfigController = registry .getService(dataSourceConfigServiceName); if (dataSourceConfigController == null || !((XaDataSource) dataSourceConfigController.getValue()).isEnabled()) { final ServiceTarget serviceTarget = context.getServiceTarget(); final XaDataSourcePropertiesService service = new XaDataSourcePropertiesService(configPropertyName, configPropertyValue); ServiceController<?> controller = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.NEVER) .install(); } else { context.reloadRequired(); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { Class<?> providerClass = (Class<?>) context.getServiceRegistry(false).getService(DriverDefinition.AGROAL_DRIVER_CAPABILITY.getCapabilityServiceName(context.getCurrentAddress())).getValue(); if (providerClass == null) { context.getResult().set(new ModelNode()); return; } ModelNode result = new ModelNode(); // consistent with io.agroal.pool.util.PropertyInjector if (javax.sql.XADataSource.class.isAssignableFrom(providerClass) || javax.sql.DataSource.class.isAssignableFrom(providerClass)) { for (Method method : providerClass.getMethods()) { String name = method.getName(); if (method.getParameterCount() == 1 && name.startsWith("set")) { result.get(name.substring(3)).set(method.getParameterTypes()[0].getName()); } } } // from java.sql.Driver maybe use Driver.getPropertyInfo context.getResult().set(result); } } }
static ListenerService getListenerService(OperationContext context) { final String name = context.getCurrentAddressValue(); ServiceName serviceName = LISTENER_CAPABILITY.getCapabilityServiceName(name); ServiceController<ListenerService> listenerSC = (ServiceController<ListenerService>) context.getServiceRegistry(false).getService(serviceName); if (listenerSC == null || listenerSC.getState() != ServiceController.State.UP) { return null; } return listenerSC.getValue(); }
@Override protected ServiceController<?> getService(final OperationContext context, final ModelNode model) throws OperationFailedException { final String name = Util.getNameFromAddress(model.require(OP_ADDR)); final ServiceName serviceName = ThreadsServices.threadFactoryName(name); ServiceController<?> controller = context.getServiceRegistry(true).getService(serviceName); if(controller == null) { throw ThreadsLogger.ROOT_LOGGER.threadFactoryServiceNotFound(serviceName); } return controller; }