in src/main/java/org/apache/sling/servlets/resolver/internal/resolution/ResolutionCache.java [97:148]
protected void activate(final BundleContext context,
final ResolverConfig config) throws InvalidSyntaxException {
// create cache - if a cache size is configured
this.cacheSize = config.servletresolver_cacheSize();
if (this.cacheSize > 5) {
this.cache.set(new ConcurrentHashMap<>(cacheSize));
this.logCacheSizeWarning = true;
// register MBean
try {
Dictionary<String, String> mbeanProps = new Hashtable<>(); // NOSONAR
mbeanProps.put("jmx.objectname", "org.apache.sling:type=servletResolver,service=SlingServletResolverCache");
ServletResolverCacheMBeanImpl mbean = new ServletResolverCacheMBeanImpl();
mbeanRegistration.set(context.registerService(SlingServletResolverCacheMBean.class, mbean, mbeanProps));
} catch (final Throwable t) { // NOSONAR
logger.warn("Unable to register servlets resolver cache MBean", t);
}
}
// and finally register as event listener
// to invalidate cache and script extensions
final Dictionary<String, Object> props = new Hashtable<>(); // NOSONAR
props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Servlet Resolver Event Handler");
props.put(Constants.SERVICE_VENDOR,"The Apache Software Foundation");
// the event listener is for updating the script engine extensions
props.put(EventConstants.EVENT_TOPIC, new String[] {
"javax/script/ScriptEngineFactory/*",
"org/apache/sling/scripting/core/BindingsValuesProvider/*" });
this.eventHandlerRegistration.set(context.registerService(EventHandler.class, this, props));
// we need a resource change listener to invalidate the cache
if ( this.cache != null ) {
final String[] listenerPaths = new String[config.servletresolver_paths().length];
for(int i=0; i<config.servletresolver_paths().length; i++) {
final Path p = new Path(config.servletresolver_paths()[i]);
listenerPaths[i] = p.getPath();
}
final Dictionary<String, Object> listenerProps = new Hashtable<>(); // NOSONAR
listenerProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Servlet Resolver Resource Listener");
listenerProps.put(Constants.SERVICE_VENDOR,"The Apache Software Foundation");
listenerProps.put(ResourceChangeListener.PATHS, listenerPaths);
this.resourceListenerRegistration.set(context.registerService(ResourceChangeListener.class, this, listenerProps));
}
context.addServiceListener(this, "(".concat(Constants.OBJECTCLASS).concat("=org.apache.sling.adapter.Adaption)"));
updateScriptEngineExtensions();
}