geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1165547 - in /geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2: Axis2SystemInitializer.java osgi/GeronimoBundleClassFinder.java
Date Tue, 06 Sep 2011 07:54:19 GMT
Author: xuhaihong
Date: Tue Sep  6 07:54:19 2011
New Revision: 1165547

URL: http://svn.apache.org/viewvc?rev=1165547&view=rev
Log:
GERONIMO-6147
a. Cache the jaxb classes searching result in Axis2 BundleClassFinder - ASF JIRA
b. Come up a quick fix for jaxb class not found while equonix jar urlclassloader is enabled

Modified:
    geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2SystemInitializer.java
    geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/osgi/GeronimoBundleClassFinder.java

Modified: geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2SystemInitializer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2SystemInitializer.java?rev=1165547&r1=1165546&r2=1165547&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2SystemInitializer.java
(original)
+++ geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2SystemInitializer.java
Tue Sep  6 07:54:19 2011
@@ -38,6 +38,8 @@ public class Axis2SystemInitializer impl
 
     private ServiceReference packageAdminServiceReference;
 
+    private GeronimoBundleClassFinder bundleClassFinder;
+
     public Axis2SystemInitializer(@ParamSpecial(type = SpecialAttributeType.bundleContext)
BundleContext bundleContext) {
         this.bundleContext = bundleContext;
     }
@@ -55,7 +57,9 @@ public class Axis2SystemInitializer impl
         packageAdminServiceReference = bundleContext.getServiceReference(PackageAdmin.class.getName());
         PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminServiceReference);
         ClassFinderFactory classFinderFactory = (ClassFinderFactory) FactoryRegistry.getFactory(ClassFinderFactory.class);
-        classFinderFactory.setClassFinder(new GeronimoBundleClassFinder(packageAdmin));
+        bundleClassFinder = new GeronimoBundleClassFinder(packageAdmin);
+        classFinderFactory.setClassFinder(bundleClassFinder);
+        bundleContext.addBundleListener(bundleClassFinder);
     }
 
     @Override
@@ -68,6 +72,7 @@ public class Axis2SystemInitializer impl
             } catch (Exception e) {
             }
         }
+        bundleContext.removeBundleListener(bundleClassFinder);
     }
 
 }

Modified: geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/osgi/GeronimoBundleClassFinder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/osgi/GeronimoBundleClassFinder.java?rev=1165547&r1=1165546&r2=1165547&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/osgi/GeronimoBundleClassFinder.java
(original)
+++ geronimo/server/trunk/plugins/axis2/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/osgi/GeronimoBundleClassFinder.java
Tue Sep  6 07:54:19 2011
@@ -18,7 +18,9 @@
 package org.apache.geronimo.axis2.osgi;
 
 import java.util.ArrayList;
+import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.axis2.jaxws.message.databinding.ClassFinder;
 import org.apache.xbean.osgi.bundle.util.BundleClassFinder;
@@ -26,6 +28,8 @@ import org.apache.xbean.osgi.bundle.util
 import org.apache.xbean.osgi.bundle.util.ClassDiscoveryFilter;
 import org.apache.xbean.osgi.bundle.util.DiscoveryRange;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,10 +37,12 @@ import org.slf4j.LoggerFactory;
 /**
  * @version $Rev$ $Date$
  */
-public class GeronimoBundleClassFinder implements ClassFinder {
+public class GeronimoBundleClassFinder implements ClassFinder, SynchronousBundleListener
{
 
     private static final Logger logger = LoggerFactory.getLogger(GeronimoBundleClassFinder.class);
 
+    private Map<Long, Map<String, Set<String>>> bundleIdPackageClassNamesMap
= new ConcurrentHashMap<Long, Map<String, Set<String>>>();
+
     private PackageAdmin packageAdmin;
 
     public GeronimoBundleClassFinder(PackageAdmin packageAdmin) {
@@ -44,40 +50,80 @@ public class GeronimoBundleClassFinder i
     }
 
     @Override
+    public void bundleChanged(BundleEvent event) {
+        if (event.getType() == BundleEvent.UPDATED || event.getType() == BundleEvent.UNINSTALLED)
{
+            bundleIdPackageClassNamesMap.remove(event.getBundle().getBundleId());
+        }
+    }
+
+    @Override
     public ArrayList<Class> getClassesFromJarFile(final String packageName, ClassLoader
cl) throws ClassNotFoundException {
         Bundle bundle = BundleUtils.getBundle(cl, true);
         if (bundle == null) {
-            return new ArrayList<Class>();
-        }
-        //TODO Do we need to limit the scanning scope in the target application ? As we share
one bundle for all the sub modules except for car
-        BundleClassFinder bundleClassFinder = new BundleClassFinder(packageAdmin, bundle,
new ClassDiscoveryFilter() {
-
-            @Override
-            public boolean directoryDiscoveryRequired(String directory) {
-                return true;
+            //Special actions due to the comments below. While Equinox Jar ClassLoader is
enabled, we might got problems
+            //--- Quoted from org.apache.axis2.jaxws.server.JAXWSMessageReceiver
+            // we need to merge the deployment class loader to the TCCL. This is because,
in JAX-WS
+            // services, there can be situations where we have to load classes from the deployment
+            // artifact (JAX-WS jar file) in the message flow. Ex: Handler classes in the
service
+            // artifact. Adding this as a fix for AXIS2-4930.
+            //---
+            bundle = BundleUtils.getBundle(cl.getParent(), true);
+            if (bundle == null) {
+                return new ArrayList<Class>();
             }
-
-            @Override
-            public boolean jarFileDiscoveryRequired(String jarFile) {
-                return true;
-            }
-
-            @Override
-            public boolean packageDiscoveryRequired(String p) {
-                return p.equals(packageName);
+        }
+        Long bundleId = bundle.getBundleId();
+        Map<String, Set<String>> packageClassNamesMap = bundleIdPackageClassNamesMap.get(bundleId);
+        Set<String> classNames = null;
+        if (packageClassNamesMap == null) {
+            synchronized (bundleIdPackageClassNamesMap) {
+                packageClassNamesMap = bundleIdPackageClassNamesMap.get(bundleId);
+                if (packageClassNamesMap == null) {
+                    packageClassNamesMap = new ConcurrentHashMap<String, Set<String>>();
+                    bundleIdPackageClassNamesMap.put(bundleId, packageClassNamesMap);
+                }
             }
+        } else {
+            classNames = packageClassNamesMap.get(packageName);
+        }
 
-            @Override
-            public boolean rangeDiscoveryRequired(DiscoveryRange discoveryRange) {
-                return discoveryRange == DiscoveryRange.BUNDLE_CLASSPATH;
+        if (classNames == null) {
+            synchronized (packageClassNamesMap) {
+                classNames = packageClassNamesMap.get(packageName);
+                if (classNames == null) {
+                    //TODO Do we need to limit the scanning scope in the target application
? As we share one bundle for all the sub modules except for car
+                    BundleClassFinder bundleClassFinder = new BundleClassFinder(packageAdmin,
bundle, new ClassDiscoveryFilter() {
+
+                        @Override
+                        public boolean directoryDiscoveryRequired(String directory) {
+                            return true;
+                        }
+
+                        @Override
+                        public boolean jarFileDiscoveryRequired(String jarFile) {
+                            return true;
+                        }
+
+                        @Override
+                        public boolean packageDiscoveryRequired(String p) {
+                            return p.equals(packageName);
+                        }
+
+                        @Override
+                        public boolean rangeDiscoveryRequired(DiscoveryRange discoveryRange)
{
+                            return discoveryRange == DiscoveryRange.BUNDLE_CLASSPATH;
+                        }
+                    });
+                    classNames = bundleClassFinder.find();
+                    packageClassNamesMap.put(packageName, classNames);
+                }
             }
-        });
-        Set<String> classNames = bundleClassFinder.find();
-        ArrayList<Class> clses = new ArrayList<Class>(classNames.size());
+        }
+        ArrayList clses = new ArrayList<Class>(classNames.size());
         for (String className : classNames) {
             try {
                 Class<?> cls = bundle.loadClass(className);
-                //Invoke getConstructors() to force the classloader to resolve the target
class 
+                //Invoke getConstructors() to force the classloader to resolve the target
class
                 cls.getConstructors();
                 clses.add(cls);
             } catch (Throwable e) {



Mime
View raw message