You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2008/06/19 08:12:30 UTC

svn commit: r669395 - in /synapse/trunk/java: ./ modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ modules/core/src/main/java/org/apache/synapse/core/ modules/core/src/main/java/org/apache/synapse/core/axis2/ modules/core/src/main/jav...

Author: ruwan
Date: Wed Jun 18 23:12:29 2008
New Revision: 669395

URL: http://svn.apache.org/viewvc?rev=669395&view=rev
Log:
Committing for azeez (SYNAPSE-360) with some changes to the patch :-)

Added:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DynamicLoadbalanceEndpointFactory.java   (with props)
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/LoadBalanceMembershipHandler.java   (with props)
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2LoadBalanceMembershipHandler.java   (with props)
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java   (with props)
    synapse/trunk/java/repository/conf/sample/synapse_sample_57.xml
      - copied, changed from r667460, synapse/trunk/java/repository/conf/sample/synapse_sample_52.xml
Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/LoadbalanceEndpoint.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/LoadbalanceAlgorithm.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java
    synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java
    synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2ServerManager.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ClientHandler.java
    synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
    synapse/trunk/java/pom.xml
    synapse/trunk/java/repository/conf/axis2.xml
    synapse/trunk/java/repository/conf/sample/resources/misc/server/axis2.xml
    synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DynamicLoadbalanceEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DynamicLoadbalanceEndpointFactory.java?rev=669395&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DynamicLoadbalanceEndpointFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DynamicLoadbalanceEndpointFactory.java Wed Jun 18 23:12:29 2008
@@ -0,0 +1,135 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.synapse.config.xml.endpoints;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.xml.XMLConfigConstants;
+import org.apache.synapse.config.xml.endpoints.utils.LoadbalanceAlgorithmFactory;
+import org.apache.synapse.core.LoadBalanceMembershipHandler;
+import org.apache.synapse.endpoints.DynamicLoadbalanceEndpoint;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ * Creates {@link DynamicLoadbalanceEndpoint} using an XML configuration.
+ *
+ * <pre>
+ * &lt;endpoint>
+ *       &lt;dynamicLoadbalance [failover="true|false"] [policy="load balance algorithm"]&gt;
+ *           &lt;membershipHandler
+ *                   class="HandlerClass"&gt;
+ *              &lt;property name="some name" value="some domain"/&gt;+
+ *           &lt;/membershipHandler&gt;
+ *       &lt;/dynamicLoadbalance&gt;
+ * &lt;/endpoint&gt;
+ * </pre>
+ */
+public class DynamicLoadbalanceEndpointFactory extends EndpointFactory {
+
+    private static final Log log = LogFactory.getLog(DynamicLoadbalanceEndpointFactory.class);
+    private static DynamicLoadbalanceEndpointFactory instance =
+            new DynamicLoadbalanceEndpointFactory();
+
+    private DynamicLoadbalanceEndpointFactory() {
+    }
+
+    public static DynamicLoadbalanceEndpointFactory getInstance() {
+        return instance;
+    }
+
+    protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint) {
+
+        OMElement loadbalanceElement =
+                epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE,
+                                                         "dynamicLoadbalance"));
+
+        if (loadbalanceElement != null) {
+
+            DynamicLoadbalanceEndpoint loadbalanceEndpoint = new DynamicLoadbalanceEndpoint();
+
+            // set endpoint name
+            OMAttribute name =
+                    epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
+
+            if (name != null) {
+                loadbalanceEndpoint.setName(name.getAttributeValue());
+            }
+
+            //TODO: Handle session affinity
+
+            // set if failover is turned off
+            String failover = loadbalanceElement.getAttributeValue(new QName("failover"));
+            if (failover != null && failover.equalsIgnoreCase("false")) {
+                loadbalanceEndpoint.setFailover(false);
+            }
+
+            OMElement eventHandler =
+                    loadbalanceElement.
+                            getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE,
+                                                            "membershipHandler"));
+            if (eventHandler != null) {
+                String clazz =
+                        eventHandler.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE,
+                                                                 "class")).trim();
+                try {
+                    LoadBalanceMembershipHandler lbMembershipHandler =
+                            (LoadBalanceMembershipHandler) Class.forName(clazz).newInstance();
+                    Properties properties = new Properties();
+                    for (Iterator props =
+                            eventHandler.getChildrenWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE,
+                                                                       "property"));
+                         props.hasNext();) {
+                        OMElement prop = (OMElement) props.next();
+                        String propName =
+                                prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE,
+                                                                 "name")).trim();
+                        String propValue =
+                                prop.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE,
+                                                                 "value")).trim();
+                        properties.put(propName, propValue);
+                    }
+
+                    // Set load balance algorithm
+                    LoadbalanceAlgorithm algorithm =
+                            LoadbalanceAlgorithmFactory.
+                                    createLoadbalanceAlgorithm(loadbalanceElement, null);
+                    lbMembershipHandler.init(properties, algorithm);
+                    loadbalanceEndpoint.setLoadBalanceMembershipHandler(lbMembershipHandler);
+                } catch (Exception e) {
+                    String msg = "Could not instantiate LoadBalanceMembershipHandler implementation " +
+                                 clazz;
+                    log.error(msg, e);
+                    throw new SynapseException(msg, e);
+                }
+            }
+
+            return loadbalanceEndpoint;
+        }
+        return null;
+    }
+}

Propchange: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DynamicLoadbalanceEndpointFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java Wed Jun 18 23:12:29 2008
@@ -31,7 +31,6 @@
 import org.apache.synapse.endpoints.Endpoint;
 import org.apache.synapse.endpoints.IndirectEndpoint;
 import org.apache.synapse.endpoints.utils.EndpointDefinition;
-import org.apache.synapse.util.PolicyInfo;
 
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
@@ -316,6 +315,13 @@
             }
         }
 
+        OMElement dlbElement = configElement.getFirstChildWithName
+                (new QName(SynapseConstants.SYNAPSE_NAMESPACE, "dynamicLoadbalance"));
+        if (dlbElement != null) {
+            //TODO: Handle Session affinitiy & failover
+            return DynamicLoadbalanceEndpointFactory.getInstance();
+        }
+
         OMElement foElement = configElement.getFirstChildWithName
                 (new QName(SynapseConstants.SYNAPSE_NAMESPACE, "failover"));
         if (foElement != null) {

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/LoadBalanceMembershipHandler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/LoadBalanceMembershipHandler.java?rev=669395&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/LoadBalanceMembershipHandler.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/LoadBalanceMembershipHandler.java Wed Jun 18 23:12:29 2008
@@ -0,0 +1,64 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.synapse.core;
+
+import org.apache.axis2.clustering.Member;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.synapse.endpoints.algorithms.AlgorithmContext;
+import org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * This interface is responsible for providing the next member to which a message has to be sent to.
+ * Generally, this interface will work with a GCF or other membership doscovery mechanism
+ */
+public interface LoadBalanceMembershipHandler {
+
+    /**
+     * Initialize this
+     *
+     * @param properties The properties specific to this LoadBalanceMembershipHandler
+     * @param algorithm  The load balancing algorithm
+     */
+    void init(Properties properties, LoadbalanceAlgorithm algorithm);
+
+    /**
+     * Set the Axis2 ConfigurationContext
+     *
+     * @param configCtx Axis2 ConfigurationContext
+     */
+    void setConfigurationContext(ConfigurationContext configCtx);
+
+    /**
+     * Get the Axis2 ConfigurationContext
+     *
+     * @return Axis2 ConfigurationContext
+     */
+    ConfigurationContext getConfigurationContext();
+
+    /**
+     * Get the next application member to whom the message has to be sent to
+     *
+     * @param context The AlgorithmContext which holds information needed for the algorithm
+     * @return Next application member to whom the message has to be sent to
+     */
+     Member getNextApplicationMember(AlgorithmContext context);
+
+}

Propchange: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/LoadBalanceMembershipHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2LoadBalanceMembershipHandler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2LoadBalanceMembershipHandler.java?rev=669395&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2LoadBalanceMembershipHandler.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2LoadBalanceMembershipHandler.java Wed Jun 18 23:12:29 2008
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.synapse.core.axis2;
+
+import org.apache.axis2.clustering.ClusterManager;
+import org.apache.axis2.clustering.LoadBalanceEventHandler;
+import org.apache.axis2.clustering.Member;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.core.LoadBalanceMembershipHandler;
+import org.apache.synapse.endpoints.algorithms.AlgorithmContext;
+import org.apache.synapse.endpoints.algorithms.LoadbalanceAlgorithm;
+
+import java.util.Properties;
+
+/**
+ * Bridge between Axis2 membership notification and Synapse load balancing
+ */
+public class Axis2LoadBalanceMembershipHandler implements LoadBalanceMembershipHandler{
+    private static final Log log = LogFactory.getLog(Axis2LoadBalanceMembershipHandler.class);
+
+    private String lbDomain;
+    private LoadBalanceEventHandler lbEventHandler;
+    private ConfigurationContext configCtx;
+    private LoadbalanceAlgorithm algorithm;
+
+    public void init(Properties props, LoadbalanceAlgorithm algorithm) {
+        this.lbDomain = props.getProperty("applicationDomain");
+        if(lbDomain == null){
+            String msg = "The applicationDomain property has not been specified in the " +
+                         "dynamicLoadbalance configuration in the synapse.xml file. This has " +
+                         "to be the same as the applicationDomain entry in the loadBalancer" +
+                         " entry in the axis2.xml file.";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+        this.algorithm = algorithm;
+    }
+
+    public void setConfigurationContext(ConfigurationContext configCtx) {
+        this.configCtx = configCtx;
+
+        // The following code does the bridging between Axis2 and Synapse load balancing
+        ClusterManager clusterManager = configCtx.getAxisConfiguration().getClusterManager();
+        if(clusterManager == null){
+            String msg = "In order to enable load balancing across an Axis2 cluster, " +
+                         "the cluster entry should be enabled in the axis2.xml file";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+        lbEventHandler = clusterManager.getLoadBalanceEventHandler(lbDomain);
+        if(lbEventHandler == null){
+            String msg =
+                    "A LoadBalanceEventHandler has not been specified in the axis2.xml " +
+                    "file for the domain " + lbDomain;
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+    }
+
+    public ConfigurationContext getConfigurationContext(){
+        return configCtx;
+    }
+
+    /**
+     * Getting the next member to which the request has to be sent in a round-robin fashion
+     *
+     * @param context The AlgorithmContext
+     * @return The current member
+     */
+    public Member getNextApplicationMember(AlgorithmContext context) {
+        algorithm.setApplicationMembers(lbEventHandler.getMembers());
+        return algorithm.getNextApplicationMember(context);
+    }
+}

Propchange: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2LoadBalanceMembershipHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java?rev=669395&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java Wed Jun 18 23:12:29 2008
@@ -0,0 +1,152 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.synapse.endpoints;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.clustering.Member;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.FaultHandler;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.core.LoadBalanceMembershipHandler;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.synapse.endpoints.algorithms.AlgorithmContext;
+import org.apache.synapse.endpoints.utils.EndpointDefinition;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Represents a dynamic load balance endpoint. The application membership is not static, but discovered
+ * through some mechanism such as using a GCF
+ */
+public class DynamicLoadbalanceEndpoint extends LoadbalanceEndpoint {
+
+    private static final Log log = LogFactory.getLog(DynamicLoadbalanceEndpoint.class);
+
+    /**
+     * The algorithm context , place holder for keep any runtime states related to the load balance
+     * algorithm
+     */
+    private final AlgorithmContext algorithmContext = new AlgorithmContext();
+
+    private LoadBalanceMembershipHandler lbMembershipHandler;
+
+    public DynamicLoadbalanceEndpoint() {
+    }
+
+    public void setLoadBalanceMembershipHandler(LoadBalanceMembershipHandler lbMembershipHandler) {
+        this.lbMembershipHandler = lbMembershipHandler;
+    }
+
+    public void send(MessageContext synCtx) {
+        EndpointReference to = synCtx.getTo();
+        DynamicLoadbalanceFaultHandler faultHandler = new DynamicLoadbalanceFaultHandler(to);
+        if (failover) {
+            synCtx.pushFaultHandler(faultHandler);
+        }
+        ConfigurationContext configCtx =
+                ((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
+        if (lbMembershipHandler.getConfigurationContext() == null) {
+            lbMembershipHandler.setConfigurationContext(configCtx);
+        }
+        algorithmContext.setConfigurationContext(configCtx);
+        sendToApplicationMember(synCtx, to, faultHandler);
+    }
+
+    public void setName(String name) {
+        super.setName(name);
+        algorithmContext.setContextID(name);
+    }
+
+    private void sendToApplicationMember(MessageContext synCtx,
+                                         EndpointReference to,
+                                         DynamicLoadbalanceFaultHandler faultHandler) {
+        org.apache.axis2.context.MessageContext axis2MsgCtx =
+                ((Axis2MessageContext) synCtx).getAxis2MessageContext();
+
+        String transport = axis2MsgCtx.getTransportIn().getName();
+        Member currentMember =
+                lbMembershipHandler.getNextApplicationMember(algorithmContext);
+        faultHandler.setCurrentMember(currentMember);
+        if (currentMember != null) {
+
+            // URL rewrite
+            if (transport.equals("http") || transport.equals("https")) {
+                String address = to.getAddress();
+                if (address.indexOf(":") != -1) {
+                    try {
+                        address = new URL(address).getPath();
+                    } catch (MalformedURLException e) {
+                        String msg = "URL " + address + " is malformed";
+                        log.error(msg, e);
+                        throw new SynapseException(msg, e);
+                    }
+                }
+                EndpointReference epr =
+                        new EndpointReference(transport + "://" + currentMember.getHostName() +
+                                              ":" + currentMember.getHttpPort() + address);
+                synCtx.setTo(epr);
+                if (failover) {
+                    synCtx.getEnvelope().build();
+                }
+
+                AddressEndpoint endpoint = new AddressEndpoint();
+                EndpointDefinition definition = new EndpointDefinition();
+                endpoint.setEndpoint(definition);
+                endpoint.send(synCtx);
+            } else {
+                log.error("Cannot load balance for non-HTTP/S transport " + transport);
+            }
+        } else {
+            synCtx.getFaultStack().pop(); // Remove the DynamicLoadbalanceFaultHandler
+            String msg = "No application members available";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+    }
+
+    /**
+     * This FaultHandler will try to resend the message to another member if an error occurs
+     * while sending to some member. This is a failover mechanism
+     */
+    private class DynamicLoadbalanceFaultHandler extends FaultHandler {
+
+        private EndpointReference to;
+        private Member currentMember;
+
+        public void setCurrentMember(Member currentMember) {
+            this.currentMember = currentMember;
+        }
+
+        private DynamicLoadbalanceFaultHandler(EndpointReference to) {
+            this.to = to;
+        }
+
+        public void onFault(MessageContext synCtx) {
+            if (currentMember == null) {
+                return;
+            }
+            synCtx.pushFaultHandler(this);
+            sendToApplicationMember(synCtx, to, this);
+        }
+    }
+}

Propchange: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/DynamicLoadbalanceEndpoint.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/LoadbalanceEndpoint.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/LoadbalanceEndpoint.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/LoadbalanceEndpoint.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/LoadbalanceEndpoint.java Wed Jun 18 23:12:29 2008
@@ -65,7 +65,7 @@
      * If this supports load balancing with failover. If true, request will be directed to the next
      * endpoint if the current one is failing.
      */
-    private boolean failover = true;
+    protected boolean failover = true;
 
     /**
      * Parent endpoint of this endpoint if this used inside another endpoint. Possible parents are
@@ -100,7 +100,7 @@
 
         ClusterManager clusterManager = cc.getAxisConfiguration().getClusterManager();
         if (clusterManager != null &&
-                clusterManager.getContextManager() != null) {
+            clusterManager.getContextManager() != null) {
             isClusteringEnable = true;
         }
 
@@ -109,8 +109,8 @@
 
             if (isClusteringEnable) {
                 log.warn("In a clustering environment , the endpoint  name should be specified" +
-                        "even for anonymous endpoints. Otherwise , the clustering would not be " +
-                        "functioned correctly if there are more than one anonymous endpoints. ");
+                         "even for anonymous endpoints. Otherwise , the clustering would not be " +
+                         "functioned correctly if there are more than one anonymous endpoints. ");
             }
             endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
         }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/AlgorithmContext.java Wed Jun 18 23:12:29 2008
@@ -79,7 +79,7 @@
             }
             try {
                 if (value instanceof Integer) {
-                    return ((Integer) value).intValue();
+                    return (Integer) value;
                 } else if (value instanceof String) {
                     return Integer.parseInt((String) value);
                 }
@@ -97,7 +97,7 @@
      *
      * @param currentEPR The current position
      */
-    public void setCurrentEPR(int currentEPR) {
+    public void setCurrentEndpointIndex(int currentEPR) {
 
         if (isClusteringEnable) {  // if this is a clustering env.
 

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/LoadbalanceAlgorithm.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/LoadbalanceAlgorithm.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/LoadbalanceAlgorithm.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/LoadbalanceAlgorithm.java Wed Jun 18 23:12:29 2008
@@ -19,9 +19,12 @@
 
 package org.apache.synapse.endpoints.algorithms;
 
+import org.apache.axis2.clustering.Member;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.endpoints.Endpoint;
 
+import java.util.List;
+
 /**
  * All load balance algorithms must implement this interface. Implementations of this interface can
  * be registered in LoadbalanceManagers.
@@ -29,17 +32,36 @@
 public interface LoadbalanceAlgorithm {
 
     /**
+     * Set the application members
+     *
+     * @param members The application members
+     */
+    void setApplicationMembers(List<Member> members);
+
+    /**
      * This method returns the next node according to the algorithm implementation.
      *
      * @param synapseMessageContext SynapseMessageContext of the current message
-     * @param algorithmContext The context in which holds run time states related to the algorithm
+     * @param algorithmContext      The context in which holds run time states related to the algorithm
      * @return Next node for directing the message
      */
-    public Endpoint getNextEndpoint(MessageContext synapseMessageContext, AlgorithmContext algorithmContext);
+    Endpoint getNextEndpoint(MessageContext synapseMessageContext,
+                             AlgorithmContext algorithmContext);
+
+
+    /**
+     * This method returns the next member to which the request has been sent to,
+     * according to the algorithm implementation.
+     *
+     * @param algorithmContext The context in which holds run time states related to the algorithm
+     * @return Next application member to which the request has to be sent to
+     */
+    Member getNextApplicationMember(AlgorithmContext algorithmContext);
 
     /**
      * Resets the algorithm to its initial position. Initial position depends on the implementation.
+     *
      * @param algorithmContext The context in which holds run time states related to the algorithm
      */
-    public void reset(AlgorithmContext algorithmContext);
+    void reset(AlgorithmContext algorithmContext);
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/algorithms/RoundRobin.java Wed Jun 18 23:12:29 2008
@@ -19,12 +19,14 @@
 
 package org.apache.synapse.endpoints.algorithms;
 
+import org.apache.axis2.clustering.Member;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.endpoints.Endpoint;
 
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This is the implementation of the round robin load balancing algorithm. It simply iterates
@@ -39,20 +41,26 @@
      */
     private ArrayList endpoints = null;
 
+    private List<Member> members;
+
     public RoundRobin(ArrayList endpoints) {
         this.endpoints = endpoints;
     }
 
+    public void setApplicationMembers(List<Member> members) {
+        this.members = members;
+    }
+
     /**
      * Choose an active endpoint using the round robin algorithm. If there are no active endpoints
      * available, returns null.
      *
      * @param synapseMessageContext MessageContext instance which holds all per-message properties
-     * @param  algorithmContext The context in which holds run time states related to the algorithm
+     * @param algorithmContext      The context in which holds run time states related to the algorithm
      * @return endpoint to send the next message
      */
     public Endpoint getNextEndpoint(MessageContext synapseMessageContext,
-        AlgorithmContext algorithmContext) {
+                                    AlgorithmContext algorithmContext) {
 
         if (log.isDebugEnabled()) {
             log.debug("Using the Round Robin loadbalancing algorithm to select the next endpoint");
@@ -71,7 +79,7 @@
                 } else {
                     currentEPR++;
                 }
-                algorithmContext.setCurrentEPR(currentEPR);
+                algorithmContext.setCurrentEndpointIndex(currentEPR);
             }
 
             attempts++;
@@ -85,10 +93,32 @@
         return nextEndpoint;
     }
 
+    public Member getNextApplicationMember(AlgorithmContext algorithmContext) {
+        if (members.size() == 0) {
+            return null;
+        }
+        int currentMemberIndex = algorithmContext.getCurrentEndpointIndex();
+        if (currentMemberIndex >= members.size()) {
+            currentMemberIndex = 0;
+        }
+        Member current = members.get(currentMemberIndex);
+        if (currentMemberIndex == members.size() - 1) {
+            currentMemberIndex = 0;
+        } else {
+            currentMemberIndex++;
+        }
+        algorithmContext.setCurrentEndpointIndex(currentMemberIndex);
+        if(log.isDebugEnabled()) {
+            log.debug("Members       : " + members.size());
+            log.debug("Current member: " + current);
+        }
+        return current;
+    }
+
     public void reset(AlgorithmContext algorithmContext) {
         if (log.isDebugEnabled()) {
             log.debug("Resetting the Round Robin loadbalancing algorithm ...");
         }
-        algorithmContext.setCurrentEPR(0);
+        algorithmContext.setCurrentEndpointIndex(0);
     }
 }

Modified: synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java (original)
+++ synapse/trunk/java/modules/samples/src/main/java/samples/userguide/LoadbalanceFailoverClient.java Wed Jun 18 23:12:29 2008
@@ -109,7 +109,7 @@
         value.setText("Sample string");
 
         Options options = new Options();
-        options.setTo(new EndpointReference("http://localhost:" + synapsePort));
+        options.setTo(new EndpointReference("http://localhost:" + synapsePort + "/soap/LBService1"));
 
         options.setAction("urn:sampleOperation");
 
@@ -208,7 +208,7 @@
         }
 
         Options options = new Options();
-        options.setTo(new EndpointReference("http://localhost:" + synapsePort));
+        options.setTo(new EndpointReference("http://localhost:" + synapsePort + "/soap/LBService1"));
         options.setAction("urn:sampleOperation");
         options.setTimeOutInMilliSeconds(10000000);
 
@@ -252,7 +252,7 @@
             client.setOptions(options);
 
             int i = 0;
-            int sessionNumber = 0;
+            int sessionNumber;
             while (i < iterations || infinite) {
 
                 i++;

Modified: synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2ServerManager.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2ServerManager.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2ServerManager.java (original)
+++ synapse/trunk/java/modules/samples/src/main/java/samples/util/SampleAxis2ServerManager.java Wed Jun 18 23:12:29 2008
@@ -25,6 +25,7 @@
 import org.apache.axis2.util.CommandLineOption;
 import org.apache.axis2.util.CommandLineOptionParser;
 import org.apache.axis2.util.OptionsValidator;
+import org.apache.axis2.clustering.ClusterManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -98,6 +99,16 @@
             listenerManager.init(configctx);
             listenerManager.start();
             log.info("[SimpleAxisServer] Started");
+
+            // Need to initialize the cluster manager at last since we are changing the servers
+            // HTTP/S ports above. In the axis2.xml file, we need to set the "AvoidInitiation" param
+            // to "true"
+            ClusterManager clusterManager =
+                    configctx.getAxisConfiguration().getClusterManager();
+            if(clusterManager != null) {
+                clusterManager.setConfigurationContext(configctx);
+                clusterManager.init();
+            }
         } catch (Throwable t) {
             log.fatal("[SimpleAxisServer] Shutting down. Error starting SimpleAxisServer", t);
             System.exit(1); // must stop application

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ClientHandler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ClientHandler.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ClientHandler.java (original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ClientHandler.java Wed Jun 18 23:12:29 2008
@@ -447,6 +447,10 @@
 
                 return;
             }
+            case HttpStatus.SC_BAD_REQUEST : {  
+                log.error("Received bad request: " + response.getStatusLine().getReasonPhrase());
+                return;
+            }
             case HttpStatus.SC_INTERNAL_SERVER_ERROR : {
                 Header contentType = response.getFirstHeader(CONTENT_TYPE);
                 if (contentType != null) {

Modified: synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java (original)
+++ synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/nhttp/ServerWorker.java Wed Jun 18 23:12:29 2008
@@ -18,23 +18,10 @@
  */
 package org.apache.synapse.transport.nhttp;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.StringTokenizer;
-
 import org.apache.axiom.om.util.UUIDGenerator;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisOperation;
@@ -47,15 +34,19 @@
 import org.apache.axis2.util.MessageContextBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.Header;
-import org.apache.http.HttpInetConnection;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
+import org.apache.http.*;
 import org.apache.http.nio.NHttpServerConnection;
 import org.apache.http.protocol.HTTP;
-import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.synapse.transport.base.MetricsCollector;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.*;
 
 /**
  * Processes an incoming request through Axis2. An instance of this class would be created to

Modified: synapse/trunk/java/pom.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/pom.xml?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/pom.xml (original)
+++ synapse/trunk/java/pom.xml Wed Jun 18 23:12:29 2008
@@ -1126,7 +1126,7 @@
         <jms-1.1-spec.version>1.1</jms-1.1-spec.version>
 
         <!-- Axis2 1.4 and its dependencies -->
-        <axis2.version>1.4</axis2.version>
+        <axis2.version>SNAPSHOT</axis2.version>
         <axiom.version>SNAPSHOT</axiom.version>
         <xml_schema.version>1.4.2</xml_schema.version>
         <xml_apis.version>1.3.04</xml_apis.version>
@@ -1135,7 +1135,7 @@
         <commons.logging.version>1.1</commons.logging.version>
 
         <!-- addressing, rampart, neethi -->
-        <addressing.version>1.4</addressing.version>
+        <addressing.version>SNAPSHOT</addressing.version>
         <rampart.version>SNAPSHOT</rampart.version>
         <mercury.version>0.91</mercury.version>
         <neethi.version>2.0.4</neethi.version>

Modified: synapse/trunk/java/repository/conf/axis2.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/axis2.xml?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/axis2.xml (original)
+++ synapse/trunk/java/repository/conf/axis2.xml Wed Jun 18 23:12:29 2008
@@ -296,13 +296,121 @@
     <!--</moduleConfig>-->
 
     <!-- ================================================= -->
-    <!-- Clustering  -->
+    <!--                  Clustering                       -->
     <!-- ================================================= -->
-    <!-- Configure and uncomment following for preparing Synapse to a clustered environment -->
-    <!--<cluster class="org.apache.axis2.clustering.tribes.TribesClusterManager">
+    <!-- Configure the following for preparing Synapse to a clustered environment -->
+    <cluster class="org.apache.axis2.clustering.tribes.TribesClusterManager" enable="false">
+
+        <!--
+           This parameter indicates whther the cluster has to be automatically initalized
+           when the AxisConfiguration is built. If set to "true" the initialization will not be
+           done at that stage, and some other party will have to explictly initialize the cluster.
+        -->
         <parameter name="AvoidInitiation">false</parameter>
-        <parameter name="domain">apache-synapse.domain</parameter>
-        <contextManager class="org.apache.axis2.clustering.context.DefaultContextManager">
+
+        <!--
+           The membership scheme used in this setup. The only values supported at the moment are
+           "multicast" and "wka"
+
+           1. multicast - membership is automatically discovered using multicasting
+           2. wka - Well-Known Address based multicasting. Membership is discovered with the help
+                    of one or more nodes running at a Well-Known Address. New members joining a
+                    cluster will first connect to a well-known node, register with the well-known node
+                    and get the membership list from it. When new members join, one of the well-known
+                    nodes will notify the others in the group. When a member leaves the cluster or
+                    is deemed to have left the cluster, it will be detected by the Group Membership
+                    Service (GMS) using a TCP ping mechanism.
+        -->
+        <parameter name="membershipScheme">multicast</parameter>
+
+        <!--
+         The clustering domain/group. Nodes in the same group will belong to the same multicast
+         domain. There will not be interference between nodes in different groups.
+        -->
+        <parameter name="domain">apache.synapse.domain</parameter>
+
+        <!--
+           When a Web service request is received, and processed, before the response is sent to the
+           client, should we update the states of all members in the cluster? If the value of
+           this parameter is set to "true", the response to the client will be sent only after
+           all the members have been updated. Obviously, this can be time consuming. In some cases,
+           such this overhead may not be acceptable, in which case the value of this parameter
+           should be set to "false"
+        -->
+        <parameter name="synchronizeAll">true</parameter>
+
+        <!--
+          The maximum number of times we need to retry to send a message to a particular node
+          before giving up and considering that node to be faulty
+        -->
+        <parameter name="maxRetries">10</parameter>
+
+        <!-- The multicast address to be used -->
+        <parameter name="mcastAddress">228.0.0.4</parameter>
+
+        <!-- The multicast port to be used -->
+        <parameter name="mcastPort">45564</parameter>
+
+        <!-- The frequency of sending membership multicast messages (in ms) -->
+        <parameter name="mcastFrequency">500</parameter>
+
+        <!-- The time interval within which if a member does not respond, the member will be
+         deemed to have left the group (in ms)
+         -->
+        <parameter name="memberDropTime">3000</parameter>
+
+        <!--
+           The IP address of the network interface to which the multicasting has to be bound to.
+           Multicasting would be done using this interface.
+        -->
+        <parameter name="mcastBindAddress">127.0.0.1</parameter>
+
+        <!-- The host name or IP address of this member -->
+        <parameter name="localMemberHost">127.0.0.1</parameter>
+
+        <!--
+        The TCP port used by this member. This is the port through which other nodes will
+        contact this member
+         -->
+        <parameter name="localMemberPort">4000</parameter>
+
+        <!--
+           The list of static or well-known members. These entries will only be valid if the
+           "membershipScheme" above is set to "wka"
+        -->
+        <members>
+            <member>
+                <hostName>127.0.0.1</hostName>
+                <port>4000</port>
+            </member>
+            <member>
+                <hostName>127.0.0.1</hostName>
+                <port>4001</port>
+            </member>
+        </members>
+
+        <!--
+        Enable the load balancer entry if you need to run this node as a load balancer.
+        Multiple application domains with different LoadBalanceEventHandler implementations
+        can be defined in this section.
+        -->
+        <loadBalancer enable="false">
+            <applicationDomain name="apache.axis2.app.domain"
+                               handler="org.apache.axis2.clustering.DefaultLoadBalanceEventHandler"/>
+        </loadBalancer>
+            
+        <!--
+           This interface is responsible for handling context replication. The property changes in
+           the Axis2 context hierarchy in this node, are propagated to all other nodes in the cluster.
+
+           The "excludes" patterns can be used to specify the prefixes (e.g. local_*) or
+           suffixes (e.g. *_local) of the properties to be excluded from replication. The pattern
+           "*" indicates that all properties in a particular context should not be replicated.
+
+            The "enable" attribute indicates whether context replication has been enabled
+        -->
+        <contextManager class="org.apache.axis2.clustering.context.DefaultContextManager"
+                         enable="false">
             <listener class="org.apache.axis2.clustering.context.DefaultContextManagerListener"/>
             <replication>
                 <defaults>
@@ -312,13 +420,6 @@
                 <context class="org.apache.axis2.context.ConfigurationContext">
                     <exclude name="UseAsyncOperations"/>
                     <exclude name="SequencePropertyBeanMap"/>
-                    <exclude name="WORK_DIR"/>
-                    <exclude name="NextMsgBeanMap"/>
-                    <exclude name="RetransmitterBeanMap"/>
-                    <exclude name="StorageMapBeanMap"/>
-                    <exclude name="CreateSequenceBeanMap"/>
-                    <exclude name="ConfigContextTimeoutInterval"/>
-                    <exclude name="ContainerManaged"/>
                 </context>
                 <context class="org.apache.axis2.context.ServiceGroupContext">
                     <exclude name="my.sandesha.*"/>
@@ -328,7 +429,7 @@
                 </context>
             </replication>
         </contextManager>
-    </cluster>-->
+    </cluster>
 
     <!-- ================================================= -->
     <!-- Phases  -->

Modified: synapse/trunk/java/repository/conf/sample/resources/misc/server/axis2.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/resources/misc/server/axis2.xml?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/sample/resources/misc/server/axis2.xml (original)
+++ synapse/trunk/java/repository/conf/sample/resources/misc/server/axis2.xml Wed Jun 18 23:12:29 2008
@@ -255,19 +255,40 @@
     <!-- ================================================= -->
     <!-- Clustering  -->
     <!-- ================================================= -->
-    <!-- Configure and uncomment following for preparing Axis2 to a clustered environment -->
-    <!-- 
-    <cluster class="org.apache.axis2.cluster.tribes.TribesClusterManager">
-        <parameter name="param1">value1</parameter>
-        <parameter name="domain">apache.axis2.domain</parameter>
-    	<configurationManager class="org.apache.axis2.cluster.configuration.TribesConfigurationManager">
-    	    <listener class="org.apache.axis2.cluster.configuration.DefaultConfigurationManagerListener"/>
-    	</configurationManager>
-    	<contextManager class="org.apache.axis2.cluster.context.TribesContextManager">
-    	    <listener class="org.apache.axis2.cluster.context.DefaultContextManagerListener"/>
-    	</contextManager>
+    <!-- Configure the following for preparing Axis2 to a clustered environment -->
+    <cluster class="org.apache.axis2.clustering.tribes.TribesClusterManager" enable="false">
+        <parameter name="AvoidInitiation">true</parameter>
+        <parameter name="membershipScheme">multicast</parameter>
+        <parameter name="domain">apache.axis2.app.domain</parameter>
+        <parameter name="synchronizeAll">true</parameter>
+        <parameter name="maxRetries">10</parameter>
+        <parameter name="mcastAddress">228.0.0.4</parameter>
+        <parameter name="mcastPort">45564</parameter>
+        <parameter name="mcastFrequency">500</parameter>
+        <parameter name="memberDropTime">3000</parameter>
+        <parameter name="mcastBindAddress">127.0.0.1</parameter>
+        <parameter name="localMemberHost">127.0.0.1</parameter>
+        <contextManager class="org.apache.axis2.clustering.context.DefaultContextManager"
+                         enable="false">
+            <listener class="org.apache.axis2.clustering.context.DefaultContextManagerListener"/>
+            <replication>
+                <defaults>
+                    <exclude name="local_*"/>
+                    <exclude name="LOCAL_*"/>
+                </defaults>
+                <context class="org.apache.axis2.context.ConfigurationContext">
+                    <exclude name="UseAsyncOperations"/>
+                    <exclude name="SequencePropertyBeanMap"/>
+                </context>
+                <context class="org.apache.axis2.context.ServiceGroupContext">
+                    <exclude name="my.sandesha.*"/>
+                </context>
+                <context class="org.apache.axis2.context.ServiceContext">
+                    <exclude name="my.sandesha.*"/>
+                </context>
+            </replication>
+        </contextManager>
     </cluster>
-     -->
      
     <!-- ================================================= -->
     <!-- Phases  -->

Copied: synapse/trunk/java/repository/conf/sample/synapse_sample_57.xml (from r667460, synapse/trunk/java/repository/conf/sample/synapse_sample_52.xml)
URL: http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_57.xml?p2=synapse/trunk/java/repository/conf/sample/synapse_sample_57.xml&p1=synapse/trunk/java/repository/conf/sample/synapse_sample_52.xml&r1=667460&r2=669395&rev=669395&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_52.xml (original)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_57.xml Wed Jun 18 23:12:29 2008
@@ -23,27 +23,13 @@
     <sequence name="main" onError="errorHandler">
         <in>
             <send>
-                <endpoint>
-                    <loadbalance>
-                        <endpoint>
-                            <address uri="http://localhost:9001/soap/LBService1">
-                                <enableAddressing/>
-                                <suspendDurationOnFailure>60</suspendDurationOnFailure>
-                            </address>
-                        </endpoint>
-                        <endpoint>
-                            <address uri="http://localhost:9002/soap/LBService1">
-                                <enableAddressing/>
-                                <suspendDurationOnFailure>60</suspendDurationOnFailure>
-                            </address>
-                        </endpoint>
-                        <endpoint>
-                            <address uri="http://localhost:9003/soap/LBService1">
-                                <enableAddressing/>
-                                <suspendDurationOnFailure>60</suspendDurationOnFailure>
-                            </address>
-                        </endpoint>
-                    </loadbalance>
+                <endpoint name="dynamicLB">
+                    <dynamicLoadbalance failover="true" policy="roundrobin">
+                        <membershipHandler
+                                class="org.apache.synapse.core.axis2.Axis2LoadBalanceMembershipHandler">
+                            <property name="applicationDomain" value="apache.axis2.app.domain"/>
+                        </membershipHandler>
+                    </dynamicLoadbalance>
                 </endpoint>
             </send>
             <drop/>

Modified: synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml?rev=669395&r1=669394&r2=669395&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml Wed Jun 18 23:12:29 2008
@@ -214,6 +214,10 @@
             <li>
               <a href="#Sample56">Sample 56: WSDL endpoint</a>
             </li>
+            <li>
+              <a href="#Sample57">Sample 57: Dynamic load balancing
+              between 3 nodes</a>
+            </li>
           </ul>
         </li>
         <li>
@@ -1620,6 +1624,7 @@
       configuration. Therefore, load balance endpoint will suspend any failed
       child endpoint only for 60 seconds after detecting the failure.
     </p>
+
     <h2>
       <a name="Sample53" id="Sample53">Sample 53: Failover sending among 3
       endpoints</a>
@@ -2033,6 +2038,132 @@
       on port 9000. Observe the Axis2 console and the Synapse console to verify
       this behavior.
     </p>
+
+          <h2>
+      <a name="Sample57" id="Sample57">Sample 57: Dynamic load balancing between 3 nodes</a>
+    </h2>
+<pre xml:space="preserve">
+
+&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
+
+    &lt;sequence name="main" onError="errorHandler"&gt;
+        &lt;in&gt;
+            &lt;send&gt;
+                &lt;endpoint name="dynamicLB"&gt;
+                    &lt;dynamicLoadbalance failover="true" policy="roundrobin"&gt;
+                        &lt;membershipHandler
+                                class="org.apache.synapse.core.axis2.Axis2LoadBalanceMembershipHandler"&gt;
+                            &lt;property name="applicationDomain" value="apache.axis2.app.domain"/&gt;
+                        &lt;/membershipHandler&gt;
+                    &lt;/dynamicLoadbalance&gt;
+                &lt;/endpoint&gt;
+            &lt;/send&gt;
+            &lt;drop/&gt;
+        &lt;/in&gt;
+
+        &lt;out&gt;
+            &lt;send/&gt;
+        &lt;/out&gt;
+    &lt;/sequence&gt;
+
+    &lt;sequence name="errorHandler"&gt;
+
+        &lt;makefault&gt;
+            &lt;code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/&gt;
+            &lt;eason value="COULDN'T SEND THE MESSAGE TO THE SERVER."/&gt;
+        &lt;/makefault&gt;
+
+        &lt;header name="To" action="remove"/&gt;
+        &lt;property name="RESPONSE" value="true"/&gt;
+
+        &lt;send/&gt;
+    &lt;/sequence&gt;
+
+&lt;/definitions&gt;
+
+</pre>
+    <p>
+      <strong>Objective: Demonstrate the simple dynamic load balancing among a set of
+      nodes</strong>
+    </p>
+    <p>
+      <strong>Prerequisites:</strong>
+    </p>
+    <p>
+    Enable clustering and load balancing in the  &lt;Synapse installation directory&gt;/
+        repository/conf/axis2.xml file. This can be done by setting
+        the "enable" attribute of the "cluster" and "loadBalancer" elements. Also provide the IP
+        address of you machine as the values of the "mcastBindAddress" and "localMemberHost"
+        parameters.
+    </p>
+    <p>
+      Start Synapse with sample configuration 57. (i.e. synapse -sample 57)
+    </p>
+    <p>
+      Deploy the LoadbalanceFailoverService by switching to &lt;Synapse
+      installation directory&gt;/samples/axis2Server/src/LoadbalanceFailoverService
+      directory and running ant.
+    </p>
+    <p>
+      Enable clustering in the  &lt;Synapse installation directory&gt;/samples/axis2Server/
+        repository/conf/axis2.xml file. This can be done by setting
+        the "enable" attribute of the "cluster" element. Also provide the IP
+        address of you machine as the values of the "mcastBindAddress" and "localMemberHost"
+        parameters. Then Start three instances of sample Axis2 server on HTTP ports 9001, 9002 and
+      9003 and give some unique names to each server.
+    </p>
+    <p>
+      Example commands to run sample Axis2 servers from the &lt;Synapse
+      installation directory&gt;/samples/axis2Server directory in Linux are
+      listed below:
+    </p>
+<pre xml:space="preserve">./axis2server.sh -http 9001 -https 9005 -name MyServer1
+./axis2server.sh -http 9002 -https 9006 -name MyServer2
+./axis2server.sh -http 9003 -https 9007 -name MyServer3</pre>
+    <p>
+      Now we are done with setting up the environment for load balance sample.
+      Start the load balance and failover client using the following command:
+    </p>
+<pre xml:space="preserve">ant loadbalancefailover -Di=100</pre>
+    <p>
+      This client sends 100 requests to the LoadbalanceFailoverService through
+      Synapse. Synapse will distribute the load among the three nodes
+      mentioned in the configuration in a round-robin manner.
+      LoadbalanceFailoverService appends the name of the server to the response,
+      so that client can determine which server has processed the message. If
+      you examine the console output of the client, you can see that requests
+      are processed by three servers as follows:
+    </p>
+<pre xml:space="preserve">[java] Request: 1 ==&gt; Response from server: MyServer1
+[java] Request: 2 ==&gt; Response from server: MyServer2
+[java] Request: 3 ==&gt; Response from server: MyServer3
+[java] Request: 4 ==&gt; Response from server: MyServer1
+[java] Request: 5 ==&gt; Response from server: MyServer2
+[java] Request: 6 ==&gt; Response from server: MyServer3
+[java] Request: 7 ==&gt; Response from server: MyServer1
+...</pre>
+    <p>
+      Now run the client without the -Di=100 parameter, i.e. ant loadbalancefailover,
+      to send infinite requests. While running the client shutdown the server named MyServer1.
+      You can observe that requests are only distributed among MyServer2 and
+      MyServer3 after shutting down MyServer1. Console output before and after
+      shutting down MyServer1 is listed below (MyServer1 was shutdown after
+      request 63):
+    </p>
+<pre xml:space="preserve">...
+[java] Request: 61 ==&gt; Response from server: MyServer1
+[java] Request: 62 ==&gt; Response from server: MyServer2
+[java] Request: 63 ==&gt; Response from server: MyServer3
+[java] Request: 64 ==&gt; Response from server: MyServer2
+[java] Request: 65 ==&gt; Response from server: MyServer3
+[java] Request: 66 ==&gt; Response from server: MyServer2
+[java] Request: 67 ==&gt; Response from server: MyServer3
+...</pre>
+    <p>
+      Now restart MyServer1. You can observe that requests will be again sent to
+      all three servers.
+    </p>
+
     <h1>
       <a name="MessageMediationQoS" id="MessageMediationQoS">Quality of
       Service addition or deduction samples in message mediation</a>