444721 - PushCacheFilter cleanup/improvements.

Only associating secondary resources that have been requested with a GET.
This commit is contained in:
Simone Bordet 2015-04-13 17:16:26 +02:00
parent 599ab9bb1b
commit 3169e3becf

View File

@ -156,45 +156,48 @@ public class PushCacheFilter implements Filter
if (port <= 0) if (port <= 0)
port = request.isSecure() ? 443 : 80; port = request.isSecure() ? 443 : 80;
boolean referred_from_here = _hosts.size() > 0 ? _hosts.contains(host) : host.equals(request.getServerName()); boolean referredFromHere = _hosts.size() > 0 ? _hosts.contains(host) : host.equals(request.getServerName());
referred_from_here &= _ports.size() > 0 ? _ports.contains(port) : port == request.getServerPort(); referredFromHere &= _ports.size() > 0 ? _ports.contains(port) : port == request.getServerPort();
if (referred_from_here) if (referredFromHere)
{ {
String referrerPath = referrerURI.getPath(); if ("GET".equalsIgnoreCase(request.getMethod()))
if (referrerPath.startsWith(request.getContextPath()))
{ {
String referrerPathNoContext = referrerPath.substring(request.getContextPath().length()); String referrerPath = referrerURI.getPath();
PrimaryResource primaryResource = _cache.get(referrerPathNoContext); if (referrerPath.startsWith(request.getContextPath()))
if (primaryResource != null)
{ {
long primaryTimestamp = primaryResource._timestamp.get(); String referrerPathNoContext = referrerPath.substring(request.getContextPath().length());
if (primaryTimestamp != 0) PrimaryResource primaryResource = _cache.get(referrerPathNoContext);
if (primaryResource != null)
{ {
RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher(path); long primaryTimestamp = primaryResource._timestamp.get();
if (now - primaryTimestamp < TimeUnit.MILLISECONDS.toNanos(_associatePeriod)) if (primaryTimestamp != 0)
{ {
ConcurrentMap<String, RequestDispatcher> associated = primaryResource._associated; RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher(path);
// Not strictly concurrent-safe, just best effort to limit associations. if (now - primaryTimestamp < TimeUnit.MILLISECONDS.toNanos(_associatePeriod))
if (associated.size() <= _maxAssociations)
{ {
if (associated.putIfAbsent(path, dispatcher) == null) ConcurrentMap<String, RequestDispatcher> associated = primaryResource._associated;
// Not strictly concurrent-safe, just best effort to limit associations.
if (associated.size() <= _maxAssociations)
{
if (associated.putIfAbsent(path, dispatcher) == null)
{
if (LOG.isDebugEnabled())
LOG.debug("Associated {} to {}", path, referrerPathNoContext);
}
}
else
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Associated {} to {}", path, referrerPathNoContext); LOG.debug("Not associated {} to {}, exceeded max associations of {}", path, referrerPathNoContext, _maxAssociations);
} }
} }
else else
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Not associated {} to {}, exceeded max associations of {}", path, referrerPathNoContext, _maxAssociations); LOG.debug("Not associated {} to {}, outside associate period of {}ms", path, referrerPathNoContext, _associatePeriod);
} }
} }
else
{
if (LOG.isDebugEnabled())
LOG.debug("Not associated {} to {}, outside associate period of {}ms", path, referrerPathNoContext, _associatePeriod);
}
} }
} }
} }