You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2021/10/31 09:38:21 UTC
[sling-org-apache-sling-servlets-resolver] branch master updated:
SLING-10896 : Use service events for detecting adapter changes
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new 00a2e32 SLING-10896 : Use service events for detecting adapter changes
00a2e32 is described below
commit 00a2e32791b37ddb3a40a2c8f2ee3b2658dc988e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Oct 31 10:38:08 2021 +0100
SLING-10896 : Use service events for detecting adapter changes
---
.../internal/resolution/ResolutionCache.java | 24 ++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/resolution/ResolutionCache.java b/src/main/java/org/apache/sling/servlets/resolver/internal/resolution/ResolutionCache.java
index 5ae49b5..66733d0 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/resolution/ResolutionCache.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/resolution/ResolutionCache.java
@@ -40,8 +40,12 @@ import org.apache.sling.api.resource.path.Path;
import org.apache.sling.servlets.resolver.internal.ResolverConfig;
import org.apache.sling.servlets.resolver.internal.helper.AbstractResourceCollector;
import org.apache.sling.servlets.resolver.jmx.SlingServletResolverCacheMBean;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@@ -61,7 +65,7 @@ import org.slf4j.LoggerFactory;
@Component(configurationPid = ResolverConfig.PID,
service = {ResolutionCache.class})
public class ResolutionCache
- implements EventHandler, ResourceChangeListener, ExternalResourceChangeListener {
+ implements EventHandler, ResourceChangeListener, ExternalResourceChangeListener, ServiceListener {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -88,10 +92,11 @@ public class ResolutionCache
/**
* Activate this component.
+ * @throws InvalidSyntaxException
*/
@Activate
protected void activate(final BundleContext context,
- final ResolverConfig config) {
+ final ResolverConfig config) throws InvalidSyntaxException {
// create cache - if a cache size is configured
this.cacheSize = config.servletresolver_cacheSize();
if (this.cacheSize > 5) {
@@ -119,7 +124,6 @@ public class ResolutionCache
// the event listener is for updating the script engine extensions
props.put(EventConstants.EVENT_TOPIC, new String[] {
"javax/script/ScriptEngineFactory/*",
- "org/apache/sling/api/adapter/AdapterFactory/*",
"org/apache/sling/scripting/core/BindingsValuesProvider/*" });
this.eventHandlerRegistration.set(context.registerService(EventHandler.class, this, props));
@@ -139,13 +143,15 @@ public class ResolutionCache
this.resourceListenerRegistration.set(context.registerService(ResourceChangeListener.class, this, listenerProps));
}
+ context.addServiceListener(this, "(".concat(Constants.OBJECTCLASS).concat("=org.apache.sling.adapter.Adaption)"));
+
updateScriptEngineExtensions();
}
@Modified
protected void modified(final BundleContext context,
- final ResolverConfig config) {
- this.deactivate();
+ final ResolverConfig config) throws InvalidSyntaxException {
+ this.deactivate(context);
this.activate(context, config);
}
@@ -153,7 +159,8 @@ public class ResolutionCache
* Deactivate this component.
*/
@Deactivate
- protected void deactivate() {
+ protected void deactivate(final BundleContext context) {
+ context.removeServiceListener(this);
this.cache = null;
// unregister mbean
@@ -211,6 +218,11 @@ public class ResolutionCache
updateScriptEngineExtensions();
}
+ @Override
+ public void serviceChanged(final ServiceEvent event) {
+ this.handleEvent(null);
+ }
+
public void flushCache() {
// use local variable to avoid racing with deactivate
final Map<AbstractResourceCollector, Servlet> localCache = this.cache.get();