Search in sources :

Example 1 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class StatefulTimeoutMergingProcessor method handleAnnotations.

@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    final EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
    // we only care about annotations on the bean class itself
    if (clazz == null) {
        return;
    }
    final ClassAnnotationInformation<StatefulTimeout, StatefulTimeoutInfo> timeout = clazz.getAnnotationInformation(StatefulTimeout.class);
    if (timeout == null) {
        return;
    }
    if (!timeout.getClassLevelAnnotations().isEmpty()) {
        componentConfiguration.setStatefulTimeout(timeout.getClassLevelAnnotations().get(0));
    }
}
Also used : StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo) StatefulTimeout(javax.ejb.StatefulTimeout) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription)

Example 2 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class StatefulTimeoutMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    final SessionBeanMetaData data = componentConfiguration.getDescriptorData();
    if (data == null) {
        return;
    }
    if (data instanceof SessionBean31MetaData) {
        SessionBean31MetaData sessionBean31MetaData = (SessionBean31MetaData) data;
        final StatefulTimeoutMetaData statefulTimeout = sessionBean31MetaData.getStatefulTimeout();
        if (statefulTimeout != null) {
            TimeUnit unit = TimeUnit.MINUTES;
            if (statefulTimeout.getUnit() != null) {
                unit = statefulTimeout.getUnit();
            }
            componentConfiguration.setStatefulTimeout(new StatefulTimeoutInfo(statefulTimeout.getTimeout(), unit));
        }
    }
}
Also used : SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo) TimeUnit(java.util.concurrent.TimeUnit) StatefulTimeoutMetaData(org.jboss.metadata.ejb.spec.StatefulTimeoutMetaData) SessionBean31MetaData(org.jboss.metadata.ejb.spec.SessionBean31MetaData)

Example 3 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class StatefulComponentDescription method createConfiguration.

@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
    final ComponentConfiguration statefulComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
    // setup the component create service
    statefulComponentConfiguration.setComponentCreateServiceFactory(new StatefulComponentCreateServiceFactory());
    if (getTransactionManagementType() == TransactionManagementType.BEAN) {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final ComponentInstanceInterceptorFactory bmtComponentInterceptorFactory = new ComponentInstanceInterceptorFactory() {

                    @Override
                    protected Interceptor create(Component component, InterceptorFactoryContext context) {
                        if (!(component instanceof StatefulSessionComponent)) {
                            throw EjbLogger.ROOT_LOGGER.componentNotInstanceOfSessionComponent(component, component.getComponentClass(), "stateful");
                        }
                        return new StatefulBMTInterceptor((StatefulSessionComponent) component);
                    }
                };
                configuration.addComponentInterceptor(bmtComponentInterceptorFactory, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
            }
        });
    } else {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
                InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
                configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), false), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), false), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                if (description.isPassivationApplicable()) {
                    configuration.addPrePassivateInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPrePassivate(), false), InterceptorOrder.ComponentPassivation.TRANSACTION_INTERCEPTOR);
                    configuration.addPostActivateInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostActivate(), false), InterceptorOrder.ComponentPassivation.TRANSACTION_INTERCEPTOR);
                }
            }
        });
    }
    addStatefulSessionSynchronizationInterceptor();
    this.getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            DeploymentUnit unit = context.getDeploymentUnit();
            CapabilityServiceSupport support = unit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
            StatefulComponentDescription statefulDescription = (StatefulComponentDescription) description;
            ServiceTarget target = context.getServiceTarget();
            ServiceBuilder<?> builder = target.addService(statefulDescription.getCacheFactoryServiceName().append("installer"));
            Supplier<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>> cacheFactoryBuilder = builder.requires(this.getCacheFactoryBuilderRequirement(statefulDescription));
            Service service = new ChildTargetService(new Consumer<ServiceTarget>() {

                @Override
                public void accept(ServiceTarget target) {
                    cacheFactoryBuilder.get().getServiceConfigurator(unit, statefulDescription, configuration).configure(support).build(target).install();
                }
            });
            builder.setInstance(service).install();
        }

        private ServiceName getCacheFactoryBuilderRequirement(StatefulComponentDescription description) {
            if (!description.isPassivationApplicable()) {
                return CacheFactoryBuilderServiceNameProvider.DEFAULT_PASSIVATION_DISABLED_CACHE_SERVICE_NAME;
            }
            CacheInfo cache = description.getCache();
            return (cache != null) ? new CacheFactoryBuilderServiceNameProvider(cache.getName()).getServiceName() : CacheFactoryBuilderServiceNameProvider.DEFAULT_CACHE_SERVICE_NAME;
        }
    });
    return statefulComponentConfiguration;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ComponentInstanceInterceptorFactory(org.jboss.as.ee.component.ComponentInstanceInterceptorFactory) StatefulBMTInterceptor(org.jboss.as.ejb3.tx.StatefulBMTInterceptor) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) InterceptorFactoryContext(org.jboss.invocation.InterceptorFactoryContext) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) Consumer(java.util.function.Consumer) Supplier(java.util.function.Supplier) Component(org.jboss.as.ee.component.Component) LifecycleCMTTxInterceptor(org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor) Interceptor(org.jboss.invocation.Interceptor) StatefulBMTInterceptor(org.jboss.as.ejb3.tx.StatefulBMTInterceptor) CacheInfo(org.jboss.as.ejb3.cache.CacheInfo) ComponentInstanceInterceptorFactory(org.jboss.as.ee.component.ComponentInstanceInterceptorFactory) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) ServiceTarget(org.jboss.msc.service.ServiceTarget) Service(org.jboss.msc.Service) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) CacheFactoryBuilderServiceNameProvider(org.jboss.as.ejb3.cache.CacheFactoryBuilderServiceNameProvider) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionID(org.jboss.ejb.client.SessionID)

Example 4 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class CacheDependenciesProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) {
    DeploymentUnit unit = context.getDeploymentUnit();
    final ServiceName name = unit.getServiceName();
    EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final CapabilityServiceSupport support = unit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
    final ServiceTarget target = context.getServiceTarget();
    Set<SupplierDependency<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>>> dependencies = new HashSet<>();
    for (ComponentDescription description : moduleDescription.getComponentDescriptions()) {
        if (description instanceof StatefulComponentDescription) {
            StatefulComponentDescription statefulDescription = (StatefulComponentDescription) description;
            dependencies.add(new ServiceSupplierDependency<>(getCacheFactoryBuilderServiceName(statefulDescription)));
        }
    }
    Service service = new ChildTargetService(new Consumer<ServiceTarget>() {

        @Override
        public void accept(ServiceTarget target) {
            // Cache factory builder dependencies might still contain duplicates (if referenced via alias), so ensure we collect only distinct instances.
            Set<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>> builders = new HashSet<>(dependencies.size());
            for (Supplier<CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance>> dependency : dependencies) {
                builders.add(dependency.get());
            }
            for (CacheFactoryBuilder<SessionID, StatefulSessionComponentInstance> builder : builders) {
                for (CapabilityServiceConfigurator configurator : builder.getDeploymentServiceConfigurators(unit)) {
                    configurator.configure(support).build(target).install();
                }
            }
        }
    });
    ServiceBuilder<?> builder = target.addService(name.append("cache-dependencies-installer"));
    for (Dependency dependency : dependencies) {
        dependency.register(builder);
    }
    builder.setInstance(service).install();
    // Install versioned marshalling configuration
    new MarshallingConfigurationRepositoryServiceConfigurator(unit).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
}
Also used : StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashSet(java.util.HashSet) Set(java.util.Set) StatefulSessionComponentInstance(org.jboss.as.ejb3.component.stateful.StatefulSessionComponentInstance) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) CacheFactoryBuilder(org.jboss.as.ejb3.cache.CacheFactoryBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) ServiceTarget(org.jboss.msc.service.ServiceTarget) MarshallingConfigurationRepositoryServiceConfigurator(org.jboss.as.ejb3.component.stateful.MarshallingConfigurationRepositoryServiceConfigurator) Service(org.jboss.msc.Service) ChildTargetService(org.wildfly.clustering.service.ChildTargetService) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) Dependency(org.wildfly.clustering.service.Dependency) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) ServiceName(org.jboss.msc.service.ServiceName) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionID(org.jboss.ejb.client.SessionID)

Example 5 with StatefulComponentDescription

use of org.jboss.as.ejb3.component.stateful.StatefulComponentDescription in project wildfly by wildfly.

the class DistributableCacheFactoryBuilderServiceConfigurator method getServiceConfigurator.

@Override
public CapabilityServiceConfigurator getServiceConfigurator(DeploymentUnit unit, StatefulComponentDescription description, ComponentConfiguration configuration) {
    StatefulBeanConfiguration context = new StatefulBeanConfiguration() {

        @Override
        public String getName() {
            return configuration.getComponentName();
        }

        @Override
        public ServiceName getDeploymentUnitServiceName() {
            return unit.getServiceName();
        }

        @Override
        public Module getModule() {
            return unit.getAttachment(Attachments.MODULE);
        }

        @Override
        public Duration getTimeout() {
            StatefulTimeoutInfo info = description.getStatefulTimeout();
            // A value of -1 means the bean will never be removed due to timeout
            return (info != null && info.getValue() >= 0) ? Duration.of(info.getValue(), info.getTimeUnit().toChronoUnit()) : null;
        }
    };
    CapabilityServiceConfigurator configurator = this.factory.getBeanManagerFactoryServiceConfigurator(context);
    return new DistributableCacheFactoryServiceConfigurator<K, V>(description.getCacheFactoryServiceName(), configurator);
}
Also used : StatefulBeanConfiguration(org.wildfly.clustering.ejb.StatefulBeanConfiguration) CapabilityServiceConfigurator(org.jboss.as.clustering.controller.CapabilityServiceConfigurator) StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo)

Aggregations

StatefulComponentDescription (org.jboss.as.ejb3.component.stateful.StatefulComponentDescription)7 ServiceName (org.jboss.msc.service.ServiceName)5 StatefulTimeoutInfo (org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo)4 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)3 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)3 CacheInfo (org.jboss.as.ejb3.cache.CacheInfo)3 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Method (java.lang.reflect.Method)2 HashSet (java.util.HashSet)2 Supplier (java.util.function.Supplier)2 CapabilityServiceConfigurator (org.jboss.as.clustering.controller.CapabilityServiceConfigurator)2 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)2 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)2 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 SessionID (org.jboss.ejb.client.SessionID)2 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)2