[jboss-cvs] JBoss Messaging SVN: r4030 - branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 10 23:50:44 EDT 2008


Author: clebert.suconic at jboss.com
Date: 2008-04-10 23:50:44 -0400 (Thu, 10 Apr 2008)
New Revision: 4030

Modified:
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactory.java
Log:
Mock should just create new channels on every call

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-11 02:43:30 UTC (rev 4029)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/server/channelfactory/MockChannelFactory.java	2008-04-11 03:50:44 UTC (rev 4030)
@@ -23,19 +23,9 @@
 package org.jboss.test.messaging.jms.server.channelfactory;
 
 
-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
@@ -48,59 +38,11 @@
 
 public class MockChannelFactory extends org.jgroups.JChannelFactory implements MockChannelFactoryMBean
 {
-   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;
-   private static final int STOPPING = ServiceMBean.STOPPING;
-   private static final int STOPPED = ServiceMBean.STOPPED;
-   private static final int DESTROYED = ServiceMBean.DESTROYED;
-   private static final int FAILED = ServiceMBean.FAILED;
-   
-   private InetAddress nodeAddress;
-   private String nodeName;
-   private int namingServicePort = -1;
-   private int state;
-   private boolean assignLogicalAddresses = true;
-
-   /**
-    * Overrides the superclass version by generating a unique node id
-    * and passing it down the Channel as additional_data and by suppressing the 
-    * <code>register_for_state_transfer</code> param.
-    * <p/>
-    * The additional data is the value of {@link #getNodeName()} which either
-    * can be injected as part of configuration or will be calculated 
-    * the first time a channel is created.
-    * <p/>
-    * Suppressing the <code>register_for_state_transfer</code> param is necessary
-    * to avoid issues that occur with JGroups when it is <code>true</code>.
-    * In JBoss AS there is little benefit to setting this to true, as the 
-    * single-threaded nature of deployments in the AS ensures that services 
-    * always connect channels and request state transfer in series, with no
-    * interleaving. 
-    * 
-    * @param register_for_state_transfer  ignored; always treated as <code>false</code>
-    */
    @Override
    public Channel createMultiplexerChannel(String stack_name, String id, boolean register_for_state_transfer, String substate_id) throws Exception
    {
-      // Due to problems with coordinated state transfer, we suppress register_for_state_transfer usage.
-      // TODO revert to normal if coordinated state transfer is fixed
-//      Channel channel = super.createMultiplexerChannel(stack_name, id, register_for_state_transfer, substate_id);
-      Channel channel = createSharedTransportChannel(stack_name);
-      
-      if (channel == null)      
-      {
-         log.debug("Config for " + stack_name + " does not include singleton_name; creating MuxChannel. Config is " + getConfig(stack_name));
-         channel = super.createMultiplexerChannel(stack_name, id, false, null);
-      }
-      
-      if (assignLogicalAddresses)
-         setChannelUniqueId(channel);
-      
-      return channel;
+      // on the mock we aways create a new channel
+      return createChannel(stack_name); 
    }
    
    /**
@@ -112,315 +54,5 @@
    {
       return createMultiplexerChannel(stack_name, id, false, null);
    }
-
-   public InetAddress getNodeAddress()
-   {
-      return nodeAddress;
-   }
-
-
-   public void setNodeAddress(InetAddress nodeAddress)
-   {
-      this.nodeAddress = nodeAddress;
-   }
-
-
-   public String getNodeName()
-   {
-      return nodeName;
-   }
-
-
-   public void setNodeName(String nodeName)
-   {
-      this.nodeName = nodeName;
-   }
-
-   public int getNamingServicePort()
-   {
-      return namingServicePort;
-   }
-
-   public void setNamingServicePort(int jndiPort)
-   {
-      this.namingServicePort = jndiPort;
-   }
-   
-   /**
-    * Gets whether this factory should create a "logical address" (or use
-    * one set via {@link #setNodeName(String)} and assign it to
-    * any newly created <code>Channel</code> as JGroups "additional_data".
-    * 
-    * @see #setAssignLogicalAddresses(boolean)
-    */
-   public boolean getAssignLogicalAddresses()
-   {
-      return assignLogicalAddresses;
-   }
-
-   /**
-    * Sets whether this factory should create a "logical address" (or use
-    * one set via {@link #setNodeName(String)} and assign it to
-    * any newly created <code>Channel</code> as JGroups "additional_data".
-    * <p>
-    * Any such logical address will be used by <code>HAPartition</code>
-    * to assign a name to the <code>ClusterNode</code> object representing 
-    * this node. If a logical address is not set, the <code>ClusterNode</code> 
-    * will use the address and port JGroups is using to receive messages to
-    * create its name.
-    * </p>
-    * <p>
-    * Default is <code>true</code>.
-    * </p>
-    */
-   public void setAssignLogicalAddresses(boolean logicalAddresses)
-   {
-      this.assignLogicalAddresses = logicalAddresses;
-   }
-
-   @Override
-   public void create() throws Exception
-   {
-
-      if (state == CREATED || state == STARTING || state == STARTED
-         || state == STOPPING || state == STOPPED)
-      {
-         log.debug("Ignoring create call; current state is " + getStateString());
-         return;
-      }
-      
-      log.debug("Creating JChannelFactory");
-      
-      try
-      {
-         super.create();
-         state = CREATED;
-      }
-      catch (Exception e)
-      {
-         log.debug("Initialization failed JChannelFactory", e);
-         throw e;
-      }
-      
-      log.debug("Created JChannelFactory");
-      super.create();
-   }
-
-   @Override
-   public void start() throws Exception
-   {
-      if (state == STARTING || state == STARTED || state == STOPPING)
-      {
-         log.debug("Ignoring start call; current state is " + getStateString());
-         return;
-      }
-      
-      if (state != CREATED && state != STOPPED && state != FAILED)
-      {
-         log.debug("Start requested before create, calling create now");         
-         create();
-      }
-      
-      state = STARTING;
-      log.debug("Starting JChannelFactory");
-
-      try
-      {
-         super.start();
-      }
-      catch (Exception e)
-      {
-         state = FAILED;
-         log.debug("Starting failed JChannelFactory", e);
-         throw e;
-      }
-
-      state = STARTED;
-      log.debug("Started JChannelFactory");
-      
-   }
-
-   @Override
-   public void stop()
-   {
-      if (state != STARTED)
-      {
-         log.debug("Ignoring stop call; current state is " + getStateString());
-         return;
-      }
-      
-      state = STOPPING;
-      log.debug("Stopping JChannelFactory");
-
-      try
-      {
-         super.stop();
-      }
-      catch (Throwable e)
-      {
-         state = FAILED;
-         log.warn("Stopping failed JChannelFactory", e);
-         return;
-      }
-      
-      state = STOPPED;
-      log.debug("Stopped JChannelFactory");
-   }
-
-   @Override
-   public void destroy()
-   {
-      if (state == DESTROYED)
-      {
-         log.debug("Ignoring destroy call; current state is " + getStateString());
-         return;
-      }
-      
-      if (state == STARTED)
-      {
-         log.debug("Destroy requested before stop, calling stop now");
-         stop();
-      }
-      
-      log.debug("Destroying JChannelFactory");
-      
-      try
-      {
-         super.destroy();
-      }
-      catch (Throwable t)
-      {
-         log.warn("Destroying failed JChannelFactory", t);
-      }
-      state = DESTROYED;
-      log.debug("Destroyed JChannelFactory");
-   }
-   
-   /**
-    * Checks whether the transport protocol configuration for <code>stack_name</code>
-    * supports the shared use of the protocol between channels, creating a
-    * returning a channel if it does.
-    * <p>
-    * Determines whether a shared transport is possible by looking for the
-    * {@link Global#SINGLETON_NAME} parameter in the configuration of the
-    * first protocol in the string returned by {@link #getConfig(String)}.
-    * </p> 
-    * 
-    * @param stack_name the name of the protocol stack
-    * @return a channel configured per <code>stack_name</code>, or <code>null</code>
-    *         if <code>stack_name</code> is not a register protocol stack or
-    *         its transport protocol configuration does not support sharing.
-    * 
-    * @throws Exception
-    */
-   public Channel createSharedTransportChannel(String stack_name) throws Exception
-   {
-      Channel ch = null;
-      String config = getConfig(stack_name);
-      if (config != null)
-      {
-         // Format of string is 
-         // PROTOCOL1(param1=value1;param2=value2):PROTOCOL2(param1=value1;param2=value2):
-         // PROTOCOL1 is always the transport protocol.
-         // We look for the singleton_name param in the transport protocol
-         int tp_idx = config.indexOf("):");
-         int singleton_idx = config.indexOf(Global.SINGLETON_NAME);
-         if (singleton_idx > -1 && singleton_idx < tp_idx)
-         {
-            ch = createChannel(stack_name);
-         }
-      }      
-      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




More information about the jboss-cvs-commits mailing list