cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/2] git commit: No need to lock for the getClassObject call once the class is loaded. Removes most locking in most cases within ExtensionManagerImpl.
Date Tue, 12 Aug 2014 16:15:32 GMT
No need to lock for the getClassObject call once the class is loaded.  Removes most locking
in most cases within ExtensionManagerImpl.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/cdcccb9e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/cdcccb9e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/cdcccb9e

Branch: refs/heads/master
Commit: cdcccb9e278404fed32af38afc60fe47554009ac
Parents: 4cf959b
Author: Daniel Kulp <dkulp@apache.org>
Authored: Tue Aug 12 11:54:47 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Tue Aug 12 12:15:03 2014 -0400

----------------------------------------------------------------------
 .../org/apache/cxf/bus/extension/Extension.java | 19 +++--
 .../cxf/bus/extension/ExtensionManagerImpl.java | 75 ++++++++++----------
 2 files changed, 51 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/cdcccb9e/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/bus/extension/Extension.java b/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
index 85e0860..81cd8aa 100644
--- a/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
+++ b/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
@@ -37,8 +37,8 @@ public class Extension {
     
     protected String className;
     protected ClassLoader classloader;
-    protected Class<?> clazz;
-    protected Class<?> intf;
+    protected volatile Class<?> clazz;
+    protected volatile Class<?> intf;
     protected String interfaceName;
     protected boolean deferred;
     protected Collection<String> namespaces = new ArrayList<String>();
@@ -191,8 +191,13 @@ public class Extension {
         if (notFound) {
             return null;
         }
-        if (clazz == null) {
-            clazz = tryClass(className, cl);
+        if (clazz != null) {
+            return clazz;
+        }
+        synchronized (this) {
+            if (clazz == null) {
+                clazz = tryClass(className, cl);
+            }
         }
         return clazz;
     }
@@ -287,7 +292,11 @@ public class Extension {
         if (intf != null || notFound) {
             return intf;
         }
-        intf = tryClass(interfaceName, cl);
+        synchronized (this) {
+            if (intf == null) {
+                intf = tryClass(interfaceName, cl);
+            }
+        }
         return intf;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/cdcccb9e/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java b/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
index 79b88a6..620a7b9 100644
--- a/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
+++ b/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
@@ -134,9 +134,9 @@ public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLoc
     public <T> void activateAllByType(Class<T> type) {
         for (Extension e : all.values()) {
             if (e.getLoadedObject() == null) {
-                synchronized (e) {
-                    Class<?> cls = e.getClassObject(loader);
-                    if (cls != null && type.isAssignableFrom(cls)) {
+                Class<?> cls = e.getClassObject(loader);
+                if (cls != null && type.isAssignableFrom(cls)) {
+                    synchronized (e) {
                         loadAndRegister(e);
                     }
                 }
@@ -191,18 +191,17 @@ public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLoc
     }
 
     final void loadAndRegister(Extension e) {
+        Class<?> cls = null;
+        if (null != e.getInterfaceName() && !"".equals(e.getInterfaceName())) {
+            cls = e.loadInterface(loader);
+        }  else {
+            cls = e.getClassObject(loader);
+        }
+        if (null != activated && null != cls && null != activated.get(cls))
{
+            return;
+        }
+        
         synchronized (e) {
-            Class<?> cls = null;
-            if (null != e.getInterfaceName() && !"".equals(e.getInterfaceName()))
{
-                cls = e.loadInterface(loader);
-            }  else {
-                cls = e.getClassObject(loader);
-            }
-    
-            if (null != activated && null != cls && null != activated.get(cls))
{
-                return;
-            }
-            
             Object obj = e.load(loader, bus);
             if (obj == null) {
                 return;
@@ -255,10 +254,9 @@ public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLoc
         }
         Extension e = all.get(name);
         if (e != null) {
-            synchronized (e) {
-                Class<?> cls = e.getClassObject(loader);
-            
-                if (cls != null && type.isAssignableFrom(e.getClassObject(loader)))
{
+            Class<?> cls = e.getClassObject(loader);
+            if (cls != null && type.isAssignableFrom(cls)) {
+                synchronized (e) {
                     if (e.getLoadedObject() == null) {
                         loadAndRegister(e);
                     }
@@ -295,9 +293,9 @@ public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLoc
     public List<String> getBeanNamesOfType(Class<?> type) {
         List<String> ret = new LinkedList<String>();
         for (Extension ex : all.values()) {
-            synchronized (ex) {
-                Class<?> cls = ex.getClassObject(loader);
-                if (cls != null && type.isAssignableFrom(cls)) {
+            Class<?> cls = ex.getClassObject(loader);
+            if (cls != null && type.isAssignableFrom(cls)) {
+                synchronized (ex) {
                     ret.add(ex.getName());
                 }
             }            
@@ -321,9 +319,9 @@ public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLoc
         List<T> ret = new LinkedList<T>();
         Extension ext = all.get(type.getName());
         if (ext != null) {
-            synchronized (ext) {
-                Class<?> cls = ext.getClassObject(loader);
-                if (cls != null && type.isAssignableFrom(cls)) {
+            Class<?> cls = ext.getClassObject(loader);
+            if (cls != null && type.isAssignableFrom(cls)) {
+                synchronized (ext) {
                     if (ext.getLoadedObject() == null) {
                         loadAndRegister(ext);
                     }
@@ -333,9 +331,9 @@ public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLoc
         }
         for (Extension ex : all.values()) {
             if (ex != ext) {
-                synchronized (ex) {
-                    Class<?> cls = ex.getClassObject(loader);
-                    if (cls != null && type.isAssignableFrom(cls)) {
+                Class<?> cls = ex.getClassObject(loader);
+                if (cls != null && type.isAssignableFrom(cls)) {
+                    synchronized (ex) {
                         if (ex.getLoadedObject() == null) {
                             loadAndRegister(ex);
                         }
@@ -349,18 +347,19 @@ public class ExtensionManagerImpl implements ExtensionManager, ConfiguredBeanLoc
     public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T>
listener) {
         boolean loaded = false;
         for (Extension ex : all.values()) {
-            synchronized (ex) {
-                Class<?> cls = ex.getClassObject(loader);
-                if (cls != null 
-                    && type.isAssignableFrom(cls)
-                    && listener.loadBean(ex.getName(), cls.asSubclass(type))) {
-                    if (ex.getLoadedObject() == null) {
-                        loadAndRegister(ex);
-                    }
-                    if (listener.beanLoaded(ex.getName(), type.cast(ex.getLoadedObject())))
{
-                        return true;
+            Class<?> cls = ex.getClassObject(loader);
+            if (cls != null 
+                && type.isAssignableFrom(cls)) {
+                synchronized (ex) {
+                    if (listener.loadBean(ex.getName(), cls.asSubclass(type))) {
+                        if (ex.getLoadedObject() == null) {
+                            loadAndRegister(ex);
+                        }
+                        if (listener.beanLoaded(ex.getName(), type.cast(ex.getLoadedObject())))
{
+                            return true;
+                        }
+                        loaded = true;
                     }
-                    loaded = true;
                 }
             }
         }


Mime
View raw message