use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class BridgeAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> service = registry.getService(serviceName);
if (service != null) {
// The original subsystem initialization is complete; use the control object to create the divert
if (service.getState() != ServiceController.State.UP) {
throw MessagingLogger.ROOT_LOGGER.invalidServiceState(serviceName, ServiceController.State.UP, service.getState());
}
final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
BridgeConfiguration bridgeConfig = createBridgeConfiguration(context, name, model);
// noinspection RedundantClassCall
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
createBridge(bridgeConfig, server);
}
// else the initial subsystem install is not complete; MessagingSubsystemAdd will add a
// handler that calls addBridgeConfigs
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class DivertAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> service = registry.getService(serviceName);
if (service != null) {
// The original subsystem initialization is complete; use the control object to create the divert
if (service.getState() != ServiceController.State.UP) {
throw MessagingLogger.ROOT_LOGGER.invalidServiceState(serviceName, ServiceController.State.UP, service.getState());
}
final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
DivertConfiguration divertConfiguration = createDivertConfiguration(context, name, model);
ActiveMQServerControl serverControl = ActiveMQServer.class.cast(service.getValue()).getActiveMQServerControl();
createDivert(name, divertConfiguration, serverControl);
}
// else the initial subsystem install is not complete; MessagingSubsystemAdd will add a
// handler that calls addDivertConfigs
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class DivertRemove method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
final ServiceController<?> service = registry.getService(serviceName);
if (service != null && service.getState() == ServiceController.State.UP) {
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
try {
server.getActiveMQServerControl().destroyDivert(name);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
// TODO should this be an OFE instead?
throw new RuntimeException(e);
}
}
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class HandlerAdd method performRuntime.
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
// modify the runtime if we're booting, otherwise set reload required and leave the runtime unchanged
if (context.isBooting()) {
final PathAddress address = context.getCurrentAddress();
final PathElement confElem = address.getElement(address.size() - 3);
final String configType = confElem.getKey();
final String configName = confElem.getValue();
final String handlerChainType = address.getElement(address.size() - 2).getKey();
final String handlerChainId = address.getElement(address.size() - 2).getValue();
final String handlerName = address.getElement(address.size() - 1).getValue();
final String handlerClass = Attributes.CLASS.resolveModelAttribute(context, model).asString();
final ServiceTarget target = context.getServiceTarget();
final ServiceName configServiceName = getConfigServiceName(configType, configName);
final ServiceRegistry registry = context.getServiceRegistry(false);
if (registry.getService(configServiceName) == null) {
throw WSLogger.ROOT_LOGGER.missingConfig(configName);
}
final ServiceName handlerChainServiceName = getHandlerChainServiceName(configServiceName, handlerChainType, handlerChainId);
if (registry.getService(handlerChainServiceName) == null) {
throw WSLogger.ROOT_LOGGER.missingHandlerChain(configName, handlerChainType, handlerChainId);
}
final ServiceName handlerServiceName = getHandlerServiceName(handlerChainServiceName, handlerName);
final ServiceBuilder<?> handlerServiceBuilder = target.addService(handlerServiceName);
final Consumer<UnifiedHandlerMetaData> handlerConsumer = handlerServiceBuilder.provides(handlerServiceName);
handlerServiceBuilder.setInstance(new HandlerService(handlerName, handlerClass, counter.incrementAndGet(), handlerConsumer));
handlerServiceBuilder.install();
} else {
context.reloadRequired();
}
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class WeldDeploymentCleanupProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
// obtain service names
ServiceName weldStartCompletionServiceName = parent.getServiceName().append(WeldStartCompletionService.SERVICE_NAME);
ServiceName weldBootstrapServiceName = parent.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
ServiceName weldStartServiceName = parent.getServiceName().append(WeldStartService.SERVICE_NAME);
// if it is not Weld deployment, we skip it
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
return;
}
// only register this on top level deployments
if (deploymentUnit.getParent() != null) {
return;
}
// add dependency on our WeldBootstrapService and WeldStartService to ensure this goes after them
ServiceBuilder<?> weldStartCompletionServiceBuilder = serviceTarget.addService(weldStartCompletionServiceName);
final Supplier<WeldBootstrapService> bootstrapSupplier = weldStartCompletionServiceBuilder.requires(weldBootstrapServiceName);
weldStartCompletionServiceBuilder.requires(weldStartServiceName);
// require component start services from top level deployment
for (ServiceName componentStartSN : getComponentStartServiceNames(deploymentUnit)) {
weldStartCompletionServiceBuilder.requires(componentStartSN);
}
// require component start services from sub-deployments
final List<DeploymentUnit> subDeployments = deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
for (DeploymentUnit sub : subDeployments) {
ServiceRegistry registry = sub.getServiceRegistry();
List<ServiceName> componentStartServiceNames = getComponentStartServiceNames(sub);
for (ServiceName componentStartSN : componentStartServiceNames) {
weldStartCompletionServiceBuilder.requires(componentStartSN);
}
}
weldStartCompletionServiceBuilder.setInstance(new WeldStartCompletionService(bootstrapSupplier, WeldDeploymentProcessor.getSetupActions(deploymentUnit), module.getClassLoader()));
weldStartCompletionServiceBuilder.install();
}
Aggregations