[jboss-cvs] JBoss Messaging SVN: r2061 - in branches/Branch_1_0/src/main/org/jboss/jms/server: connectionmanager and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 25 16:52:12 EST 2007


Author: juha at jboss.org
Date: 2007-01-25 16:52:12 -0500 (Thu, 25 Jan 2007)
New Revision: 2061

Modified:
   branches/Branch_1_0/src/main/org/jboss/jms/server/ConnectionManager.java
   branches/Branch_1_0/src/main/org/jboss/jms/server/ServerPeer.java
   branches/Branch_1_0/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-605

Modified: branches/Branch_1_0/src/main/org/jboss/jms/server/ConnectionManager.java
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/jms/server/ConnectionManager.java	2007-01-25 20:28:09 UTC (rev 2060)
+++ branches/Branch_1_0/src/main/org/jboss/jms/server/ConnectionManager.java	2007-01-25 21:52:12 UTC (rev 2061)
@@ -27,6 +27,8 @@
 /**
  * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
+ * 
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -43,4 +45,6 @@
    void handleClientFailure(String remotingSessionID);
    
    boolean containsSession(String remotingClientSessionID);
+
+   void closeAllConnections();
 }

Modified: branches/Branch_1_0/src/main/org/jboss/jms/server/ServerPeer.java
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/jms/server/ServerPeer.java	2007-01-25 20:28:09 UTC (rev 2060)
+++ branches/Branch_1_0/src/main/org/jboss/jms/server/ServerPeer.java	2007-01-25 21:52:12 UTC (rev 2061)
@@ -26,13 +26,9 @@
 import java.net.URL;
 import java.util.Map;
 import java.util.Set;
-
 import javax.management.Attribute;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 
 import org.jboss.aop.AspectXmlLoader;
 import org.jboss.jms.destination.JBossQueue;
@@ -60,9 +56,9 @@
 import org.jboss.remoting.serialization.SerializationStreamFactory;
 import org.jboss.system.ServiceCreator;
 import org.jboss.system.ServiceMBeanSupport;
-import org.w3c.dom.Element;
 
 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+import org.w3c.dom.Element;
 
 /**
  * A JMS server peer.
@@ -228,8 +224,8 @@
    
          initializeRemoting(mbeanServer);
    
-         createRecoverable();
-         
+         addShutdownHook();
+
          started = true;
    
          log.info("JBoss Messaging " + getVersion().getProviderVersion() + " server [" +
@@ -254,8 +250,6 @@
    
          started = false;
    
-         removeRecoverable();
-   
          // stop the internal components
          memoryManager.stop();
          txRepository.stop();
@@ -640,56 +634,30 @@
    // Private -------------------------------------------------------
 
    /**
-    * Place a Recoverable instance in the JNDI tree. This can be used by a transaction manager in
-    * order to obtain an XAResource so it can perform XA recovery.
+    * JBMESSAGING-605 [JPL]
     */
-
-   //Commented out until XA Recovery is complete
-
-   private void createRecoverable() throws Exception
+   private void addShutdownHook()
    {
-      //Disabled until XA Recovery is complete with Arjuna transaction integration
-
-//      InitialContext ic = new InitialContext();
-//
-//      int connFactoryID = connFactoryJNDIMapper.registerConnectionFactory(null, null);
-//
-//      XAConnectionFactory xaConnFactory =
-//         (XAConnectionFactory)connFactoryJNDIMapper.getConnectionFactory(connFactoryID);
-//
-//      JMSRecoverable recoverable = new JMSRecoverable(serverPeerID, xaConnFactory);
-//
-//      Context recCtx = null;
-//      try
-//      {
-//         recCtx = (Context)ic.lookup(RECOVERABLE_CTX_NAME);
-//      }
-//      catch (NamingException e)
-//      {
-//         //Ignore
-//      }
-//
-//      if (recCtx == null)
-//      {
-//         recCtx = ic.createSubcontext(RECOVERABLE_CTX_NAME);
-//      }
-//
-//      recCtx.rebind(this.serverPeerID, recoverable);
-   }
-
-   private void removeRecoverable() throws Exception
-   {
-      InitialContext ic = new InitialContext();
-
-      Context recCtx = null;
       try
       {
-         recCtx = (Context)ic.lookup(RECOVERABLE_CTX_NAME);
-         recCtx.unbind(serverPeerID);
+         // NOTE: Not invoking as a privileged operation since it's not critical for running messaging.
+         //       Handling the potential security exception below [JPL]
+
+         Runtime.getRuntime().addShutdownHook(
+               new Thread(
+                     new Runnable()
+                     {
+                        public void run()
+                        {
+                           connectionManager.closeAllConnections();
+                        }
+                     }
+               )
+         );
       }
-      catch (NamingException e)
+      catch (SecurityException e)
       {
-         //Ignore
+         log.warn("Unable to register shutdown hook for closing unhandled connections.", e);
       }
    }
 

Modified: branches/Branch_1_0/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java	2007-01-25 20:28:09 UTC (rev 2060)
+++ branches/Branch_1_0/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java	2007-01-25 21:52:12 UTC (rev 2061)
@@ -41,6 +41,8 @@
 /**
  * @author <a href="tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
+ *
  * @version 1.1
  *
  * SimpleConnectionManager.java,v 1.1 2006/02/21 07:44:00 timfox Exp
@@ -51,6 +53,8 @@
 
    private static final Logger log = Logger.getLogger(SimpleConnectionManager.class);
 
+   private static boolean trace = log.isTraceEnabled();
+
    // Static --------------------------------------------------------
 
    // Attributes ----------------------------------------------------
@@ -88,6 +92,57 @@
                 Util.guidToString(remotingClientSessionID));
    }
 
+   public synchronized void closeAllConnections()
+   {
+      if (jmsClients == null)
+         return;
+
+      Iterator jmsClientVMIds = jmsClients.keySet().iterator();
+
+      if (trace)
+      {
+         log.trace("Found " + jmsClients.size() + " jms clients.");
+      }
+
+      while (jmsClientVMIds.hasNext())
+      {
+         String jmsClientVMId = (String)jmsClientVMIds.next();
+         Map endpoints = (Map)jmsClients.get(jmsClientVMId);
+
+         if (endpoints != null)
+         {
+            Iterator it = endpoints.values().iterator();
+
+            while (it.hasNext())
+            {
+               ConnectionEndpoint e = (ConnectionEndpoint)it.next();
+
+               if (!e.isClosed())
+               {
+                  try
+                  {
+                     log.warn("Closing endpoint " + e);
+
+                     e.closing();
+                     e.close();
+                  }
+                  catch (Throwable t)
+                  {
+                     log.warn("Failed to close endpoint " + e);
+                  }
+               }
+            }
+
+            endpoints.clear();
+         }
+      }
+
+      if (sessions != null)
+         sessions.clear();
+      
+      jmsClients.clear();
+   }
+
    public synchronized ConnectionEndpoint unregisterConnection(String jmsClientVMId, String remotingClientSessionID)
    {
       Map endpoints = (Map)jmsClients.get(jmsClientVMId);




More information about the jboss-cvs-commits mailing list