Package org.jboss.weld.contexts
Class AbstractConversationContext<R,S>
- java.lang.Object
-
- org.jboss.weld.contexts.AbstractContext
-
- org.jboss.weld.contexts.AbstractManagedContext
-
- org.jboss.weld.contexts.AbstractBoundContext<R>
-
- org.jboss.weld.contexts.AbstractConversationContext<R,S>
-
- All Implemented Interfaces:
AlterableContext
,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 Summary
Fields Modifier and Type Field Description static String
CONVERSATIONS_ATTRIBUTE_NAME
static String
DESTRUCTION_QUEUE_ATTRIBUTE_NAME
-
Constructor Summary
Constructors Constructor Description AbstractConversationContext(String contextId, org.jboss.weld.bootstrap.api.ServiceRegistry services)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
activate()
Activate the Context.void
activate(String cid)
Activate the conversation context, using the id provided to attempt to restore a long-running conversationboolean
associate(R request)
Associate the context with the storage (for this thread).protected void
associateRequest(ManagedConversation conversation)
protected void
associateRequestWithNewConversation()
void
conversationPromotedToLongRunning(ConversationImpl conversation)
protected void
copyConversationIdGeneratorAndConversationsToSession()
protected abstract BoundBeanStore
createRequestBeanStore(NamingScheme namingScheme, R request)
protected abstract BoundBeanStore
createSessionBeanStore(NamingScheme namingScheme, S session)
void
deactivate()
Deactivate the Context, destroying any instances if the context is invalid.boolean
destroy(S session)
protected void
destroyConversation(S session, String id, boolean fireEvents)
boolean
dissociate(R request)
Dissociate the context from the storage (for this thread).String
generateConversationId()
Generate a new, unique, conversation idlong
getConcurrentAccessTimeout()
Get the current concurrent access timeoutManagedConversation
getConversation(String id)
Get the conversation with the given id.protected ConversationIdGenerator
getConversationIdGenerator()
Collection<ManagedConversation>
getConversations()
Get conversations currently known to the context.ManagedConversation
getCurrentConversation()
Get a handle the current conversation (transient or otherwise).long
getDefaultTimeout()
Get the default inactivity timeout.protected abstract String
getNamingSchemePrefix()
String
getParameterName()
Get the name of the parameter used to propagate the conversation idprotected R
getRequest()
Get the associated storeprotected abstract Object
getRequestAttribute(R request, String name)
Retrieve an attribute value from the requestClass<? extends Annotation>
getScope()
Get the scope type of the context object.protected abstract Object
getSessionAttribute(R request, String name, boolean create)
Get an attribute value from the session.protected abstract Object
getSessionAttributeFromSession(S session, String name)
Get an attribute value from the session.protected abstract Iterator<String>
getSessionAttributeNames(S session)
protected abstract S
getSessionFromRequest(R request, boolean create)
protected void
initialize(String cid)
void
invalidate()
Mark the context as due for destruction when deactivate is called.protected boolean
isAssociated()
Check if the context is currently associatedprotected abstract void
removeRequestAttribute(R request, String name)
Remove an attribute from the request.void
sessionCreated()
void
setConcurrentAccessTimeout(long timeout)
Set the concurrent access timeoutvoid
setDefaultTimeout(long timeout)
Set the default inactivity timeout.void
setParameterName(String cid)
Set the name of the parameter used to propagate the conversation idprotected abstract void
setRequestAttribute(R request, String name, Object value)
Set an attribute in the request.protected abstract void
setSessionAttribute(R request, String name, Object value, boolean create)
Set an attribute in the session.-
Methods inherited from class org.jboss.weld.contexts.AbstractBoundContext
cleanup, clearAndSet, getAllContextualInstances, getBeanStore, setBeanStore
-
Methods inherited from class org.jboss.weld.contexts.AbstractManagedContext
isActive, isValid, removeState, setActive
-
Methods inherited from class org.jboss.weld.contexts.AbstractContext
checkContextInitialized, destroy, destroy, get, get, getContextual, getId, getServiceRegistry, isMultithreaded
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jakarta.enterprise.context.spi.AlterableContext
destroy
-
Methods inherited from interface org.jboss.weld.context.WeldAlterableContext
clearAndSet, getAllContextualInstances
-
-
-
-
Constructor Detail
-
AbstractConversationContext
public AbstractConversationContext(String contextId, org.jboss.weld.bootstrap.api.ServiceRegistry services)
-
-
Method Detail
-
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 interfaceConversationContext
- 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 interfaceConversationContext
- 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 interfaceConversationContext
- 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 interfaceConversationContext
- 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 usingConversation.setTimeout(long)
- Specified by:
setDefaultTimeout
in interfaceConversationContext
- 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 interfaceConversationContext
- 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). OnceBoundContext.associate(Object)
has been called, further calls toBoundContext.associate(Object)
will be ignored, until the context has been subsequentlyBoundContext.dissociate(Object)
from the storage.- Specified by:
associate
in interfaceBoundContext<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 interfaceBoundContext<R>
- Overrides:
dissociate
in classAbstractBoundContext<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 interfaceConversationContext
- Specified by:
activate
in interfaceManagedContext
- Overrides:
activate
in classAbstractBoundContext<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 interfaceConversationContext
- 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 interfaceManagedContext
- Overrides:
deactivate
in classAbstractBoundContext<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 interfaceConversationContext
- Specified by:
invalidate
in interfaceManagedContext
- Overrides:
invalidate
in classAbstractManagedContext
-
destroy
public boolean destroy(S session)
-
generateConversationId
public String generateConversationId()
Description copied from interface:ConversationContext
Generate a new, unique, conversation id- Specified by:
generateConversationId
in interfaceConversationContext
- 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 interfaceConversationContext
- 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 interfaceConversationContext
- 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 interfaceConversationContext
- Returns:
- the current conversation
-
getScope
public Class<? extends Annotation> getScope()
Description copied from interface:Context
Get the scope type of the context object.
-
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 inname
- the name of the attributevalue
- the value of the attributecreate
- 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 fromname
- the name of the attributecreate
- 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 fromname
- 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 fromname
- 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 fromname
- the name of the attributevalue
- 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 fromname
- 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)
-
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
-
-