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 2013/07/09 14:49:16 UTC

svn commit: r1501227 - in /sling/trunk/bundles/jcr/classloader: ./ src/main/java/org/apache/sling/jcr/classloader/internal/ src/main/resources/OSGI-INF/metatype/

Author: cziegeler
Date: Tue Jul  9 12:49:16 2013
New Revision: 1501227

URL: http://svn.apache.org/r1501227
Log:
SLING-2956 :  Store compiled classes in a cluster aware way 

Modified:
    sling/trunk/bundles/jcr/classloader/pom.xml
    sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java
    sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoader.java
    sling/trunk/bundles/jcr/classloader/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/jcr/classloader/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/pom.xml?rev=1501227&r1=1501226&r2=1501227&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/pom.xml (original)
+++ sling/trunk/bundles/jcr/classloader/pom.xml Tue Jul  9 12:49:16 2013
@@ -103,6 +103,18 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.settings</artifactId>
+            <version>1.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.mime</artifactId>
             <version>2.1.4</version>
             <scope>provided</scope>

Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java?rev=1501227&r1=1501226&r2=1501227&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java (original)
+++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/ClassLoaderWriterImpl.java Tue Jul  9 12:49:16 2013
@@ -44,7 +44,9 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.commons.classloader.ClassLoaderWriter;
 import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
 import org.apache.sling.commons.mime.MimeTypeService;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
@@ -77,6 +79,11 @@ public class ClassLoaderWriterImpl
     @org.apache.felix.scr.annotations.Property(value=CLASS_PATH_DEFAULT)
     private static final String CLASS_PATH_PROP = "classpath";
 
+    private static final boolean APPEND_ID_DEFAULT = true;
+
+    @org.apache.felix.scr.annotations.Property(boolValue=APPEND_ID_DEFAULT)
+    private static final String APPEND_ID_PROP = "appendId";
+
     /** Node type for packages/folders. */
     private static final String NT_FOLDER = "nt:folder";
 
@@ -86,6 +93,8 @@ public class ClassLoaderWriterImpl
     @org.apache.felix.scr.annotations.Property(value=OWNER_DEFAULT)
     private static final String OWNER_PROP = "owner";
 
+    @Reference
+    private SlingSettingsService settings;
 
     /** The owner of the class loader / JCR user. */
     private String classLoaderOwner;
@@ -118,18 +127,15 @@ public class ClassLoaderWriterImpl
      */
     @Activate
     protected void activate(final ComponentContext componentContext, final Map<String, Object> properties) {
-        Object prop = properties.get(CLASS_PATH_PROP);
-        if ( prop instanceof String[] && ((String[])prop).length > 0 ) {
-            this.classPath = ((String[])prop)[0];
-        } else {
-            this.classPath = CLASS_PATH_DEFAULT;
-        }
+        this.classPath = PropertiesUtil.toString(properties.get(CLASS_PATH_PROP), CLASS_PATH_DEFAULT);
         if ( this.classPath.endsWith("/") ) {
             this.classPath = this.classPath.substring(0, this.classPath.length() - 1);
         }
+        if ( PropertiesUtil.toBoolean(properties.get(APPEND_ID_PROP), APPEND_ID_DEFAULT) ) {
+            this.classPath = this.classPath + '/' + this.settings.getSlingId();
+        }
 
-        prop = properties.get(OWNER_PROP);
-        this.classLoaderOwner = (prop instanceof String)? (String) prop : OWNER_DEFAULT;
+        this.classLoaderOwner = PropertiesUtil.toString(properties.get(OWNER_PROP), OWNER_DEFAULT);
 
         this.callerBundle = componentContext.getUsingBundle();
     }
@@ -330,7 +336,7 @@ public class ClassLoaderWriterImpl
                         // create the node "at the same time"
                         current = parentNode.addNode(names[i], NT_FOLDER);
                         session.save();
-                    } catch (RepositoryException re) {
+                    } catch (final RepositoryException re) {
                         // let's first refresh the session
                         // we don't catch an exception here, because if
                         // session refresh fails, we might have a serious problem!

Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoader.java?rev=1501227&r1=1501226&r2=1501227&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoader.java (original)
+++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoader.java Tue Jul  9 12:49:16 2013
@@ -86,7 +86,7 @@ public final class RepositoryClassLoader
      * repository path.
      *
      * @param classPath The path making up the class path of this class
-     *                  loder
+     *                  loader
      * @param writer The class loader write to get a jcr session.
      * @param parent The parent <code>ClassLoader</code>, which may be
      *      <code>null</code>.
@@ -148,6 +148,7 @@ public final class RepositoryClassLoader
      * @throws ClassNotFoundException If the named class could not be found or
      *      if this class loader has already been destroyed.
      */
+    @Override
     protected Class<?> findClass(final String name) throws ClassNotFoundException {
         if (!this.writer.isActivate()) {
             throw new ClassNotFoundException(name + " (Classloader destroyed)");
@@ -177,6 +178,7 @@ public final class RepositoryClassLoader
      *      if the resource could not be found or if the class loader has
      *      already been destroyed.
      */
+    @Override
     public URL findResource(final String name) {
         if (!this.writer.isActivate()) {
             logger.warn("Destroyed class loader cannot find a resource: " + name, new IllegalStateException());
@@ -208,6 +210,7 @@ public final class RepositoryClassLoader
      *      empty enumeration if no resources are found by this class loader
      *      or if this class loader has already been destroyed.
      */
+    @Override
     public Enumeration<URL> findResources(final String name) {
         if (!this.writer.isActivate()) {
             logger.warn("Destroyed class loader cannot find a resources: " + name, new IllegalStateException());
@@ -395,6 +398,7 @@ public final class RepositoryClassLoader
     /**
      * Returns a string representation of this class loader.
      */
+    @Override
     public String toString() {
         StringBuilder buf = new StringBuilder(getClass().getName());
         if (destroyed) {

Modified: sling/trunk/bundles/jcr/classloader/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1501227&r1=1501226&r2=1501227&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ sling/trunk/bundles/jcr/classloader/src/main/resources/OSGI-INF/metatype/metatype.properties Tue Jul  9 12:49:16 2013
@@ -32,10 +32,13 @@ classpath.description = The class path i
  with the same class path. This class path must include any destinations used \
  by Java compilers writing to the Repository such as the JSP Script Handler, \
  which by default writes to "/var/classes". If no class path is defined, the \
- "/var/classes" folder is used by default.
+ "/var/classes" folder is used by default. See also "Append Sling ID below".
 
 owner.name = Repository Session User
 owner.description = Name of a user owning the Repository Class Loader sessions. \
  If this is empty a simple administrative session is used. Otherwise the \
  administrative session is used to impersonate as the given user.
  
+appendId.name = Append Sling ID
+appendId.description = If this flag is enabled, the Sling ID is appended to the path \
+ to store/read class files from.
\ No newline at end of file