本文整理汇总了Java中org.apache.deltaspike.cdise.api.ContextControl类的典型用法代码示例。如果您正苦于以下问题:Java ContextControl类的具体用法?Java ContextControl怎么用?Java ContextControl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextControl类属于org.apache.deltaspike.cdise.api包,在下文中一共展示了ContextControl类的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);
}
}
示例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;
}
示例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);
}
});
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例11: preStop
import org.apache.deltaspike.cdise.api.ContextControl; //导入依赖的package包/类
@Override
public void preStop() {
final ContextControl contextControl = this.container.getContextControl();
contextControl.stopContext(RequestScoped.class);
contextControl.stopContext(SessionScoped.class);
contextControl.stopContext(ApplicationScoped.class);
}
示例12: 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);
}
示例13: startContexts
import org.apache.deltaspike.cdise.api.ContextControl; //导入依赖的package包/类
public void startContexts(Scheduled scheduled)
{
Collections.addAll(this.scopes, scheduled.startScopes());
if (!this.scopes.isEmpty())
{
this.contextControl = BeanProvider.getDependent(ContextControl.class);
for (Class<? extends Annotation> scopeAnnotation : this.scopes)
{
contextControl.get().startContext(scopeAnnotation);
}
}
}
示例14: getContextControlForDeployment
import org.apache.deltaspike.cdise.api.ContextControl; //导入依赖的package包/类
public static JavaArchive getContextControlForDeployment()
{
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "cdi-control.jar")
.addClass(ContextControl.class);
if (CdiContainerUnderTest.is("owb"))
{
jar.addPackage("org.apache.deltaspike.cdise.owb");
}
return jar;
}
示例15: requestDestroyed
import org.apache.deltaspike.cdise.api.ContextControl; //导入依赖的package包/类
@Override
public void requestDestroyed(ServletRequestEvent servletRequestEvent)
{
LOG.log(Level.FINER,"Request done.");
ContextControl contextControl = (ContextControl)servletRequestEvent.getServletRequest()
.getAttribute(CDI_REQ_CONTEXT);
contextControl.stopContext(RequestScoped.class);
}