You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2017/03/01 15:59:04 UTC
svn commit: r1784980 -
/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java
Author: kwin
Date: Wed Mar 1 15:59:04 2017
New Revision: 1784980
URL: http://svn.apache.org/viewvc?rev=1784980&view=rev
Log:
SLING-5660 really invalidate the models cache for all resource deleted/modified/added events anywhere in the class path
Restrict the amount of according OSGi Events being sent through the event admin, by starting at most 2 invalidations and for each invalidation request wait 500ms
Modified:
sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java
Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java?rev=1784980&r1=1784979&r2=1784980&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java (original)
+++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/resourcemodel/ResourceValidationModelProviderImpl.java Wed Mar 1 15:59:04 2017
@@ -36,8 +36,10 @@ import org.apache.sling.api.resource.Res
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.commons.threads.ModifiableThreadPoolConfig;
import org.apache.sling.commons.threads.ThreadPool;
import org.apache.sling.commons.threads.ThreadPoolManager;
+import org.apache.sling.commons.threads.ThreadPoolConfig.ThreadPoolPolicy;
import org.apache.sling.serviceusermapping.ServiceUserMapped;
import org.apache.sling.validation.impl.model.ChildResourceImpl;
import org.apache.sling.validation.impl.model.ParameterizedValidatorImpl;
@@ -79,7 +81,6 @@ public class ResourceValidationModelProv
public static final String PROPERTY_MULTIPLE = "propertyMultiple";
public static final String PROPERTIES = "properties";
public static final String VALIDATION_MODEL_RESOURCE_TYPE = "sling/validation/model";
- public static final String MODELS_HOME = "validation/";
public static final String APPLICABLE_PATHS = "applicablePaths";
public static final String VALIDATED_RESOURCE_TYPE = "validatedResourceType";
public static final String SEVERITY = "severity";
@@ -104,7 +105,12 @@ public class ResourceValidationModelProv
@Activate
protected void activate(ComponentContext componentContext) throws LoginException {
- threadPool = tpm.get("Validation Service Thread Pool");
+ ModifiableThreadPoolConfig threadPoolConfig = new ModifiableThreadPoolConfig();
+ threadPoolConfig.setMinPoolSize(1);
+ threadPoolConfig.setMaxPoolSize(1);
+ threadPoolConfig.setQueueSize(2); // make sure at most 2 invalidation requests queue up
+ threadPoolConfig.setBlockPolicy(ThreadPoolPolicy.DISCARD);
+ threadPool = tpm.create(threadPoolConfig, "Validation Service Thread Pool");
ResourceResolver rr = null;
try {
rr = rrf.getServiceResourceResolver(null);
@@ -114,11 +120,7 @@ public class ResourceValidationModelProv
sb.append("|");
}
for (String searchPath : searchPaths) {
- if (searchPath.endsWith("/")) {
- searchPath = searchPath.substring(0, searchPath.length() - 1);
- }
- String path = searchPath + "/*" + ResourceValidationModelProviderImpl.MODELS_HOME;
- sb.append("(path=").append(path).append("*)");
+ sb.append("(path=").append(searchPath + "*").append(")");
}
sb.append(")");
Dictionary<String, Object> eventHandlerProperties = new Hashtable<String, Object>();
@@ -151,6 +153,12 @@ public class ResourceValidationModelProv
Runnable task = new Runnable() {
@Override
public void run() {
+ try {
+ // defer invalidating the cache, to prevent to many invalidation events to be sent in a row when a lot of modifications happen below the resource resolver's search paths
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ LOG.warn("Could not wait 500 seconds till invalidating the cache", e);
+ }
cache.invalidate();
}
};