本文整理汇总了Java中org.apache.deltaspike.cdise.api.CdiContainer.getContextControl方法的典型用法代码示例。如果您正苦于以下问题:Java CdiContainer.getContextControl方法的具体用法?Java CdiContainer.getContextControl怎么用?Java CdiContainer.getContextControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.deltaspike.cdise.api.CdiContainer
的用法示例。
在下文中一共展示了CdiContainer.getContextControl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的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: main
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的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();
}
示例3: main
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的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();
}
示例4: ContextControlWrapper
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的package包/类
private ContextControlWrapper() {
final CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
if (!isCdiContainerBooted(cdiContainer)) {
LOG.info("booting cdi container");
long start = System.currentTimeMillis();
cdiContainer.boot();
long end = System.currentTimeMillis();
LOG.info("booting cdi container finished in " + (end - start) + " ms");
}
contextControl = cdiContainer.getContextControl();
}
示例5: startContainer
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的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);
}
示例6: startScopes
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的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);
}
}
}
示例7: requestDestroyed
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的package包/类
@Override
public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
CdiContainer container = CdiContainerLoader.getCdiContainer();
ContextControl contextControl = container.getContextControl();
contextControl.stopContext(RequestScoped.class);
}
示例8: requestInitialized
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的package包/类
@Override
public void requestInitialized(ServletRequestEvent servletRequestEvent) {
CdiContainer container = CdiContainerLoader.getCdiContainer();
ContextControl contextControl = container.getContextControl();
contextControl.startContext(RequestScoped.class);
}
示例9: getContextControl
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的package包/类
private ContextControl getContextControl()
{
CdiContainer container = CdiContainerLoader.getCdiContainer();
return container.getContextControl();
}
示例10: testParallelThreadExecution
import org.apache.deltaspike.cdise.api.CdiContainer; //导入方法依赖的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();
}