axis-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From az...@apache.org
Subject svn commit: r1369326 - in /axis/axis2/java/core/trunk/modules: clustering/src/org/apache/axis2/clustering/management/ clustering/src/org/apache/axis2/clustering/tribes/ kernel/src/org/apache/axis2/clustering/
Date Sat, 04 Aug 2012 13:50:59 GMT
Author: azeez
Date: Sat Aug  4 13:50:58 2012
New Revision: 1369326

URL: http://svn.apache.org/viewvc?rev=1369326&view=rev
Log:
Support for cluster sub-domains


Modified:
    axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/management/DefaultGroupManagementAgent.java
    axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/ClusterManagementMode.java
    axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusteringAgent.java
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/ClusteringAgent.java
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/Member.java

Modified: axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/management/DefaultGroupManagementAgent.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/management/DefaultGroupManagementAgent.java?rev=1369326&r1=1369325&r2=1369326&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/management/DefaultGroupManagementAgent.java
(original)
+++ axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/management/DefaultGroupManagementAgent.java
Sat Aug  4 13:50:58 2012
@@ -1,20 +1,17 @@
-/*
- * 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.
+/*                                                                             
+ * 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.management;
 
@@ -65,9 +62,11 @@ public class DefaultGroupManagementAgent
     }
 
     public void applicationMemberAdded(Member member) {
-        Thread th = new Thread(new MemberAdder(member));
-        th.setPriority(Thread.MAX_PRIORITY);
-        th.start();
+        if (!members.contains(member)) {
+            Thread th = new Thread(new MemberAdder(member));
+            th.setPriority(Thread.MAX_PRIORITY);
+            th.start();
+        }
     }
 
     public void applicationMemberRemoved(Member member) {
@@ -101,8 +100,7 @@ public class DefaultGroupManagementAgent
             if (canConnect(member)) {
                 try {
                     Thread.sleep(10000);   // Sleep for sometime to allow complete initialization
of the node
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
+                } catch (InterruptedException ignored) {
                 }
                 if (!members.contains(member)) {
                     members.add(member);

Modified: axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/ClusterManagementMode.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/ClusterManagementMode.java?rev=1369326&r1=1369325&r2=1369326&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/ClusterManagementMode.java
(original)
+++ axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/ClusterManagementMode.java
Sat Aug  4 13:50:58 2012
@@ -1,20 +1,17 @@
-/*
- * 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.
+/*                                                                             
+ * 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.tribes;
 
@@ -42,13 +39,17 @@ public class ClusterManagementMode imple
     private static final Log log = LogFactory.getLog(ClusterManagementMode.class);
 
     private final byte[] clusterManagerDomain;
-    private final Map<String, GroupManagementAgent> groupManagementAgents;
+
+    /**
+     * Map[key, value=Map[key, value]] = [domain, [subDomain, GroupManagementAgent]]
+     */
+    private final Map<String, Map<String, GroupManagementAgent>> groupManagementAgents;
     private final List<MembershipManager> membershipManagers = new ArrayList<MembershipManager>();
     private final MembershipManager primaryMembershipManager;
 
     public ClusterManagementMode(byte[] clusterManagerDomain,
-                            Map<String, GroupManagementAgent> groupManagementAgents,
-                            MembershipManager primaryMembershipManager) {
+                                 Map<String, Map<String, GroupManagementAgent>>
groupManagementAgents,
+                                 MembershipManager primaryMembershipManager) {
         this.clusterManagerDomain = clusterManagerDomain;
         this.groupManagementAgents = groupManagementAgents;
         this.primaryMembershipManager = primaryMembershipManager;
@@ -67,27 +68,27 @@ public class ClusterManagementMode imple
     public void init(Channel channel) {
         // Have multiple RPC channels with multiple RPC request handlers for each domain
         // This is needed only when this member is running as a load balancer
-        for (Object o : groupManagementAgents.keySet()) {
-            String domain = (String) o;
-            final MembershipManager membershipManager = new MembershipManager();
-            membershipManager.setDomain(domain.getBytes());
-            GroupManagementAgent groupMgtAgent = groupManagementAgents.get(domain);
-            membershipManager.setGroupManagementAgent(groupMgtAgent);
-            if(groupMgtAgent instanceof DefaultGroupManagementAgent) {
-                ((DefaultGroupManagementAgent) groupMgtAgent).setMembershipManager(membershipManager);
-            }
-
-            MembershipListener membershipListener = new MembershipListener() {
-                public void memberAdded(org.apache.catalina.tribes.Member member) {
-                    membershipManager.memberAdded(member);
+        for (String domain : groupManagementAgents.keySet()) {
+            Map<String, GroupManagementAgent> groupMgtAgents = groupManagementAgents.get(domain);
+            for (GroupManagementAgent groupMgtAgent : groupMgtAgents.values()) {
+                final MembershipManager membershipManager = new MembershipManager();
+                membershipManager.setDomain(domain.getBytes());
+                membershipManager.setGroupManagementAgent(groupMgtAgent);
+                if(groupMgtAgent instanceof DefaultGroupManagementAgent) {
+                    ((DefaultGroupManagementAgent) groupMgtAgent).setMembershipManager(membershipManager);
                 }
+                MembershipListener membershipListener = new MembershipListener() {
+                    public void memberAdded(org.apache.catalina.tribes.Member member) {
+                        membershipManager.memberAdded(member);
+                    }
 
-                public void memberDisappeared(org.apache.catalina.tribes.Member member) {
-                    membershipManager.memberDisappeared(member);
-                }
-            };
-            channel.addMembershipListener(membershipListener);
-            membershipManagers.add(membershipManager);
+                    public void memberDisappeared(org.apache.catalina.tribes.Member member)
{
+                        membershipManager.memberDisappeared(member);
+                    }
+                };
+                channel.addMembershipListener(membershipListener);
+                membershipManagers.add(membershipManager);
+            }
         }
     }
 

Modified: axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusteringAgent.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusteringAgent.java?rev=1369326&r1=1369325&r2=1369326&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusteringAgent.java
(original)
+++ axis/axis2/java/core/trunk/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusteringAgent.java
Sat Aug  4 13:50:58 2012
@@ -22,14 +22,7 @@ package org.apache.axis2.clustering.trib
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axis2.AxisFault;
-import org.apache.axis2.clustering.ClusteringAgent;
-import org.apache.axis2.clustering.ClusteringCommand;
-import org.apache.axis2.clustering.ClusteringConstants;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.clustering.ClusteringMessage;
-import org.apache.axis2.clustering.MembershipListener;
-import org.apache.axis2.clustering.MembershipScheme;
-import org.apache.axis2.clustering.RequestBlockingHandler;
+import org.apache.axis2.clustering.*;
 import org.apache.axis2.clustering.control.ControlCommand;
 import org.apache.axis2.clustering.control.GetConfigurationCommand;
 import org.apache.axis2.clustering.control.GetStateCommand;
@@ -41,6 +34,7 @@ import org.apache.axis2.clustering.state
 import org.apache.axis2.clustering.state.DefaultStateManager;
 import org.apache.axis2.clustering.state.StateManager;
 import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.description.HandlerDescription;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.PhaseRule;
@@ -54,6 +48,7 @@ import org.apache.catalina.tribes.ErrorH
 import org.apache.catalina.tribes.ManagedChannel;
 import org.apache.catalina.tribes.Member;
 import org.apache.catalina.tribes.UniqueId;
+import org.apache.catalina.tribes.group.GroupChannel;
 import org.apache.catalina.tribes.group.Response;
 import org.apache.catalina.tribes.group.RpcChannel;
 import org.apache.catalina.tribes.group.interceptors.NonBlockingCoordinator;
@@ -68,6 +63,8 @@ import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -81,6 +78,7 @@ import java.util.Set;
 public class TribesClusteringAgent implements ClusteringAgent {
 
     private static final Log log = LogFactory.getLog(TribesClusteringAgent.class);
+    public static final String DEFAULT_SUB_DOMAIN = "__$default";
 
     private DefaultNodeManager configurationManager;
     private DefaultStateManager contextManager;
@@ -114,8 +112,11 @@ public class TribesClusteringAgent imple
      */
     private List<org.apache.axis2.clustering.Member> members;
 
-    private final Map<String, GroupManagementAgent> groupManagementAgents =
-            new HashMap<String, GroupManagementAgent>();
+    /**
+     * Map[key, value=Map[key, value]] = [domain, [subDomain, GroupManagementAgent]]
+     */
+    private final Map<String, Map<String, GroupManagementAgent>> groupManagementAgents
=
+            new HashMap<String, Map<String, GroupManagementAgent>>();
     private boolean clusterManagementMode;
     private RpcMessagingHandler rpcMessagingHandler;
 
@@ -131,16 +132,42 @@ public class TribesClusteringAgent imple
         return members;
     }
 
-    public void addGroupManagementAgent(GroupManagementAgent agent,
-                                        String applicationDomain) {
-        log.info("Managing group application domain " + applicationDomain +
-                 " using agent " + agent.getClass());
-        groupManagementAgents.put(applicationDomain, agent);
+    public int getAliveMemberCount() {
+        return primaryMembershipManager.getMembers().length;
+    }
+
+    public void addGroupManagementAgent(GroupManagementAgent agent, String applicationDomain)
{
+        addGroupManagementAgent(agent, applicationDomain, null);
+    }
+
+    public void addGroupManagementAgent(GroupManagementAgent agent, String applicationDomain,
+                                        String applicationSubDomain) {
+        if (applicationSubDomain == null) {
+            applicationSubDomain = DEFAULT_SUB_DOMAIN; // default sub-domain since a sub-domain
is not specified
+        }
+        log.info("Managing group application domain:" + applicationDomain + ", sub-domain:"
+
+                 applicationSubDomain + " using agent " + agent.getClass());
+        if(!groupManagementAgents.containsKey(applicationDomain)){
+            groupManagementAgents.put(applicationDomain, new HashMap<String, GroupManagementAgent>());
+        }
+        groupManagementAgents.get(applicationDomain).put(applicationSubDomain, agent);
         clusterManagementMode = true;
     }
 
     public GroupManagementAgent getGroupManagementAgent(String applicationDomain) {
-        return groupManagementAgents.get(applicationDomain);
+        return getGroupManagementAgent(applicationDomain, null);
+    }
+
+    public GroupManagementAgent getGroupManagementAgent(String applicationDomain,
+                                                        String applicationSubDomain) {
+        if (applicationSubDomain == null) {
+            applicationSubDomain = DEFAULT_SUB_DOMAIN; // default sub-domain since a sub-domain
is not specified
+        }
+        Map<String, GroupManagementAgent> groupManagementAgentMap = groupManagementAgents.get(applicationDomain);
+        if (groupManagementAgentMap != null) {
+            return groupManagementAgentMap.get(applicationSubDomain);
+        }
+        return null;
     }
 
     public Set<String> getDomains() {
@@ -243,6 +270,7 @@ public class TribesClusteringAgent imple
             ClusteringContextListener contextListener = new ClusteringContextListener(channelSender);
             configurationContext.addContextListener(contextListener);
         }
+
         configurationContext.
                 setNonReplicableProperty(ClusteringConstants.CLUSTER_INITIALIZED, "true");
         log.info("Cluster initialization completed.");
@@ -307,9 +335,14 @@ public class TribesClusteringAgent imple
         AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
         TransportInDescription httpTransport = axisConfig.getTransportIn("http");
         int portOffset = 0;
-        if(System.getProperty("portOffset") != null){
-            portOffset = Integer.parseInt(System.getProperty("portOffset"));
+        Parameter param = getParameter(ClusteringConstants.Parameters.AVOID_INITIATION);
+        if(param != null && !JavaUtils.isTrueExplicitly(param.getValue())){
+            //AvoidInitialization = false, Hence we set the portOffset
+            if(System.getProperty("portOffset") != null){
+                portOffset = Integer.parseInt(System.getProperty("portOffset"));
+            }
         }
+
         if (httpTransport != null) {
             Parameter port = httpTransport.getParameter("port");
             if (port != null) {
@@ -325,6 +358,11 @@ public class TribesClusteringAgent imple
                                String.valueOf(Integer.valueOf((String)port.getValue()) +
portOffset));
             }
         }
+        Parameter isActiveParam = getParameter(ClusteringConstants.Parameters.IS_ACTIVE);
+        if (isActiveParam != null) {
+            memberInfo.setProperty(ClusteringConstants.Parameters.IS_ACTIVE,
+                                   (String) isActiveParam.getValue());
+        }
 
         memberInfo.setProperty("hostName",
                                TribesUtil.getLocalHost(getParameter(TribesConstants.LOCAL_MEMBER_HOST)));
@@ -371,7 +409,7 @@ public class TribesClusteringAgent imple
         // and are assumed to be System properties
         while (indexOfStartingChars < text.indexOf("${") &&
                (indexOfStartingChars = text.indexOf("${")) != -1 &&
-            (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used?
+               (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used?
             String sysProp = text.substring(indexOfStartingChars + 2,
                                             indexOfClosingBrace);
             String propValue = props.getProperty(sysProp);
@@ -495,10 +533,11 @@ public class TribesClusteringAgent imple
     private void configureMode(byte[] domain) {
         if (clusterManagementMode) {
             mode = new ClusterManagementMode(domain, groupManagementAgents, primaryMembershipManager);
-            for (GroupManagementAgent agent : groupManagementAgents.values()) {
-
-                if (agent instanceof DefaultGroupManagementAgent) {
-                    ((DefaultGroupManagementAgent) agent).setSender(channelSender);
+            for (Map<String, GroupManagementAgent> agents : groupManagementAgents.values())
{
+                for (GroupManagementAgent agent : agents.values()) {
+                    if (agent instanceof DefaultGroupManagementAgent) {
+                        ((DefaultGroupManagementAgent) agent).setSender(channelSender);
+                    }
                 }
             }
         } else {
@@ -837,3 +876,4 @@ public class TribesClusteringAgent imple
         return syncAllParam == null || Boolean.parseBoolean((String) syncAllParam.getValue());
     }
 }
+    
\ No newline at end of file

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/ClusteringAgent.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/ClusteringAgent.java?rev=1369326&r1=1369325&r2=1369326&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/ClusteringAgent.java
(original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/ClusteringAgent.java
Sat Aug  4 13:50:58 2012
@@ -160,25 +160,50 @@ public interface ClusteringAgent extends
     List<Member> getMembers();
 
     /**
+     * Get the number of members alive.
+     *
+     * @return the number of members alive.
+     */
+    int getAliveMemberCount();
+
+    /**
      * Set the load balance event handler which will be notified when load balance events
occur.
      * This will be valid only when this node is running in loadBalance mode
      *
-     * @param agent      The load balance event handler
-     * @param applicationDomain The application domain which is handled by the eventHandler
+     * @param agent      The GroupManagementAgent to be added
+     * @param applicationDomain The application domain which is handled by the GroupManagementAgent
      */
     void addGroupManagementAgent(GroupManagementAgent agent, String applicationDomain);
 
     /**
-     * Get the LoadBalanceEventHandler which corresponds to the <code>applicationDomain</code>
-     * This will be valid only when this node is running in loadBalance mode
+     * Add a GroupManagementAgent to an application domain + sub-domain
+     * @param agent  The GroupManagementAgent to be added
+     * @param applicationDomain  The application domain which is handled by the GroupManagementAgent
+     * @param applicationSubDomain The application sub-domain which is handled by the GroupManagementAgent
+     */
+    void addGroupManagementAgent(GroupManagementAgent agent, String applicationDomain,
+                                 String applicationSubDomain);
+
+    /**
+     * Get the GroupManagementAgent which corresponds to the <code>applicationDomain</code>
+     * This will be valid only when this node is running in groupManagement
      *
      * @param applicationDomain The application domain to which the application nodes being
      *                          load balanced belong to
-     * @return LoadBalanceEventHandler which corresponds to the <code>applicationDomain</code>
+     * @return GroupManagementAgent which corresponds to the <code>applicationDomain</code>
      */
     GroupManagementAgent getGroupManagementAgent(String applicationDomain);
 
     /**
+     * Get the GroupManagementAgent which corresponds to the <code>applicationDomain
+ sub-domain</code>
+     * @param applicationDomain  The application domain which is handled by the GroupManagementAgent
+     * @param applicationSubDomain The application sub-domain which is handled by the GroupManagementAgent
+     * @return  GroupManagementAgent which corresponds to the <code>applicationDomain
+ sub-domain</code>
+     */
+    GroupManagementAgent getGroupManagementAgent(String applicationDomain,
+                                                 String applicationSubDomain);
+
+    /**
      * Get all the domains that this ClusteringAgent belongs to
      *
      * @return the domains of this ClusteringAgent
@@ -192,6 +217,7 @@ public interface ClusteringAgent extends
      */
     boolean isCoordinator();
 
+
     /**
      * Send a message to all members in this member's primary cluster
      *

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/Member.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/Member.java?rev=1369326&r1=1369325&r2=1369326&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/Member.java
(original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/clustering/Member.java
Sat Aug  4 13:50:58 2012
@@ -170,6 +170,8 @@ public class Member {
 
     public String toString() {
         return "Host:" + hostName + ", Port: " + port +
-               ", HTTP:" + httpPort + ", HTTPS:" + httpsPort +", ACTIVE:" + isActive;
+               ", HTTP:" + httpPort + ", HTTPS:" + httpsPort +
+               ", Domain: " + domain + ", Sub-domain:" + properties.getProperty("subDomain")
+
+               ", Active:" + isActive;
     }
 }



Mime
View raw message