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

Elias Ross genman at noderunner.net
Tue Feb 6 21:21:14 EST 2007


  User: genman  
  Date: 07/02/06 21:21:14

  Modified:    src/org/jboss/cache/interceptors 
                        DataGravitatorInterceptor.java
  Log:
  Minor code clean-up
  
  Revision  Changes    Path
  1.39      +42 -56    JBossCache/src/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DataGravitatorInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/DataGravitatorInterceptor.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -b -r1.38 -r1.39
  --- DataGravitatorInterceptor.java	29 Jan 2007 18:08:00 -0000	1.38
  +++ DataGravitatorInterceptor.java	7 Feb 2007 02:21:14 -0000	1.39
  @@ -114,10 +114,10 @@
                     {
                        // create node locally so I don't gravitate again
                        // when I do the put() call to the cluster!
  -                     createNode(true, data.backupData);
  +                     createNode(data.backupData, true);
                        // Make sure I replicate to my buddies.
                        log.trace("Passing the put call locally to make sure state is persisted and ownership is correctly established.");
  -                     createNode(false, data.backupData);
  +                     createNode(data.backupData, false);
   
                        // Clean up the other nodes
                        cleanBackupData(data);
  @@ -235,16 +235,15 @@
   
         BackupData result = null;
   
  -      Object[] resp = gravitateData(name);
  +      GravitateResult gr = gravitateData(name);
   
  -      if (resp[0] != null)
  +      if (gr.isDataFound())
         {
            if (log.isTraceEnabled())
            {
  -            log.trace("Got response " + resp[0]);
  +            log.trace("Got response " + gr);
            }
   
  -         List nodes = null;
   //         if (configuration.isUseRegionBasedMarshalling())
   //         {
   //            ClassLoader cl = Thread.currentThread().getContextClassLoader();
  @@ -265,11 +264,9 @@
   //         }
   //         else
   //         {
  -            nodes = (List) resp[0];
   //         }
   
  -         Fqn bkup = (Fqn) resp[1];
  -         result = new BackupData(name, bkup, nodes);
  +         result = new BackupData(name, gr);
         }
   
         return result;
  @@ -317,7 +314,7 @@
         }
      }
   
  -   private Object[] gravitateData(Fqn fqn) throws Exception
  +   private GravitateResult gravitateData(Fqn fqn) throws Exception
      {
         if (log.isTraceEnabled())
         {
  @@ -327,21 +324,20 @@
         Boolean searchSubtrees = (buddyManager.isDataGravitationSearchBackupTrees() ? Boolean.TRUE : Boolean.FALSE);
         MethodCall dGrav = MethodCallFactory.create(MethodDeclarations.dataGravitationMethod, fqn, searchSubtrees);
         List resps = cache.getRPCManager().callRemoteMethods(mbrs, dGrav, GroupRequest.GET_FIRST, true, buddyManager.getBuddyCommunicationTimeout());
  +      if (log.isTraceEnabled())
  +      {
  +         log.trace("got responses " + resps);
  +      }
         if (resps == null)
         {
            log.error("No replies to call " + dGrav + ".  Perhaps we're alone in the cluster?");
  -         return new Object[]{null, null};
  +         return GravitateResult.noDataFound();
         }
  -      else
  -      {
  -         // test for and remove exceptions
  -         Iterator i = resps.iterator();
  -         Object result = null;
  -         Object backupFqn = null;
   
  -         while (i.hasNext())
  +      // test for and remove exceptions
  +      GravitateResult result = GravitateResult.noDataFound();
  +      for (Object o : resps)
            {
  -            Object o = i.next();
               if (o instanceof Throwable)
               {
                  if (log.isDebugEnabled())
  @@ -351,13 +347,9 @@
               }
               else if (o != null)
               {
  -               // keep looping till we find a FOUND answer.
  -               GravitateResult dGravResp = (GravitateResult) o;
  -               // found?
  -               if (dGravResp.isDataFound())
  +            result = (GravitateResult) o;
  +            if (result.isDataFound())
                  {
  -                  result = dGravResp.getNodeData();
  -                  backupFqn = dGravResp.getBuddyBackupFqn();
                     break;
                  }
               }
  @@ -371,18 +363,13 @@
   
            }
   
  -         if (log.isTraceEnabled()) log.trace("got responses " + resps);
  -         return new Object[]{result, backupFqn};
  -      }
  +      return result;
      }
   
  -   private void createNode(boolean localOnly, List nodeData) throws CacheException
  +   private void createNode(List<NodeData> nodeData, boolean localOnly) throws CacheException
      {
  -      Iterator nodes = nodeData.iterator();
  -
  -      while (nodes.hasNext())
  +      for (NodeData data : nodeData)
         {
  -         NodeData data = (NodeData) nodes.next();
            if (localOnly)
            {
               if (cache.peek(data.getFqn(), false) == null)
  @@ -458,8 +445,7 @@
         if (found)
         {
            Fqn backupFqn = result.getBuddyBackupFqn();
  -         List nodeData = result.getNodeData();
  -         data = new BackupData(fqn, backupFqn, nodeData);
  +         data = new BackupData(fqn, result);
            // now the cleanup
            if (buddyManager.isDataGravitationRemoveOnFind())
            {
  @@ -487,13 +473,13 @@
      {
         Fqn primaryFqn;
         Fqn backupFqn;
  -      List backupData;
  +      List<NodeData> backupData;
   
  -      BackupData(Fqn primary, Fqn backup, List data)
  +      public BackupData(Fqn primaryFqn, GravitateResult gr)
         {
  -         this.primaryFqn = primary;
  -         this.backupFqn = backup;
  -         this.backupData = data;
  +         this.primaryFqn = primaryFqn;
  +         this.backupFqn = gr.getBuddyBackupFqn();
  +         this.backupData = gr.getNodeData();
         }
      }
   
  
  
  



More information about the jboss-cvs-commits mailing list