[jboss-cvs] JBossAS SVN: r107159 - projects/cluster/ha-client/trunk/src/main/java/org/jboss/ha/framework/interfaces.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 28 11:14:50 EDT 2010


Author: pferraro
Date: 2010-07-28 11:14:50 -0400 (Wed, 28 Jul 2010)
New Revision: 107159

Modified:
   projects/cluster/ha-client/trunk/src/main/java/org/jboss/ha/framework/interfaces/ClusteringTargetsRepository.java
Log:
Optimized for concurrency.

Modified: projects/cluster/ha-client/trunk/src/main/java/org/jboss/ha/framework/interfaces/ClusteringTargetsRepository.java
===================================================================
--- projects/cluster/ha-client/trunk/src/main/java/org/jboss/ha/framework/interfaces/ClusteringTargetsRepository.java	2010-07-28 15:02:49 UTC (rev 107158)
+++ projects/cluster/ha-client/trunk/src/main/java/org/jboss/ha/framework/interfaces/ClusteringTargetsRepository.java	2010-07-28 15:14:50 UTC (rev 107159)
@@ -21,8 +21,9 @@
  */ 
 package org.jboss.ha.framework.interfaces;
 
-import java.util.Hashtable;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 /**
  * JVM singleton that associates a list of targets (+ other info) 
@@ -51,16 +52,16 @@
    
    // Attributes ----------------------------------------------------
    
-   protected static Hashtable families = new Hashtable ();
+   private static ConcurrentMap<String, FamilyClusterInfo> families = new ConcurrentHashMap<String, FamilyClusterInfo>();
    
    // Static --------------------------------------------------------
    
    /**
     * Same as {@link #initTarget(String, List, long) initTarget(familyName, targets, 0L)}
     */
-   public synchronized static FamilyClusterInfo initTarget (String familyName, List targets)
+   public static FamilyClusterInfo initTarget(String familyName, @SuppressWarnings("rawtypes") List targets)
    {
-      return initTarget (familyName, targets, 0L);
+      return initTarget(familyName, targets, 0L);
    }
    
    /**
@@ -79,26 +80,24 @@
     *                    
     * @return a {@link FamilyClusterInfo} encapsulating the current state of the <code>familyName</code>.
     */
-   public synchronized static FamilyClusterInfo initTarget (String familyName, List targets, long viewId)
+   public static FamilyClusterInfo initTarget(String familyName, @SuppressWarnings("rawtypes") List targets, long viewId)
    {
       // this method must be somehow synchronized to avoid multiple FamilyClusterInfoImpl 
       // for the same familyName in multi-threaded app accessing the same bean
-      //
-      FamilyClusterInfoImpl family = (FamilyClusterInfoImpl)families.get (familyName);
-      if (family == null)
+      FamilyClusterInfo existing = families.get(familyName);
+      
+      if (existing == null)
       {
-         family = new FamilyClusterInfoImpl (familyName, targets, viewId);
-         families.put (familyName, family);         
-      }
-      else
-      {
-         // no need to initialize: it is already done: we keep the same object
-         //
-         family.updateClusterInfo (targets, viewId); // should not happen: possible if redeploy after undeploy fails
-      }
+         FamilyClusterInfo family = new FamilyClusterInfoImpl(familyName, targets, viewId);
          
-      return family;
+         existing = families.putIfAbsent(familyName, family);
          
+         if (existing == null) return family;
+      }
+      
+      existing.updateClusterInfo(targets, viewId); // should not happen: possible if redeploy after undeploy fails
+      
+      return existing;
    }
    
    /**
@@ -108,28 +107,13 @@
     * 
     * @return the FamilyClusterInfo, or <code>null</code> if none is registered
     */
-   public static FamilyClusterInfo getFamilyClusterInfo (String familyName)
+   public static FamilyClusterInfo getFamilyClusterInfo(String familyName)
    {
-      return (FamilyClusterInfo)families.get (familyName);
+      return families.get(familyName);
    }
    
    // Constructors --------------------------------------------------
    
    /** Prevent external instantiation */
    private ClusteringTargetsRepository () {}
-   
-   // Public --------------------------------------------------------
-   
-   // Z implementation ----------------------------------------------
-   
-   // Y overrides ---------------------------------------------------
-   
-   // Package protected ---------------------------------------------
-   
-   // Protected -----------------------------------------------------
-   
-   // Private -------------------------------------------------------
-   
-   // Inner classes -------------------------------------------------
-   
 }



More information about the jboss-cvs-commits mailing list