[jboss-cvs] JBossAS SVN: r59383 - trunk/cluster/src/main/org/jboss/ha/framework/server

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 5 13:50:26 EST 2007


Author: bstansberry at jboss.com
Date: 2007-01-05 13:50:25 -0500 (Fri, 05 Jan 2007)
New Revision: 59383

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java
Log:
[JBAS-3968] Ensure the unique node id is set when JBC creates a channel

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java	2007-01-05 18:42:09 UTC (rev 59382)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java	2007-01-05 18:50:25 UTC (rev 59383)
@@ -39,6 +39,7 @@
 import org.jboss.system.server.ServerConfigUtil;
 import org.jgroups.Channel;
 import org.jgroups.Event;
+import org.jgroups.mux.MuxChannel;
 import org.jgroups.stack.IpAddress;
 
 /**
@@ -56,26 +57,34 @@
    private InetAddress nodeAddress;
    private String nodeName;
 
+   /**
+    * Overrides the superclass version by generating a unique node id
+    * and passing it down the Channel as additional_data.
+    */
+   @Override
    public Channel createMultiplexerChannel(String stack_name, String id, boolean register_for_state_transfer, String substate_id) throws Exception
    {
       Channel channel = super.createMultiplexerChannel(stack_name, id, register_for_state_transfer, substate_id);
       
-      IpAddress address = (IpAddress) channel.getLocalAddress();
-      if (address == null)
-      {
-         // We push the independent name in the protocol stack before connecting to the cluster
-         if (this.nodeName == null || "".equals(this.nodeName)) {
-            this.nodeName = generateUniqueNodeName();
-         }
-         java.util.HashMap staticNodeName = new java.util.HashMap();
-         staticNodeName.put("additional_data", this.nodeName.getBytes());
-         channel.down(new Event(Event.CONFIG, staticNodeName));
-         
-      }
+      setChannelUniqueId(channel);
+      
       return channel;
    }
+   
+   /**
+    * Overrides the superclass version by generating a unique node id
+    * and passing it down the Channel as additional_data.
+    */
+   @Override
+   public Channel createMultiplexerChannel(String stack_name, String id) throws Exception
+   {
+      Channel channel = super.createMultiplexerChannel(stack_name, id);
+      
+      setChannelUniqueId(channel);
+      
+      return channel;
+   }
 
-   
    public InetAddress getNodeAddress()
    {
       return nodeAddress;
@@ -99,6 +108,44 @@
       this.nodeName = nodeName;
    }
 
+   private void setChannelUniqueId(Channel channel) throws Exception
+   {
+      IpAddress address = (IpAddress) channel.getLocalAddress();
+      if (address == null)
+      {
+         // We push the independent name in the protocol stack before connecting to the cluster
+         if (this.nodeName == null || "".equals(this.nodeName)) {
+            this.nodeName = generateUniqueNodeName();
+         }
+         
+         log.debug("Passing unique node id " + nodeName + " to the channel as additional data");
+         
+         java.util.HashMap staticNodeName = new java.util.HashMap();
+         staticNodeName.put("additional_data", this.nodeName.getBytes());
+         channel.down(new Event(Event.CONFIG, staticNodeName));
+         
+      }
+      else if (address.getAdditionalData() == null)
+      {
+         Channel testee = channel;
+         if (channel instanceof MuxChannel)
+         {
+            testee = ((MuxChannel) channel).getChannel();
+         }
+         
+         if (testee.isConnected())
+         {
+            throw new IllegalStateException("Underlying JChannel was " +
+                    "connected before additional_data was set");
+         }
+      }
+      else if (this.nodeName == null || "".equals(this.nodeName))
+      {         
+         this.nodeName = new String(address.getAdditionalData());
+         log.warn("Field nodeName was not set but mux channel already had " +
+                "additional data -- setting nodeName to " + nodeName);
+      }
+   }
 
    private String generateUniqueNodeName () throws Exception
    {




More information about the jboss-cvs-commits mailing list