[jboss-svn-commits] JBL Code SVN: r10314 - in labs/jbossesb/trunk/product/core: rosetta/src/org/jboss/internal/soa/esb/couriers and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Mar 18 17:19:24 EDT 2007


Author: kevin.conner at jboss.com
Date: 2007-03-18 17:19:24 -0400 (Sun, 18 Mar 2007)
New Revision: 10314

Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
Log:
Added courier tracking/release. Add courier release/jms cleanup to controller

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java	2007-03-18 21:09:25 UTC (rev 10313)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java	2007-03-18 21:19:24 UTC (rev 10314)
@@ -23,6 +23,11 @@
 
 import java.util.Collection;
 
+import javax.jms.JMSException;
+
+import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
+import org.jboss.soa.esb.couriers.CourierFactory;
+
 /**
  * Controller class to manage the lifecycles of a set of managed instances.
  *
@@ -86,6 +91,17 @@
    {
       stopInstances();
       destroyInstances();
+      
+      // Cleanup resources.
+      CourierFactory.releaseCouriers() ;
+      try
+      {
+         JmsConnectionPoolContainer.removeAllPools() ;
+      }
+      catch (final JMSException jmse)
+      {
+         throw new ManagedLifecycleException("Unexpected exception clearing JMS pools", jmse) ;
+      }
    }
 
    /**

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java	2007-03-18 21:09:25 UTC (rev 10313)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/TwoWayCourierImpl.java	2007-03-18 21:19:24 UTC (rev 10314)
@@ -28,6 +28,7 @@
 import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
 import org.jboss.soa.esb.addressing.eprs.JMSEpr;
 import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
 import org.jboss.soa.esb.couriers.CourierTimeoutException;
 import org.jboss.soa.esb.couriers.CourierUtil;
 import org.jboss.soa.esb.couriers.TwoWayCourier;
@@ -187,6 +188,9 @@
         public void cleanup ()
         {
             CourierUtil.cleanCourier(_deliverCourier) ;
+            _deliverCourier = null ;
             CourierUtil.cleanCourier(_pickupCourier) ;
+            _pickupCourier = null ;
+            CourierFactory.deregisterCourier(this) ;
         }
 }

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java	2007-03-18 21:09:25 UTC (rev 10313)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java	2007-03-18 21:19:24 UTC (rev 10314)
@@ -26,6 +26,12 @@
  * @author - kstam at redhat.com
  *
  */
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.couriers.TwoWayCourierImpl;
 import org.jboss.soa.esb.addressing.EPR;
 import org.jboss.soa.esb.addressing.MalformedEPRException;
@@ -33,6 +39,16 @@
 public class CourierFactory 
 {
 	private static final CourierFactory _instance = new CourierFactory();
+        
+        /**
+         * The logger for this instance.
+         */
+        private static final Logger LOGGER = Logger.getLogger(CourierFactory.class) ;
+        
+        /**
+         * Track couriers.
+         */
+        private static final Map<TwoWayCourier, Exception> couriers = new HashMap<TwoWayCourier, Exception>() ;
 	
 	// private default constructor
 	private CourierFactory() {}
@@ -76,6 +92,65 @@
 	 */
 	public static TwoWayCourier getCourier(EPR toEPR, EPR replyToEPR) throws CourierException, MalformedEPRException
 	{
-		return new TwoWayCourierImpl(toEPR, replyToEPR);
+		final TwoWayCourier result = new TwoWayCourierImpl(toEPR, replyToEPR);
+                registerCourier(result) ;
+                return result ;
 	}
+        
+        /**
+         * Register the courier as part of the current set.
+         * @param courier The current courier.
+         */
+        private static synchronized void registerCourier(final TwoWayCourier courier)
+        {
+            final Exception ex ;
+            if (LOGGER.isDebugEnabled())
+            {
+                ex = new Exception("Courier Assignment stacktrace") ;
+            }
+            else
+            {
+                ex = null ;
+            }
+            couriers.put(courier, ex) ;
+        }
+        
+        /**
+         * Deregister the courier from the current set.
+         * @param courier The current courier.
+         */
+        public static synchronized void deregisterCourier(final TwoWayCourier courier)
+        {
+            couriers.remove(courier) ;
+        }
+        
+        /**
+         * Release all couriers.
+         */
+        public static synchronized void releaseCouriers()
+        {
+            if (couriers.size() > 0)
+            {
+                LOGGER.warn("Calling cleanup on existing couriers") ;
+                final Iterator<Entry<TwoWayCourier, Exception>> entryIter = couriers.entrySet().iterator() ;
+                while(entryIter.hasNext())
+                {
+                    final Entry<TwoWayCourier, Exception> entry = entryIter.next();
+                    entryIter.remove() ;
+                    if (LOGGER.isDebugEnabled() && (entry.getValue() != null))
+                    {
+                        LOGGER.debug("Courier allocation stacktrace", entry.getValue()) ;
+                    }
+                    
+                    try
+                    {
+                        entry.getKey().cleanup() ;
+                    }
+                    catch (final Exception ex)
+                    {
+                        LOGGER.warn("Unexpected exception cleaning up courier", ex) ;
+                    }
+                }
+            }
+        }
 }




More information about the jboss-svn-commits mailing list