Search in sources :

Example 11 with ImmediateInterceptorFactory

use of org.jboss.invocation.ImmediateInterceptorFactory in project wildfly by wildfly.

the class DefaultInterceptorConfigurator method configure.

public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final boolean metadataComplete = MetadataCompleteMarker.isMetadataComplete(deploymentUnit);
    // Module stuff
    final Deque<InterceptorFactory> instantiators = new ArrayDeque<>();
    final Deque<InterceptorFactory> injectors = new ArrayDeque<>();
    final Deque<InterceptorFactory> uninjectors = new ArrayDeque<>();
    final Deque<InterceptorFactory> destructors = new ArrayDeque<>();
    final Map<String, List<InterceptorFactory>> userAroundInvokesByInterceptorClass = new HashMap<>();
    final Map<String, List<InterceptorFactory>> userAroundConstructsByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
    final Map<String, List<InterceptorFactory>> userAroundTimeoutsByInterceptorClass;
    final Map<String, List<InterceptorFactory>> userPrePassivatesByInterceptorClass;
    final Map<String, List<InterceptorFactory>> userPostActivatesByInterceptorClass;
    final Map<String, List<InterceptorFactory>> userPostConstructByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
    final Map<String, List<InterceptorFactory>> userPreDestroyByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
    final Set<MethodIdentifier> timeoutMethods = description.getTimerMethods();
    if (description.isTimerServiceRequired()) {
        userAroundTimeoutsByInterceptorClass = new HashMap<>();
    } else {
        userAroundTimeoutsByInterceptorClass = null;
    }
    if (description.isPassivationApplicable()) {
        userPrePassivatesByInterceptorClass = new HashMap<>();
        userPostActivatesByInterceptorClass = new HashMap<>();
    } else {
        userPrePassivatesByInterceptorClass = null;
        userPostActivatesByInterceptorClass = null;
    }
    //the actual component creation interceptor
    //this really belongs in DefaultComponentConfigurator, but all the other AroundConstruct chain is assembled here
    final InterceptorFactory instantiator;
    // Primary instance
    final ComponentFactory instanceFactory = configuration.getInstanceFactory();
    if (instanceFactory != null) {
        instantiator = new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(instanceFactory, BasicComponentInstance.INSTANCE_KEY, true));
    } else {
        final ClassReflectionIndex componentClassIndex = deploymentReflectionIndex.getClassIndex(configuration.getComponentClass());
        //use the default constructor if no instanceFactory has been set
        final Constructor<?> constructor = componentClassIndex.getConstructor(EMPTY_CLASS_ARRAY);
        if (constructor == null) {
            throw EeLogger.ROOT_LOGGER.defaultConstructorNotFound(configuration.getComponentClass());
        }
        instantiator = new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(new ConstructorComponentFactory(constructor), BasicComponentInstance.INSTANCE_KEY, true));
    }
    //all interceptors with lifecycle callbacks, in the correct order
    final List<InterceptorDescription> interceptorWithLifecycleCallbacks = new ArrayList<InterceptorDescription>();
    if (!description.isExcludeDefaultInterceptors()) {
        interceptorWithLifecycleCallbacks.addAll(description.getDefaultInterceptors());
    }
    interceptorWithLifecycleCallbacks.addAll(description.getClassInterceptors());
    for (final InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
        final String interceptorClassName = interceptorDescription.getInterceptorClassName();
        final Class<?> interceptorClass;
        try {
            interceptorClass = ClassLoadingUtils.loadClass(interceptorClassName, module);
        } catch (ClassNotFoundException e) {
            throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptorClassName);
        }
        final InterceptorEnvironment interceptorEnvironment = moduleDescription.getInterceptorEnvironment().get(interceptorClassName);
        if (interceptorEnvironment != null) {
            //if the interceptor has environment config we merge it into the components environment
            description.getBindingConfigurations().addAll(interceptorEnvironment.getBindingConfigurations());
            for (final ResourceInjectionConfiguration injection : interceptorEnvironment.getResourceInjections()) {
                description.addResourceInjection(injection);
            }
        }
        //we store the interceptor instance under the class key
        final Object contextKey = interceptorClass;
        configuration.getInterceptorContextKeys().add(contextKey);
        final ClassReflectionIndex interceptorIndex = deploymentReflectionIndex.getClassIndex(interceptorClass);
        final Constructor<?> constructor = interceptorIndex.getConstructor(EMPTY_CLASS_ARRAY);
        if (constructor == null) {
            throw EeLogger.ROOT_LOGGER.defaultConstructorNotFoundOnComponent(interceptorClassName, configuration.getComponentClass());
        }
        instantiators.addFirst(new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(new ConstructorComponentFactory(constructor), contextKey, false)));
        destructors.addLast(new ImmediateInterceptorFactory(new ManagedReferenceReleaseInterceptor(contextKey)));
        final boolean interceptorHasLifecycleCallbacks = interceptorWithLifecycleCallbacks.contains(interceptorDescription);
        new ClassDescriptionTraversal(interceptorClass, applicationClasses) {

            @Override
            public void handle(final Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
                mergeInjectionsForClass(clazz, interceptorClass, classDescription, moduleDescription, deploymentReflectionIndex, description, configuration, context, injectors, contextKey, uninjectors, metadataComplete);
                final InterceptorClassDescription interceptorConfig;
                if (classDescription != null && !metadataComplete) {
                    interceptorConfig = InterceptorClassDescription.merge(classDescription.getInterceptorClassDescription(), moduleDescription.getInterceptorClassOverride(clazz.getName()));
                } else {
                    interceptorConfig = InterceptorClassDescription.merge(null, moduleDescription.getInterceptorClassOverride(clazz.getName()));
                }
                // methods, as per interceptors spec
                if (interceptorHasLifecycleCallbacks && !description.isIgnoreLifecycleInterceptors()) {
                    final MethodIdentifier postConstructMethodIdentifier = interceptorConfig.getPostConstruct();
                    handleInterceptorClass(clazz, postConstructMethodIdentifier, userPostConstructByInterceptorClass, true, true);
                    final MethodIdentifier preDestroyMethodIdentifier = interceptorConfig.getPreDestroy();
                    handleInterceptorClass(clazz, preDestroyMethodIdentifier, userPreDestroyByInterceptorClass, true, true);
                    final MethodIdentifier aroundConstructMethodIdentifier = interceptorConfig.getAroundConstruct();
                    handleInterceptorClass(clazz, aroundConstructMethodIdentifier, userAroundConstructsByInterceptorClass, true, true);
                }
                final MethodIdentifier aroundInvokeMethodIdentifier = interceptorConfig.getAroundInvoke();
                handleInterceptorClass(clazz, aroundInvokeMethodIdentifier, userAroundInvokesByInterceptorClass, false, false);
                if (description.isTimerServiceRequired()) {
                    final MethodIdentifier aroundTimeoutMethodIdentifier = interceptorConfig.getAroundTimeout();
                    handleInterceptorClass(clazz, aroundTimeoutMethodIdentifier, userAroundTimeoutsByInterceptorClass, false, false);
                }
                if (description.isPassivationApplicable()) {
                    handleInterceptorClass(clazz, interceptorConfig.getPrePassivate(), userPrePassivatesByInterceptorClass, false, false);
                    handleInterceptorClass(clazz, interceptorConfig.getPostActivate(), userPostActivatesByInterceptorClass, false, false);
                }
            }

            private void handleInterceptorClass(final Class<?> clazz, final MethodIdentifier methodIdentifier, final Map<String, List<InterceptorFactory>> classMap, final boolean changeMethod, final boolean lifecycleMethod) throws DeploymentUnitProcessingException {
                if (methodIdentifier != null) {
                    final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, methodIdentifier);
                    if (isNotOverriden(clazz, method, interceptorClass, deploymentReflectionIndex)) {
                        final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new ManagedReferenceLifecycleMethodInterceptor(contextKey, method, changeMethod, lifecycleMethod));
                        List<InterceptorFactory> factories = classMap.get(interceptorClassName);
                        if (factories == null) {
                            classMap.put(interceptorClassName, factories = new ArrayList<InterceptorFactory>());
                        }
                        factories.add(interceptorFactory);
                    }
                }
            }
        }.run();
    }
    final List<InterceptorFactory> userAroundConstruct = new ArrayList<InterceptorFactory>();
    final List<InterceptorFactory> userPostConstruct = new ArrayList<InterceptorFactory>();
    final List<InterceptorFactory> userPreDestroy = new ArrayList<InterceptorFactory>();
    final List<InterceptorFactory> userPrePassivate = new ArrayList<InterceptorFactory>();
    final List<InterceptorFactory> userPostActivate = new ArrayList<InterceptorFactory>();
    //now add the lifecycle interceptors in the correct order
    for (final InterceptorDescription interceptorClass : interceptorWithLifecycleCallbacks) {
        if (userPostConstructByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
            userPostConstruct.addAll(userPostConstructByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
        }
        if (userAroundConstructsByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
            userAroundConstruct.addAll(userAroundConstructsByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
        }
        if (userPreDestroyByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
            userPreDestroy.addAll(userPreDestroyByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
        }
        if (description.isPassivationApplicable()) {
            if (userPrePassivatesByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
                userPrePassivate.addAll(userPrePassivatesByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
            }
            if (userPostActivatesByInterceptorClass.containsKey(interceptorClass.getInterceptorClassName())) {
                userPostActivate.addAll(userPostActivatesByInterceptorClass.get(interceptorClass.getInterceptorClassName()));
            }
        }
    }
    if (!injectors.isEmpty()) {
        configuration.addPostConstructInterceptors(new ArrayList<>(injectors), InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_RESOURCE_INJECTION_INTERCEPTORS);
    }
    if (!instantiators.isEmpty()) {
        configuration.addPostConstructInterceptors(new ArrayList<>(instantiators), InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_INSTANTIATION_INTERCEPTORS);
    }
    if (!userAroundConstruct.isEmpty()) {
        configuration.addAroundConstructInterceptors(userAroundConstruct, InterceptorOrder.AroundConstruct.INTERCEPTOR_AROUND_CONSTRUCT);
    }
    configuration.addAroundConstructInterceptor(instantiator, InterceptorOrder.AroundConstruct.CONSTRUCT_COMPONENT);
    configuration.addAroundConstructInterceptor(new ImmediateInterceptorFactory(Interceptors.getTerminalInterceptor()), InterceptorOrder.AroundConstruct.TERMINAL_INTERCEPTOR);
    if (!configuration.getAroundConstructInterceptors().isEmpty()) {
        configuration.addPostConstructInterceptor(new AroundConstructInterceptorFactory(Interceptors.getChainedInterceptorFactory(configuration.getAroundConstructInterceptors())), InterceptorOrder.ComponentPostConstruct.AROUND_CONSTRUCT_CHAIN);
    }
    if (!userPostConstruct.isEmpty()) {
        configuration.addPostConstructInterceptors(userPostConstruct, InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_USER_INTERCEPTORS);
    }
    // Apply pre-destroy
    if (!uninjectors.isEmpty()) {
        configuration.addPreDestroyInterceptors(new ArrayList<>(uninjectors), InterceptorOrder.ComponentPreDestroy.INTERCEPTOR_UNINJECTION_INTERCEPTORS);
    }
    if (!destructors.isEmpty()) {
        configuration.addPreDestroyInterceptors(new ArrayList<>(destructors), InterceptorOrder.ComponentPreDestroy.INTERCEPTOR_DESTRUCTION_INTERCEPTORS);
    }
    if (!userPreDestroy.isEmpty()) {
        configuration.addPreDestroyInterceptors(userPreDestroy, InterceptorOrder.ComponentPreDestroy.INTERCEPTOR_USER_INTERCEPTORS);
    }
    if (description.isPassivationApplicable()) {
        if (!userPrePassivate.isEmpty()) {
            configuration.addPrePassivateInterceptors(userPrePassivate, InterceptorOrder.ComponentPassivation.INTERCEPTOR_USER_INTERCEPTORS);
        }
        if (!userPostActivate.isEmpty()) {
            configuration.addPostActivateInterceptors(userPostActivate, InterceptorOrder.ComponentPassivation.INTERCEPTOR_USER_INTERCEPTORS);
        }
    }
    // @AroundInvoke interceptors
    final List<InterceptorDescription> classInterceptors = description.getClassInterceptors();
    final Map<MethodIdentifier, List<InterceptorDescription>> methodInterceptors = description.getMethodInterceptors();
    if (description.isIntercepted()) {
        for (final Method method : configuration.getDefinedComponentMethods()) {
            //now add the interceptor that initializes and the interceptor that actually invokes to the end of the interceptor chain
            final MethodIdentifier identifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
            final List<InterceptorFactory> userAroundInvokes = new ArrayList<InterceptorFactory>();
            final List<InterceptorFactory> userAroundTimeouts = new ArrayList<InterceptorFactory>();
            // first add the default interceptors (if not excluded) to the deque
            final boolean requiresTimerChain = description.isTimerServiceRequired() && timeoutMethods.contains(identifier);
            if (!description.isExcludeDefaultInterceptors() && !description.isExcludeDefaultInterceptors(identifier)) {
                for (InterceptorDescription interceptorDescription : description.getDefaultInterceptors()) {
                    String interceptorClassName = interceptorDescription.getInterceptorClassName();
                    List<InterceptorFactory> aroundInvokes = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                    if (aroundInvokes != null) {
                        userAroundInvokes.addAll(aroundInvokes);
                    }
                    if (requiresTimerChain) {
                        List<InterceptorFactory> aroundTimeouts = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                        if (aroundTimeouts != null) {
                            userAroundTimeouts.addAll(aroundTimeouts);
                        }
                    }
                }
            }
            // now add class level interceptors (if not excluded) to the deque
            if (!description.isExcludeClassInterceptors(identifier)) {
                for (InterceptorDescription interceptorDescription : classInterceptors) {
                    String interceptorClassName = interceptorDescription.getInterceptorClassName();
                    List<InterceptorFactory> aroundInvokes = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                    if (aroundInvokes != null) {
                        userAroundInvokes.addAll(aroundInvokes);
                    }
                    if (requiresTimerChain) {
                        List<InterceptorFactory> aroundTimeouts = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                        if (aroundTimeouts != null) {
                            userAroundTimeouts.addAll(aroundTimeouts);
                        }
                    }
                }
            }
            // now add method level interceptors for to the deque so that they are triggered after the class interceptors
            List<InterceptorDescription> methodLevelInterceptors = methodInterceptors.get(identifier);
            if (methodLevelInterceptors != null) {
                for (InterceptorDescription methodLevelInterceptor : methodLevelInterceptors) {
                    String interceptorClassName = methodLevelInterceptor.getInterceptorClassName();
                    List<InterceptorFactory> aroundInvokes = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                    if (aroundInvokes != null) {
                        userAroundInvokes.addAll(aroundInvokes);
                    }
                    if (requiresTimerChain) {
                        List<InterceptorFactory> aroundTimeouts = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                        if (aroundTimeouts != null) {
                            userAroundTimeouts.addAll(aroundTimeouts);
                        }
                    }
                }
            }
            if (requiresTimerChain) {
                configuration.addComponentInterceptor(method, new UserInterceptorFactory(weaved(userAroundInvokes), weaved(userAroundTimeouts)), InterceptorOrder.Component.INTERCEPTOR_USER_INTERCEPTORS);
            } else {
                configuration.addComponentInterceptors(method, userAroundInvokes, InterceptorOrder.Component.INTERCEPTOR_USER_INTERCEPTORS);
            }
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ArrayList(java.util.ArrayList) List(java.util.List) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) ArrayDeque(java.util.ArrayDeque) InterceptorFactory(org.jboss.invocation.InterceptorFactory) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 12 with ImmediateInterceptorFactory

use of org.jboss.invocation.ImmediateInterceptorFactory in project wildfly by wildfly.

the class NamespaceConfigurator method configure.

/** {@inheritDoc} */
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final ComponentNamingMode namingMode = description.getNamingMode();
    final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector();
    final String applicationName = configuration.getApplicationName();
    final String moduleName = configuration.getModuleName();
    final String compName = configuration.getComponentName();
    final ServiceName appContextServiceName = ContextNames.contextServiceNameOfApplication(applicationName);
    final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(applicationName, moduleName);
    final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(applicationName, moduleName, compName);
    final Injector<NamingStore> appInjector = selector.getAppContextInjector();
    final Injector<NamingStore> moduleInjector = selector.getModuleContextInjector();
    final Injector<NamingStore> compInjector = selector.getCompContextInjector();
    final Injector<NamingStore> jbossInjector = selector.getJbossContextInjector();
    final Injector<NamingStore> globalInjector = selector.getGlobalContextInjector();
    final Injector<NamingStore> exportedInjector = selector.getExportedContextInjector();
    configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

        public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) {
            serviceBuilder.addDependency(appContextServiceName, NamingStore.class, appInjector);
            serviceBuilder.addDependency(moduleContextServiceName, NamingStore.class, moduleInjector);
            if (namingMode == ComponentNamingMode.CREATE) {
                serviceBuilder.addDependency(compContextServiceName, NamingStore.class, compInjector);
            } else if (namingMode == ComponentNamingMode.USE_MODULE) {
                serviceBuilder.addDependency(moduleContextServiceName, NamingStore.class, compInjector);
            }
            serviceBuilder.addDependency(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, NamingStore.class, globalInjector);
            serviceBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, NamingStore.class, jbossInjector);
            serviceBuilder.addDependency(ContextNames.EXPORTED_CONTEXT_SERVICE_NAME, NamingStore.class, exportedInjector);
        }
    });
    final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new NamespaceContextInterceptor(selector, context.getDeploymentUnit().getServiceName()));
    configuration.addPostConstructInterceptor(interceptorFactory, InterceptorOrder.ComponentPostConstruct.JNDI_NAMESPACE_INTERCEPTOR);
    configuration.addPreDestroyInterceptor(interceptorFactory, InterceptorOrder.ComponentPreDestroy.JNDI_NAMESPACE_INTERCEPTOR);
    if (description.isPassivationApplicable()) {
        configuration.addPrePassivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
        configuration.addPostActivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
    }
    configuration.setNamespaceContextInterceptorFactory(interceptorFactory);
    configuration.setNamespaceContextSelector(selector);
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ServiceName(org.jboss.msc.service.ServiceName) InjectedEENamespaceContextSelector(org.jboss.as.ee.naming.InjectedEENamespaceContextSelector) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory)

Example 13 with ImmediateInterceptorFactory

use of org.jboss.invocation.ImmediateInterceptorFactory in project wildfly by wildfly.

the class AbstractComponentConfigurator method mergeInjectionsForClass.

/**
     * Sets up all resource injections for a class. This takes into account injections that have been specified in the module and component deployment descriptors
     * <p/>
     * Note that this does not take superclasses into consideration, only injections on the current class
     *
     * @param clazz             The class or superclass to perform injection for
     * @param actualClass       The actual component or interceptor class
     * @param classDescription  The class description, may be null
     * @param moduleDescription The module description
     * @param description       The component description
     * @param configuration     The component configuration
     * @param context           The phase context
     * @param injectors         The list of injectors for the current component
     * @param instanceKey       The key that identifies the instance to inject in the interceptor context
     * @param uninjectors       The list of uninjections for the current component
     * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
     *
     */
protected void mergeInjectionsForClass(final Class<?> clazz, final Class<?> actualClass, final EEModuleClassDescription classDescription, final EEModuleDescription moduleDescription, final DeploymentReflectionIndex deploymentReflectionIndex, final ComponentDescription description, final ComponentConfiguration configuration, final DeploymentPhaseContext context, final Deque<InterceptorFactory> injectors, final Object instanceKey, final Deque<InterceptorFactory> uninjectors, boolean metadataComplete) throws DeploymentUnitProcessingException {
    final Map<InjectionTarget, ResourceInjectionConfiguration> mergedInjections = new HashMap<InjectionTarget, ResourceInjectionConfiguration>();
    if (classDescription != null && !metadataComplete) {
        mergedInjections.putAll(classDescription.getInjectionConfigurations());
    }
    mergedInjections.putAll(moduleDescription.getResourceInjections(clazz.getName()));
    mergedInjections.putAll(description.getResourceInjections(clazz.getName()));
    for (final ResourceInjectionConfiguration injectionConfiguration : mergedInjections.values()) {
        if (!moduleDescription.isAppClient() && injectionConfiguration.getTarget().isStatic(context.getDeploymentUnit())) {
            ROOT_LOGGER.debugf("Injection for a member with static modifier is only acceptable on application clients, ignoring injection for target %s", injectionConfiguration.getTarget());
            continue;
        }
        if (injectionConfiguration.getTarget() instanceof MethodInjectionTarget) {
            //we need to make sure that if this is a method injection it has not been overriden
            final MethodInjectionTarget mt = (MethodInjectionTarget) injectionConfiguration.getTarget();
            Method method = mt.getMethod(deploymentReflectionIndex, clazz);
            if (!isNotOverriden(clazz, method, actualClass, deploymentReflectionIndex)) {
                continue;
            }
        }
        final Object valueContextKey = new Object();
        final InjectedValue<ManagedReferenceFactory> managedReferenceFactoryValue = new InjectedValue<ManagedReferenceFactory>();
        configuration.getStartDependencies().add(new ComponentDescription.InjectedConfigurator(injectionConfiguration, configuration, context, managedReferenceFactoryValue));
        injectors.addFirst(injectionConfiguration.getTarget().createInjectionInterceptorFactory(instanceKey, valueContextKey, managedReferenceFactoryValue, context.getDeploymentUnit(), injectionConfiguration.isOptional()));
        uninjectors.addLast(new ImmediateInterceptorFactory(new ManagedReferenceReleaseInterceptor(valueContextKey)));
    }
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory)

Example 14 with ImmediateInterceptorFactory

use of org.jboss.invocation.ImmediateInterceptorFactory in project wildfly by wildfly.

the class StartupAwaitDeploymentUnitProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        if (component instanceof EJBComponentDescription) {
            component.getConfigurators().add(new ComponentConfigurator() {

                @Override
                public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
                    StartupCountdown countdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
                    for (ViewConfiguration view : configuration.getViews()) {
                        EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
                        if (INTFS.contains(ejbView.getMethodIntf())) {
                            ejbView.addViewInterceptor(new ImmediateInterceptorFactory(new StartupAwaitInterceptor(countdown)), InterceptorOrder.View.STARTUP_AWAIT_INTERCEPTOR);
                        }
                    }
                }
            });
        }
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown)

Example 15 with ImmediateInterceptorFactory

use of org.jboss.invocation.ImmediateInterceptorFactory in project wildfly by wildfly.

the class WeldComponentIntegrationProcessor method addCommonLifecycleInterceptionSupport.

private static void addCommonLifecycleInterceptionSupport(final ComponentConfiguration configuration, ServiceBuilder<WeldComponentService> builder, final ServiceName bindingServiceName, final ServiceName beanManagerServiceName, final ComponentInterceptorSupport componentInterceptorSupport) {
    configuration.addPreDestroyInterceptor(factory(InterceptionType.PRE_DESTROY, builder, bindingServiceName, componentInterceptorSupport), InterceptorOrder.ComponentPreDestroy.CDI_INTERCEPTORS);
    configuration.addAroundConstructInterceptor(factory(InterceptionType.AROUND_CONSTRUCT, builder, bindingServiceName, componentInterceptorSupport), InterceptorOrder.AroundConstruct.WELD_AROUND_CONSTRUCT_INTERCEPTORS);
    configuration.addPostConstructInterceptor(factory(InterceptionType.POST_CONSTRUCT, builder, bindingServiceName, componentInterceptorSupport), InterceptorOrder.ComponentPostConstruct.CDI_INTERCEPTORS);
    /*
         * Add interceptor to activate the request scope for the @PostConstruct callback.
         * See https://issues.jboss.org/browse/CDI-219 for details
         */
    final EjbRequestScopeActivationInterceptor.Factory postConstructRequestContextActivationFactory = new EjbRequestScopeActivationInterceptor.Factory(beanManagerServiceName);
    configuration.addPostConstructInterceptor(postConstructRequestContextActivationFactory, InterceptorOrder.ComponentPostConstruct.REQUEST_SCOPE_ACTIVATING_INTERCEPTOR);
    // @AroundConstruct support
    configuration.addAroundConstructInterceptor(new ImmediateInterceptorFactory(WeldConstructionStartInterceptor.INSTANCE), InterceptorOrder.AroundConstruct.CONSTRUCTION_START_INTERCEPTOR);
}
Also used : ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) WeldManagedReferenceFactory(org.jboss.as.weld.injection.WeldManagedReferenceFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EjbRequestScopeActivationInterceptor(org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor)

Aggregations

ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)20 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)10 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)10 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)10 Method (java.lang.reflect.Method)9 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)9 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 InterceptorFactory (org.jboss.invocation.InterceptorFactory)7 ArrayList (java.util.ArrayList)6 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)6 ViewDescription (org.jboss.as.ee.component.ViewDescription)6 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)5 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)5 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)5 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 HashMap (java.util.HashMap)4 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)4 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)4 ServiceName (org.jboss.msc.service.ServiceName)4 HashSet (java.util.HashSet)3