Search in sources :

Example 31 with ServiceRegistry

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

the class JMSBridgeRemove method recoverServices.

protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String bridgeName = address.getLastElement().getValue();
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName jmsBridgeServiceName = MessagingServices.getJMSBridgeServiceName(bridgeName);
    final ServiceController<?> jmsBridgeServiceController = registry.getService(jmsBridgeServiceName);
    if (jmsBridgeServiceController != null && jmsBridgeServiceController.getState() == ServiceController.State.UP) {
        JMSBridgeService jmsBridgeService = (JMSBridgeService) jmsBridgeServiceController.getService();
        try {
            jmsBridgeService.startBridge();
        } catch (Exception e) {
            throw MessagingLogger.ROOT_LOGGER.failedToRecover(e, bridgeName);
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 32 with ServiceRegistry

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

the class AbstractPojoPhase method startInternal.

protected void startInternal(StartContext context) throws StartException {
    try {
        executeInstalls();
        // only after describe do we have a bean
        if (getLifecycleState().isAfter(BeanState.DESCRIBED)) {
            addCallbacks(true);
            addCallbacks(false);
            ServiceRegistry registry = context.getController().getServiceContainer();
            InstancesService.addInstance(registry, context.getChildTarget(), getLifecycleState(), getBean());
        }
        // do we have a next phase
        final AbstractPojoPhase nextPhase = createNextPhase();
        if (nextPhase != null) {
            final BeanState state = getLifecycleState();
            final BeanState next = state.next();
            final BeanMetaDataConfig beanConfig = getBeanConfig();
            final ServiceName name = BeanMetaDataConfig.toBeanName(beanConfig.getName(), next);
            final ServiceTarget serviceTarget = context.getChildTarget();
            final ServiceBuilder serviceBuilder = serviceTarget.addService(name, nextPhase);
            registerAliases(serviceBuilder, next);
            final ConfigVisitor visitor = new DefaultConfigVisitor(serviceBuilder, state, getModule(), getIndex(), getBeanInfo());
            beanConfig.visit(visitor);
            nextPhase.setModule(getModule());
            nextPhase.setBeanConfig(getBeanConfig());
            nextPhase.setIndex(getIndex());
            nextPhase.setBeanInfo(getBeanInfo());
            nextPhase.setBean(getBean());
            serviceBuilder.install();
        }
    } catch (Throwable t) {
        throw new StartException(t);
    }
}
Also used : DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) ConfigVisitor(org.jboss.as.pojo.descriptor.ConfigVisitor) DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) BeanState(org.jboss.as.pojo.BeanState) BeanMetaDataConfig(org.jboss.as.pojo.descriptor.BeanMetaDataConfig) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) StartException(org.jboss.msc.service.StartException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 33 with ServiceRegistry

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

the class ActiveMQServerControlWriteHandler method revertUpdateToRuntime.

@Override
protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode valueToRestore, final ModelNode valueToRevert, final Void handback) throws OperationFailedException {
    AttributeDefinition attr = getAttributeDefinition(attributeName);
    if (attr.equals(CREDENTIAL_REFERENCE)) {
        rollbackCredentialStoreUpdate(attr, context, valueToRevert);
    }
    if (!attr.getFlags().contains(AttributeAccess.Flag.RESTART_ALL_SERVICES)) {
        ServiceRegistry registry = context.getServiceRegistry(true);
        final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(OP_ADDR)));
        ServiceController<?> service = registry.getService(serviceName);
        if (service != null && service.getState() == ServiceController.State.UP) {
            applyOperationToActiveMQService(operation, attributeName, valueToRestore, service);
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 34 with ServiceRegistry

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

the class ActiveMQServerControlWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<Void> handbackHolder) throws OperationFailedException {
    AttributeDefinition attr = getAttributeDefinition(attributeName);
    if (attr.equals(CREDENTIAL_REFERENCE)) {
        return applyCredentialReferenceUpdateToRuntime(context, operation, newValue, currentValue, attributeName);
    }
    if (attr.getFlags().contains(AttributeAccess.Flag.RESTART_ALL_SERVICES)) {
        // Restart required
        return true;
    } else {
        ServiceRegistry registry = context.getServiceRegistry(true);
        final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(OP_ADDR)));
        ServiceController<?> service = registry.getService(serviceName);
        if (service == null) {
            // The service isn't installed, so the work done in the Stage.MODEL part is all there is to it
            return false;
        } else if (service.getState() != ServiceController.State.UP) {
            // No, don't barf; just let the update apply to the model and put the server in a reload-required state
            return true;
        } else {
            if (!ActiveMQActivationService.isActiveMQServerActive(context, operation)) {
                return false;
            }
            applyOperationToActiveMQService(operation, attributeName, newValue, service);
            return false;
        }
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 35 with ServiceRegistry

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

the class BridgeRemove 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 BridgeConfiguration bridgeConfiguration = BridgeAdd.createBridgeConfiguration(context, name, model);
        ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        BridgeAdd.createBridge(bridgeConfiguration, server);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Aggregations

ServiceRegistry (org.jboss.msc.service.ServiceRegistry)75 ServiceName (org.jboss.msc.service.ServiceName)52 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 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 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