incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r794169 - in /sling/trunk/bundles/extensions/event: ./ src/main/java/org/apache/sling/event/ src/main/java/org/apache/sling/event/impl/
Date Wed, 15 Jul 2009 07:52:30 GMT
Author: cziegeler
Date: Wed Jul 15 07:52:30 2009
New Revision: 794169

URL: http://svn.apache.org/viewvc?rev=794169&view=rev
Log:
SLING-1046 : Use commons class loader instead of dynamic import package *.

Modified:
    sling/trunk/bundles/extensions/event/pom.xml
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobBlockingQueue.java

Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=794169&r1=794168&r2=794169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Wed Jul 15 07:52:30 2009
@@ -61,8 +61,6 @@
                             org.apache.sling.event.impl,
                             org.apache.jackrabbit.util
                         </Private-Package>
-                        <!-- We need the dynamic import as events can contain any classes
-->
-                        <DynamicImport-Package>*</DynamicImport-Package>
                         <Sling-Nodetypes>
                             SLING-INF/nodetypes/event.cnd
                         </Sling-Nodetypes>
@@ -131,6 +129,11 @@
             <version>2.0.2-incubator</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.classloader</artifactId>
+            <version>0.9.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=794169&r1=794168&r2=794169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
Wed Jul 15 07:52:30 2009
@@ -21,7 +21,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.ObjectInputStream;
+import java.io.InputStream;
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -612,4 +612,29 @@
         buffer.append("]");
         return buffer.toString();
     }
-}
+
+    /**
+     * This is an extended version of the object input stream which uses the
+     * thread context class loader.
+     */
+    private static class ObjectInputStream extends java.io.ObjectInputStream {
+
+        private ClassLoader classloader;
+
+        public ObjectInputStream(InputStream in) throws IOException {
+            super(in);
+            this.classloader = Thread.currentThread().getContextClassLoader();
+        }
+
+        /**
+         * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
+         */
+        @Override
+        protected Class<?> resolveClass(java.io.ObjectStreamClass classDesc) throws
IOException, ClassNotFoundException {
+            if ( this.classloader != null ) {
+                return Class.forName(classDesc.getName(), true, this.classloader);
+            }
+            return super.resolveClass(classDesc);
+        }
+    }
+}
\ No newline at end of file

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=794169&r1=794168&r2=794169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
Wed Jul 15 07:52:30 2009
@@ -29,6 +29,7 @@
 import javax.jcr.Session;
 import javax.jcr.observation.EventListener;
 
+import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
 import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.engine.SlingSettingsService;
 import org.apache.sling.event.EventPropertiesMap;
@@ -78,7 +79,7 @@
     protected String repositoryPath;
 
     /** Is the background task still running? */
-    protected boolean running;
+    protected volatile boolean running;
 
     /** A local queue for serialising the event processing. */
     protected final BlockingQueue<EventInfo> queue = new LinkedBlockingQueue<EventInfo>();
@@ -86,6 +87,9 @@
     /** A local queue for writing received events into the repository. */
     protected final BlockingQueue<Event> writeQueue = new LinkedBlockingQueue<Event>();
 
+    /** @scr.reference */
+    protected DynamicClassLoaderManager classLoaderManager;
+
     /**
      * Our thread pool.
      * @scr.reference */
@@ -288,20 +292,26 @@
      */
     protected Event readEvent(Node eventNode)
     throws RepositoryException, ClassNotFoundException {
-        final String topic = eventNode.getProperty(EventHelper.NODE_PROPERTY_TOPIC).getString();
-        final EventPropertiesMap eventProps = EventUtil.readProperties(eventNode,
-                EventHelper.NODE_PROPERTY_PROPERTIES,
-                IGNORE_PREFIXES);
-
-        eventProps.put(JobStatusProvider.PROPERTY_EVENT_ID, eventNode.getPath());
-        this.addEventProperties(eventNode, eventProps);
+        final ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
         try {
-            final Event event = new Event(topic, eventProps);
-            return event;
-        } catch (IllegalArgumentException iae) {
-            // this exception occurs if the topic is not correct (it should never happen,
-            // but you never know)
-            throw new RepositoryException("Unable to read event: " + iae.getMessage(), iae);
+            Thread.currentThread().setContextClassLoader(this.classLoaderManager.getDynamicClassLoader());
+            final String topic = eventNode.getProperty(EventHelper.NODE_PROPERTY_TOPIC).getString();
+            final EventPropertiesMap eventProps = EventUtil.readProperties(eventNode,
+                    EventHelper.NODE_PROPERTY_PROPERTIES,
+                    IGNORE_PREFIXES);
+
+            eventProps.put(JobStatusProvider.PROPERTY_EVENT_ID, eventNode.getPath());
+            this.addEventProperties(eventNode, eventProps);
+            try {
+                final Event event = new Event(topic, eventProps);
+                return event;
+            } catch (IllegalArgumentException iae) {
+                // this exception occurs if the topic is not correct (it should never happen,
+                // but you never know)
+                throw new RepositoryException("Unable to read event: " + iae.getMessage(),
iae);
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldCL);
         }
     }
 

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobBlockingQueue.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobBlockingQueue.java?rev=794169&r1=794168&r2=794169&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobBlockingQueue.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobBlockingQueue.java
Wed Jul 15 07:52:30 2009
@@ -28,20 +28,20 @@
  */
 public final class JobBlockingQueue extends LinkedBlockingQueue<EventInfo> {
 
-    private EventInfo eventInfo;
+    private volatile EventInfo eventInfo;
 
     private final Object lock = new Object();
 
-    private boolean isWaiting = false;
+    private volatile boolean isWaiting = false;
 
-    private boolean markForCleanUp = false;
+    private volatile boolean markForCleanUp = false;
 
-    private boolean finished = false;
+    private volatile boolean finished = false;
 
-    private boolean isSleeping = false;
+    private volatile boolean isSleeping = false;
 
-    private String schedulerJobName;
-    private Thread sleepingThread;
+    private volatile String schedulerJobName;
+    private volatile Thread sleepingThread;
 
     public EventInfo waitForFinish() throws InterruptedException {
         this.isWaiting = true;



Mime
View raw message