本文整理汇总了Java中org.apache.webbeans.spi.ContextsService类的典型用法代码示例。如果您正苦于以下问题:Java ContextsService类的具体用法?Java ContextsService怎么用?Java ContextsService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextsService类属于org.apache.webbeans.spi包,在下文中一共展示了ContextsService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeStopApplication
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
public void beforeStopApplication(Object endObject)
{
WebBeansContext webBeansContext = getWebBeansContext();
ContextsService contextsService = webBeansContext.getContextsService();
contextsService.endContext(Singleton.class, null);
contextsService.endContext(ApplicationScoped.class, null);
contextsService.endContext(RequestScoped.class, null);
contextsService.endContext(SessionScoped.class, mockHttpSession);
ELContextStore elStore = ELContextStore.getInstance(false);
if (elStore == null)
{
return;
}
elStore.destroyELContextStore();
}
示例2: contextEntered
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
final BeanContext beanContext = newContext.getBeanContext();
final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext();
if (webBeansContext == null) {
return;
}
final ContextsService contextsService = webBeansContext.getContextsService();
final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false);
if (requestContext == null) {
contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT);
newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext));
}
}
示例3: ensureRequestContextCanBeRestarted
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
@Test
public void ensureRequestContextCanBeRestarted() throws Exception {
final ApplicationComposers composers = new ApplicationComposers(EnsureRequestScopeThreadLocalIsCleanUpTest.class);
composers.before(this);
final CdiAppContextsService contextsService = CdiAppContextsService.class.cast(WebBeansContext.currentInstance().getService(ContextsService.class));
final Context req1 = contextsService.getCurrentContext(RequestScoped.class);
assertNotNull(req1);
final Context session1 = contextsService.getCurrentContext(SessionScoped.class);
assertNotNull(session1);
contextsService.endContext(RequestScoped.class, null);
contextsService.startContext(RequestScoped.class, null);
final Context req2 = contextsService.getCurrentContext(RequestScoped.class);
assertNotSame(req1, req2);
final Context session2 = contextsService.getCurrentContext(SessionScoped.class);
assertSame(session1, session2);
composers.after();
assertNull(contextsService.getCurrentContext(RequestScoped.class));
assertNull(contextsService.getCurrentContext(SessionScoped.class));
}
示例4: startConversation
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
@Before
public void startConversation() {
final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
webBeansContext.registerService(ConversationService.class, new ConversationService() {
@Override
public String getConversationId() {
return "conversation-test";
}
@Override
public String generateConversationId() {
return "cid_1";
}
});
webBeansContext.getService(ContextsService.class).startContext(ConversationScoped.class, null);
}
示例5: startSessionScope
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
private void startSessionScope()
{
ContextsService contextsService = getContextsService();
Object mockSession = null;
if (isServletApiAvailable())
{
mockSession = mockSessions.get();
if (mockSession == null)
{
// we simply use the ThreadName as 'sessionId'
mockSession = OwbHelper.getMockSession(Thread.currentThread().getName());
mockSessions.set(mockSession);
}
}
contextsService.startContext(SessionScoped.class, mockSession);
}
示例6: doReinjectSessionBasedBean
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
private static void doReinjectSessionBasedBean(BeanManagerImpl beanManager, Class<?> beanClass, InjectionTargetBean<?> bean) {
ContextsService contextsService = beanManager.getWebBeansContext().getContextsService();
// SessionContextsTracker can't be directly used here, since it may not be in the visible class loader (Tomee)
// therefore inner Iterator is used as workaround
Object sessionContextsTracker =
ReflectionHelper.get(contextsService, WebBeansContextsServiceTransformer.SESSION_CONTEXTS_TRACKER_FIELD);
if (sessionContextsTracker != null) {
try {
Iterator<?> sessionContextIterator = ((Iterable<?> ) sessionContextsTracker).iterator();
while (sessionContextIterator.hasNext()) {
sessionContextIterator.next(); // Set next active session context
Context sessionContext = beanManager.getContext(SessionScoped.class);
if (bean.getScope() == SessionScoped.class) {
doReinjectBeanInstance(beanManager, beanClass, bean, sessionContext);
} else {
doReinjectCustomScopedBean(beanManager, beanClass, bean, sessionContext);
}
SessionScopedBeanInterceptorHandler.removeThreadLocals();
}
} finally {
contextsService.removeThreadLocals();
}
} else {
LOGGER.error("Field '{}' not found in class '{}'", WebBeansContextsServiceTransformer.SESSION_CONTEXTS_TRACKER_FIELD,
contextsService.getClass().getName());
}
}
示例7: HAOpenWebBeansTestLifeCycle
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
public HAOpenWebBeansTestLifeCycle()
{
super(new Properties()
{{
setProperty(ContextsService.class.getName(), WebContextsService.class.getName());
}});
this.logger = WebBeansLoggerFacade.getLogger(HAOpenWebBeansTestLifeCycle.class);
}
示例8: beforeStartApplication
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
public void beforeStartApplication(Object object)
{
WebBeansContext webBeansContext = getWebBeansContext();
ContextsService contextsService = webBeansContext.getContextsService();
contextsService.startContext(Singleton.class, null);
contextsService.startContext(ApplicationScoped.class, null);
}
示例9: ensureRequestScope
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
public static void ensureRequestScope(final ContextsService cs, final ServletRequestListener listener) {
final Context reqCtx = cs.getCurrentContext(RequestScoped.class);
if (reqCtx == null || !cs.getCurrentContext(RequestScoped.class).isActive()) {
listener.requestInitialized(null);
FAKE_REQUEST.set(true);
}
}
示例10: EndWebBeansListener
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
/**
* Default constructor
*
* @param webBeansContext the OWB context
*/
public EndWebBeansListener(WebBeansContext webBeansContext) {
this.webBeansContext = webBeansContext;
if (webBeansContext != null) {
this.contextsService = CdiAppContextsService.class.cast(webBeansContext.getService(ContextsService.class));
this.cleanUpSession = Boolean.parseBoolean(webBeansContext.getOpenWebBeansConfiguration()
.getProperty("tomee.session.remove-cdi-beans-on-passivate", "false"));
} else {
this.contextsService = null;
this.cleanUpSession = false; // ignored anyway
}
}
示例11: stopContexts
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
public static void stopContexts(final ContextsService contextsService, final ServletContext servletContext, final HttpSession session) throws Exception {
contextsService.endContext(SessionScoped.class, session);
contextsService.endContext(RequestScoped.class, null);
contextsService.endContext(ConversationScoped.class, null);
if (CdiAppContextsService.class.isInstance(contextsService)) {
CdiAppContextsService.class.cast(contextsService).removeThreadLocals();
}
}
示例12: runAndCheckThreadLocal
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
@Test
public void runAndCheckThreadLocal() throws Exception {
final ApplicationComposers composers = new ApplicationComposers(EnsureRequestScopeThreadLocalIsCleanUpTest.class);
composers.before(this);
final CdiAppContextsService contextsService = CdiAppContextsService.class.cast(WebBeansContext.currentInstance().getService(ContextsService.class));
assertNotNull(contextsService.getCurrentContext(RequestScoped.class));
assertNotNull(contextsService.getCurrentContext(SessionScoped.class));
composers.after();
assertNull(contextsService.getCurrentContext(RequestScoped.class));
assertNull(contextsService.getCurrentContext(SessionScoped.class));
}
示例13: startContexts
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
@Override
public void startContexts()
{
ContextsService contextsService = getContextsService();
startSingletonScope();
startApplicationScope();
startSessionScope();
startRequestScope();
startConversationScope();
}
示例14: startSingletonScope
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
private void startSingletonScope()
{
ContextsService contextsService = getContextsService();
Object mockServletContext = null;
if (isServletApiAvailable())
{
mockServletContext = OwbHelper.getMockServletContext();
}
contextsService.startContext(Singleton.class, mockServletContext);
}
示例15: startApplicationScope
import org.apache.webbeans.spi.ContextsService; //导入依赖的package包/类
private void startApplicationScope()
{
ContextsService contextsService = getContextsService();
Object mockServletContext = null;
if (isServletApiAvailable())
{
mockServletContext = OwbHelper.getMockServletContext();
}
contextsService.startContext(ApplicationScoped.class, mockServletContext);
}