[jboss-cvs] JBoss Messaging SVN: r4001 - in branches/Branch_Stable/tests: src/org/jboss/test/messaging/core and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 3 15:54:09 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-04-03 15:54:09 -0400 (Thu, 03 Apr 2008)
New Revision: 4001

Added:
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactoryMBean.java
Modified:
   branches/Branch_Stable/tests/etc/server/default/deploy/mock-channelfactory-service.xml
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactory.java
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/tools/jboss/MBeanConfigurationElement.java
Log:
Fixing JGroups factories

Modified: branches/Branch_Stable/tests/etc/server/default/deploy/mock-channelfactory-service.xml
===================================================================
--- branches/Branch_Stable/tests/etc/server/default/deploy/mock-channelfactory-service.xml	2008-04-03 15:04:11 UTC (rev 4000)
+++ branches/Branch_Stable/tests/etc/server/default/deploy/mock-channelfactory-service.xml	2008-04-03 19:54:09 UTC (rev 4001)
@@ -8,7 +8,7 @@
     Author: Bela Ban
     Version: $Id$
     -->
-    <mbean code="org.jgroups.jmx.JChannelFactory" name="jboss.jgroups:service=ChannelFactory">
+    <mbean code="org.jboss.test.messaging.jms.server.channelfactory.MockChannelFactory" name="jboss.jgroups:service=ChannelFactory" >
     <!--mbean code="org.jgroups.JChannelFactory" name="jgroups.mux:name=Multiplexer" xmbean-dd="resource:META-INF/multiplexer-xmbean.xml" -->
         <attribute name="Domain">jboss.jgroups</attribute>
         <attribute name="MultiplexerConfig">server/default/deploy/mock-channelfactory-stacks.xml</attribute>

Modified: branches/Branch_Stable/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java	2008-04-03 15:04:11 UTC (rev 4000)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java	2008-04-03 19:54:09 UTC (rev 4001)
@@ -84,8 +84,7 @@
 
       String configFilePath = sc.getPersistenceConfigFile(true);
 
-      // TODO (ovidiu) we're temporarily ignoring the multiplex option, it doesn't work well
-      boolean ignoreMultiplexer = true;
+      boolean ignoreMultiplexer = false;
       ChannelFactory jChannelFactory =
          new ClusteredPersistenceServiceConfigFileJChannelFactory(configFilePath,
                                                                   ignoreMultiplexer,

Modified: branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactory.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactory.java	2008-04-03 15:04:11 UTC (rev 4000)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactory.java	2008-04-03 19:54:09 UTC (rev 4001)
@@ -24,13 +24,19 @@
 
 
 import java.net.InetAddress;
+import java.rmi.dgc.VMID;
+import java.rmi.server.UID;
+import java.util.UUID;
 
 import org.jboss.logging.Logger;
 import org.jboss.system.ServiceMBean;
+import org.jboss.system.server.ServerConfigUtil;
 import org.jgroups.Channel;
+import org.jgroups.Event;
 import org.jgroups.Global;
+import org.jgroups.mux.MuxChannel;
+import org.jgroups.stack.IpAddress;
 
-
 /**
  * Extension to the JGroups JChannelFactory that supports the addition
  * of "additional_data" to the channel config.
@@ -40,10 +46,11 @@
  * @version $Revision$
  */
 
-public class MockChannelFactory extends org.jgroups.JChannelFactory
+public class MockChannelFactory extends org.jgroups.JChannelFactory implements MockChannelFactoryMBean
 {
-   protected static Logger log = Logger.getLogger(MockChannelFactory.class);
-   
+   private static final Logger log =
+      Logger.getLogger(MockChannelFactory.class);
+
    private static final int CREATED = ServiceMBean.CREATED;
    private static final int STARTING = ServiceMBean.STARTING;
    private static final int STARTED = ServiceMBean.STARTED;
@@ -90,6 +97,9 @@
          channel = super.createMultiplexerChannel(stack_name, id, false, null);
       }
       
+      if (assignLogicalAddresses)
+         setChannelUniqueId(channel);
+      
       return channel;
    }
    
@@ -323,10 +333,94 @@
       return ch;
    }
 
+   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 getStateString()
    {
       return ServiceMBean.states[state];
    }
 
+   private String generateUniqueNodeName () throws Exception
+   {
+      // we first try to find a simple meaningful name:
+      // 1st) "local-IP:JNDI_PORT" if JNDI is running on this machine
+      // 2nd) "local-IP:JMV_GUID" otherwise
+      // 3rd) return a fully GUID-based representation
+      //
+
+      // Before anything we determine the local host IP (and NOT name as this could be
+      // resolved differently by other nodes...)
+
+      // But use the specified node address for multi-homing
+
+      String hostIP = null;
+      InetAddress address = ServerConfigUtil.fixRemoteAddress(nodeAddress);
+      if (address == null)
+      {
+         log.debug ("unable to create a GUID for this cluster, check network configuration is correctly setup (getLocalHost has returned an exception)");
+         log.debug ("using a full GUID strategy");
+         return new VMID().toString();
+      }
+      else
+      {
+         hostIP = address.getHostAddress();
+      }
+
+      // 1st: is JNDI up and running?
+      //
+      if (namingServicePort > 0)
+      {
+         // we can proceed with the JNDI trick!
+         return hostIP + ":" + namingServicePort;
+      }
+      else
+      {
+         log.debug("JNDI has been found but the service wasn't started so we cannot " +
+                   "be entirely sure we are the only one that wants to use this PORT " +
+                   "as a GUID on this host.");
+      }
+
+      // 2nd: host-GUID strategy
+      //
+      String uid = new UID().toString();
+      return hostIP + ":" + uid;
+   }
    
-}
+}
\ No newline at end of file

Added: branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactoryMBean.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactoryMBean.java	                        (rev 0)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactoryMBean.java	2008-04-03 19:54:09 UTC (rev 4001)
@@ -0,0 +1,6 @@
+package org.jboss.test.messaging.jms.server.channelfactory;
+
+public interface MockChannelFactoryMBean extends org.jgroups.jmx.JChannelFactoryMBean
+{
+
+}


Property changes on: branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactoryMBean.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Modified: branches/Branch_Stable/tests/src/org/jboss/test/messaging/tools/jboss/MBeanConfigurationElement.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/tools/jboss/MBeanConfigurationElement.java	2008-04-03 15:04:11 UTC (rev 4000)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/tools/jboss/MBeanConfigurationElement.java	2008-04-03 19:54:09 UTC (rev 4001)
@@ -196,7 +196,12 @@
 
    public String getAttributeValue(String name)
    {
-      return (String)mbeanConfigAttributes.get(name);
+      String value = (String)mbeanConfigAttributes.get(name);
+      if (value == null)
+      {
+         value = (String)mbeanOptionalAttributeNames.get(name);
+      }
+      return value;
    }
 
    public void setAttribute(String name, String value)




More information about the jboss-cvs-commits mailing list