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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 14 18:11:10 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-09-14 18:11:10 -0400 (Fri, 14 Sep 2007)
New Revision: 65416

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java
Log:
[JBAS-4728] AS's JChannelFactory subclass should ignore duplicate lifecycle calls

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java	2007-09-14 21:48:58 UTC (rev 65415)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java	2007-09-14 22:11:10 UTC (rev 65416)
@@ -26,15 +26,7 @@
 import java.rmi.dgc.VMID;
 import java.rmi.server.UID;
 
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
-import javax.management.ReflectionException;
-
 import org.jboss.logging.Logger;
-import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.naming.NamingServiceMBean;
 import org.jboss.system.ServiceMBean;
 import org.jboss.system.server.ServerConfigUtil;
 import org.jgroups.Channel;
@@ -44,8 +36,7 @@
 
 /**
  * Extension to the JGroups JChannelFactory that supports the addition
- * of "additional_data" to the channel config.  Needed until logical
- * addresses are supported in JGroups.
+ * of "additional_data" to the channel config.
  * 
  * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
  * @version $Revision$
@@ -54,9 +45,18 @@
 {
    protected static Logger log = Logger.getLogger(JChannelFactory.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;
 
    /**
     * Overrides the superclass version by generating a unique node id
@@ -115,6 +115,124 @@
       this.namingServicePort = jndiPort;
    }
 
+   @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");
+   }
+
    private void setChannelUniqueId(Channel channel) throws Exception
    {
       IpAddress address = (IpAddress) channel.getLocalAddress();
@@ -153,6 +271,11 @@
                 "additional data -- setting nodeName to " + nodeName);
       }
    }
+   
+   private String getStateString()
+   {
+      return ServiceMBean.states[state];
+   }
 
    private String generateUniqueNodeName () throws Exception
    {




More information about the jboss-cvs-commits mailing list