[jboss-cvs] JBossAS SVN: r109380 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 19 00:21:40 EST 2010


Author: pferraro
Date: 2010-11-19 00:21:39 -0500 (Fri, 19 Nov 2010)
New Revision: 109380

Modified:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java
Log:
Add batching to ViewChangeListener.
Remove batching from getSessionData(...).

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java	2010-11-18 22:59:28 UTC (rev 109379)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java	2010-11-19 05:21:39 UTC (rev 109380)
@@ -281,7 +281,7 @@
       
       try
       {
-         return this.batch(operation);
+         return this.invoker.invoke(this.sessionCache, operation);
       }
       catch (Exception e)
       {
@@ -562,9 +562,36 @@
       this.manager.sessionActivated();
    }
    
+   private <R> R batch(Operation<R> operation)
+   {
+      boolean started = this.sessionCache.startBatch();
+      boolean success = false;
+      
+      try
+      {
+         R result = this.invoker.invoke(this.sessionCache, operation);
+         
+         success = true;
+         
+         return result;
+      }
+      finally
+      {
+         if (started)
+         {
+            this.sessionCache.endBatch(success);
+         }
+      }
+   }
+   
    @Listener(sync = false)
    public static class JvmRouteHandler
    {
+      // Simplified CacheInvoker.Operation using assigned key/value types
+      static interface Operation<R> extends CacheInvoker.Operation<Address, String, R>
+      {
+      }
+      
       private final LocalDistributableSessionManager manager;
       private final CacheSource source;
       
@@ -574,72 +601,81 @@
          this.manager = manager;
       }
       
-      public Cache<Address, String> getCache()
+      Cache<Address, String> getCache()
       {
          return this.source.getCache(this.manager);
       }
       
-      @ViewChanged
-      public void viewChanged(ViewChangedEvent event)
+      <R> R batch(Operation<R> operation)
       {
-         Collection<Address> oldMembers = event.getOldMembers();
-         Collection<Address> newMembers = event.getNewMembers();
-         
          Cache<Address, String> cache = this.getCache();
+         boolean started = cache.startBatch();
+         boolean success = false;
          
-         // Remove jvm route of crashed member
-         for (Address member: oldMembers)
+         try
          {
-            if (!newMembers.contains(member))
+            R result = operation.invoke(cache);
+            
+            success = true;
+            
+            return result;
+         }
+         finally
+         {
+            if (started)
             {
-               if (cache.remove(member) != null)
-               {
-                  log.info("Removed stale jvm route entry from web session cache on behalf of member " + member);
-               }
+               cache.endBatch(success);
             }
          }
+      }
+      
+      @ViewChanged
+      public void viewChanged(final ViewChangedEvent event)
+      {
+         final Collection<Address> oldMembers = event.getOldMembers();
+         final Collection<Address> newMembers = event.getNewMembers();
+         final String jvmRoute = this.manager.getJvmRoute();
          
-         // Restore our jvm route in cache if we are joining (result of a split/merge)
-         String jvmRoute = this.manager.getJvmRoute();
-         if (jvmRoute != null)
+         Operation<Void> operation = new Operation<Void>()
          {
-            Address localAddress = event.getLocalAddress();
-            if (!oldMembers.contains(localAddress) && newMembers.contains(localAddress))
+            @Override
+            public Void invoke(Cache<Address, String> cache)
             {
-               String oldJvmRoute = cache.put(localAddress, jvmRoute);
-               if (oldJvmRoute == null)
+               // Remove jvm route of crashed member
+               for (Address member: oldMembers)
                {
-                  log.info("Adding missing jvm route entry to web session cache");
+                  if (!newMembers.contains(member))
+                  {
+                     if (cache.remove(member) != null)
+                     {
+                        log.info("Removed stale jvm route entry from web session cache on behalf of member " + member);
+                     }
+                  }
                }
-               else if (!oldJvmRoute.equals(jvmRoute))
+               
+               // Restore our jvm route in cache if we are joining (result of a split/merge)
+               if (jvmRoute != null)
                {
-                  log.info("Updating jvm route entry in web session cache.  old = " + oldJvmRoute + ", new = " + jvmRoute);
+                  Address localAddress = event.getLocalAddress();
+                  if (!oldMembers.contains(localAddress) && newMembers.contains(localAddress))
+                  {
+                     String oldJvmRoute = cache.put(localAddress, jvmRoute);
+                     if (oldJvmRoute == null)
+                     {
+                        log.info("Adding missing jvm route entry to web session cache");
+                     }
+                     else if (!oldJvmRoute.equals(jvmRoute))
+                     {
+                        log.info("Updating jvm route entry in web session cache.  old = " + oldJvmRoute + ", new = " + jvmRoute);
+                     }
+                  }
                }
+               return null;
             }
-         }
-      }
-   }
-   
-   private <R> R batch(Operation<R> operation)
-   {
-      boolean started = this.sessionCache.startBatch();
-      boolean success = false;
-      
-      try
-      {
-         R result = this.invoker.invoke(this.sessionCache, operation);
+         };
          
-         success = true;
-         
-         return result;
+         this.batch(operation);
       }
-      finally
-      {
-         if (started)
-         {
-            this.sessionCache.endBatch(success);
-         }
-      }
    }
    
    private static void trace(String message, Object... args)

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java	2010-11-18 22:59:28 UTC (rev 109379)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java	2010-11-19 05:21:39 UTC (rev 109380)
@@ -235,9 +235,7 @@
       
       Capture<DistributedCacheManager.Operation<IncomingDistributableSessionData>> capturedOperation = new Capture<DistributedCacheManager.Operation<IncomingDistributableSessionData>>();
       
-      EasyMock.expect(this.sessionCache.startBatch()).andReturn(true);
       EasyMock.expect(this.invoker.invoke(EasyMock.same(this.sessionCache), EasyMock.capture(capturedOperation))).andReturn(data);
-      this.sessionCache.endBatch(true);
       
       this.control.replay();
       
@@ -317,9 +315,7 @@
       IncomingDistributableSessionData expected = this.control.createMock(IncomingDistributableSessionData.class);
       Capture<DistributedCacheManager.Operation<IncomingDistributableSessionData>> capturedOperation = new Capture<DistributedCacheManager.Operation<IncomingDistributableSessionData>>();
       
-      EasyMock.expect(this.sessionCache.startBatch()).andReturn(true);
       EasyMock.expect(this.invoker.invoke(EasyMock.same(this.sessionCache), EasyMock.capture(capturedOperation))).andReturn(expected);
-      this.sessionCache.endBatch(true);
       
       this.control.replay();
       
@@ -741,6 +737,8 @@
       DistributedCacheManager.JvmRouteHandler handler = this.start(ComponentStatus.RUNNING, false);
       
       EasyMock.expect(this.jvmRouteCacheSource.<Address, String>getCache(this.sessionManager)).andReturn(jvmRouteCache);
+
+      EasyMock.expect(jvmRouteCache.startBatch()).andReturn(true);
       
       EasyMock.expect(event.getOldMembers()).andReturn(Arrays.asList(member, oldMember));
       EasyMock.expect(event.getNewMembers()).andReturn(Arrays.asList(member, newMember));
@@ -749,6 +747,8 @@
       EasyMock.expect(event.getLocalAddress()).andReturn(newMember);
       EasyMock.expect(this.sessionManager.getJvmRoute()).andReturn(jvmRoute);
       EasyMock.expect(jvmRouteCache.put(EasyMock.same(newMember), EasyMock.same(jvmRoute))).andReturn(null);
+
+      jvmRouteCache.endBatch(true);
       
       this.control.replay();
       



More information about the jboss-cvs-commits mailing list