Search in sources :

Example 1 with Context

use of javax.enterprise.context.spi.Context in project Payara by payara.

the class ClusterScopedInterceptor method refresh.

private void refresh(Class<?> beanClass) {
    Bean<?> bean = Iterables.getOnlyElement(beanManager.getBeans(beanClass));
    String beanName = getBeanName(bean, getAnnotation(beanManager, bean));
    Context ctx = beanManager.getContext(ClusterScoped.class);
    clusteredLookup.getClusteredSingletonMap().put(beanName, ctx.get(bean));
}
Also used : Context(javax.enterprise.context.spi.Context) InvocationContext(javax.interceptor.InvocationContext)

Example 2 with Context

use of javax.enterprise.context.spi.Context in project joynr by bmwcarit.

the class JoynrJeeMessageContextTest method testContextRegistered.

@Test
public void testContextRegistered() {
    JoynrJeeMessageContext.getInstance().activate();
    Context result = beanManager.getContext(JoynrJeeMessageScoped.class);
    assertNotNull(result);
    assertTrue(result instanceof JoynrJeeMessageContext);
    JoynrJeeMessageContext.getInstance().deactivate();
    try {
        result = beanManager.getContext(JoynrJeeMessageScoped.class);
        fail("Shouldn't get it after deactivation.");
    } catch (ContextNotActiveException e) {
        logger.trace("Context not available after deactivation as expected.");
    }
}
Also used : Context(javax.enterprise.context.spi.Context) JoynrJeeMessageContext(io.joynr.jeeintegration.context.JoynrJeeMessageContext) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) JoynrJeeMessageContext(io.joynr.jeeintegration.context.JoynrJeeMessageContext) JoynrJeeMessageScoped(io.joynr.jeeintegration.api.JoynrJeeMessageScoped) Test(org.junit.Test)

Example 3 with Context

use of javax.enterprise.context.spi.Context in project microservice_framework by CJSCommonPlatform.

the class BeanInstantiaterTest method shouldInstantiateABean.

@Test
@SuppressWarnings("unchecked")
public void shouldInstantiateABean() throws Exception {
    final Bean<Object> bean = mock(Bean.class);
    final Context context = mock(Context.class);
    final CreationalContext<Object> creationalContext = mock(CreationalContext.class);
    final Object instance = mock(Object.class);
    when(beanManager.getContext(bean.getScope())).thenReturn(context);
    when(beanManager.createCreationalContext(bean)).thenReturn(creationalContext);
    when(context.get(bean, creationalContext)).thenReturn(instance);
    final Object result = beanInstantiater.instantiate(bean);
    assertThat(result, is(instance));
}
Also used : Context(javax.enterprise.context.spi.Context) CreationalContext(javax.enterprise.context.spi.CreationalContext) Test(org.junit.Test)

Example 4 with Context

use of javax.enterprise.context.spi.Context in project core by weld.

the class WeldStartup method createContexts.

protected Collection<ContextHolder<? extends Context>> createContexts(ServiceRegistry services) {
    List<ContextHolder<? extends Context>> contexts = new ArrayList<ContextHolder<? extends Context>>();
    BeanIdentifierIndex beanIdentifierIndex = services.get(BeanIdentifierIndex.class);
    /*
        * Register a full set of bound and unbound contexts. Although we may not use all of
        * these (e.g. if we are running in a servlet environment) they may be
        * useful for an application.
        */
    Set<Annotation> boundQualifires = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(BoundLiteral.INSTANCE).build();
    Set<Annotation> unboundQualifiers = ImmutableSet.<Annotation>builder().addAll(Bindings.DEFAULT_QUALIFIERS).add(UnboundLiteral.INSTANCE).build();
    contexts.add(new ContextHolder<ApplicationContext>(new ApplicationContextImpl(contextId), ApplicationContext.class, unboundQualifiers));
    contexts.add(new ContextHolder<SingletonContext>(new SingletonContextImpl(contextId), SingletonContext.class, unboundQualifiers));
    contexts.add(new ContextHolder<BoundSessionContext>(new BoundSessionContextImpl(contextId, beanIdentifierIndex), BoundSessionContext.class, boundQualifires));
    contexts.add(new ContextHolder<BoundConversationContext>(new BoundConversationContextImpl(contextId, services), BoundConversationContext.class, boundQualifires));
    contexts.add(new ContextHolder<BoundRequestContext>(new BoundRequestContextImpl(contextId), BoundRequestContext.class, boundQualifires));
    contexts.add(new ContextHolder<RequestContext>(new RequestContextImpl(contextId), RequestContext.class, unboundQualifiers));
    contexts.add(new ContextHolder<DependentContext>(new DependentContextImpl(services.get(ContextualStore.class)), DependentContext.class, unboundQualifiers));
    services.get(WeldModules.class).postContextRegistration(contextId, services, contexts);
    /*
        * Register the contexts with the bean manager and add the beans to the
        * deployment manager so that they are easily accessible (contexts are app
        * scoped)
        */
    for (ContextHolder<? extends Context> context : contexts) {
        deploymentManager.addContext(context.getContext());
        deploymentManager.addBean(ContextBean.of(context, deploymentManager));
    }
    return contexts;
}
Also used : ArrayList(java.util.ArrayList) BoundRequestContextImpl(org.jboss.weld.contexts.bound.BoundRequestContextImpl) RequestContextImpl(org.jboss.weld.contexts.unbound.RequestContextImpl) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) BoundRequestContextImpl(org.jboss.weld.contexts.bound.BoundRequestContextImpl) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) ApplicationContext(org.jboss.weld.context.ApplicationContext) SingletonContext(org.jboss.weld.context.SingletonContext) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) RequestContext(org.jboss.weld.context.RequestContext) DependentContext(org.jboss.weld.context.DependentContext) DependentContext(org.jboss.weld.context.DependentContext) BoundRequestContext(org.jboss.weld.context.bound.BoundRequestContext) SingletonContext(org.jboss.weld.context.SingletonContext) ApplicationContext(org.jboss.weld.context.ApplicationContext) Context(javax.enterprise.context.spi.Context) BoundSessionContext(org.jboss.weld.context.bound.BoundSessionContext) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) RequestContext(org.jboss.weld.context.RequestContext) SingletonContextImpl(org.jboss.weld.contexts.unbound.SingletonContextImpl) BoundSessionContext(org.jboss.weld.context.bound.BoundSessionContext) WeldModules(org.jboss.weld.module.WeldModules) Annotation(java.lang.annotation.Annotation) DependentContextImpl(org.jboss.weld.contexts.unbound.DependentContextImpl) ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) ApplicationContextImpl(org.jboss.weld.contexts.unbound.ApplicationContextImpl) BoundSessionContextImpl(org.jboss.weld.contexts.bound.BoundSessionContextImpl) BoundConversationContextImpl(org.jboss.weld.contexts.bound.BoundConversationContextImpl)

Example 5 with Context

use of javax.enterprise.context.spi.Context in project core by weld.

the class BeanManagerImpl method internalGetContext.

private Context internalGetContext(Class<? extends Annotation> scopeType) {
    Context activeContext = null;
    final List<Context> ctx = contexts.get(scopeType);
    if (ctx == null) {
        return null;
    }
    for (Context context : ctx) {
        if (context.isActive()) {
            if (activeContext == null) {
                activeContext = context;
            } else {
                throw BeanManagerLogger.LOG.duplicateActiveContexts(scopeType.getName());
            }
        }
    }
    return activeContext;
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) WeldCreationalContext(org.jboss.weld.contexts.WeldCreationalContext) Context(javax.enterprise.context.spi.Context)

Aggregations

Context (javax.enterprise.context.spi.Context)20 CreationalContext (javax.enterprise.context.spi.CreationalContext)8 WebBeansContext (org.apache.webbeans.config.WebBeansContext)4 Test (org.junit.Test)4 Annotation (java.lang.annotation.Annotation)3 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)3 WeldCreationalContext (org.jboss.weld.contexts.WeldCreationalContext)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Dependent (javax.enterprise.context.Dependent)2 RequestScoped (javax.enterprise.context.RequestScoped)2 AlterableContext (javax.enterprise.context.spi.AlterableContext)2 InvocationContext (javax.interceptor.InvocationContext)2 BeanContext (org.apache.openejb.BeanContext)2 ContextsService (org.apache.webbeans.spi.ContextsService)2 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)2 JoynrJeeMessageScoped (io.joynr.jeeintegration.api.JoynrJeeMessageScoped)1 JoynrJeeMessageContext (io.joynr.jeeintegration.context.JoynrJeeMessageContext)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1