[jboss-cvs] JBossCache/src/org/jboss/cache ...

Brian Stansberry brian.stansberry at jboss.com
Tue Nov 7 13:22:58 EST 2006


  User: bstansberry
  Date: 06/11/07 13:22:58

  Modified:    src/org/jboss/cache  Tag: JBossCache_1_3_0_SP3_JBCACHE-837
                        TreeCache.java
  Log:
  [JBCACHE-837] Port JBCACHE-836 patch to 1.3.0.SP3
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.142.4.1 +51 -43    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.4.1
  diff -u -b -r1.142 -r1.142.4.1
  --- TreeCache.java	1 Apr 2006 00:45:38 -0000	1.142
  +++ TreeCache.java	7 Nov 2006 18:22:58 -0000	1.142.4.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.4.1 2006/11/07 18:22:58 bstansberry Exp $
    *          <p/>
    */
   public class TreeCache extends ServiceMBeanSupport implements TreeCacheMBean, Cloneable, MembershipListener
  @@ -1340,7 +1340,10 @@
            cacheLoaderManager.preloadCache();
         }
   
  -      coordinator = determineCoordinator();
  +      // Find out if we are coordinator (blocks until view is received)
  +      // TODO should this be moved above the buddy manager code??
  +      determineCoordinator();
  +      
         notifyCacheStarted();
      }
   
  @@ -1388,6 +1391,8 @@
         if (members != null && members.size() > 0)
            members.clear();
   
  +      coordinator = false;
  +
         if (repl_queue != null)
            repl_queue.stop();
   
  @@ -1458,28 +1463,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 +2740,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 +4657,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