You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by az...@apache.org on 2008/05/17 17:46:11 UTC

svn commit: r657379 - in /webservices/axis2/trunk/java/modules: clustering/src/org/apache/axis2/clustering/tribes/ clustering/test/org/apache/axis2/clustering/ kernel/conf/ kernel/src/org/apache/axis2/clustering/ kernel/src/org/apache/axis2/context/

Author: azeez
Date: Sat May 17 08:46:11 2008
New Revision: 657379

URL: http://svn.apache.org/viewvc?rev=657379&view=rev
Log:
Improvements to clustering code - Introducing appropriate constants


Added:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesConstants.java
Modified:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
    webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/ContextReplicationTest.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/context/ConfigurationContext.java

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=657379&r1=657378&r2=657379&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 Sat May 17 08:46:11 2008
@@ -149,9 +149,7 @@
                 channel.stop(Channel.DEFAULT);
                 throw new ClusteringFault("Cannot join cluster using IP " + localHost +
                                           ". Please set an IP address other than " +
-                                          localHost + " in your /etc/hosts file or set the " +
-                                          ClusteringConstants.LOCAL_IP_ADDRESS +
-                                          " System property and retry."); //TODO: setting the value in the axis2.xml file
+                                          localHost + " in the axis2.xml file"); 
             }
         } catch (ChannelException e) {
             String msg = "Error starting Tribes channel";
@@ -193,7 +191,8 @@
      * @return The membership scheme. Only "wka" & "multicast" are valid return values.
      */
     private String getMembershipScheme() {
-        Parameter membershipSchemeParam = getParameter("membershipScheme");
+        Parameter membershipSchemeParam =
+                getParameter(ClusteringConstants.Parameters.MEMBERSHIP_SCHEME);
         String membershipScheme = ClusteringConstants.MembershipScheme.MULTICAST_BASED;
         if (membershipSchemeParam != null) {
             membershipScheme = ((String) membershipSchemeParam.getValue()).trim();
@@ -207,7 +206,7 @@
      * @return The clustering domain to which this node belongs to
      */
     private byte[] getClusterDomain() {
-        Parameter domainParam = getParameter(ClusteringConstants.DOMAIN);
+        Parameter domainParam = getParameter(ClusteringConstants.Parameters.DOMAIN);
         byte[] domain;
         if (domainParam != null) {
             domain = ((String) domainParam.getValue()).getBytes();
@@ -300,15 +299,15 @@
             StaticMember localMember = new StaticMember();
             membershipManager.setLocalMember(localMember);
             ReceiverBase receiver = (ReceiverBase) channel.getChannelReceiver();
-            Parameter tcpListenHost = getParameter("tcpListenHost");
-            if (tcpListenHost != null) {
-                String host = ((String) tcpListenHost.getValue()).trim();
+            Parameter localHost = getParameter(TribesConstants.LOCAL_MEMBER_HOST);
+            if (localHost != null) {
+                String host = ((String) localHost.getValue()).trim();
                 receiver.setAddress(host);
                 localMember.setHost(host);
             }
-            Parameter tcpListenPort = getParameter("tcpListenPort");
-            if (tcpListenPort != null) {
-                String port = ((String) tcpListenPort.getValue()).trim();
+            Parameter localPort = getParameter(TribesConstants.LOCAL_MEMBER_PORT);
+            if (localPort != null) {
+                String port = ((String) localPort.getValue()).trim();
                 receiver.setPort(Integer.parseInt(port));
                 localMember.setPort(Integer.parseInt(port));
             }
@@ -369,11 +368,11 @@
                                                            member.getPort());
             new Socket().connect(sockaddr, 3000);
             canConnect = true;
-        } catch (IOException ignored) {
+        } catch (IOException e) {
             // A debug level log is sufficient here since we are only trying to verify whether
             // the member in concern is online or offline
-//            log.debug("Cannot connect to member " +
-//                      member.getHostName() + ":" + member.getPort(), e);
+            log.debug("Cannot connect to member " +
+                      member.getHostName() + ":" + member.getPort(), e);
         }
         return canConnect;
     }
@@ -443,35 +442,40 @@
     private void configureMulticastParameters(ManagedChannel channel,
                                               byte[] domain) {
         Properties mcastProps = channel.getMembershipService().getProperties();
-        Parameter mcastAddress = getParameter("multicastAddress");
+        Parameter mcastAddress = getParameter(TribesConstants.MCAST_ADDRESS);
         if (mcastAddress != null) {
-            mcastProps.setProperty("mcastAddress", ((String) mcastAddress.getValue()).trim());
+            mcastProps.setProperty(TribesConstants.MCAST_ADDRESS,
+                                   ((String) mcastAddress.getValue()).trim());
         }
-        Parameter mcastBindAddress = getParameter("multicastBindAddress");
+        Parameter mcastBindAddress = getParameter(TribesConstants.MCAST_BIND_ADDRESS);
         if (mcastBindAddress != null) {
-            mcastProps.setProperty("mcastBindAddress", ((String) mcastBindAddress.getValue()).trim());
+            mcastProps.setProperty(TribesConstants.MCAST_BIND_ADDRESS,
+                                   ((String) mcastBindAddress.getValue()).trim());
         }
 
-        Parameter mcastPort = getParameter("multicastPort");
+        Parameter mcastPort = getParameter(TribesConstants.MCAST_PORT);
         if (mcastPort != null) {
-            mcastProps.setProperty("mcastPort", ((String) mcastPort.getValue()).trim());
+            mcastProps.setProperty(TribesConstants.MCAST_PORT, 
+                                   ((String) mcastPort.getValue()).trim());
         }
-        Parameter mcastFrequency = getParameter("multicastFrequency");
+        Parameter mcastFrequency = getParameter(TribesConstants.MCAST_FREQUENCY);
         if (mcastFrequency != null) {
-            mcastProps.setProperty("mcastFrequency", ((String) mcastFrequency.getValue()).trim());
+            mcastProps.setProperty(TribesConstants.MCAST_FREQUENCY,
+                                   ((String) mcastFrequency.getValue()).trim());
         }
-        Parameter mcastMemberDropTime = getParameter("multicastMemberDropTime");
+        Parameter mcastMemberDropTime = getParameter(TribesConstants.MEMBER_DROP_TIME);
         if (mcastMemberDropTime != null) {
-            mcastProps.setProperty("memberDropTime", ((String) mcastMemberDropTime.getValue()).trim());
+            mcastProps.setProperty(TribesConstants.MEMBER_DROP_TIME,
+                                   ((String) mcastMemberDropTime.getValue()).trim());
         }
 
         // Set the IP address that will be advertised by this node
         ReceiverBase receiver = (ReceiverBase) channel.getChannelReceiver();
-        Parameter tcpListenHost = getParameter("tcpListenHost");
+        Parameter tcpListenHost = getParameter(TribesConstants.LOCAL_MEMBER_HOST);
         if (tcpListenHost != null) {
             String host = ((String) tcpListenHost.getValue()).trim();
-            mcastProps.setProperty("tcpListenHost", host);
-            mcastProps.setProperty("bindAddress", host);
+            mcastProps.setProperty(TribesConstants.TCP_LISTEN_HOST, host);
+            mcastProps.setProperty(TribesConstants.BIND_ADDRESS, host);
             receiver.setAddress(host);
         }
         String localIP = System.getProperty(ClusteringConstants.LOCAL_IP_ADDRESS);
@@ -479,14 +483,14 @@
             receiver.setAddress(localIP);
         }
 
-        Parameter tcpListenPort = getParameter("tcpListenPort");
+        Parameter tcpListenPort = getParameter(TribesConstants.LOCAL_MEMBER_PORT);
         if (tcpListenPort != null) {
             String port = ((String) tcpListenPort.getValue()).trim();
-            mcastProps.setProperty("tcpListenPort", port);
+            mcastProps.setProperty(TribesConstants.TCP_LISTEN_PORT, port);
             receiver.setPort(Integer.parseInt(port));
         }
 
-        mcastProps.setProperty("mcastClusterDomain", new String(domain));
+        mcastProps.setProperty(TribesConstants.MCAST_CLUSTER_DOMAIN, new String(domain));
     }
 
     /**
@@ -626,7 +630,7 @@
     }
 
     /**
-     * Method to check whether all members in the cluster have to be kep in sync at all times.
+     * Method to check whether all members in the cluster have to be kept in sync at all times.
      * Typically, this will require each member in the cluster to ACKnowledge receipt of a
      * particular message, which may have a significant performance hit.
      *
@@ -634,7 +638,7 @@
      *         otherwise
      */
     public boolean synchronizeAllMembers() {
-        Parameter syncAllParam = getParameter(ClusteringConstants.SYNCHRONIZE_ALL_MEMBERS);
+        Parameter syncAllParam = getParameter(ClusteringConstants.Parameters.SYNCHRONIZE_ALL_MEMBERS);
         return syncAllParam == null || Boolean.parseBoolean((String) syncAllParam.getValue());
     }
 }

Added: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesConstants.java?rev=657379&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesConstants.java (added)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesConstants.java Sat May 17 08:46:11 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.tribes;
+
+/**
+ * This class holds the configuration parameters which are specific to Tribes
+ */
+public final class TribesConstants {
+
+    public static final String LOCAL_MEMBER_HOST = "localMemberHost";
+    public static final String LOCAL_MEMBER_PORT = "localMemberPort";
+
+    public static final String MCAST_ADDRESS = "mcastAddress";
+    public static final String MCAST_BIND_ADDRESS = "multicastBindAddress";
+    public static final String MCAST_PORT = "mcastPort";
+    public static final String MCAST_FREQUENCY = "mcastFrequency";
+    public static final String MEMBER_DROP_TIME = "memberDropTime";
+    public static final String MCAST_CLUSTER_DOMAIN = "mcastClusterDomain";
+    public static final String TCP_LISTEN_HOST = "tcpListenHost";
+    public static final String BIND_ADDRESS = "bindAddress";
+    public static final String TCP_LISTEN_PORT = "tcpListenPort";
+}

Modified: webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/ContextReplicationTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/ContextReplicationTest.java?rev=657379&r1=657378&r2=657379&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/ContextReplicationTest.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/test/org/apache/axis2/clustering/ContextReplicationTest.java Sat May 17 08:46:11 2008
@@ -57,7 +57,8 @@
     private static final String TEST_SERVICE_NAME = "testService";
 
     private static final Parameter domainParam =
-            new Parameter(ClusteringConstants.DOMAIN, "axis2.domain." + UUIDGenerator.getUUID());
+            new Parameter(ClusteringConstants.Parameters.DOMAIN,
+                          "axis2.domain." + UUIDGenerator.getUUID());
 
     // --------------- Cluster-1 ------------------------------------------------------
     private ClusterManager clusterManager1;

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=657379&r1=657378&r2=657379&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml Sat May 17 08:46:11 2008
@@ -252,14 +252,14 @@
         <parameter name="synchronizeAll">true</parameter>
         <parameter name="maxRetries">10</parameter>
 
-        <parameter name="multicastAddress">228.0.0.4</parameter>
-        <parameter name="multicastBindAddress">127.0.0.1</parameter>
-        <parameter name="multicastPort">45564</parameter>
-        <parameter name="multicastFrequency">500</parameter>
-        <parameter name="multicastMemberDropTime">3000</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="tcpListenHost">127.0.0.1</parameter>
-        <parameter name="tcpListenPort">4000</parameter>
+        <parameter name="localMemberHost">127.0.0.1</parameter>
+        <parameter name="localMemberPort">4000</parameter>
 
         <members>
             <member>

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=657379&r1=657378&r2=657379&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 Sat May 17 08:46:11 2008
@@ -28,14 +28,6 @@
     private ClusteringConstants() {
     }
 
-    public static final String AVOID_INITIATION_KEY = "AvoidInitiation";
-
-    /**
-     * 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 group.
-     */
-    public static final String DOMAIN = "domain";
-
     /**
      * The default domain to which this node belongs to
      */
@@ -50,15 +42,37 @@
     public static final String LOCAL_IP_ADDRESS = "axis2.local.ip.address";
 
     /**
-     * Synchronize the states of all members in the cluster
-     */
-    public static final String SYNCHRONIZE_ALL_MEMBERS = "synchronizeAll";
-
-    /**
      * The main cluster configuration parameters
      */
     public static final class Parameters {
 
+        /**
+         * The membership scheme used in this setup. The only values supported at the moment are
+         * "multicast" and "wka"
+         */
+        public static final String MEMBERSHIP_SCHEME = "membershipScheme";
+
+        /**
+         * 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.
+         */
+        public static final String DOMAIN = "domain";
+
+        /**
+         * 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"
+         */
+        public static final String SYNCHRONIZE_ALL_MEMBERS = "synchronizeAll";
+
+        /**
+         * Do not automatically initialize the cluster. The programmer has to explicitly initialize
+         * the cluster.
+         */
+        public static final String AVOID_INITIATION = "AvoidInitiation";
     }
 
     public static final class MembershipScheme {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java?rev=657379&r1=657378&r2=657379&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java Sat May 17 08:46:11 2008
@@ -113,7 +113,7 @@
 
     /**
      * Initializes the ClusterManager for this ConfigurationContext
-     * 
+     *
      * @throws AxisFault
      */
     public void initCluster() throws AxisFault {
@@ -134,8 +134,15 @@
         }
     }
 
+    /**
+     *
+     * @param clusterManager The ClusterManager implementation
+     * @return true, if the cluster needs to be automatically initialized by the framework;
+     *         false, otherwise
+     */
     private static boolean shouldClusterBeInitiated(ClusterManager clusterManager) {
-        Parameter param = clusterManager.getParameter(ClusteringConstants.AVOID_INITIATION_KEY);
+        Parameter param =
+                clusterManager.getParameter(ClusteringConstants.Parameters.AVOID_INITIATION);
         return !(param != null && JavaUtils.isTrueExplicitly(param.getValue()));
     }
 
@@ -290,31 +297,31 @@
      * @param messageID
      * @param mepContext
      */
-    public boolean registerOperationContext(String messageID, 
+    public boolean registerOperationContext(String messageID,
                                             OperationContext mepContext) {
         return registerOperationContext(messageID, mepContext, false);
     }
-    
+
     /**
      * Registers a OperationContext with a given message ID.
      * If the given message id already has a registered operation context,
-     * no change is made unless the override flag is set. 
+     * no change is made unless the override flag is set.
      *
      * @param messageID
      * @param mepContext
      * @param override
      */
-    public boolean registerOperationContext(String messageID, 
-                                            OperationContext mepContext, 
+    public boolean registerOperationContext(String messageID,
+                                            OperationContext mepContext,
                                             boolean override) {
-    	
+
     	if(messageID == null){
     		if(log.isDebugEnabled()){
     			log.debug("messageID is null. Returning false");
     		}
     		return false;
     	}
-    	
+
         boolean alreadyInMap = false;
         mepContext.setKey(messageID);
 
@@ -357,10 +364,10 @@
     public boolean isAnyOperationContextRegistered(){
     	return !operationContextMap.isEmpty();
     }
-    
+
     /**
      * Adds the given ServiceGroupContext into the SOAP session table
-     * 
+     *
      * @param serviceGroupContext ServiceGroup Context to add
      */
     public void addServiceGroupContextIntoSoapSessionTable(
@@ -421,7 +428,7 @@
 
     /**
      * Finds the OperationContext given the Operation name, Service Name, and ServiceGroupName
-     * 
+     *
      * @param operationName - OperationName to find
      * @param serviceName - ServiceName to find
      * @param serviceGroupName - ServiceGroupName to find
@@ -518,7 +525,7 @@
 
     /**
      * Retrieve the ServiceGroupContext from the SOAP session table
-     * 
+     *
      * @param serviceGroupContextId Service Group Context ID to search on
      * @param msgContext Message Context to search on
      * @return Returns a ServiceGroupContext
@@ -617,7 +624,7 @@
 
     /**
      * Set the AxisConfiguration to the specified configuration
-     * 
+     *
      * @param configuration
      */
     public void setAxisConfiguration(AxisConfiguration configuration) {
@@ -658,8 +665,8 @@
             return;
         }
         long currentTime = new Date().getTime();
-        
-        synchronized (serviceGroupContextMap) { 
+
+        synchronized (serviceGroupContextMap) {
             for (Iterator sgCtxtMapKeyIter = serviceGroupContextMap.keySet().iterator();
                  sgCtxtMapKeyIter.hasNext();) {
                 String sgCtxtId = (String) sgCtxtMapKeyIter.next();
@@ -677,7 +684,7 @@
 
     /**
      * Retrieve the ListenerManager
-     * 
+     *
      * @return Returns the ListenerManager
      */
     public ListenerManager getListenerManager() {
@@ -686,7 +693,7 @@
 
     /**
      * Set the TransportManager to the given ListenerManager
-     * 
+     *
      * @param listenerManager The ListenerManager for which to set the TransportManager
      */
     public void setTransportManager(ListenerManager listenerManager) {
@@ -734,9 +741,9 @@
     }
 
     /**
-     * Invoked during shutdown to stop the ListenerManager and 
+     * Invoked during shutdown to stop the ListenerManager and
      * perform configuration cleanup
-     * 
+     *
      * @throws AxisFault
      */
     public void terminate() throws AxisFault {
@@ -800,7 +807,7 @@
 
     /**
      * Retrieves the ServiceContext path
-     * 
+     *
      * @return path to the ServiceContext
      */
     public String getServiceContextPath() {