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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 16 17:26:01 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-04-16 17:26:01 -0400 (Wed, 16 Apr 2008)
New Revision: 72318

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java
Log:
[JBAS-5451] Avoid ConcurrentModificationException at shutdown

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java	2008-04-16 20:48:54 UTC (rev 72317)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/JChannelFactory.java	2008-04-16 21:26:01 UTC (rev 72318)
@@ -118,6 +118,8 @@
    @Override
    public Channel createChannel(Object properties) throws ChannelException
    {
+      checkStarted();
+      
       Channel channel = super.createChannel(properties);
       
       if (manageChannelThreadPools)
@@ -149,6 +151,8 @@
    @Override
    public Channel createChannel(String stack_name) throws Exception
    {
+      checkStarted();
+      
       String props=stack_name != null? getConfig(stack_name) : null;
       if (props == null)
       {
@@ -188,6 +192,8 @@
    @Override
    public Channel createMultiplexerChannel(String stack_name, String id) throws Exception
    {
+      checkStarted();
+      
       String configStr = getConfig(stack_name);
       
       if (configStr == null)
@@ -452,13 +458,19 @@
       
       log.debug("Destroying JChannelFactory");
       
+      // DON'T call super.destroy() as that may deregister the JMX proxy
+      // to this pojo service, leading to ugliness when the proxy is destroyed
       try
       {
-         // DON'T call super.destroy() as that may deregister the JMX proxy
-         // to this pojo service, leading to ugliness when the proxy is destroyed
          
-         for (String channelId : registeredChannels)
+         Set<String> toUnregister = null;
+         synchronized (registeredChannels)
          {
+            toUnregister = new HashSet<String>(registeredChannels);
+         }
+         
+         for (String channelId : toUnregister)
+         {
             unregister(channelId);
          }
       }
@@ -507,6 +519,12 @@
    // ----------------------------------------------------------------- Private
 
 
+   private void checkStarted()
+   {
+      if (state != ServiceMBean.STARTED)
+         throw new IllegalStateException("Cannot use factory; state is " + getStateString());
+   }
+   
    private void setChannelUniqueId(Channel channel)
    {
       IpAddress address = (IpAddress) channel.getLocalAddress();
@@ -820,7 +838,7 @@
    
    private void unregister(String channelId) 
    {
-      if(getServer() != null)
+      if(getServer() != null && registeredChannels.contains(channelId))
       {
          String oname = getDomain() + ":type=channel,cluster=" + channelId;
          try
@@ -837,8 +855,6 @@
          {
             log.error("failed unregistering " + oname, e);
          }
-         
-         
       }
    }
 




More information about the jboss-cvs-commits mailing list