tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r532400 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes: ChannelException.java transport/nio/ParallelNioSender.java
Date Wed, 25 Apr 2007 16:16:38 GMT
Author: fhanik
Date: Wed Apr 25 09:16:37 2007
New Revision: 532400

URL: http://svn.apache.org/viewvc?view=rev&rev=532400
Log:
Fix error handling when a single failure occurs

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/ChannelException.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/ParallelNioSender.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/ChannelException.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/ChannelException.java?view=diff&rev=532400&r1=532399&r2=532400
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/ChannelException.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/ChannelException.java Wed Apr 25
09:16:37 2007
@@ -31,6 +31,10 @@
  */
 
 public class ChannelException extends Exception {
+    /**
+     * Empty list to avoid reinstatiating lists
+     */
+    protected static final FaultyMember[] EMPTY_LIST = new FaultyMember[0];
     /*
      * Holds a list of faulty members
      */
@@ -96,27 +100,30 @@
      * @param mbr Member
      * @param x Exception
      */
-    public void addFaultyMember(Member mbr, Exception x ) {
-        addFaultyMember(new FaultyMember(mbr,x));
+    public boolean addFaultyMember(Member mbr, Exception x ) {
+        return addFaultyMember(new FaultyMember(mbr,x));
     }
     
     /**
      * Adds a list of faulty members
      * @param mbrs FaultyMember[]
      */
-    public void addFaultyMember(FaultyMember[] mbrs) {
+    public int addFaultyMember(FaultyMember[] mbrs) {
+        int result = 0;
         for (int i=0; mbrs!=null && i<mbrs.length; i++ ) {
-            addFaultyMember(mbrs[i]);
+            if ( addFaultyMember(mbrs[i]) ) result++;
         }
+        return result;
     }
 
     /**
      * Adds a faulty member
      * @param mbr FaultyMember
      */
-    public void addFaultyMember(FaultyMember mbr) {
+    public boolean addFaultyMember(FaultyMember mbr) {
         if ( this.faultyMembers==null ) this.faultyMembers = new ArrayList();
-        faultyMembers.add(mbr);
+        if ( !faultyMembers.contains(mbr) ) return faultyMembers.add(mbr);
+        else return false;
     }
     
     /**
@@ -124,7 +131,7 @@
      * @return FaultyMember[]
      */
     public FaultyMember[] getFaultyMembers() {
-        if ( this.faultyMembers==null ) return new FaultyMember[0];
+        if ( this.faultyMembers==null ) return EMPTY_LIST;
         return (FaultyMember[])faultyMembers.toArray(new FaultyMember[faultyMembers.size()]);
     }
     
@@ -156,6 +163,15 @@
         
         public String toString() {
             return "FaultyMember:"+member.toString();
+        }
+        
+        public int hashCode() {
+            return (member!=null)?member.hashCode():0;
+        }
+        
+        public boolean equals(Object o) {
+            if (member==null || (!(o instanceof FaultyMember)) || (((FaultyMember)o).member==null))
return false;
+            return member.equals(((FaultyMember)o).member);
         }
     }
 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/ParallelNioSender.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/ParallelNioSender.java?view=diff&rev=532400&r1=532399&r2=532400
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/ParallelNioSender.java
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/transport/nio/ParallelNioSender.java
Wed Apr 25 09:16:37 2007
@@ -77,12 +77,15 @@
                 try {
                     remaining -= doLoop(selectTimeout, getMaxRetryAttempts(),waitForAck,msg);
                 } catch (Exception x ) {
+                    int faulty = (cx == null)?0:cx.getFaultyMembers().length;
                     if ( cx == null ) {
                         if ( x instanceof ChannelException ) cx = (ChannelException)x;
                         else cx = new ChannelException("Parallel NIO send failed.", x);
                     } else {
                         if (x instanceof ChannelException) cx.addFaultyMember( ( (ChannelException)
x).getFaultyMembers());
                     }
+                    //count down the remaining on an error
+                    if (faulty<cx.getFaultyMembers().length) remaining -= (cx.getFaultyMembers().length-faulty);
                 }
                 //bail out if all remaining senders are failing
                 if ( cx != null && cx.getFaultyMembers().length == remaining ) throw
cx;
@@ -90,10 +93,14 @@
             }
             if ( remaining > 0 ) {
                 //timeout has occured
-                cx = new ChannelException("Operation has timed out("+getTimeout()+" ms.).");
+                ChannelException cxtimeout = new ChannelException("Operation has timed out("+getTimeout()+"
ms.).");
+                if ( cx==null ) cx = new ChannelException("Operation has timed out("+getTimeout()+"
ms.).");
                 for (int i=0; i<senders.length; i++ ) {
-                    if (!senders[i].isComplete() ) cx.addFaultyMember(senders[i].getDestination(),null);
+                    if (!senders[i].isComplete() ) cx.addFaultyMember(senders[i].getDestination(),cxtimeout);
                 }
+                throw cx;
+            } else if ( cx != null ) {
+                //there was an error
                 throw cx;
             }
         } catch (Exception x ) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message