User: slaboure Date: 02/02/27 03:06:13 Modified: src/main/org/jboss/ha/framework/server DistributedReplicantManagerImpl.java Log: - added new "intra-view id" to detect changes even when no modification in the cluster occurs (e.g. only an app is undeployed) - changed ArrayList to List in interface Revision Changes Path 1.14 +82 -10 jbossmx/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java Index: DistributedReplicantManagerImpl.java =================================================================== RCS file: /cvsroot/jboss/jbossmx/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- DistributedReplicantManagerImpl.java 17 Feb 2002 03:34:27 -0000 1.13 +++ DistributedReplicantManagerImpl.java 27 Feb 2002 11:06:12 -0000 1.14 @@ -14,6 +14,7 @@ import java.util.Iterator; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.io.Serializable; @@ -28,7 +29,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Bill Burke</a>. * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>. - * @version $Revision: 1.13 $ + * @version $Revision: 1.14 $ * * <p><b>Revisions:</b><br> * <p><b>2001/10/31: marcf</b> @@ -59,13 +60,16 @@ protected HashMap localReplicants = new HashMap(); protected HashMap replicants = new HashMap(); protected HashMap keyListeners = new HashMap(); - protected HAPartition partition; + protected HashMap intraviewIdCache = new HashMap(); + protected HAPartition partition; protected Logger log; protected javax.management.MBeanServer mbeanserver; protected javax.management.ObjectName jmxName; + protected String nodeName = null; + // Static -------------------------------------------------------- // Constructors -------------------------------------------------- @@ -80,6 +84,8 @@ this.partition = partition; this.mbeanserver = server; this.log = Logger.getLogger(partition.getPartitionName() + ":ReplicantManager"); + + this.nodeName = this.partition.getNodeName (); } // Public -------------------------------------------------------- @@ -182,7 +188,7 @@ if (local != null) { result.append ("\t\t<Location>\n"); - result.append ("\t\t\t<Name local=\"True\">").append (this.partition.getNodeName ()).append ("</Name>\n"); + result.append ("\t\t\t<Name local=\"True\">").append (this.nodeName).append ("</Name>\n"); result.append ("\t\t</Location>\n"); } @@ -233,7 +239,7 @@ public void add(String key, Serializable replicant) throws Exception { Object[] args = - {key, partition.getNodeName(), replicant}; + {key, this.nodeName, replicant}; partition.callAsynchMethodOnCluster(SERVICE_NAME, "_add", args, true); synchronized(localReplicants) { @@ -244,7 +250,7 @@ public void remove(String key) throws Exception { - Object[] args = {key, partition.getNodeName()}; + Object[] args = {key, this.nodeName}; partition.callAsynchMethodOnCluster(SERVICE_NAME, "_remove", args, true); synchronized(localReplicants) { @@ -261,7 +267,7 @@ } } - public ArrayList lookupReplicants(String key) + public List lookupReplicants(String key) { Serializable local = lookupLocalReplicant(key); synchronized(replicants) @@ -275,6 +281,20 @@ } } + public List lookupReplicantsNodeNames(String key) + { + boolean locallyReplicated = localReplicants.containsKey (key); + synchronized(replicants) + { + HashMap replicant = (HashMap)replicants.get(key); + if (replicant == null && !locallyReplicated) return null; + ArrayList rtn = new ArrayList(); + if (locallyReplicated) rtn.add(this.nodeName); + if (replicant != null) rtn.addAll(replicant.keySet ()); + return rtn; + } + } + public void registerListener(String key, DistributedReplicantManager.ReplicantListener subscriber) { @@ -304,6 +324,16 @@ } } + public int getReplicantsViewId(String key) + { + Integer result = (Integer)this.intraviewIdCache.get (key); + + if (result == null) + return 0; + else + return result.intValue (); + } + // DistributedReplicantManager cluster callbacks ---------------------------------------------- /** @@ -367,7 +397,7 @@ */ public Object[] lookupLocalReplicants() throws Exception { - Object[] rtn = {partition.getNodeName(), localReplicants}; + Object[] rtn = {this.nodeName, localReplicants}; return rtn; } @@ -375,6 +405,44 @@ // Protected ----------------------------------------------------- + protected int calculateReplicantsHash (List members) + { + int result = 0; + Object obj = null; + + for (int i=0; i<members.size (); i++) + { + obj = members.get (i); + if (obj != null) + result+= obj.hashCode (); // no explicit overflow with int addition + } + + return result; + } + + protected int updateReplicantsHashId (String key) + { + // we first get a list of all nodes names that replicate this key + // + List nodes = this.lookupReplicantsNodeNames (key); + int result = 0; + + if ( (nodes == null) || (nodes.size () == 0) ) + { + // no nore replicants for this key: we uncache our view id + // + this.intraviewIdCache.remove (key); + } + else + { + result = this.calculateReplicantsHash (nodes); + this.intraviewIdCache.put (key, new Integer (result)); + } + + return result; + + } + /////////////// // DistributedReplicantManager API /////////////// @@ -408,7 +476,7 @@ rep = new HashMap(); map.put(key, rep); } - rep.put(nodeName, replicant); + rep.put(nodeName, replicant); } } @@ -440,11 +508,15 @@ * @param key The replicant key name * @param newReplicants The new list of replicants */ - protected void notifyKeyListeners(String key, ArrayList newReplicants) + protected void notifyKeyListeners(String key, List newReplicants) { log.debug("notifyKeyListeners"); synchronized(keyListeners) { + // we first update the intra-view id for this particular key + // + int newId = updateReplicantsHashId (key); + ArrayList listeners = (ArrayList)keyListeners.get(key); if (listeners == null) { @@ -457,7 +529,7 @@ for (int i = 0; i < listeners.size(); i++) { DistributedReplicantManager.ReplicantListener listener = (DistributedReplicantManager.ReplicantListener)listeners.get(i); - listener.replicantsChanged(key, newReplicants); + listener.replicantsChanged(key, newReplicants, newId); } } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development