Search in sources :

Example 31 with ServiceBuilder

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

the class ParsedKernelDeploymentProcessor method describeBean.

protected void describeBean(final Module module, final ServiceTarget serviceTarget, DeploymentReflectionIndex deploymentIndex, BeanMetaDataConfig beanConfig) {
    final BeanState state = BeanState.NOT_INSTALLED;
    final ServiceName describedServiceName = BeanMetaDataConfig.toBeanName(beanConfig.getName(), state.next());
    final DescribedPojoPhase describedService = new DescribedPojoPhase(deploymentIndex, beanConfig);
    final ServiceBuilder describedServiceBuilder = serviceTarget.addService(describedServiceName, describedService);
    describedService.registerAliases(describedServiceBuilder);
    final ConfigVisitor visitor = new DefaultConfigVisitor(describedServiceBuilder, state, module, deploymentIndex);
    beanConfig.visit(visitor);
    describedServiceBuilder.setInitialMode(beanConfig.getMode().getMode());
    describedServiceBuilder.install();
}
Also used : DescribedPojoPhase(org.jboss.as.pojo.service.DescribedPojoPhase) DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) ConfigVisitor(org.jboss.as.pojo.descriptor.ConfigVisitor) DefaultConfigVisitor(org.jboss.as.pojo.descriptor.DefaultConfigVisitor) ServiceName(org.jboss.msc.service.ServiceName) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 32 with ServiceBuilder

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

the class CacheContainerBuilder method build.

@Override
public ServiceBuilder<CacheContainer> build(ServiceTarget target) {
    Function<EmbeddedCacheManager, CacheContainer> mapper = manager -> new DefaultCacheContainer(this.name, manager, this.defaultCache, this.batcherFactory);
    Supplier<EmbeddedCacheManager> supplier = () -> {
        GlobalConfiguration config = this.configuration.getValue();
        EmbeddedCacheManager manager = new DefaultCacheManager(config, null, false);
        manager.addListener(this);
        manager.start();
        InfinispanLogger.ROOT_LOGGER.debugf("%s cache container started", this.name);
        return manager;
    };
    Consumer<EmbeddedCacheManager> destroyer = manager -> {
        manager.stop();
        manager.removeListener(this);
        InfinispanLogger.ROOT_LOGGER.debugf("%s cache container stopped", this.name);
    };
    Service<CacheContainer> service = new SuppliedValueService<>(mapper, supplier, destroyer);
    ServiceBuilder<CacheContainer> builder = target.addService(this.getServiceName(), service).addAliases(this.aliases.stream().toArray(ServiceName[]::new)).setInitialMode(ServiceController.Mode.PASSIVE);
    return this.configuration.register(builder);
}
Also used : ValueDependency(org.wildfly.clustering.service.ValueDependency) Service(org.jboss.msc.service.Service) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) InfinispanBatcherFactory(org.jboss.as.clustering.infinispan.InfinispanBatcherFactory) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CacheStoppedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStoppedEvent) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ALIASES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.ALIASES) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) OperationContext(org.jboss.as.controller.OperationContext) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) InfinispanLogger(org.jboss.as.clustering.infinispan.InfinispanLogger) InfinispanRequirement(org.wildfly.clustering.infinispan.spi.InfinispanRequirement) CacheStopped(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStopped) CacheStartedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStartedEvent) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) ServiceTarget(org.jboss.msc.service.ServiceTarget) LinkedList(java.util.LinkedList) BatcherFactory(org.jboss.as.clustering.infinispan.BatcherFactory) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) Listener(org.infinispan.notifications.Listener) CONTAINER(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Capability.CONTAINER) PathAddress(org.jboss.as.controller.PathAddress) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceServiceBuilder(org.jboss.as.clustering.controller.ResourceServiceBuilder) Consumer(java.util.function.Consumer) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) CacheStarted(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStarted) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) DEFAULT_CACHE(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.DEFAULT_CACHE) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 33 with ServiceBuilder

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

the class InfinispanBeanManagerFactoryBuilderFactory method getDeploymentBuilders.

@Override
public Collection<CapabilityServiceBuilder<?>> getDeploymentBuilders(final ServiceName name) {
    String cacheName = getCacheName(name);
    String containerName = this.config.getContainerName();
    String templateCacheName = this.config.getCacheName();
    List<CapabilityServiceBuilder<?>> builders = new ArrayList<>(4);
    builders.add(new TemplateConfigurationBuilder(ServiceName.parse(InfinispanCacheRequirement.CONFIGURATION.resolve(containerName, cacheName)), containerName, cacheName, templateCacheName));
    builders.add(new CacheBuilder<Object, Object>(ServiceName.parse(InfinispanCacheRequirement.CACHE.resolve(containerName, cacheName)), containerName, cacheName) {

        @Override
        public ServiceBuilder<Cache<Object, Object>> build(ServiceTarget target) {
            return super.build(target).addDependency(name.append("marshalling"));
        }
    });
    builders.add(new BuilderAdapter<>(new RemoveOnCancelScheduledExecutorServiceBuilder(name.append(this.name, "expiration"), EXPIRATION_THREAD_FACTORY)));
    builders.add(new BuilderAdapter<>(new CachedThreadPoolExecutorServiceBuilder(name.append(this.name, "eviction"), EVICTION_THREAD_FACTORY)));
    return builders;
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) CachedThreadPoolExecutorServiceBuilder(org.wildfly.clustering.service.concurrent.CachedThreadPoolExecutorServiceBuilder) ArrayList(java.util.ArrayList) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) RemoveOnCancelScheduledExecutorServiceBuilder(org.wildfly.clustering.service.concurrent.RemoveOnCancelScheduledExecutorServiceBuilder) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) CachedThreadPoolExecutorServiceBuilder(org.wildfly.clustering.service.concurrent.CachedThreadPoolExecutorServiceBuilder) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) RemoveOnCancelScheduledExecutorServiceBuilder(org.wildfly.clustering.service.concurrent.RemoveOnCancelScheduledExecutorServiceBuilder) TemplateConfigurationBuilder(org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationBuilder)

Example 34 with ServiceBuilder

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

the class AsynchronousMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
    final SessionBeanMetaData data = description.getDescriptorData();
    final boolean isSecurityDomainKnown = description.isSecurityDomainKnown();
    if (data != null) {
        if (data instanceof SessionBean31MetaData) {
            final SessionBean31MetaData sessionBeanData = (SessionBean31MetaData) data;
            final AsyncMethodsMetaData async = sessionBeanData.getAsyncMethods();
            if (async != null) {
                for (AsyncMethodMetaData method : async) {
                    final Collection<Method> methods = MethodResolutionUtils.resolveMethods(method.getMethodName(), method.getMethodParams(), componentClass, deploymentReflectionIndex);
                    for (final Method m : methods) {
                        description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(m));
                    }
                }
            }
        }
    }
    if (!description.getAsynchronousClasses().isEmpty() || !description.getAsynchronousMethods().isEmpty()) {
        //setup a dependency on the executor service
        description.getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                configuration.getCreateDependencies().add(new DependencyConfigurator<SessionBeanComponentCreateService>() {

                    @Override
                    public void configureDependency(final ServiceBuilder<?> serviceBuilder, final SessionBeanComponentCreateService service) throws DeploymentUnitProcessingException {
                        serviceBuilder.addDependency(asynchronousThreadPoolService, ExecutorService.class, service.getAsyncExecutorService());
                    }
                });
            }
        });
        for (final ViewDescription view : description.getViews()) {
            final EJBViewDescription ejbView = (EJBViewDescription) view;
            ejbView.getConfigurators().add(new ViewConfigurator() {

                @Override
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
                    for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
                        //we need the component method to get the correct declaring class
                        final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, componentClass, method);
                        if (componentMethod != null) {
                            if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) {
                                addAsyncInterceptor(configuration, method, isSecurityDomainKnown);
                                configuration.addAsyncMethod(method);
                            } else {
                                MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method);
                                if (componentDescription.getAsynchronousMethods().contains(id)) {
                                    addAsyncInterceptor(configuration, method, isSecurityDomainKnown);
                                    configuration.addAsyncMethod(method);
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) SessionBean31MetaData(org.jboss.metadata.ejb.spec.SessionBean31MetaData) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AsyncMethodsMetaData(org.jboss.metadata.ejb.spec.AsyncMethodsMetaData) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) AsyncMethodMetaData(org.jboss.metadata.ejb.spec.AsyncMethodMetaData) SessionBeanComponentCreateService(org.jboss.as.ejb3.component.session.SessionBeanComponentCreateService) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Aggregations

ServiceBuilder (org.jboss.msc.service.ServiceBuilder)34 ServiceName (org.jboss.msc.service.ServiceName)17 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)11 ModelNode (org.jboss.dmr.ModelNode)10 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)8 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 InjectedValue (org.jboss.msc.value.InjectedValue)8 OperationContext (org.jboss.as.controller.OperationContext)7 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)7 Module (org.jboss.modules.Module)7 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 Resource (org.jboss.as.controller.registry.Resource)6 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)6 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)6 HashMap (java.util.HashMap)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)5 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)5 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)5