当前位置: 首页>>代码示例>>Java>>正文


Java ContextControl.startContext方法代码示例

本文整理汇总了Java中org.apache.deltaspike.cdise.api.ContextControl.startContext方法的典型用法代码示例。如果您正苦于以下问题:Java ContextControl.startContext方法的具体用法?Java ContextControl.startContext怎么用?Java ContextControl.startContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.deltaspike.cdise.api.ContextControl的用法示例。


在下文中一共展示了ContextControl.startContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	final CdiContainer container = CdiContainerLoader.getCdiContainer();
	try {
		container.boot();

        ContextControl contextControl = container.getContextControl();
        contextControl.startContext(ApplicationScoped.class);

		Quickstart quickstart = CDI.current().select(Quickstart.class).get();
		quickstart.run();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		container.shutdown();
		System.out.println("Shutting down...");
		System.exit(0);
	}
}
 
开发者ID:kamaladafrica,项目名称:axon-cdi-quickstart,代码行数:19,代码来源:Main.java

示例2: startRequestScope

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@AroundInvoke
public Object startRequestScope(final InvocationContext ctx) throws Exception {
    Object result = null;
    ContextControl contextControl = null;
    if(!isRequestScopeActive()) {
        contextControl = CDI.current().select(ContextControl.class).get();
        contextControl.startContext(RequestScoped.class);
    }
    try {
        result = ctx.proceed();
    }
    finally {
        if(contextControl != null) {
            contextControl.stopContext(RequestScoped.class);
        }
    }
    return result;
}
 
开发者ID:johnament,项目名称:restful-and-beyond-tut2184,代码行数:19,代码来源:RequestScopeInterceptor.java

示例3: testRequestScopedBeanPerformance

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Test(priority = 3)
public void testRequestScopedBeanPerformance() throws InterruptedException
{
    final SimpleRequestScopedBeanWithoutInterceptor underTest = getInstance(cdiContainer.getBeanManager(), SimpleRequestScopedBeanWithoutInterceptor.class);
    final ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(RequestScoped.class);
    Assert.assertEquals(underTest.theMeaningOfLife(), 42);
    contextControl.stopContext(RequestScoped.class);

    executeInParallel("invocation on @RequestScoped bean", new Runnable()
    {

        @Override
        public void run()
        {
            contextControl.startContext(RequestScoped.class);
            for (int i = 0; i < NUM_ITERATION; i++)
            {
                // this line does the actual bean invocation.
                underTest.theMeaningOfLife();
            }
            contextControl.stopContext(RequestScoped.class);
        }
    });
}
 
开发者ID:struberg,项目名称:cdi-performance,代码行数:26,代码来源:CdiPerformanceTest.java

示例4: setUp

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Before
public final void setUp() throws Exception {
    System.out.printf("AbstractCdiContainerTest#setUp() containerRefCount=%d, cdiContainer=%s\n", containerRefCount.get(), cdiContainer );

    if ( cdiContainer != null ) {
        containerRefCount.incrementAndGet();

        final ContextControl ctxCtrl = BeanProvider.getContextualReference(ContextControl.class);

        //stop the RequestContext to dispose of the @RequestScoped EntityManager
        ctxCtrl.stopContext(RequestScoped.class);

        //immediately restart the context again
        ctxCtrl.startContext(RequestScoped.class);

        // perform injection into the very own test class
        final BeanManager beanManager = cdiContainer.getBeanManager();
        final CreationalContext creationalContext = beanManager.createCreationalContext(null);

        final AnnotatedType annotatedType = beanManager.createAnnotatedType(this.getClass());
        final InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
        injectionTarget.inject(this, creationalContext);
    }
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:25,代码来源:AbstractCdiContainerTest.java

示例5: tearDown

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@After
    public final void tearDown() throws Exception {
        System.out.printf("AbstractCdiContainerTest#tearDown() containerRefCount=%d, cdiContainer=%s\n", containerRefCount.get(), cdiContainer );
        if (cdiContainer != null) {
            final ContextControl ctxCtrl = BeanProvider.getContextualReference(ContextControl.class);

            //stop the RequestContext to dispose of the @RequestScoped EntityManager
            ctxCtrl.stopContext(RequestScoped.class);

            //immediately restart the context again
            ctxCtrl.startContext(RequestScoped.class);

//            cdiContainer.getContextControl().stopContext(RequestScoped.class);
//            cdiContainer.getContextControl().startContext(RequestScoped.class);
            containerRefCount.decrementAndGet();
        }
    }
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:18,代码来源:AbstractCdiContainerTest.java

示例6: main

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException
{
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();

    ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(ApplicationScoped.class);

    GlobalResultHolder globalResultHolder =
        BeanProvider.getContextualReference(GlobalResultHolder.class);

    while (globalResultHolder.getCount() < 100)
    {
        Thread.sleep(500);
        LOG.info("current count: " + globalResultHolder.getCount());
    }
    LOG.info("completed!");

    contextControl.stopContext(ApplicationScoped.class);
    cdiContainer.shutdown();
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:22,代码来源:SimpleSchedulerExample.java

示例7: main

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
public static void main(String[] args)
{
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();

    ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(ApplicationScoped.class);

    SettingsBean settingsBean = BeanProvider.getContextualReference(SettingsBean.class, false);

    LOG.info("configured int-value #1: " + settingsBean.getIntProperty1());
    LOG.info("configured long-value #2: " + settingsBean.getProperty2());
    LOG.info("configured inverse-value #2: " + settingsBean.getInverseProperty());
    LOG.info("configured location (custom config): " + settingsBean.getLocationId().name());
    
    cdiContainer.shutdown();
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:18,代码来源:ConfigExample.java

示例8: requestInitialized

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Override
public void requestInitialized(ServletRequestEvent servletRequestEvent)
{
    LOG.log(Level.FINER,"Incoming request.");
    ContextControl contextControl = getContextControl();
    servletRequestEvent.getServletRequest().setAttribute(CDI_REQ_CONTEXT, contextControl);
    contextControl.startContext(RequestScoped.class);
}
 
开发者ID:johnament,项目名称:restful-and-beyond-tut2184,代码行数:9,代码来源:RequestScopedServletRequestListener.java

示例9: testCreateEmployee

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Test
public void testCreateEmployee() {
    ContextControl contextControl = CDI.current().select(ContextControl.class).get();
    contextControl.startContext(RequestScoped.class);
    Employees e = new Employees();
    e.setFirstName("Bob");
    e.setLastName("Hope");
    EntityManager em = CDI.current().select(EntityManager.class).get();
    Employees e2 = em.merge(e);
    System.out.println("Employee id :"+e2.getId());
    contextControl.stopContext(RequestScoped.class);
}
 
开发者ID:johnament,项目名称:restful-and-beyond-tut2184,代码行数:13,代码来源:JPALongTest.java

示例10: postStart

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Override
public void postStart() {
    final ContextControl contextControl = this.container.getContextControl();
    contextControl.startContext(ApplicationScoped.class);
    contextControl.startContext(SessionScoped.class);
    contextControl.startContext(RequestScoped.class);
}
 
开发者ID:qjafcunuas,项目名称:jbromo,代码行数:8,代码来源:DeltaSpikeCdiContainer.java

示例11: startContainer

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
protected void startContainer()
{
    CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
    cdiContainer.boot();
    ContextControl contextControl = cdiContainer.getContextControl();
    contextControl.startContext(ApplicationScoped.class);
    contextControl.startContext(SessionScoped.class);
    contextControl.startContext(RequestScoped.class);
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgent,代码行数:10,代码来源:HAAbstractUnitTest.java

示例12: startScopes

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
private void startScopes(CdiContainer container,
                         Class testClass,
                         Method testMethod,
                         Class<? extends Annotation>... restrictedScopes) {

    ContextControl contextControl = container.getContextControl();

    List<Class<? extends Annotation>> scopeClasses = new ArrayList<Class<? extends Annotation>>();

    Collections.addAll(scopeClasses, this.testControl.startScopes());

    if (scopeClasses.isEmpty()) {
        addScopesForDefaultBehavior(scopeClasses);
    } else {
        List<TestControlValidator> testControlValidatorList =
                ServiceUtils.loadServiceImplementations(TestControlValidator.class);

        for (TestControlValidator testControlValidator : testControlValidatorList) {
            if (testControlValidator instanceof TestAware) {
                if (testMethod != null) {
                    ((TestAware) testControlValidator).setTestMethod(testMethod);
                }
                ((TestAware) testControlValidator).setTestClass(testClass);
            }
            try {
                testControlValidator.validate(this.testControl);
            } finally {
                if (testControlValidator instanceof TestAware) {
                    ((TestAware) testControlValidator).setTestClass(null);
                    ((TestAware) testControlValidator).setTestMethod(null);
                }
            }
        }
    }

    for (Class<? extends Annotation> scopeAnnotation : scopeClasses) {
        if (this.parent != null && this.parent.isScopeStarted(scopeAnnotation)) {
            continue;
        }

        if (isRestrictedScope(scopeAnnotation, restrictedScopes)) {
            continue;
        }

        try {
            //force a clean context - TODO discuss onScopeStopped call
            contextControl.stopContext(scopeAnnotation);

            contextControl.startContext(scopeAnnotation);
            this.startedScopes.add(scopeAnnotation);

            onScopeStarted(scopeAnnotation);
        } catch (RuntimeException e) {
            Logger logger = Logger.getLogger(CdiCucumberTestRunner.class.getName());
            logger.setLevel(Level.SEVERE);
            logger.log(Level.SEVERE, "failed to start scope @" + scopeAnnotation.getName(), e);
        }
    }

}
 
开发者ID:database-rider,项目名称:database-rider,代码行数:61,代码来源:CdiCucumberTestRunner.java

示例13: requestInitialized

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Override
public void requestInitialized(ServletRequestEvent servletRequestEvent) {
    CdiContainer container = CdiContainerLoader.getCdiContainer();
    ContextControl contextControl = container.getContextControl();
    contextControl.startContext(RequestScoped.class);
}
 
开发者ID:johnament,项目名称:microservices-tutorial,代码行数:7,代码来源:CDIListener.java

示例14: testParallelThreadExecution

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Test
public void testParallelThreadExecution() throws Exception
{
    final CdiContainer cc = CdiContainerLoader.getCdiContainer();
    Assert.assertNotNull(cc);

    cc.boot();
    cc.getContextControl().startContexts();

    final BeanManager bm = cc.getBeanManager();
    Assert.assertNotNull(bm);

    final AtomicInteger numErrors = new AtomicInteger(0);
    final ContextControl contextControl = cc.getContextControl();

    Runnable runnable = new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                contextControl.startContext(SessionScoped.class);
                contextControl.startContext(RequestScoped.class);


                Set<Bean<?>> beans = bm.getBeans(CarRepair.class);
                Bean<?> bean = bm.resolve(beans);

                CarRepair carRepair = (CarRepair)
                        bm.getReference(bean, CarRepair.class, bm.createCreationalContext(bean));
                Assert.assertNotNull(carRepair);

                for (int i = 0; i < 100000; i++)
                {
                    // we need the threads doing something ;)
                    Assert.assertNotNull(carRepair.getCar());
                    Assert.assertNotNull(carRepair.getCar().getUser());
                    Assert.assertNull(carRepair.getCar().getUser().getName());
                }
                contextControl.stopContext(RequestScoped.class);
                contextControl.stopContext(SessionScoped.class);
            }
            catch (Throwable e)
            {
                log.log(Level.SEVERE, "An exception happened on a new worker thread", e);
                numErrors.incrementAndGet();
            }
        }
    };


    Thread[] threads = new Thread[NUM_THREADS];
    for (int i = 0 ; i < NUM_THREADS; i++)
    {
        threads[i] = new Thread(runnable);
    }

    for (int i = 0 ; i < NUM_THREADS; i++)
    {
        threads[i].start();
    }

    for (int i = 0 ; i < NUM_THREADS; i++)
    {
        threads[i].join();
    }

    Assert.assertEquals("An error happened while executing parallel threads", 0, numErrors.get());


    cc.shutdown();
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:74,代码来源:ContainerCtrlTckTest.java

示例15: helloRequestScoped

import org.apache.deltaspike.cdise.api.ContextControl; //导入方法依赖的package包/类
@Test
@InSequence(0)
@Ignore
public void helloRequestScoped() {
    Assert.assertNotNull(myRequestBean);
    ContextControl ctxCtrl = BeanProvider.getContextualReference(ContextControl.class);


    ctxCtrl.startContext(RequestScoped.class);


    int myBeanHashcode = myRequestBean.getMyBean().hashCode();
    int myKieSessionHashcode = myRequestBean.getkSession().hashCode();

    int result = myRequestBean.doSomething("hello 0");
    Assert.assertEquals(1, result);

    ctxCtrl.stopContext(RequestScoped.class);
    ctxCtrl.startContext(RequestScoped.class);
    

    Assert.assertNotEquals(myBeanHashcode, myRequestBean.getMyBean().hashCode());
    Assert.assertNotEquals(myKieSessionHashcode, myRequestBean.getkSession().hashCode());


    myBeanHashcode = myRequestBean.getMyBean().hashCode();
    myKieSessionHashcode = myRequestBean.getkSession().hashCode();

    result = myRequestBean.doSomething("hello 1");
    Assert.assertEquals(1, result);
    ctxCtrl.stopContext(RequestScoped.class);
    ctxCtrl.startContext(RequestScoped.class);

    
    Assert.assertNotEquals(myBeanHashcode, myRequestBean.getMyBean().hashCode());
    Assert.assertNotEquals(myKieSessionHashcode, myRequestBean.getkSession().hashCode());

    myBeanHashcode = myRequestBean.getMyBean().hashCode();
    myKieSessionHashcode = myRequestBean.getkSession().hashCode();

    result = myRequestBean.doSomething("hello 2");
    Assert.assertEquals(1, result);
   
    myBeanHashcode = myRequestBean.getMyBean().hashCode();
    myKieSessionHashcode = myRequestBean.getkSession().hashCode();
    
    ctxCtrl.stopContext(RequestScoped.class);
    ctxCtrl.startContext(RequestScoped.class);

    Assert.assertNotEquals(myBeanHashcode, myRequestBean.getMyBean().hashCode());
    Assert.assertNotEquals(myKieSessionHashcode, myRequestBean.getkSession().hashCode());

}
 
开发者ID:Salaboy,项目名称:drools-workshop,代码行数:54,代码来源:SingletonRulesJUnitTest.java


注:本文中的org.apache.deltaspike.cdise.api.ContextControl.startContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。