/** * {@inheritDoc} */ @Override public long getTimeout() { checkThreadUsage(); return timeout; }
/** * {@inheritDoc} */ @Override public void begin() { begin(null); }
/** * Constructor */ public ConversationContext(WebBeansContext webBeansContext) { super(ConversationScoped.class); this.conversation = new ConversationImpl(webBeansContext); }
private void startConversationContext() { ConversationManager conversationManager = webBeansContext.getConversationManager(); ConversationContext ctx = conversationManager.getConversationContext(getCurrentSessionContext()); ctx.setActive(true); conversationContext.set(ctx); if (ctx.getConversation().isTransient()) { webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent( conversationManager.getLifecycleEventPayload(ctx), InitializedLiteral.INSTANCE_CONVERSATION_SCOPED); } }
private void cleanupConversation() { if (webBeansContext.getService(ConversationService.class) == null) { return; } final ConversationContext conversationContext = getConversationContext(); if (conversationContext == null) { return; } final ConversationManager conversationManager = webBeansContext.getConversationManager(); final Conversation conversation = conversationManager.getConversationBeanReference(); if (conversation == null) { return; } if (conversation.isTransient()) { webBeansContext.getContextsService().endContext(ConversationScoped.class, null); } else { final ConversationImpl conversationImpl = (ConversationImpl) conversation; conversationImpl.updateTimeOut(); conversationImpl.setInUsed(false); } }
public boolean isPassivatingScope() { final CdiEjbBean<?> bean = get(CdiEjbBean.class); if (bean == null) { return true; } if (ConversationScoped.class == bean.getScope()) { try { return !bean.getWebBeansContext().getConversationManager().getConversationBeanReference().isTransient(); } catch (final RuntimeException re) { // conversation not found for instance so act as @RequestScoped return false; } } return true; }
/** * {@inheritDoc} * * This will also remove the current ConversationContext from the SessionContext */ @Override public void end() { checkThreadUsage(); if (!isTransient) { iDontUseItAnymore(); id = null; isTransient = true; } else { logger.log(Level.WARNING, OWBLogConst.WARN_0004, id); throw new IllegalStateException(toString() + " has already ended"); } // now store this conversation in the SessionContext ConversationManager conversationManager = webBeansContext.getConversationManager(); ConversationContext conversationContext = (ConversationContext) webBeansContext.getContextsService().getCurrentContext(ConversationScoped.class); conversationManager.removeConversationFromStorage(conversationContext); }
public boolean conversationTimedOut(ConversationImpl conv) { long timeout = 0L; try { timeout = conv.getTimeout(); } catch (BusyConversationException bce) { // if the Conversation is concurrently used by another thread then it is surely not timed out return false; } if (timeout != 0L && (System.currentTimeMillis() - conv.getLastAccessTime()) > timeout) { logger.log(Level.FINE, OWBLogConst.INFO_0011, conv.getId()); return true; } return false; }
/** * Add the given ConversationContext to the SessionContext. * This method usually will get called at {@link Conversation#begin()}. */ public void addToConversationStorage(ConversationContext conversationContext, String conversationId) { Asserts.assertNotNull(conversationId, "conversationId"); Context sessionContext = webBeansContext.getContextsService().getCurrentContext(SessionScoped.class); Set<ConversationContext> sessionConversations = getSessionConversations(sessionContext, true); // check whether this conversation already exists for (ConversationContext sessionConversation : sessionConversations) { if (conversationId.equals(sessionConversation.getConversation().getId())) { throw new IllegalArgumentException("Conversation with id=" + conversationId + " already exists!"); } } // if not, then simply add this conversation sessionConversations.add(conversationContext); }
/** * Destroy the given ConversationContext and fire the proper * @Destroyed event with the correct payload. */ public void destroyConversationContext(ConversationContext ctx) { webBeansContext.getBeanManagerImpl().fireEvent( getLifecycleEventPayload(ctx), BeforeDestroyedLiteral.INSTANCE_CONVERSATION_SCOPED); ctx.destroy(); webBeansContext.getBeanManagerImpl().fireEvent( getLifecycleEventPayload(ctx), DestroyedLiteral.INSTANCE_CONVERSATION_SCOPED); }
/** * {@inheritDoc} */ public void sessionDestroyed(HttpSessionEvent event) { if (logger.wblWillLogDebug()) { logger.debug("Destroying a session with session id : [{0}]", event.getSession().getId()); } this.webBeansContext.getContextsService().endContext(SessionScoped.class, event.getSession()); ConversationManager conversationManager = webBeansContext.getConversationManager(); conversationManager.destroyConversationContextWithSessionId(event.getSession().getId()); }
@Override public int hashCode() { return getId().hashCode(); }
public void run() { webBeansContext.getConversationManager().destroyWithRespectToTimout(); } }
@Override public void destroy(Set<ConversationContext> instance, CreationalContext<Set<ConversationContext>> context) { if (instance == null || instance.isEmpty()) { return; } ConversationManager conversationManager = webBeansContext.getConversationManager(); for (ConversationContext conversationContext : instance) { conversationManager.destroyConversationContext(conversationContext); } }
/** * Remove the given ConversationContext from the SessionContext storage. * This method usually will get called at {@link Conversation#end()} or during cleanup. * Not that this does <b>not</b> destroy the ConversationContext! * @return {@code true} if the conversationContext got removed */ public boolean removeConversationFromStorage(ConversationContext conversationContext) { Context sessionContext = webBeansContext.getContextsService().getCurrentContext(SessionScoped.class); Set<ConversationContext> sessionConversations = getSessionConversations(sessionContext, true); return sessionConversations.remove(conversationContext); }
/** * Creates new conversation manager */ public ConversationManager(WebBeansContext webBeansContext) { this.webBeansContext = webBeansContext; // We cannot use this directly since it will change after passivation ConversationStorageBean convBean = new ConversationStorageBean(webBeansContext); BeanManagerImpl bm = webBeansContext.getBeanManagerImpl(); bm.addInternalBean(convBean); // this will return the internally wrapped ThirdPartyBean. conversationStorageBean = (Bean<Set<ConversationContext>>) bm.resolve(bm.getBeans(ConversationStorageBean.OWB_INTERNAL_CONVERSATION_STORAGE_BEAN_PASSIVATION_ID)); }
public boolean isPassivatingScope() { final CdiEjbBean<?> bean = get(CdiEjbBean.class); if (bean == null) { return true; } if (ConversationScoped.class == bean.getScope()) { try { return !bean.getWebBeansContext().getConversationManager().getConversationBeanReference().isTransient(); } catch (final RuntimeException re) { // conversation not found for instance so act as @RequestScoped return false; } } return true; }
/** * {@inheritDoc} */ @Override public boolean isTransient() { checkThreadUsage(); return isTransient; }
/** * {@inheritDoc} */ @Override public void setTimeout(long milliseconds) { checkThreadUsage(); timeout = milliseconds; }