You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/02/25 21:19:57 UTC

svn commit: r630979 - in /servicemix/smx4/nmr/trunk/jbi: deployer/src/main/java/org/apache/servicemix/jbi/deployer/ deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ runtime/

Author: gnodet
Date: Mon Feb 25 12:19:42 2008
New Revision: 630979

URL: http://svn.apache.org/viewvc?rev=630979&view=rev
Log:
Use synchronous calls when deploying/undeploying JBI artifacts to avoid deadlocks, use a single classloader for a SL

Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java
    servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java?rev=630979&r1=630978&r2=630979&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java Mon Feb 25 12:19:42 2008
@@ -44,6 +44,6 @@
      * Create a classloader for this shared library
      * @return a new classloader
      */
-    //ClassLoader createClassLoader();
+    ClassLoader getClassLoader();
     
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java?rev=630979&r1=630978&r2=630979&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractBundleWatcher.java Mon Feb 25 12:19:42 2008
@@ -18,6 +18,8 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -59,7 +61,9 @@
         Bundle[] bundles = bundleContext.getBundles();
         if (bundles != null) {
             for (Bundle bundle : bundles) {
-                onBundleStarted(bundle);
+                if (bundle.getState() == Bundle.ACTIVE) {
+                    onBundleStarted(bundle);
+                }
             }
         }
     }
@@ -67,9 +71,7 @@
     public void destroy() throws Exception {
         bundleContext.removeBundleListener(bundleListener);
         for (Bundle bundle : bundles.toArray(new Bundle[bundles.size()])) {
-            if (bundle.getState() == Bundle.ACTIVE) {
-                onBundleStopped(bundle);
-            }
+            onBundleStopped(bundle);
         }
     }
 

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=630979&r1=630978&r2=630979&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java Mon Feb 25 12:19:42 2008
@@ -122,7 +122,7 @@
     }
 
     @Override
-    protected synchronized void register(Bundle bundle) {
+    protected void register(Bundle bundle) {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
@@ -334,19 +334,15 @@
     protected void uninstallSharedLibrary(SharedLibraryDesc sharedLibraryDesc, Bundle bundle) throws JBIException {
     }
 
-    protected synchronized void checkPendingBundles() {
+    protected void checkPendingBundles() {
         if (!pendingBundles.isEmpty()) {
             final List<Bundle> pending = pendingBundles;
             pendingBundles = new ArrayList<Bundle>();
-            Thread th = new Thread() {
-                public void run() {
-                    for (Bundle bundle : pending) {
-                        register(bundle);
-                    }
-                }
-            };
-            th.setDaemon(true);
-            th.start();
+            // Synchronous call because if using a separate thread
+            // we run into deadlocks
+            for (Bundle bundle : pending) {
+                register(bundle);
+            }
         }
     }
 
@@ -407,7 +403,7 @@
     protected ClassLoader getSharedLibraryClassLoader(SharedLibraryList sharedLibraryList) {
         SharedLibraryImpl sl = sharedLibraries.get(sharedLibraryList.getName());
         if (sl != null) {
-            return sl.createClassLoader();
+            return sl.getClassLoader();
         } else {
             throw new IllegalStateException("SharedLibrary not installed: " + sharedLibraryList.getName());
         }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java?rev=630979&r1=630978&r2=630979&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java Mon Feb 25 12:19:42 2008
@@ -32,6 +32,7 @@
 
     private SharedLibraryDesc library;
     private Bundle bundle;
+    private ClassLoader classLoader;
 
     public SharedLibraryImpl(SharedLibraryDesc library, Bundle bundle) {
         this.library = library;
@@ -50,25 +51,28 @@
         return library.getVersion();
     }
 
-    public ClassLoader createClassLoader() {
-        // Make the current ClassLoader the parent
-        ClassLoader parent = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle, getClass().getClassLoader());
-        boolean parentFirst = library.isParentFirstClassLoaderDelegation();
-        ClassPath cp = library.getSharedLibraryClassPath();
-        String[] classPathNames = cp.getPathElements();
-        URL[] urls = new URL[classPathNames.length];
-        for (int i = 0; i < classPathNames.length; i++) {
-            urls[i] = bundle.getResource(classPathNames[i]);
-            if (urls[i] == null) {
-                throw new IllegalArgumentException("SharedLibrary classpath entry not found: '" +  classPathNames[i] + "'");
+    public ClassLoader getClassLoader() {
+        if (classLoader == null) {
+            // Make the current ClassLoader the parent
+            ClassLoader parent = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle, getClass().getClassLoader());
+            boolean parentFirst = library.isParentFirstClassLoaderDelegation();
+            ClassPath cp = library.getSharedLibraryClassPath();
+            String[] classPathNames = cp.getPathElements();
+            URL[] urls = new URL[classPathNames.length];
+            for (int i = 0; i < classPathNames.length; i++) {
+                urls[i] = bundle.getResource(classPathNames[i]);
+                if (urls[i] == null) {
+                    throw new IllegalArgumentException("SharedLibrary classpath entry not found: '" +  classPathNames[i] + "'");
+                }
             }
+            classLoader = new MultiParentClassLoader(
+                            library.getIdentification().getName(),
+                            urls,
+                            parent,
+                            !parentFirst,
+                            new String[0],
+                            new String[] {"java.", "javax." });
         }
-        return new MultiParentClassLoader(
-                        library.getIdentification().getName(),
-                        urls,
-                        parent,
-                        !parentFirst,
-                        new String[0],
-                        new String[] {"java.", "javax." });
+        return classLoader;
     }
 }

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml?rev=630979&r1=630978&r2=630979&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml Mon Feb 25 12:19:42 2008
@@ -106,7 +106,6 @@
                     <instructions>
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                         <Export-Package>${pom.artifactId}*</Export-Package>
-                        <DynamicImport-Package>*</DynamicImport-Package>
                     </instructions>
                 </configuration>
             </plugin>