PRODUCTS AND SERVICES INDUSTRIES SUPPORT PARTNERS COMMUNITIES ABOUT
  Coherence 3.5 User Guide
  Coherence*Web Session Distribution Controller
Added by Rob Misek, last edited by Jason Howes on Jun 02, 2009  (view change)

Labels

 
(None)

Description

The Coherence*Web Session Distribution Controller is an interface that allows users to override the default distribution of HTTP sessions and attributes in a web application. An implementation of the SessionDistributionController interface can choose to mark sessions and/or attributes as follows:

  • "local" - a "local" session and/or attribute is stored on the originating server's heap, and thus, only accessible by that server
  • "distributed" - a "distributed" session and/or attribute is stored within the Coherence grid, and thus, accessible to other server JVMs

At any point during the life of a session, the session and/or attributes for that session can be transitioned from "local" or "distributed". However, once a session and/or attribute is "distributed" it cannot transition back to "local".

Use Cases

  1. It is acceptable for new sessions to be "local" until the user adds an attribute (i.e. the first item added to a shopping cart); the idea being that a session only needs to be fault tolerant when it contains valuable data.
  2. Some web frameworks make use of session attributes to store UI rendering state. Many times this data is not serializable which prevents it from being distributed. Using this feature, these attributes can be kept local while allowing for the rest of the session attributes to be distributed.
  3. This feature can be used to assist in the conversion from non-distributed to distributed systems, particularly when concerns exist about the cost of distribution of all sessions and all attributes.

Example implementation


import com.tangosol.coherence.servlet.HttpSessionCollection;
import com.tangosol.coherence.servlet.HttpSessionModel;

/**
* Sample implementation of SessionDistributionController
*/
public class CustomSessionDistributionController
        implements HttpSessionCollection.SessionDistributionController
    {
    public void init(HttpSessionCollection collection)
        {
        }

    /**
    * Only distribute sessions that have a shopping cart.
    *
    * @param model  Coherence representation of the HTTP session
    *
    * @return true if the session should be distributed
    */
    public boolean isSessionDistributed(HttpSessionModel model)
        {
        return model.getAttribute("shopping-cart") != null;
        }

    /**
    * If a session is "distributed," distribute all attributes with
    * the exception of the "ui-rendering" attribute.
    *
    * @param model  Coherence representation of the HTTP session
    * @param sName  name of the attribute to check
    *
    * @return true if the attribute should be distributed
    */
    public boolean isSessionAttributeDistributed(HttpSessionModel model,
            String sName)
        {
        return !"ui-rendering".equals(sName);
        }
    }

Configuration

Implementations of SessionDistributionController can be configured via the coherence-distributioncontroller-class configuration element. Note that this feature requires sticky session optimizations to be enabled; see the coherence-sticky-sessions configuration element.