Only lock when incrementing the counter on sending messages, can be further optimized...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 21 May 2007 09:14:08 +0000 (09:14 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 21 May 2007 09:14:08 +0000 (09:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@540077 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/tribes/group/interceptors/OrderInterceptor.java

index 02597ae..7dc2d43 100644 (file)
@@ -69,21 +69,29 @@ public class OrderInterceptor extends ChannelInterceptorBase {
             super.sendMessage(destination, msg, payload);
             return;
         }
-        try {
-            outLock.writeLock().lock();
-            for ( int i=0; i<destination.length; i++ ) {
-                int nr = incCounter(destination[i]);
+        ChannelException cx = null;
+        for (int i=0; i<destination.length; i++ ) {
+            try {
+                int nr = 0;
+                try {
+                    outLock.writeLock().lock();
+                    nr = incCounter(destination[i]);
+                } finally {
+                    outLock.writeLock().unlock();
+                }
                 //reduce byte copy
                 msg.getMessage().append(nr);
                 try {
                     getNext().sendMessage(new Member[] {destination[i]}, msg, payload);
-                }finally {
+                } finally {
                     msg.getMessage().trim(4);
                 }
+            }catch ( ChannelException x ) {
+                if ( cx == null ) cx = x;
+                cx.addFaultyMember(x.getFaultyMembers());
             }
-        }finally {
-            outLock.writeLock().unlock();
-        }
+        }//for
+        if ( cx != null ) throw cx;
     }
 
     public void messageReceived(ChannelMessage msg) {