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 StringCONVERSATIONS_ATTRIBUTE_NAMEstatic StringDESTRUCTION_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 voidactivate()Activate the Context.voidactivate(String cid)Activate the conversation context, using the id provided to attempt to restore a long-running conversationbooleanassociate(R request)Associate the context with the storage (for this thread).protected voidassociateRequest(ManagedConversation conversation)protected voidassociateRequestWithNewConversation()voidconversationPromotedToLongRunning(ConversationImpl conversation)protected voidcopyConversationIdGeneratorAndConversationsToSession()protected abstract BoundBeanStorecreateRequestBeanStore(NamingScheme namingScheme, R request)protected abstract BoundBeanStorecreateSessionBeanStore(NamingScheme namingScheme, S session)voiddeactivate()Deactivate the Context, destroying any instances if the context is invalid.booleandestroy(S session)protected voiddestroyConversation(S session, String id, boolean fireEvents)booleandissociate(R request)Dissociate the context from the storage (for this thread).StringgenerateConversationId()Generate a new, unique, conversation idlonggetConcurrentAccessTimeout()Get the current concurrent access timeoutManagedConversationgetConversation(String id)Get the conversation with the given id.protected ConversationIdGeneratorgetConversationIdGenerator()Collection<ManagedConversation>getConversations()Get conversations currently known to the context.ManagedConversationgetCurrentConversation()Get a handle the current conversation (transient or otherwise).longgetDefaultTimeout()Get the default inactivity timeout.protected abstract StringgetNamingSchemePrefix()StringgetParameterName()Get the name of the parameter used to propagate the conversation idprotected RgetRequest()Get the associated storeprotected abstract ObjectgetRequestAttribute(R request, String name)Retrieve an attribute value from the requestClass<? extends Annotation>getScope()Get the scope type of the context object.protected abstract ObjectgetSessionAttribute(R request, String name, boolean create)Get an attribute value from the session.protected abstract ObjectgetSessionAttributeFromSession(S session, String name)Get an attribute value from the session.protected abstract Iterator<String>getSessionAttributeNames(S session)protected abstract SgetSessionFromRequest(R request, boolean create)protected voidinitialize(String cid)voidinvalidate()Mark the context as due for destruction when deactivate is called.protected booleanisAssociated()Check if the context is currently associatedprotected abstract voidremoveRequestAttribute(R request, String name)Remove an attribute from the request.voidsessionCreated()voidsetConcurrentAccessTimeout(long timeout)Set the concurrent access timeoutvoidsetDefaultTimeout(long timeout)Set the default inactivity timeout.voidsetParameterName(String cid)Set the name of the parameter used to propagate the conversation idprotected abstract voidsetRequestAttribute(R request, String name, Object value)Set an attribute in the request.protected abstract voidsetSessionAttribute(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 javax.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:ConversationContextGet the name of the parameter used to propagate the conversation id- Specified by:
getParameterNamein interfaceConversationContext- Returns:
- the name of the conversation id parameter
-
setParameterName
public void setParameterName(String cid)
Description copied from interface:ConversationContextSet the name of the parameter used to propagate the conversation id- Specified by:
setParameterNamein interfaceConversationContext- Parameters:
cid- the name of the conversation id parameter
-
setConcurrentAccessTimeout
public void setConcurrentAccessTimeout(long timeout)
Description copied from interface:ConversationContextSet the concurrent access timeout- Specified by:
setConcurrentAccessTimeoutin interfaceConversationContext- Parameters:
timeout- the timeout (in ms) for the concurrent access lock
-
getConcurrentAccessTimeout
public long getConcurrentAccessTimeout()
Description copied from interface:ConversationContextGet the current concurrent access timeout- Specified by:
getConcurrentAccessTimeoutin interfaceConversationContext- Returns:
- the timeout (in ms) for the concurrent access lock
-
setDefaultTimeout
public void setDefaultTimeout(long timeout)
Description copied from interface:ConversationContextSet the default inactivity timeout. This may be overridden on a per conversation basis usingConversation.setTimeout(long)- Specified by:
setDefaultTimeoutin interfaceConversationContext- Parameters:
timeout- the default inactivity timeout (in ms)
-
getDefaultTimeout
public long getDefaultTimeout()
Description copied from interface:ConversationContextGet the default inactivity timeout. This may have been overridden on a per conversation basis.- Specified by:
getDefaultTimeoutin interfaceConversationContext- Returns:
- the default inactivity timeout (in ms)
-
associate
public boolean associate(R request)
Description copied from interface:BoundContextAssociate 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:
associatein 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:BoundContextDissociate the context from the storage (for this thread). The context will only dissociate from the same storage it associated with.- Specified by:
dissociatein interfaceBoundContext<R>- Overrides:
dissociatein 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:ManagedContextActivate the Context.- Specified by:
activatein interfaceConversationContext- Specified by:
activatein interfaceManagedContext- Overrides:
activatein classAbstractBoundContext<R>
-
activate
public void activate(String cid)
Description copied from interface:ConversationContextActivate the conversation context, using the id provided to attempt to restore a long-running conversation- Specified by:
activatein 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:ManagedContextDeactivate the Context, destroying any instances if the context is invalid.- Specified by:
deactivatein interfaceManagedContext- Overrides:
deactivatein classAbstractBoundContext<R>
-
conversationPromotedToLongRunning
public void conversationPromotedToLongRunning(ConversationImpl conversation)
-
invalidate
public void invalidate()
Description copied from interface:ManagedContextMark the context as due for destruction when deactivate is called.- Specified by:
invalidatein interfaceConversationContext- Specified by:
invalidatein interfaceManagedContext- Overrides:
invalidatein classAbstractManagedContext
-
destroy
public boolean destroy(S session)
-
generateConversationId
public String generateConversationId()
Description copied from interface:ConversationContextGenerate a new, unique, conversation id- Specified by:
generateConversationIdin interfaceConversationContext- Returns:
- a new, unique conversation id
-
getConversationIdGenerator
protected ConversationIdGenerator getConversationIdGenerator()
-
getConversation
public ManagedConversation getConversation(String id)
Description copied from interface:ConversationContextGet the conversation with the given id.- Specified by:
getConversationin 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:ConversationContextGet 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:
getConversationsin interfaceConversationContext- Returns:
- a collection containing the conversations
-
getCurrentConversation
public ManagedConversation getCurrentConversation()
Description copied from interface:ConversationContextGet a handle the current conversation (transient or otherwise).- Specified by:
getCurrentConversationin interfaceConversationContext- Returns:
- the current conversation
-
getScope
public Class<? extends Annotation> getScope()
Description copied from interface:ContextGet 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
-
-