[jboss-dev-forums] [JBoss Microcontainer Development] New message: "Re: Profiling the dependency project"

Kabir Khan do-not-reply at jboss.com
Mon Feb 22 10:43:17 EST 2010


JBoss development,

A new message was posted in the thread "Profiling the dependency project":

http://community.jboss.org/message/527633#527633

Author  : Kabir Khan
Profile : http://community.jboss.org/people/kabir.khan@jboss.com

Message:
--------------------------------------------------------------
I tried a few different things, none of which really made a difference, so I have stuck with more or less what we had, but making sure we access the (un)installCallbacks in a thread safe way:
 
===================================================================
--- dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java     (revision 101181)
+++ dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java     (working copy)
@@ -23,6 +23,7 @@
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -107,8 +108,8 @@
    private final Set<AbstractController> childControllers = new CopyOnWriteArraySet<AbstractController>();
 
    /** The callback items */
-   private final Map<Object, Set<CallbackItem<?>>> installCallbacks = new ConcurrentHashMap<Object, Set<CallbackItem<?>>>();
-   private final Map<Object, Set<CallbackItem<?>>> uninstallCallbacks = new ConcurrentHashMap<Object, Set<CallbackItem<?>>>();
+   private final Map<Object, Set<CallbackItem<?>>> installCallbacks = new HashMap<Object, Set<CallbackItem<?>>>();
+   private final Map<Object, Set<CallbackItem<?>>> uninstallCallbacks = new HashMap<Object, Set<CallbackItem<?>>>();
 
    /** Whether an on demand context has been enabled */
    private boolean onDemandEnabled = true;
@@ -1831,14 +1832,20 @@
     * @param isInstallPhase install or uninstall phase
     * @return all matching registered callbacks or empty set if no such item
     */ 
-   protected Set<CallbackItem<?>> getCallbacks(Object name, boolean isInstallPhase)
+   protected Set<CallbackItem<?>> getCallbacks(Set<CallbackItem<?>> result, Object name, boolean isInstallPhase)
    {
       lockRead();
       try
       {
          Map<Object, Set<CallbackItem<?>>> map = (isInstallPhase ? installCallbacks : uninstallCallbacks);
          Set<CallbackItem<?>> callbacks = map.get(name);
-         return callbacks != null ? callbacks : Collections.<CallbackItem<?>>emptySet();
+         if (callbacks != null)
+         {
+            if (result == null)
+               result = new HashSet<CallbackItem<?>>();
+            result.addAll(callbacks);
+         }
+         return result;
       }
       finally
       {
@@ -1910,20 +1917,16 @@
          if (dependencyInfo != null && dependencyInfo.isAutowireCandidate())
          {
             // match callbacks by name
-            existingCallbacks = new HashSet<CallbackItem<?>>();
-            existingCallbacks.addAll(getCallbacks(context.getName(), isInstallPhase));
+            existingCallbacks = getCallbacks(existingCallbacks, context.getName(), isInstallPhase);
             // match by classes
             Collection<Class<?>> classes = getExposedClasses(context);
             if (classes != null && classes.isEmpty() == false)
             {
                for (Class<?> clazz : classes)
                {
-                  existingCallbacks.addAll(getCallbacks(clazz, isInstallPhase));
+                  existingCallbacks = getCallbacks(existingCallbacks, clazz, isInstallPhase);
                }
             }
-            
-            if (existingCallbacks.isEmpty())
-               existingCallbacks = null;
          }
          
          if (installs != null || uninstalls != null || existingCallbacks != null)
 
 


--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/527633#527633




More information about the jboss-dev-forums mailing list