Search in sources :

Example 1 with ComponentInstance

use of org.jboss.as.ee.component.ComponentInstance in project wildfly by wildfly.

the class SFSBCreateInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    Map<String, ExtendedEntityManager> entityManagers = null;
    if (componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY) == null) {
        // Get all of the extended persistence contexts in use by the bean (some of which may of been inherited from
        // other beans).
        entityManagers = new HashMap<String, ExtendedEntityManager>();
        componentInstance.setInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY, new ImmediateManagedReference(entityManagers));
    } else {
        ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY);
        entityManagers = (Map<String, ExtendedEntityManager>) entityManagerRef.getInstance();
    }
    final ExtendedEntityManager[] ems = CreatedEntityManagers.getDeferredEntityManagers();
    for (ExtendedEntityManager e : ems) {
        entityManagers.put(e.getScopedPuName(), e);
    }
    return interceptorContext.proceed();
}
Also used : ComponentInstance(org.jboss.as.ee.component.ComponentInstance) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) ManagedReference(org.jboss.as.naming.ManagedReference) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) ExtendedEntityManager(org.jboss.as.jpa.container.ExtendedEntityManager)

Example 2 with ComponentInstance

use of org.jboss.as.ee.component.ComponentInstance in project wildfly by wildfly.

the class SFSBInvocationInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext context) throws Exception {
    final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
    ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY);
    if (entityManagerRef != null) {
        Map<String, ExtendedEntityManager> entityManagers = (Map<String, ExtendedEntityManager>) entityManagerRef.getInstance();
        SFSBCallStack.pushCall(entityManagers);
    }
    try {
        // call the next interceptor or target
        return context.proceed();
    } finally {
        if (entityManagerRef != null) {
            SFSBCallStack.popCall();
        }
    }
}
Also used : ComponentInstance(org.jboss.as.ee.component.ComponentInstance) ManagedReference(org.jboss.as.naming.ManagedReference) ExtendedEntityManager(org.jboss.as.jpa.container.ExtendedEntityManager) Map(java.util.Map)

Example 3 with ComponentInstance

use of org.jboss.as.ee.component.ComponentInstance in project wildfly by wildfly.

the class Jsr299BindingsInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
    final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
    final InterceptorInstances interceptorInstances = interceptorSupport.getInterceptorInstances(componentInstance);
    final InterceptorBindings interceptorBindings = this.interceptorBindings.getValue();
    switch(interceptionType) {
        case AROUND_INVOKE:
            return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_INVOKE, interceptorInstances, interceptorBindings);
        case AROUND_TIMEOUT:
            return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_TIMEOUT, interceptorInstances, interceptorBindings);
        case PRE_DESTROY:
            try {
                return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
            } finally {
                interceptorInstances.getCreationalContext().release();
            }
        case POST_CONSTRUCT:
            return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
        case AROUND_CONSTRUCT:
            return doLifecycleInterception(context, interceptorInstances, interceptorBindings);
        default:
            //should never happen
            return context.proceed();
    }
}
Also used : InterceptorInstances(org.jboss.as.weld.spi.InterceptorInstances) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) ComponentInstance(org.jboss.as.ee.component.ComponentInstance)

Example 4 with ComponentInstance

use of org.jboss.as.ee.component.ComponentInstance in project wildfly by wildfly.

the class Jsr299BindingsCreateInterceptor method processInvocation.

@Override
public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    BeanManagerImpl beanManager = this.beanManager;
    if (beanManager == null) {
        //cache the BM lookup, as it is quite slow
        beanManager = this.beanManager = this.weldContainer.getValue().getBeanManager(beanArchiveId);
    }
    //this is not always called with the deployments TCCL set
    //which causes weld to blow up
    SessionBean<Object> bean = null;
    if (ejbName != null) {
        EjbDescriptor<Object> descriptor = beanManager.getEjbDescriptor(this.ejbName);
        if (descriptor != null) {
            bean = beanManager.getBean(descriptor);
        }
    }
    InterceptorBindings interceptorBindings = this.interceptorBindings.getValue();
    final ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    InterceptorInstances existing = interceptorSupport.getInterceptorInstances(componentInstance);
    if (existing == null) {
        CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean);
        HashMap<String, SerializableContextualInstance<Interceptor<Object>, Object>> interceptorInstances = new HashMap<String, SerializableContextualInstance<Interceptor<Object>, Object>>();
        if (interceptorBindings != null) {
            for (Interceptor<?> interceptor : interceptorBindings.getAllInterceptors()) {
                addInterceptorInstance((Interceptor<Object>) interceptor, beanManager, interceptorInstances, creationalContext);
            }
        }
        interceptorSupport.setInterceptorInstances(componentInstance, new WeldInterceptorInstances(creationalContext, interceptorInstances));
    }
    return interceptorContext.proceed();
}
Also used : HashMap(java.util.HashMap) InterceptorInstances(org.jboss.as.weld.spi.InterceptorInstances) SerializableContextualInstance(org.jboss.weld.serialization.spi.helpers.SerializableContextualInstance) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) InterceptorBindings(org.jboss.weld.ejb.spi.InterceptorBindings) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) Interceptor(javax.enterprise.inject.spi.Interceptor)

Example 5 with ComponentInstance

use of org.jboss.as.ee.component.ComponentInstance in project wildfly by wildfly.

the class ManagedBeanCreateInterceptor method processInvocation.

public Object processInvocation(final InterceptorContext context) throws Exception {
    final ComponentClientInstance instance = context.getPrivateData(ComponentClientInstance.class);
    final Component component = context.getPrivateData(Component.class);
    final ComponentInstance componentInstance = component.createInstance();
    boolean ok = false;
    try {
        context.putPrivateData(ComponentInstance.class, componentInstance);
        instance.setViewInstanceData(ComponentInstance.class, componentInstance);
        final Object result = context.proceed();
        ok = true;
        return result;
    } finally {
        context.putPrivateData(ComponentInstance.class, null);
        if (!ok) {
            componentInstance.destroy();
            instance.setViewInstanceData(ComponentInstance.class, null);
        }
    }
}
Also used : ComponentClientInstance(org.jboss.as.ee.component.ComponentClientInstance) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) Component(org.jboss.as.ee.component.Component)

Aggregations

ComponentInstance (org.jboss.as.ee.component.ComponentInstance)13 ManagedReference (org.jboss.as.naming.ManagedReference)3 Method (java.lang.reflect.Method)2 RemoteException (java.rmi.RemoteException)2 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)2 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)2 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)2 ExtendedEntityManager (org.jboss.as.jpa.container.ExtendedEntityManager)2 InterceptorInstances (org.jboss.as.weld.spi.InterceptorInstances)2 InterceptorBindings (org.jboss.weld.ejb.spi.InterceptorBindings)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MessageDrivenBean (javax.ejb.MessageDrivenBean)1 MessageDrivenContext (javax.ejb.MessageDrivenContext)1 Interceptor (javax.enterprise.inject.spi.Interceptor)1 Component (org.jboss.as.ee.component.Component)1 ComponentClientInstance (org.jboss.as.ee.component.ComponentClientInstance)1 EjbComponentInstance (org.jboss.as.ejb3.component.EjbComponentInstance)1 ImmediateManagedReference (org.jboss.as.naming.ImmediateManagedReference)1 InterceptorContext (org.jboss.invocation.InterceptorContext)1