axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From az...@apache.org
Subject svn commit: r664489 - in /webservices/axis2/trunk/java/modules: clustering/src/org/apache/axis2/clustering/ clustering/src/org/apache/axis2/clustering/tribes/ kernel/conf/ kernel/src/org/apache/axis2/clustering/
Date Sun, 08 Jun 2008 12:24:30 GMT
Author: azeez
Date: Sun Jun  8 05:24:30 2008
New Revision: 664489

URL: http://svn.apache.org/viewvc?rev=664489&view=rev
Log:
Adding load balancing event notification mechanism


Added:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/DefaultLoadBalanceEventHandler.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/LoadBalanceEventHandler.java
Modified:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/LoadBalancerInterceptor.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
    webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/ClusteringConstants.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java

Added: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/DefaultLoadBalanceEventHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/DefaultLoadBalanceEventHandler.java?rev=664489&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/DefaultLoadBalanceEventHandler.java
(added)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/DefaultLoadBalanceEventHandler.java
Sun Jun  8 05:24:30 2008
@@ -0,0 +1,35 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed 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.axis2.clustering;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The default, dummy implementation of {@link LoadBalanceEventHandler}
+ */
+public class DefaultLoadBalanceEventHandler implements LoadBalanceEventHandler{
+
+    private static final Log log  = LogFactory.getLog(DefaultLoadBalanceEventHandler.class);
+
+    public void applicationMemberAdded(Member member) {
+        log.info("Application member " + member + " joined cluster.");
+    }
+
+    public void applicationMemberRemoved(Member member) {
+        log.info("Application member " + member + " left cluster.");
+    }
+}

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/LoadBalancerInterceptor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/LoadBalancerInterceptor.java?rev=664489&r1=664488&r2=664489&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/LoadBalancerInterceptor.java
(original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/LoadBalancerInterceptor.java
Sun Jun  8 05:24:30 2008
@@ -22,6 +22,7 @@
 import org.apache.catalina.tribes.membership.Membership;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.clustering.LoadBalanceEventHandler;
 
 import java.util.Arrays;
 import java.util.List;
@@ -55,6 +56,8 @@
      */
     protected byte[] applicationDomain = new byte[0];
 
+    private LoadBalanceEventHandler eventHandler;
+
     public LoadBalancerInterceptor(byte[] loadBalancerDomain,
                                    byte[] applicationDomain) {
         this.loadBalancerDomain = loadBalancerDomain;
@@ -67,6 +70,8 @@
         if (Arrays.equals(msg.getAddress().getDomain(), loadBalancerDomain)) {
             super.messageReceived(msg);
         }
+
+        // TODO: Application members may inform about their HTTP/S ports
     }
 
     public void memberAdded(Member member) {
@@ -82,11 +87,17 @@
         }
         if (notify) {
             super.memberAdded(member);
+            
         }
 
         // Is this an application domain member?
         if (Arrays.equals(applicationDomain, member.getDomain())) {
             log.info("Application member " + TribesUtil.getHost(member) + " joined cluster");
+            if(eventHandler != null){
+                org.apache.axis2.clustering.Member axis2Member =
+                        new org.apache.axis2.clustering.Member(member.getName(), member.getPort());
+                eventHandler.applicationMemberAdded(axis2Member);
+            }
             applicationMembers.add(member);
         }
 
@@ -108,7 +119,12 @@
         // Is this an application domain member?
         if (Arrays.equals(applicationDomain, member.getDomain())) {
             log.info("Application member " + TribesUtil.getHost(member) + " left cluster");
-            applicationMembers.remove(member);
+            if(eventHandler != null){
+                org.apache.axis2.clustering.Member axis2Member =
+                        new org.apache.axis2.clustering.Member(member.getName(), member.getPort());
+                eventHandler.applicationMemberRemoved(axis2Member);
+                applicationMembers.remove(member);
+            }
         }
     }
 
@@ -158,4 +174,8 @@
     public void setLoadBalancerDomain(byte[] loadBalancerDomain) {
         this.loadBalancerDomain = loadBalancerDomain;
     }
+
+    public void setEventHandler(LoadBalanceEventHandler eventHandler) {
+        this.eventHandler = eventHandler;
+    }
 }

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java?rev=664489&r1=664488&r2=664489&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
(original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
Sun Jun  8 05:24:30 2008
@@ -25,6 +25,7 @@
 import org.apache.axis2.clustering.ClusteringConstants;
 import org.apache.axis2.clustering.ClusteringFault;
 import org.apache.axis2.clustering.RequestBlockingHandler;
+import org.apache.axis2.clustering.LoadBalanceEventHandler;
 import org.apache.axis2.clustering.configuration.ConfigurationManager;
 import org.apache.axis2.clustering.configuration.DefaultConfigurationManager;
 import org.apache.axis2.clustering.context.ClusteringContextListener;
@@ -646,6 +647,20 @@
         } else if (mode.equals(ClusteringConstants.Mode.LOAD_BALANCE)) {
             LoadBalancerInterceptor lbInterceptor =
                     new LoadBalancerInterceptor(domain, applicationDomain);
+            Parameter lbEvtHandlerParam =
+                    getParameter(ClusteringConstants.Parameters.LOAD_BALANCE_EVENT_HANDLER);
+            if(lbEvtHandlerParam != null && lbEvtHandlerParam.getValue() != null){
+                String lbEvtHandlerClass = ((String)lbEvtHandlerParam.getValue()).trim();
+                try {
+                    lbInterceptor.
+                        setEventHandler((LoadBalanceEventHandler)Class.forName(lbEvtHandlerClass).newInstance());
+                } catch (Exception e) {
+                    String msg = "Could not instantiate LoadBalanceEventHandler class " +
+                                 lbEvtHandlerClass;
+                    log.error(msg, e);
+                    throw new ClusteringFault(msg, e);
+                }
+            }
             channel.addInterceptor(lbInterceptor);
         }
 

Modified: webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml?rev=664489&r1=664488&r2=664489&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml Sun Jun  8 05:24:30 2008
@@ -289,6 +289,16 @@
         <parameter name="mode">application</parameter>
 
         <!--
+        This is the even handler which will be notified in the case of load balancing events
occurring.
+        This class has to be an implementation of org.apache.axis2.clustering.LoadBalanceEventHandler
+
+        This entry is only valid if the "mode" parameter is set to loadBalance
+        -->
+        <parameter name="loadBalanceEventHandler">
+            org.apache.axis2.clustering.DefaultLoadBalanceEventHandler
+        </parameter>
+
+        <!--
         This parameter is only valid when the "mode" parameter is set to application. This
indicates
         the domain in which the the applications being load balanced are deployed.
         -->

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/ClusteringConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/ClusteringConstants.java?rev=664489&r1=664488&r2=664489&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/ClusteringConstants.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/ClusteringConstants.java
Sun Jun  8 05:24:30 2008
@@ -67,15 +67,23 @@
         /**
          * Indicates the mode in which this member is running. Valid values are "application"
and
          * "loadBalance"
-         *
+         * <p/>
          * application - This member hosts end user applications
          * loadBalance - This member is a part of the load balancer cluster
          */
         public static final String MODE = "mode";
 
         /**
+         * This is the even handler which will be notified in the case of load balancing
events occurring.
+         * This class has to be an implementation of org.apache.axis2.clustering.LoadBalanceEventHandler
+         * <p/>
+         * This entry is only valid if the "mode" parameter is set to loadBalance
+         */
+        public static final String LOAD_BALANCE_EVENT_HANDLER = "loadBalanceEventHandler";
+
+        /**
          * This parameter is only valid when the "mode" parameter is set to "application"
-         *
+         * <p/>
          * This indicates the domain in which the the applications being load balanced are
deployed.
          */
         public static final String APPLICATION_DOMAIN = "applicationDomain";
@@ -100,7 +108,7 @@
     /**
      * Represents the mode of this member
      */
-    public static final class Mode{
+    public static final class Mode {
 
         /**
          * Load balancing mode

Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/LoadBalanceEventHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/LoadBalanceEventHandler.java?rev=664489&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/LoadBalanceEventHandler.java
(added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/LoadBalanceEventHandler.java
Sun Jun  8 05:24:30 2008
@@ -0,0 +1,39 @@
+/*                                                                             
+ * Copyright 2004,2005 The Apache Software Foundation.                         
+ *                                                                             
+ * Licensed 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.axis2.clustering;
+
+/**
+ * This is the interface through which the load balancing event are notified.
+ * This will only be used when this member is running in loadBalance mode. In order to do
this,
+ * in the axis2.xml file, set the value of the "mode" parameter to "loadBalance" and then
provide
+ * the class that implements this interface using the "loadBalanceEventHandler" entry.
+ */
+public interface LoadBalanceEventHandler {
+
+    /**
+     * An application member joined the application group
+     *
+     * @param member Represents the member who joined
+     */
+    void applicationMemberAdded(Member member);
+
+    /**
+     * An application member left the application group
+     *
+     * @param member Represents the member who left
+     */
+    void applicationMemberRemoved(Member member);
+}

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java?rev=664489&r1=664488&r2=664489&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/Member.java
Sun Jun  8 05:24:30 2008
@@ -63,4 +63,8 @@
         result = 31 * result + port;
         return result;
     }
+
+    public String toString() {
+        return hostName + ":" + port;
+    }
 }



Mime
View raw message