org.apache.myfaces.orchestra.filter
Class OrchestraServletFilter

java.lang.Object
  extended by org.apache.myfaces.orchestra.filter.OrchestraServletFilter
All Implemented Interfaces:
javax.servlet.Filter

public class OrchestraServletFilter
extends java.lang.Object
implements javax.servlet.Filter

Perform a number of useful per-request tasks.

This filter is entirely optional; it can be omitted if you do not need any of the functionality provided here.

Note that it is necessary to define a filter that initialises the Orchestra framework; this can be done either via a standalone filter such as JsfFrameworkAdapterFilter, or via a filter that combines framework initialisation with the functionality of this class, such as OrchestraServletFilter.

Request Serialization

It is possible for multiple requests associated with the same http session to be received concurrently.

By default, the servlet engine simply processes all requests concurrently in different threads. However that can cause all sorts of unexpected problems with session-scoped objects.

The usual solution is to apply a filter to all requests which uses standard java synchronisation on a session-scoped object, taking the lock on request entry and releasing it on request exit. This ensures that only one request for that session runs at a time, with the others waiting until they can obtain a lock on the appropriate object. This is referred to as "request serialization" because it causes requests to be processed serially, ie one after the other, rather than concurrently. This has nothing to do with java.io.Serializable.

When using an Orchestra conversationContext, session-scoped data should be avoided and conversation-scoped beans used instead. If there is no session-scoped data in use by an application then it is possible to allow concurrent requests to the same http session, but NOT concurrent access to the same orchestra conversationContext. This filter implements that, by holding a lock on a mutex object held by the appropriate conversationContext.

The request serialization functionality can be enabled or disabled via a filter init parameter; setting "serializeRequests" to "false" disables this feature. Default value: true (enabled).

JDBC Connection Management

Orchestra provides a special DataSource wrapper that can be configured for any datasource used by the application. The datasource simply wraps all real Connection objects it returns in a proxy, and keeps track of them. Here in this servlet it checks whether all connections borrowed by this thread have been returned, and if not returns the real connection nulls out the connection held by the proxy. See ConnectionManagerDataSource for more details.


Field Summary
static java.lang.String SERIALIZE_REQUESTS
          This filter init property can be set to "true" or "false".
 
Constructor Summary
OrchestraServletFilter()
           
 
Method Summary
protected  void cleanupPersistence()
           
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)
           
 void init(javax.servlet.FilterConfig filterConfig)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERIALIZE_REQUESTS

public static final java.lang.String SERIALIZE_REQUESTS
This filter init property can be set to "true" or "false". Default: "true".

See Also:
Constant Field Values
Constructor Detail

OrchestraServletFilter

public OrchestraServletFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

doFilter

public void doFilter(javax.servlet.ServletRequest servletRequest,
                     javax.servlet.ServletResponse servletResponse,
                     javax.servlet.FilterChain filterChain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in interface javax.servlet.Filter
Throws:
java.io.IOException
javax.servlet.ServletException

cleanupPersistence

protected void cleanupPersistence()

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter


Copyright 2007 The Apache Software Foundation. All Rights Reserved.