org.dellroad.stuff.servlet
Class BigFatLock

java.lang.Object
  extended by org.springframework.web.filter.GenericFilterBean
      extended by org.springframework.web.filter.OncePerRequestFilter
          extended by org.dellroad.stuff.servlet.BigFatLock
All Implemented Interfaces:
Filter, BeanNameAware, DisposableBean, InitializingBean, ServletContextAware

public final class BigFatLock
extends OncePerRequestFilter

Class for serializing processing using a big fat lock.

The lock can be acquired using runWithLock(java.lang.Runnable). This class can also be used as a servlet filter.

Trace-level logging for displaying lock acquire and release events is included.


Field Summary
 
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
 
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
 
Constructor Summary
BigFatLock()
           
 
Method Summary
protected  void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
           
static boolean isLockHeld()
          Verify that the current thread is holding the big fat lock.
static
<V> V
runWithLock(Callable<V> action)
          Invoke the given action after acquiring the big fat lock.
static void runWithLock(Runnable action)
          Invoke the given action after acquiring the big fat lock.
 String toString()
           
 
Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, shouldNotFilter
 
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setServletContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BigFatLock

public BigFatLock()
Method Detail

doFilterInternal

protected void doFilterInternal(HttpServletRequest request,
                                HttpServletResponse response,
                                FilterChain filterChain)
                         throws ServletException,
                                IOException
Specified by:
doFilterInternal in class OncePerRequestFilter
Throws:
ServletException
IOException

runWithLock

public static void runWithLock(Runnable action)
Invoke the given action after acquiring the big fat lock.


runWithLock

public static <V> V runWithLock(Callable<V> action)
                     throws Exception
Invoke the given action after acquiring the big fat lock.

Throws:
Exception

isLockHeld

public static boolean isLockHeld()
Verify that the current thread is holding the big fat lock.


toString

public String toString()
Overrides:
toString in class Object