[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Thu Nov 23 13:08:22 EST 2006
User: msurtani
Date: 06/11/23 13:08:22
Modified: src/org/jboss/cache Tag: Branch_JBossCache_1_3_0
TreeCache.java
Log:
Backported JBCACHE-824 and JBCACHE-836
Revision Changes Path
No revision
No revision
1.142.2.1 +49 -42 JBossCache/src/org/jboss/cache/TreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
retrieving revision 1.142
retrieving revision 1.142.2.1
diff -u -b -r1.142 -r1.142.2.1
--- TreeCache.java 1 Apr 2006 00:45:38 -0000 1.142
+++ TreeCache.java 23 Nov 2006 18:08:22 -0000 1.142.2.1
@@ -60,7 +60,7 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: TreeCache.java,v 1.142 2006/04/01 00:45:38 genman Exp $
+ * @version $Id: TreeCache.java,v 1.142.2.1 2006/11/23 18:08:22 msurtani Exp $
* <p/>
*/
public class TreeCache extends ServiceMBeanSupport implements TreeCacheMBean, Cloneable, MembershipListener
@@ -1340,7 +1340,9 @@
cacheLoaderManager.preloadCache();
}
- coordinator = determineCoordinator();
+ // Find out if we are coordinator (blocks until view is received)
+ determineCoordinator();
+
notifyCacheStarted();
}
@@ -1388,6 +1390,8 @@
if (members != null && members.size() > 0)
members.clear();
+ coordinator = false;
+
if (repl_queue != null)
repl_queue.stop();
@@ -1458,28 +1462,40 @@
protected boolean determineCoordinator()
{
- if (channel == null)
- return false;
- Object local_addr = getLocalAddress();
- if (local_addr == null)
- return false;
- View view = channel.getView();
- if (view == null) return false;
- ViewId vid = view.getVid();
- if (vid == null) return false;
- Object coord = vid.getCoordAddress();
- if (coord == null) return false;
- return local_addr.equals(coord);
+ // Synchronize on members to make the answer atomic for the current view
+ synchronized (members)
+ {
+ Address coord = getCoordinator();
+ coordinator = (coord == null ? false : coord.equals(getLocalAddress()));
+ return coordinator;
+ }
}
+ /**
+ * Returns the address of the coordinator or null if there is no
+ * coordinator.
+ */
public Address getCoordinator()
{
- if (channel == null) return null;
- View view = channel.getView();
- if (view == null) return null;
- ViewId vid = view.getVid();
- if (vid == null) return null;
- return vid.getCoordAddress();
+ if (channel == null)
+ return null;
+
+ synchronized (members)
+ {
+ if (members.size() == 0)
+ {
+ log.debug("getCoordinator(): waiting on viewAccepted()");
+ try
+ {
+ members.wait();
+ }
+ catch (InterruptedException iex)
+ {
+ log.error("getCoordinator(): Interrupted while waiting for members to be set", iex);
+ }
+ }
+ return members.size() > 0 ? (Address) members.get(0) : null;
+ }
}
// ----------- Marshalling and State Transfer -----------------------
@@ -2723,22 +2739,11 @@
}
else
{
- // No one provided us with state.
- // We need to find out if we are the coordinator, so we must
- // block until viewAccepted() is called at least once
-
- synchronized (members)
- {
- while (members.size() == 0)
- {
- log.debug("waiting on viewAccepted()");
- try {
- members.wait();
- }
- catch(InterruptedException iex) {
- }
- }
- }
+ // No one provided us with state. We need to find out if that's because
+ // we are the coordinator. But we don't know if the viewAccepted() callback
+ // has been invoked, so call determineCoordinator(), which will block until
+ // viewAccepted() is called at least once
+ determineCoordinator();
if (isCoordinator())
{
@@ -4651,9 +4656,11 @@
notifyViewChange(new_view);
}
- coordinator=determineCoordinator();
+ // Now that we have a view, figure out if we are the coordinator
+ coordinator = (members.size() == 0 ? false : members.get(0).equals(getLocalAddress()));
- // Wake up any thread waiting in fetchStateOnStartup
+ // Wake up any threads that are waiting to know who the members
+ // are so they can figure out who the coordinator is
members.notifyAll();
}
}
More information about the jboss-cvs-commits
mailing list