org.apache.cocoon.components.flow
Class ContinuationsManagerImpl

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.components.flow.ContinuationsManagerImpl
All Implemented Interfaces:
Configurable, Contextualizable, org.apache.cocoon.components.flow.ContinuationsManager, Serviceable, ThreadSafe

public class ContinuationsManagerImpl
extends org.apache.cocoon.util.AbstractLogEnabled
implements org.apache.cocoon.components.flow.ContinuationsManager, Configurable, ThreadSafe, Serviceable, Contextualizable

The default implementation of ContinuationsManager.
There are two modes of work:

Since:
March 19, 2002
Version:
$Id: ContinuationsManagerImpl.html 1304280 2012-03-23 11:18:01Z ilgrosso $
See Also:
ContinuationsManager

Nested Class Summary
protected  class ContinuationsManagerImpl.HolderAwareWebContinuation
          WebContinuation extension that holds also the information about the holder.
 class ContinuationsManagerImpl.WebContinuationsHolder
          A holder for WebContinuations.
 
Field Summary
protected  boolean bindContinuationsToSession
           
protected  byte[] bytes
           
protected  Context context
           
protected  ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder
          Main continuations holder.
protected  int defaultTimeToLive
          How long does a continuation exist in memory since the last access? The time is in miliseconds, and the default is 1 hour.
protected  long expirationCheckInterval
           
protected  SortedSet expirations
          Sorted set of WebContinuation instances, based on their expiration time.
protected  Set forest
          Maintains the forest of WebContinuation trees.
protected  SecureRandom random
          Random number generator used to create continuation ID
protected  ServiceManager serviceManager
           
 
Fields inherited from interface org.apache.cocoon.components.flow.ContinuationsManager
ROLE
 
Constructor Summary
ContinuationsManagerImpl()
           
 
Method Summary
protected  void _detach(org.apache.cocoon.components.flow.WebContinuation wk)
          Detach this continuation from parent.
 void configure(Configuration config)
           
 void contextualize(Context context)
           
 org.apache.cocoon.components.flow.WebContinuation createWebContinuation(Object kont, org.apache.cocoon.components.flow.WebContinuation parent, int timeToLive, String interpreterId, org.apache.cocoon.components.flow.ContinuationsDisposer disposer)
           
 void displayAllContinuations()
          Dump to Log file all WebContinuations in the system
protected  void displayExpireSet()
          Dump to Log file the current contents of the expirations SortedSet
protected  void disposeContinuation(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder, org.apache.cocoon.components.flow.WebContinuation wk)
          Makes the continuation inaccessible for lookup, and triggers possible needed cleanup code through the ContinuationsDisposer interface.
protected  void expireContinuations()
          Remove all continuations which have already expired.
protected  org.apache.cocoon.components.flow.WebContinuation generateContinuation(Object kont, org.apache.cocoon.components.flow.WebContinuation parent, int ttl, String interpreterId, org.apache.cocoon.components.flow.ContinuationsDisposer disposer)
          Create WebContinuation and generate unique identifier for it.
 List getWebContinuationsDataBeanList()
          Get a list of all web continuations (data only)
protected  void handleLeafContinuationExpiration(org.apache.cocoon.components.flow.WebContinuation wk)
          When a new continuation is created in @link #createWebContinuation(Object, WebContinuation, int, String, ContinuationsDisposer), it is registered in the expiration set in order to be evaluated by the invalidation mechanism.
protected  void handleParentContinuationExpiration(org.apache.cocoon.components.flow.WebContinuation parent)
          When a new continuation is created in @link #createWebContinuation(Object, WebContinuation, int, String, ContinuationsDisposer), its parent continuation is removed from the expiration set.
protected  void invalidateContinuations(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder)
          Method used by WebContinuationsHolder to notify the continuations manager about session invalidation.
 void invalidateWebContinuation(org.apache.cocoon.components.flow.WebContinuation wk)
           
 org.apache.cocoon.components.flow.WebContinuation lookupWebContinuation(String id, String interpreterId)
           
 ContinuationsManagerImpl.WebContinuationsHolder lookupWebContinuationsHolder(boolean createNew)
          Lookup a proper web continuations holder.
protected  void removeContinuation(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder, org.apache.cocoon.components.flow.WebContinuation wk)
          Removes an expired leaf WebContinuation node from its continuation tree, and recursively removes its parent(s) if it they have expired and have no (other) children.
 void service(ServiceManager manager)
           
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

random

protected SecureRandom random
Random number generator used to create continuation ID


bytes

protected byte[] bytes

defaultTimeToLive

protected int defaultTimeToLive
How long does a continuation exist in memory since the last access? The time is in miliseconds, and the default is 1 hour.


forest

protected Set forest
Maintains the forest of WebContinuation trees. This set is used only for debugging puroses by displayAllContinuations() method.


continuationsHolder

protected ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder
Main continuations holder. Used unless continuations are stored in user session.


expirations

protected SortedSet expirations
Sorted set of WebContinuation instances, based on their expiration time. This is used by the background thread to invalidate continuations.


bindContinuationsToSession

protected boolean bindContinuationsToSession

serviceManager

protected ServiceManager serviceManager

context

protected Context context

expirationCheckInterval

protected long expirationCheckInterval
Constructor Detail

ContinuationsManagerImpl

public ContinuationsManagerImpl()
                         throws Exception
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException

configure

public void configure(Configuration config)
Specified by:
configure in interface Configurable

createWebContinuation

public org.apache.cocoon.components.flow.WebContinuation createWebContinuation(Object kont,
                                                                               org.apache.cocoon.components.flow.WebContinuation parent,
                                                                               int timeToLive,
                                                                               String interpreterId,
                                                                               org.apache.cocoon.components.flow.ContinuationsDisposer disposer)
Specified by:
createWebContinuation in interface org.apache.cocoon.components.flow.ContinuationsManager

handleLeafContinuationExpiration

protected void handleLeafContinuationExpiration(org.apache.cocoon.components.flow.WebContinuation wk)
When a new continuation is created in @link #createWebContinuation(Object, WebContinuation, int, String, ContinuationsDisposer), it is registered in the expiration set in order to be evaluated by the invalidation mechanism.


handleParentContinuationExpiration

protected void handleParentContinuationExpiration(org.apache.cocoon.components.flow.WebContinuation parent)
When a new continuation is created in @link #createWebContinuation(Object, WebContinuation, int, String, ContinuationsDisposer), its parent continuation is removed from the expiration set. This way only leaf continuations are part of the expiration set.


getWebContinuationsDataBeanList

public List getWebContinuationsDataBeanList()
Get a list of all web continuations (data only)

Specified by:
getWebContinuationsDataBeanList in interface org.apache.cocoon.components.flow.ContinuationsManager

lookupWebContinuation

public org.apache.cocoon.components.flow.WebContinuation lookupWebContinuation(String id,
                                                                               String interpreterId)
Specified by:
lookupWebContinuation in interface org.apache.cocoon.components.flow.ContinuationsManager

generateContinuation

protected org.apache.cocoon.components.flow.WebContinuation generateContinuation(Object kont,
                                                                                 org.apache.cocoon.components.flow.WebContinuation parent,
                                                                                 int ttl,
                                                                                 String interpreterId,
                                                                                 org.apache.cocoon.components.flow.ContinuationsDisposer disposer)
Create WebContinuation and generate unique identifier for it. The identifier is generated using a cryptographically strong algorithm to prevent people to generate their own identifiers.

It has the side effect of interning the continuation object in the idToWebCont hash table.

Parameters:
kont - an Object value representing continuation
parent - value representing parent WebContinuation
ttl - WebContinuation time to live
interpreterId - id of interpreter invoking continuation creation
disposer - ContinuationsDisposer instance to use for cleanup of the continuation.
Returns:
the generated WebContinuation with unique identifier

invalidateWebContinuation

public void invalidateWebContinuation(org.apache.cocoon.components.flow.WebContinuation wk)
Specified by:
invalidateWebContinuation in interface org.apache.cocoon.components.flow.ContinuationsManager

_detach

protected void _detach(org.apache.cocoon.components.flow.WebContinuation wk)
Detach this continuation from parent. This method removes continuation from forest set, or, if it has parent, from parent's children collection.

Parameters:
wk - Continuation to detach from parent.

disposeContinuation

protected void disposeContinuation(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder,
                                   org.apache.cocoon.components.flow.WebContinuation wk)
Makes the continuation inaccessible for lookup, and triggers possible needed cleanup code through the ContinuationsDisposer interface.

Parameters:
continuationsHolder -
wk - the continuation to dispose.

removeContinuation

protected void removeContinuation(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder,
                                  org.apache.cocoon.components.flow.WebContinuation wk)
Removes an expired leaf WebContinuation node from its continuation tree, and recursively removes its parent(s) if it they have expired and have no (other) children.

Parameters:
continuationsHolder -
wk - WebContinuation node

displayExpireSet

protected void displayExpireSet()
Dump to Log file the current contents of the expirations SortedSet


displayAllContinuations

public void displayAllContinuations()
Dump to Log file all WebContinuations in the system

Specified by:
displayAllContinuations in interface org.apache.cocoon.components.flow.ContinuationsManager

expireContinuations

protected void expireContinuations()
Remove all continuations which have already expired.


invalidateContinuations

protected void invalidateContinuations(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder)
Method used by WebContinuationsHolder to notify the continuations manager about session invalidation. Invalidates all continuations held by passed continuationsHolder.


lookupWebContinuationsHolder

public ContinuationsManagerImpl.WebContinuationsHolder lookupWebContinuationsHolder(boolean createNew)
Lookup a proper web continuations holder.

Parameters:
createNew - should the manager create a continuations holder in session when none found?

contextualize

public void contextualize(Context context)
                   throws ContextException
Specified by:
contextualize in interface Contextualizable
Throws:
ContextException


Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.