info.magnolia.cms.filters
Class SafeDestroyMgnlFilterWrapper

java.lang.Object
  extended by info.magnolia.cms.filters.SafeDestroyMgnlFilterWrapper
All Implemented Interfaces:
MgnlFilter, javax.servlet.Filter

public class SafeDestroyMgnlFilterWrapper
extends Object
implements MgnlFilter

Wrapper for a MgnlFilter that using a read/write lock ensures that the destroy method waits for requests to complete before destroying the target filter. All use of the wrapper must be done while holding the read lock. The exception to this is the destroy method that MUST NOT be called while holding the read lock, doing so would result in dead lock.

Version:
$Id$

Nested Class Summary
static class SafeDestroyMgnlFilterWrapper.Switcher
          Construct for keeping a reference to a SafeDestroyMgnlFilterWrapper and change it with the guarantee that the returned previous reference will not get more read locks.
 
Constructor Summary
SafeDestroyMgnlFilterWrapper(MgnlFilter target)
           
 
Method Summary
 void acquireReadLock()
           
 void destroy()
          Destroys the target filter after waiting for all requests to complete.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Read lock must be held when invoking this method.
 String getName()
          Read lock must be held when invoking this method.
 MgnlFilter getTargetFilter()
           
 void init(javax.servlet.FilterConfig filterConfig)
           
 boolean matches(javax.servlet.http.HttpServletRequest request)
          Read lock must be held when invoking this method.
 void releaseReadLock()
           
 void setName(String name)
          Read lock must be held when invoking this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SafeDestroyMgnlFilterWrapper

public SafeDestroyMgnlFilterWrapper(MgnlFilter target)
Method Detail

acquireReadLock

public void acquireReadLock()

releaseReadLock

public void releaseReadLock()

init

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

getName

public String getName()
Read lock must be held when invoking this method.

Specified by:
getName in interface MgnlFilter

setName

public void setName(String name)
Read lock must be held when invoking this method.

Specified by:
setName in interface MgnlFilter

matches

public boolean matches(javax.servlet.http.HttpServletRequest request)
Read lock must be held when invoking this method.

Specified by:
matches in interface MgnlFilter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException
Read lock must be held when invoking this method.

Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException

destroy

public void destroy()
Destroys the target filter after waiting for all requests to complete. Calling this method while holding the read lock will result in dead lock. Therefore a request that has passed through this filter MUST NEVER call this method.

Specified by:
destroy in interface javax.servlet.Filter

getTargetFilter

public MgnlFilter getTargetFilter()


Copyright © 2003-2013 Magnolia International Ltd.. All Rights Reserved.