You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ch...@apache.org on 2007/03/07 13:28:58 UTC

svn commit: r515549 - in /webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send: algorithms/RoundRobin.java endpoints/FailoverEndpoint.java endpoints/LoadbalanceEndpoint.java

Author: chathura_ce
Date: Wed Mar  7 04:28:57 2007
New Revision: 515549

URL: http://svn.apache.org/viewvc?view=rev&rev=515549
Log:
Improved the failover behavior of endpoints according to the FaultHandler stack model.

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java?view=diff&rev=515549&r1=515548&r2=515549
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java Wed Mar  7 04:28:57 2007
@@ -35,7 +35,8 @@
     }
 
     /**
-     * Choose an active endpoint using the round robin algorithm.
+     * Choose an active endpoint using the round robin algorithm. If there are no active endpoints
+     * available, returns null.
      *
      * @param synapseMessageContext
      * @return endpoint to send the next message
@@ -56,7 +57,7 @@
 
             attempts++;
             if (attempts > endpoints.size()) {
-                throw new SynapseException("All endpoints have failed.");
+                return null;
             }
 
         } while (!nextEndpoint.isActive());

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java?view=diff&rev=515549&r1=515548&r2=515549
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java Wed Mar  7 04:28:57 2007
@@ -20,9 +20,18 @@
 package org.apache.synapse.mediators.builtin.send.endpoints;
 
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.FaultHandler;
 
 import java.util.ArrayList;
 
+/**
+ * FailoverEndpoint can have multiple child endpoints. It will always try to send messages to current
+ * endpoint. If the current endpoint is failing, it gets another active endpoint from the list and
+ * make it the current endpoint. Then the message is sent to the current endpoint and if it fails, above
+ * procedure repeats until there are no active endpoints. If all endpoints are failing and parent
+ * endpoint is available, this will delegate the problem to the parent endpoint. If parent endpoint
+ * is not available it will pop the next FaultHandler and delegate the problem to that.
+ */
 public class FailoverEndpoint implements Endpoint {
 
     private String name = null;
@@ -52,6 +61,11 @@
             if (!foundEndpoint) {
                 if (parentEndpoint != null) {
                     parentEndpoint.onChildEndpointFail(this, synMessageContext);
+                } else {
+                    Object o = synMessageContext.getFaultStack().pop();
+                    if (o != null) {
+                        ((FaultHandler) o).handleFault(synMessageContext);
+                    }
                 }
             }
         }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java?view=diff&rev=515549&r1=515548&r2=515549
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java Wed Mar  7 04:28:57 2007
@@ -20,10 +20,20 @@
 package org.apache.synapse.mediators.builtin.send.endpoints;
 
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.FaultHandler;
 import org.apache.synapse.mediators.builtin.send.algorithms.LoadbalanceAlgorithm;
 
 import java.util.ArrayList;
 
+/**
+ * Load balance endpoint can have multiple endpoints. It will route messages according to the
+ * specified loadbalance algorithm. This will assume that all immediate child endpoints are identical
+ * in state (state is replicated) or state is not maintained at those endpoints. If an endpoint is
+ * failing, the failed endpoint is marked as inactive and the message to the next endpoint obtained
+ * using the loadbalance algorithm. If all the endpoints have failed and the parent endpoint is
+ * available, onChildEndpointFail(...) methos of parent endpoint is called. If parent is not
+ * avialable, this will call next FaultHandler for the message context.
+ */
 public class LoadbalanceEndpoint implements Endpoint {
 
     private ArrayList endpoints = null;
@@ -38,7 +48,16 @@
     public void send(MessageContext synMessageContext) {
 
         Endpoint endpoint = algorithm.getNextEndpoint(synMessageContext);
-        endpoint.send(synMessageContext);
+        if (endpoint != null) {
+            endpoint.send(synMessageContext);
+        } else {
+            if (parentEndpoint != null) {
+                parentEndpoint.onChildEndpointFail(this, synMessageContext);
+            } else {
+                Object o = synMessageContext.getFaultStack().pop();
+                ((FaultHandler) o).handleFault(synMessageContext);
+            }
+        }
     }
 
     public String getName() {



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