You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2022/02/09 09:37:28 UTC

[GitHub] [sling-org-apache-sling-scripting-core] raducotescu commented on a change in pull request #13: SLING-11119 - Optimise the service retrieval for bundled scripts

raducotescu commented on a change in pull request #13:
URL: https://github.com/apache/sling-org-apache-sling-scripting-core/pull/13#discussion_r802461016



##########
File path: src/main/java/org/apache/sling/scripting/core/impl/bundled/AbstractBundledRenderUnit.java
##########
@@ -101,83 +95,37 @@ public BundleContext getBundleContext() {
         return scriptExtension;
     }
 
+    @Override
+    public @NotNull ServiceCache getServiceCache() {
+        return serviceCache;
+    }
+
     @Override
     @Nullable
     @SuppressWarnings("unchecked")
     public <T> T getService(@NotNull String className) {
-        LOG.debug("Attempting to load class {} as an OSGi service.", className);
-        T result = (this.services == null ? null : (T) this.services.get(className));
-        if (result == null) {
-            final ServiceReference<?> ref = this.bundleContext.getServiceReference(className);
-            if (ref != null) {
-                result = (T) this.bundleContext.getService(ref);
-                if (result != null) {
-                    if (this.services == null) {
-                        this.services = new HashMap<>();
-                    }
-                    if (this.references == null) {
-                        this.references = new ArrayList<>();
-                    }
-                    this.references.add(ref);
-                    this.services.put(className, result);
-                    return result;
-                }
-            }
+        try {
+            ClassLoader bundleClassloader = getBundle().adapt(BundleWiring.class).getClassLoader();
+            return (T) serviceCache.getService(bundleClassloader.loadClass(className));
+        } catch (ClassNotFoundException e) {

Review comment:
       In HTL we always made sure that the object to load was accessible to the classloader with which the script was loaded. This was not necessarily the case for JSPs, but for bundled scripts they worked like that from the beginning - see https://github.com/apache/sling-org-apache-sling-scripting-spi/blob/47949fedc62380822961d8ef649130dee68a28e8/src/main/java/org/apache/sling/scripting/spi/bundle/BundledRenderUnit.java#L83.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org