org.apache.cocoon.components.flow
Class ContinuationsManagerImpl

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.flow.ContinuationsManagerImpl
All Implemented Interfaces:
Component, Configurable, Contextualizable, LogEnabled, Serviceable, ThreadSafe, ContinuationsManager, Instrumentable

public class ContinuationsManagerImpl
extends AbstractLogEnabled
implements ContinuationsManager, Component, Configurable, ThreadSafe, Instrumentable, Serviceable, Contextualizable

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

Since:
March 19, 2002
Version:
CVS $Id: ContinuationsManagerImpl.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Ovidiu Predescu , Michael Melhem
See Also:
ContinuationsManager

Nested Class Summary
protected static class ContinuationsManagerImpl.ExpirationPredicate
           
protected static class ContinuationsManagerImpl.HolderAwareWebContinuation
          WebContinuation extension that holds also the information about the holder.
protected  class ContinuationsManagerImpl.WebContinuationsHolder
          A holder for WebContinuations.
 
Field Summary
protected  boolean bindContinuationsToSession
           
protected  byte[] bytes
           
protected  Context context
           
protected  ValueInstrument continuationsCount
           
protected  int continuationsCounter
           
protected  CounterInstrument continuationsCreated
           
protected  ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder
          Main continuations holder.
protected  CounterInstrument continuationsInvalidated
           
protected  int defaultTimeToLive
          How long does a continuation exist in memory since the last access?
protected  SortedSet expirations
          Sorted set of WebContinuation instances, based on their expiration time.
protected  ValueInstrument expirationsSize
           
protected  String instrumentableName
           
protected  boolean isContinuationSharingBugCompatible
           
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
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
ContinuationsManagerImpl()
           
 
Method Summary
 void configure(Configuration config)
           
 void contextualize(Context context)
           
 WebContinuation createWebContinuation(Object kont, WebContinuation parent, int timeToLive, String interpreterId, ContinuationsDisposer disposer)
          Create a WebContinuation object given a native continuation object and its parent.
 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, 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  WebContinuation generateContinuation(Object kont, WebContinuation parent, int ttl, String interpreterId, ContinuationsDisposer disposer)
          Create WebContinuation and generate unique identifier for it.
 Instrumentable[] getChildInstrumentables()
           
 Set getForest()
          Get a set of all web continuations.
 String getInstrumentableName()
           
 Instrument[] getInstruments()
           
 List getWebContinuationsDataBeanList()
          Deprecated.  
protected  void invalidateContinuations(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder)
          Method used by WebContinuationsHolder to notify the continuations manager about session invalidation.
 void invalidateWebContinuation(WebContinuation wk)
          Invalidates a WebContinuation.
 WebContinuation lookupWebContinuation(String id, String interpreterId)
          Given a WebContinuation id, retrieve the associated WebContinuation object.
 ContinuationsManagerImpl.WebContinuationsHolder lookupWebContinuationsHolder(boolean createNew)
          Lookup a proper web continuations holder.
protected  void removeContinuation(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder, 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)
           
 void setInstrumentableName(String instrumentableName)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
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 final byte[] bytes

expirations

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


serviceManager

protected ServiceManager serviceManager

context

protected Context context

defaultTimeToLive

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


isContinuationSharingBugCompatible

protected boolean isContinuationSharingBugCompatible

bindContinuationsToSession

protected boolean bindContinuationsToSession

continuationsHolder

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


instrumentableName

protected String instrumentableName

continuationsCount

protected ValueInstrument continuationsCount

continuationsCounter

protected int continuationsCounter

expirationsSize

protected ValueInstrument expirationsSize

continuationsCreated

protected CounterInstrument continuationsCreated

continuationsInvalidated

protected CounterInstrument continuationsInvalidated
Constructor Detail

ContinuationsManagerImpl

public ContinuationsManagerImpl()
                         throws Exception
Throws:
Exception
Method Detail

contextualize

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

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

setInstrumentableName

public void setInstrumentableName(String instrumentableName)
Specified by:
setInstrumentableName in interface Instrumentable

getInstrumentableName

public String getInstrumentableName()
Specified by:
getInstrumentableName in interface Instrumentable

getInstruments

public Instrument[] getInstruments()
Specified by:
getInstruments in interface Instrumentable

getChildInstrumentables

public Instrumentable[] getChildInstrumentables()
Specified by:
getChildInstrumentables in interface Instrumentable

createWebContinuation

public WebContinuation createWebContinuation(Object kont,
                                             WebContinuation parent,
                                             int timeToLive,
                                             String interpreterId,
                                             ContinuationsDisposer disposer)
Description copied from interface: ContinuationsManager
Create a WebContinuation object given a native continuation object and its parent. If the parent continuation is null, the WebContinuation returned becomes the root of a tree in the forest.

Specified by:
createWebContinuation in interface ContinuationsManager
Parameters:
kont - an Object value
parent - a WebContinuation value
timeToLive - an int value indicating how long in seconds this continuation will live in the server if not accessed
interpreterId - id of interpreter invoking continuation creation
disposer - a ContinuationsDisposer instance to called when the continuation gets cleaned up.
Returns:
a WebContinuation value
See Also:
WebContinuation

lookupWebContinuation

public WebContinuation lookupWebContinuation(String id,
                                             String interpreterId)
Description copied from interface: ContinuationsManager
Given a WebContinuation id, retrieve the associated WebContinuation object.

Specified by:
lookupWebContinuation in interface ContinuationsManager
Parameters:
id - a String value
interpreterId - Id of an interpreter that queries for the continuation
Returns:
a WebContinuation object, null if no such WebContinuation could be found. Also null if WebContinuation was found but interpreter id does not match the one that the continuation was initially created for.

generateContinuation

protected WebContinuation generateContinuation(Object kont,
                                               WebContinuation parent,
                                               int ttl,
                                               String interpreterId,
                                               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.

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(WebContinuation wk)
Description copied from interface: ContinuationsManager
Invalidates a WebContinuation. This effectively means that the continuation object associated with it will no longer be accessible from Web pages. Invalidating a WebContinuation invalidates all the WebContinuations which are children of it.

Specified by:
invalidateWebContinuation in interface ContinuationsManager
Parameters:
wk - a WebContinuation value

disposeContinuation

protected void disposeContinuation(ContinuationsManagerImpl.WebContinuationsHolder continuationsHolder,
                                   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,
                                  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

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?

getForest

public Set getForest()
Description copied from interface: ContinuationsManager
Get a set of all web continuations. The set itself will only contain the root continuations. Those will provide access to their children. Since it should not be possible to mess up the actual managed continuations the returned list will contain clones of them. The purpose of this method is clearly monitoring or for debugging the application. It has no direct relationship to functionality of the ContinuationsManager.

Specified by:
getForest in interface ContinuationsManager

getWebContinuationsDataBeanList

public List getWebContinuationsDataBeanList()
Deprecated. 

Get a list of all web continuations (data only)

Specified by:
getWebContinuationsDataBeanList in interface ContinuationsManager

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. This method will be changed to be an internal method solely for debugging purposes just like displayExpireSet().

Specified by:
displayAllContinuations in interface ContinuationsManager


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