Search in sources :

Example 61 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class GroupingHandlerAdd 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) {
        final ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        if (server.getGroupingHandler() != null) {
            throw new OperationFailedException(MessagingLogger.ROOT_LOGGER.childResourceAlreadyExists(CommonAttributes.GROUPING_HANDLER));
        }
        // the groupingHandler is added as a child of the server resource. Requires a reload to restart the server with the grouping-handler
        if (context.isNormalServer()) {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    context.reloadRequired();
                    context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
// else the initial subsystem install is not complete and the grouping handler will be added in ServerAdd
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 62 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class BridgeRemove 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().destroyBridge(name);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            // TODO should this be an OFE instead?
            throw new RuntimeException(e);
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 63 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class DivertRemove method recoverServices.

@Override
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    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) {
        final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
        final DivertConfiguration divertConfiguration = DivertAdd.createDivertConfiguration(context, name, model);
        ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        DivertAdd.createDivert(name, divertConfiguration, server.getActiveMQServerControl());
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 64 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class ClusterConnectionAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    ServiceRegistry registry = context.getServiceRegistry(false);
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service != null) {
        context.reloadRequired();
    }
// else MessagingSubsystemAdd will add a handler that calls addBroadcastGroupConfigs
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 65 with ServiceRegistry

use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.

the class SocketDiscoveryGroupAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();
    ServiceRegistry registry = context.getServiceRegistry(false);
    ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = serviceName == null ? null : registry.getService(serviceName);
    if (service != null) {
        context.reloadRequired();
    } else {
        final ServiceTarget target = context.getServiceTarget();
        if (model.hasDefined(JGROUPS_CLUSTER.getName())) {
        // nothing to do, in that case, the clustering.jgroups subsystem will have setup the stack
        } else if (model.hasDefined(RemoteTransportDefinition.SOCKET_BINDING.getName())) {
            if (serviceName == null) {
                serviceName = MessagingServices.getActiveMQServiceName((String) null);
            }
            ServiceBuilder builder = target.addService(GroupBindingService.getDiscoveryBaseServiceName(serviceName).append(name));
            builder.setInstance(new GroupBindingService(builder.requires(SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()))));
            builder.install();
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceTarget(org.jboss.msc.service.ServiceTarget) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Aggregations

ServiceRegistry (org.jboss.msc.service.ServiceRegistry)74 ServiceName (org.jboss.msc.service.ServiceName)51 ModelNode (org.jboss.dmr.ModelNode)22 PathAddress (org.jboss.as.controller.PathAddress)15 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 OperationFailedException (org.jboss.as.controller.OperationFailedException)13 ServiceController (org.jboss.msc.service.ServiceController)12 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)8 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)8 OperationContext (org.jboss.as.controller.OperationContext)6 Resource (org.jboss.as.controller.registry.Resource)6 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)4 PathElement (org.jboss.as.controller.PathElement)4 DefaultAccessTimeoutService (org.jboss.as.ejb3.component.DefaultAccessTimeoutService)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 ArrayList (java.util.ArrayList)2 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)2 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)2