Class DataModifiedFilter

  • All Implemented Interfaces:
    javax.servlet.Filter

    public class DataModifiedFilter
    extends java.lang.Object
    implements javax.servlet.Filter
    Cache control based on requested binding set name and data from scope_last_modified If a request matches a certain scope, we check its last_refreshed and compare it against the request's If-Modified-Since-Header If possible according to that, we send a 304 instead of forwarding to get new data - If the scope was found in bcd_cache_scope, we are active, otherwise we do chain.doFilter - If If-Modified-Since was sent, we compare that with the scopes scope_last_modified - If If-Modified-Since was not sent or data was out-dated, we call chain.doFilter and set expires to earliest_next_modified if given See bcdui4.DataModifiedFilter in web.xml for how to use
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  DataModifiedFilter.ScopeInfo
      Holds information about a scope like when data was actually refreshed last time and possibly when it may be refreshed earliest next time
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()  
      protected boolean didSend304​(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res)
      Check whether we can send a 304 and do so of possible Will send "Last-Modified" header if the scope was found.
      void doFilter​(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)
      Handle the request brings 304 or operation
      protected java.lang.String getReqScope​(javax.servlet.http.HttpServletRequest httpReq)
      Derive the caching-scope from the request.
      protected java.lang.Long getScopeLastModified​(java.lang.String scope)
      Check whether we have a a last-modified for the scope and return it.
      protected java.lang.String getSelectSql()
      The query to get the scops' data
      void init​(javax.servlet.FilterConfig filterConfig)  
      protected boolean refreshNeeded​(java.lang.String scope)
      Check whether we need to refresh the scope's data from bcd_cache_scope That is the case if refreshPeriodMs has passed since last update and earliestNextModified is not in the future
      protected void refreshScopes()
      Read all scopes' information fresh from bcd_cache_scope
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • REFRESH_PERIOD_PARAM_NAME

        public static final java.lang.String REFRESH_PERIOD_PARAM_NAME
        See Also:
        Constant Field Values
      • logger

        protected org.apache.logging.log4j.Logger logger
      • lastRefreshedMs

        protected long lastRefreshedMs
      • refreshPeriodMs

        protected long refreshPeriodMs
      • utcCal

        protected java.util.Calendar utcCal
    • Constructor Detail

      • DataModifiedFilter

        public DataModifiedFilter()
    • Method Detail

      • doFilter

        public void doFilter​(javax.servlet.ServletRequest req,
                             javax.servlet.ServletResponse res,
                             javax.servlet.FilterChain chain)
                      throws java.io.IOException,
                             javax.servlet.ServletException
        Handle the request brings 304 or operation
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        java.io.IOException
        javax.servlet.ServletException
      • didSend304

        protected boolean didSend304​(javax.servlet.ServletRequest req,
                                     javax.servlet.ServletResponse res)
        Check whether we can send a 304 and do so of possible Will send "Last-Modified" header if the scope was found. That triggers "If-Modified-Since" to be sent next time by the client
        Parameters:
        req -
        res -
        Returns:
        false if 304 is not sufficient
      • getReqScope

        protected java.lang.String getReqScope​(javax.servlet.http.HttpServletRequest httpReq)
        Derive the caching-scope from the request. In this case we just use the BindingSet as the scope
        Parameters:
        httpReq -
        Returns:
      • getScopeLastModified

        protected java.lang.Long getScopeLastModified​(java.lang.String scope)
        Check whether we have a a last-modified for the scope and return it. Returns -1 if there was no entry found
        Parameters:
        scope -
        Returns:
      • refreshNeeded

        protected boolean refreshNeeded​(java.lang.String scope)
        Check whether we need to refresh the scope's data from bcd_cache_scope That is the case if refreshPeriodMs has passed since last update and earliestNextModified is not in the future
        Parameters:
        scope -
        Returns:
      • refreshScopes

        protected void refreshScopes()
        Read all scopes' information fresh from bcd_cache_scope
      • getSelectSql

        protected java.lang.String getSelectSql()
        The query to get the scops' data
        Returns:
      • init

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

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