Class ContentCachingFilter
java.lang.Object
net.solarnetwork.central.web.support.ContentCachingFilter
- All Implemented Interfaces:
jakarta.servlet.Filter,net.solarnetwork.service.PingTest
public class ContentCachingFilter
extends Object
implements jakarta.servlet.Filter, net.solarnetwork.service.PingTest
Filter for caching HTTP responses, returning cached data when possible.
This filter delegates most behavior to a ContentCachingService.
- Since:
- 1.16
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumStatistics for the content caching filter.static classA lock with a corresponding counter.Nested classes/interfaces inherited from interface net.solarnetwork.service.PingTest
net.solarnetwork.service.PingTest.Result -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default value for thestatLogAccessCountproperty. -
Constructor Summary
ConstructorsConstructorDescriptionContentCachingFilter(ContentCachingService contentCachingService, int lockPoolCapacity) Constructor.ContentCachingFilter(ContentCachingService contentCachingService, BlockingQueue<ContentCachingFilter.LockAndCount> lockPool, ConcurrentMap<String, ContentCachingFilter.LockAndCount> requestLocks) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoiddoFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) longlockPoolWithCapacity(int lockPoolCapacity) Create a look pool.net.solarnetwork.service.PingTest.ResultvoidsetMethodsToCache(Set<String> methodsToCache) Configure the HTTP methods that can be cached.voidsetRequestLockTimeout(long requestLockTimeout) A timeout for waiting for a request lock.voidsetStatLogAccessCount(int statLogAccessCount) Set the statistic log update count.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.Filter
destroy, init
-
Field Details
-
DEFAULT_STAT_LOG_ACCESS_COUNT
public static final int DEFAULT_STAT_LOG_ACCESS_COUNTThe default value for thestatLogAccessCountproperty.- See Also:
-
-
Constructor Details
-
ContentCachingFilter
Constructor.- Parameters:
contentCachingService- the caching service to uselockPoolCapacity- the lock pool capacity- Throws:
IllegalArgumentException- if any argument is null
-
ContentCachingFilter
public ContentCachingFilter(ContentCachingService contentCachingService, BlockingQueue<ContentCachingFilter.LockAndCount> lockPool, ConcurrentMap<String, ContentCachingFilter.LockAndCount> requestLocks) Constructor.- Parameters:
contentCachingService- the caching service to uselockPool- the request lock pool to use; this must be pre-populated with the desired number of locks to userequestLocks- the request lock map to use- Throws:
IllegalArgumentException- if any argument is null or the lock pool is empty
-
-
Method Details
-
lockPoolWithCapacity
public static BlockingQueue<ContentCachingFilter.LockAndCount> lockPoolWithCapacity(int lockPoolCapacity) Create a look pool.- Parameters:
lockPoolCapacity- the desired capacity of the pool- Returns:
- the pool
-
doFilter
public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException - Specified by:
doFilterin interfacejakarta.servlet.Filter- Throws:
IOExceptionjakarta.servlet.ServletException
-
getPingTestId
- Specified by:
getPingTestIdin interfacenet.solarnetwork.service.PingTest
-
getPingTestName
- Specified by:
getPingTestNamein interfacenet.solarnetwork.service.PingTest
-
getPingTestMaximumExecutionMilliseconds
public long getPingTestMaximumExecutionMilliseconds()- Specified by:
getPingTestMaximumExecutionMillisecondsin interfacenet.solarnetwork.service.PingTest
-
performPingTest
- Specified by:
performPingTestin interfacenet.solarnetwork.service.PingTest- Throws:
Exception
-
setMethodsToCache
Configure the HTTP methods that can be cached.The method names should be all upper case.
- Parameters:
methodsToCache- the methods to cache; defaults to GET only
-
setRequestLockTimeout
public void setRequestLockTimeout(long requestLockTimeout) A timeout for waiting for a request lock.- Parameters:
requestLockTimeout- the timeout to use, in milliseconds; defaults to 4 minutes
-
setStatLogAccessCount
public void setStatLogAccessCount(int statLogAccessCount) Set the statistic log update count.Setting this to something greater than 0 will cause INFO level statistic log entries to be emitted every
statLogAccessCounttimes a cachable request has been processed.- Parameters:
statLogAccessCount- the access count the access count; defaults toDEFAULT_STAT_LOG_ACCESS_COUNT- Since:
- 3.0
-