You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by az...@apache.org on 2007/05/25 11:24:18 UTC

svn commit: r541594 - in /webservices/axis2/trunk/java/modules: clustering/src/org/apache/axis2/clustering/control/ clustering/src/org/apache/axis2/clustering/tribes/ kernel/src/org/apache/axis2/clustering/ kernel/src/org/apache/axis2/context/

Author: azeez
Date: Fri May 25 02:24:16 2007
New Revision: 541594

URL: http://svn.apache.org/viewvc?view=rev&rev=541594
Log:
A node which receive a GetStateCommand should refrain from replying, if the receiver itself has not still initialized.
The reqeuster will randomly select another node and request the state. However, after trying several times unsuccessfully,
the requester has to break out of the loop and continue to initialize itself.


Modified:
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/control/GetStateResponseCommand.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesClusterManager.java
    webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesControlCommandProcessor.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/clustering/ClusteringConstants.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/control/GetStateResponseCommand.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/control/GetStateResponseCommand.java?view=diff&rev=541594&r1=541593&r2=541594
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/control/GetStateResponseCommand.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/control/GetStateResponseCommand.java Fri May 25 02:24:16 2007
@@ -27,6 +27,6 @@
     public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
         //TODO: Method implementation
         configurationContext.
-                setNonReplicableProperty(ClusteringConstants.GET_STATE_RESPONSE_RECEIVED, "true");
+                setNonReplicableProperty(ClusteringConstants.CLUSTER_INITIALIZED, "true");
     }
 }

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?view=diff&rev=541594&r1=541593&r2=541594
==============================================================================
--- 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 Fri May 25 02:24:16 2007
@@ -42,6 +42,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Random;
 
 public class TribesClusterManager implements ClusterManager {
     private static final Log log = LogFactory.getLog(TribesClusterManager.class);
@@ -119,7 +120,6 @@
             channel.addChannelListener(channelInfo);
             channel.addMembershipListener(memberInfo);
             membershipListener = new TribesMembershipListener();
-//            membershipListener.setConfigContext(configurationManager);  //TODO: set the config ctx here and when config context is switched
             channel.addMembershipListener(membershipListener);
             channel.start(Channel.DEFAULT);
             sender.setChannel(channel);
@@ -132,27 +132,31 @@
             TribesUtil.printMembers(members);
 
             // If there is at least one member in the Tribe, get the current state from a member
-            /*while (members.length > 0 &&
+            Random random = new Random();
+            int numberOfTries = 0;
+            while (members.length > 0 &&
                    configurationContext.
-                           getProperty(ClusteringConstants.GET_STATE_RESPONSE_RECEIVED) == null) {
+                           getNonReplicableProperty(ClusteringConstants.CLUSTER_INITIALIZED) == null &&
+                    numberOfTries < 50) { // Don't keep on trying infinitely
 
                 // While there are members and GetStateResponseCommand is not received do the following
                 try {
                     members = channel.getMembers();
+                    int memberIndex = random.nextInt(members.length);
 
-                    //TODO: select a random member and send the request to it. Otherwise the same member will
-                    // get overloaded
-                    sender.sendToMember(new GetStateCommand(), members[0]);
+                    System.err.println("###### memberIndex=" + memberIndex);
+                    sender.sendToMember(new GetStateCommand(), members[memberIndex]);
                     System.out.println("### WAITING FOR STATE UPDATE");
                     Thread.sleep(200);
                 } catch (Exception e) {
                     e.printStackTrace();
                     break;
                 }
+                numberOfTries ++;
             }
             configurationContext.
-                    removePropertyNonReplicable(ClusteringConstants.GET_STATE_RESPONSE_RECEIVED);*/
-
+                           setNonReplicableProperty(ClusteringConstants.CLUSTER_INITIALIZED,
+                                                    "true");
         } catch (ChannelException e) {
             String message = "Error starting Tribes channel";
             throw new ClusteringFault(message, e);

Modified: webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesControlCommandProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesControlCommandProcessor.java?view=diff&rev=541594&r1=541593&r2=541594
==============================================================================
--- webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesControlCommandProcessor.java (original)
+++ webservices/axis2/trunk/java/modules/clustering/src/org/apache/axis2/clustering/tribes/TribesControlCommandProcessor.java Fri May 25 02:24:16 2007
@@ -15,6 +15,7 @@
  */
 package org.apache.axis2.clustering.tribes;
 
+import org.apache.axis2.clustering.ClusteringConstants;
 import org.apache.axis2.clustering.ClusteringFault;
 import org.apache.axis2.clustering.control.ControlCommand;
 import org.apache.axis2.clustering.control.GetStateCommand;
@@ -43,10 +44,21 @@
     }
 
     public void process(ControlCommand command, Member sender) throws ClusteringFault {
-        command.execute(configurationContext);
-        if(command instanceof GetStateCommand){
+
+        if (command instanceof GetStateCommand) {
+
+            // If a GetStateRequest is received by a node which has not yet initialized
+            // (i.e. by getting the GetStateResponseCommand), this node cannot send a response
+            // to the state requester. So we simply return.
+            if (configurationContext.
+                    getNonReplicableProperty(ClusteringConstants.CLUSTER_INITIALIZED) == null) {
+                return;
+            }
+            command.execute(configurationContext);
             channelSender.sendToMember(new GetStateResponseCommand(),
                                        sender);
+        } else {
+            command.execute(configurationContext);
         }
     }
 }

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?view=diff&rev=541594&r1=541593&r2=541594
==============================================================================
--- 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 Fri May 25 02:24:16 2007
@@ -23,5 +23,5 @@
 
     public static final String AVOID_INITIATION_KEY = "AvoidInitiation";
     public static final String DOMAIN = "domain";
-    public static final String GET_STATE_RESPONSE_RECEIVED = "local_get.state.response.recd";
+    public static final String CLUSTER_INITIALIZED = "local_cluster.initialized";
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java?view=diff&rev=541594&r1=541593&r2=541594
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java Fri May 25 02:24:16 2007
@@ -100,6 +100,21 @@
     }
 
     /**
+     * Retrieves an object given a key. The retrieved property will not be replicated to
+     * other nodes in the clustered scenario.
+     *
+     * @param key - if not found, will return null
+     * @return Returns the property.
+     */
+    public Object getNonReplicableProperty(String key) {
+        Object obj = properties == null ? null : properties.get(key);
+        if ((obj == null) && (parent != null)) {
+            obj = parent.getNonReplicableProperty(key);
+        }
+        return obj;
+    }
+
+    /**
      * Store a property in this context
      *
      * @param key



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