Class AbstractConversationContext<R,S>

All Implemented Interfaces:
jakarta.enterprise.context.spi.AlterableContext, jakarta.enterprise.context.spi.Context, BoundContext<R>, ConversationContext, ManagedContext, WeldAlterableContext
Direct Known Subclasses:
BoundConversationContextImpl

public abstract class AbstractConversationContext<R,S> extends AbstractBoundContext<R> implements ConversationContext
The base of the conversation context, which can use a variety of storage forms
Author:
Pete Muir, Jozef Hartinger, George Sapountzis, Marko Luksa
  • Field Details

    • CONVERSATIONS_ATTRIBUTE_NAME

      public static final String CONVERSATIONS_ATTRIBUTE_NAME
    • DESTRUCTION_QUEUE_ATTRIBUTE_NAME

      public static final String DESTRUCTION_QUEUE_ATTRIBUTE_NAME
  • Constructor Details

    • AbstractConversationContext

      public AbstractConversationContext(String contextId, org.jboss.weld.bootstrap.api.ServiceRegistry services)
  • Method Details

    • getParameterName

      public String getParameterName()
      Description copied from interface: ConversationContext
      Get the name of the parameter used to propagate the conversation id
      Specified by:
      getParameterName in interface ConversationContext
      Returns:
      the name of the conversation id parameter
    • setParameterName

      public void setParameterName(String cid)
      Description copied from interface: ConversationContext
      Set the name of the parameter used to propagate the conversation id
      Specified by:
      setParameterName in interface ConversationContext
      Parameters:
      cid - the name of the conversation id parameter
    • setConcurrentAccessTimeout

      public void setConcurrentAccessTimeout(long timeout)
      Description copied from interface: ConversationContext
      Set the concurrent access timeout
      Specified by:
      setConcurrentAccessTimeout in interface ConversationContext
      Parameters:
      timeout - the timeout (in ms) for the concurrent access lock
    • getConcurrentAccessTimeout

      public long getConcurrentAccessTimeout()
      Description copied from interface: ConversationContext
      Get the current concurrent access timeout
      Specified by:
      getConcurrentAccessTimeout in interface ConversationContext
      Returns:
      the timeout (in ms) for the concurrent access lock
    • setDefaultTimeout

      public void setDefaultTimeout(long timeout)
      Description copied from interface: ConversationContext
      Set the default inactivity timeout. This may be overridden on a per conversation basis using Conversation.setTimeout(long)
      Specified by:
      setDefaultTimeout in interface ConversationContext
      Parameters:
      timeout - the default inactivity timeout (in ms)
    • getDefaultTimeout

      public long getDefaultTimeout()
      Description copied from interface: ConversationContext
      Get the default inactivity timeout. This may have been overridden on a per conversation basis.
      Specified by:
      getDefaultTimeout in interface ConversationContext
      Returns:
      the default inactivity timeout (in ms)
    • associate

      public boolean associate(R request)
      Description copied from interface: BoundContext
      Associate the context with the storage (for this thread). Once BoundContext.associate(Object) has been called, further calls to BoundContext.associate(Object) will be ignored, until the context has been subsequently BoundContext.dissociate(Object) from the storage.
      Specified by:
      associate in interface BoundContext<R>
      Parameters:
      request - the external storage
      Returns:
      true if the storage was attached, otherwise false
    • dissociate

      public boolean dissociate(R request)
      Description copied from interface: BoundContext
      Dissociate the context from the storage (for this thread). The context will only dissociate from the same storage it associated with.
      Specified by:
      dissociate in interface BoundContext<R>
      Overrides:
      dissociate in class AbstractBoundContext<R>
      Parameters:
      request - the external storage
      Returns:
      true if the storage was dissociated
    • copyConversationIdGeneratorAndConversationsToSession

      protected void copyConversationIdGeneratorAndConversationsToSession()
    • sessionCreated

      public void sessionCreated()
    • associateRequestWithNewConversation

      protected void associateRequestWithNewConversation()
    • associateRequest

      protected void associateRequest(ManagedConversation conversation)
    • activate

      public void activate()
      Description copied from interface: ManagedContext
      Activate the Context.
      Specified by:
      activate in interface ConversationContext
      Specified by:
      activate in interface ManagedContext
      Overrides:
      activate in class AbstractBoundContext<R>
    • activate

      public void activate(String cid)
      Description copied from interface: ConversationContext
      Activate the conversation context, using the id provided to attempt to restore a long-running conversation
      Specified by:
      activate in interface ConversationContext
      Parameters:
      cid - if the cid is null, a transient conversation will be created, otherwise the conversation will be restored
    • initialize

      protected void initialize(String cid)
    • deactivate

      public void deactivate()
      Description copied from interface: ManagedContext
      Deactivate the Context, destroying any instances if the context is invalid.
      Specified by:
      deactivate in interface ManagedContext
      Overrides:
      deactivate in class AbstractBoundContext<R>
    • conversationPromotedToLongRunning

      public void conversationPromotedToLongRunning(ConversationImpl conversation)
    • invalidate

      public void invalidate()
      Description copied from interface: ManagedContext
      Mark the context as due for destruction when deactivate is called.
      Specified by:
      invalidate in interface ConversationContext
      Specified by:
      invalidate in interface ManagedContext
      Overrides:
      invalidate in class AbstractManagedContext
    • destroy

      public boolean destroy(S session)
    • destroyConversation

      protected void destroyConversation(S session, String id, boolean fireEvents)
    • generateConversationId

      public String generateConversationId()
      Description copied from interface: ConversationContext
      Generate a new, unique, conversation id
      Specified by:
      generateConversationId in interface ConversationContext
      Returns:
      a new, unique conversation id
    • getConversationIdGenerator

      protected ConversationIdGenerator getConversationIdGenerator()
    • getConversation

      public ManagedConversation getConversation(String id)
      Description copied from interface: ConversationContext
      Get the conversation with the given id.
      Specified by:
      getConversation in interface ConversationContext
      Parameters:
      id - the id of the conversation to get
      Returns:
      the conversation, or null if no conversation is known
    • getConversations

      public Collection<ManagedConversation> getConversations()
      Description copied from interface: ConversationContext
      Get conversations currently known to the context. This will include any non transient conversations, as well as any conversations which were previously long running and have been made transient during this request.
      Specified by:
      getConversations in interface ConversationContext
      Returns:
      a collection containing the conversations
    • getCurrentConversation

      public ManagedConversation getCurrentConversation()
      Description copied from interface: ConversationContext
      Get a handle the current conversation (transient or otherwise).
      Specified by:
      getCurrentConversation in interface ConversationContext
      Returns:
      the current conversation
    • getScope

      public Class<? extends Annotation> getScope()
      Specified by:
      getScope in interface jakarta.enterprise.context.spi.Context
    • setSessionAttribute

      protected abstract void setSessionAttribute(R request, String name, Object value, boolean create)
      Set an attribute in the session.
      Parameters:
      request - the request to set the session attribute in
      name - the name of the attribute
      value - the value of the attribute
      create - if false, the attribute will only be set if the session already exists, otherwise it will always be set
      Throws:
      IllegalStateException - if create is true, and the session can't be created
    • getSessionAttribute

      protected abstract Object getSessionAttribute(R request, String name, boolean create)
      Get an attribute value from the session.
      Parameters:
      request - the request to get the session attribute from
      name - the name of the attribute
      create - if false, the attribute will only be retrieved if the session already exists, other wise it will always be retrieved
      Returns:
      attribute
      Throws:
      IllegalStateException - if create is true, and the session can't be created
    • getSessionAttributeFromSession

      protected abstract Object getSessionAttributeFromSession(S session, String name)
      Get an attribute value from the session.
      Parameters:
      session - the session to get the session attribute from
      name - the name of the attribute
      Returns:
      attribute
      Throws:
      IllegalStateException - if create is true, and the session can't be created
    • removeRequestAttribute

      protected abstract void removeRequestAttribute(R request, String name)
      Remove an attribute from the request.
      Parameters:
      request - the request to remove the attribute from
      name - the name of the attribute
    • setRequestAttribute

      protected abstract void setRequestAttribute(R request, String name, Object value)
      Set an attribute in the request.
      Parameters:
      request - the request to set the attribute from
      name - the name of the attribute
      value - the value of the attribute
    • getRequestAttribute

      protected abstract Object getRequestAttribute(R request, String name)
      Retrieve an attribute value from the request
      Parameters:
      request - the request to get the attribute from
      name - the name of the attribute to get
      Returns:
      the value of the attribute
    • createRequestBeanStore

      protected abstract BoundBeanStore createRequestBeanStore(NamingScheme namingScheme, R request)
    • createSessionBeanStore

      protected abstract BoundBeanStore createSessionBeanStore(NamingScheme namingScheme, S session)
    • getSessionFromRequest

      protected abstract S getSessionFromRequest(R request, boolean create)
    • getNamingSchemePrefix

      protected abstract String getNamingSchemePrefix()
    • isAssociated

      protected boolean isAssociated()
      Check if the context is currently associated
      Returns:
      true if the context is associated
    • getRequest

      protected R getRequest()
      Get the associated store
      Returns:
      the request
    • getSessionAttributeNames

      protected abstract Iterator<String> getSessionAttributeNames(S session)