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

Brian Stansberry brian.stansberry at jboss.com
Mon Nov 6 16:12:48 EST 2006


  User: bstansberry
  Date: 06/11/06 16:12:48

  Modified:    src/org/jboss/cache  Tag: Branch_JBossCache_1_4_0
                        TreeCache.java
  Log:
  [JBCACHE-824] Don't call Channel.getView() in viewAccepted() callback
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.195.2.17 +44 -47    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.195.2.16
  retrieving revision 1.195.2.17
  diff -u -b -r1.195.2.16 -r1.195.2.17
  --- TreeCache.java	3 Nov 2006 21:21:26 -0000	1.195.2.16
  +++ TreeCache.java	6 Nov 2006 21:12:47 -0000	1.195.2.17
  @@ -99,7 +99,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.195.2.16 2006/11/03 21:21:26 bstansberry Exp $
  + * @version $Id: TreeCache.java,v 1.195.2.17 2006/11/06 21:12:47 bstansberry Exp $
    *          <p/>
    * @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
    */
  @@ -485,7 +485,7 @@
      }
   
      /**
  -    * Returns true if this is the group coordinator.
  +    * Returns <code>true</code> if this node is the group coordinator.
       */
      public boolean isCoordinator()
      {
  @@ -1495,7 +1495,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();
      }
   
  @@ -1711,23 +1714,15 @@
         }
      }
   
  -   /**
  -    * Returns true if this TreeCache is the coordinator.
  -    */
      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;
  +      }
      }
   
      /**
  @@ -1736,12 +1731,25 @@
       */
      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 -----------------------
  @@ -3215,24 +3223,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())
            {
  @@ -5389,12 +5384,14 @@
               needNotification = true;
            }
   
  -         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()));
   
            // now notify listeners - *after* updating the coordinator. - JBCACHE-662 
            if (needNotification) notifyViewChange(new_view);
   
  -         // 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