[jboss-svn-commits] JBL Code SVN: r10388 - in labs/jbossesb/branches/JBESB_4_0_MP1/product/core: rosetta/src/org/jboss/soa/esb and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 21 09:05:31 EDT 2007
Author: kevin.conner at jboss.com
Date: 2007-03-21 09:05:31 -0400 (Wed, 21 Mar 2007)
New Revision: 10388
Added:
labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/lifecycle/
labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java
Modified:
labs/jbossesb/branches/JBESB_4_0_MP1/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
Log:
Contextualise courier lookup
Modified: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_MP1/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java 2007-03-21 12:36:41 UTC (rev 10387)
+++ labs/jbossesb/branches/JBESB_4_0_MP1/product/core/listeners/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java 2007-03-21 13:05:31 UTC (rev 10388)
@@ -27,6 +27,7 @@
import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.lifecycle.LifecycleIdentity;
/**
* Controller class to manage the lifecycles of a set of managed instances.
@@ -39,6 +40,10 @@
* The managed lifecycle instances.
*/
private final ManagedLifecycle[] instances;
+ /**
+ * The lifecycle identity.
+ */
+ private final String lifecycleIdentity ;
/**
* Construct the controller to manage the specified managed lifecycle instances.
@@ -49,6 +54,8 @@
{
final int numInstances = (lifecycles == null ? 0 : lifecycles.size());
instances = lifecycles.toArray(new ManagedLifecycle[numInstances]);
+ lifecycleIdentity = LifecycleIdentity.getSingleton().getNextLifecycleIdentity() ;
+ CourierFactory.initialiseLifecycleIdentityMap(lifecycleIdentity) ;
}
/**
@@ -61,8 +68,18 @@
public void start()
throws ManagedLifecycleException
{
- initialiseInstances();
- startInstances();
+ final LifecycleIdentity lifecycleIdentitySingleton = LifecycleIdentity.getSingleton() ;
+ final String currentIdentity = lifecycleIdentitySingleton.getThreadLifecycleIdentity() ;
+ try
+ {
+ lifecycleIdentitySingleton.setThreadLifecycleIdentity(lifecycleIdentity) ;
+ initialiseInstances();
+ startInstances();
+ }
+ finally
+ {
+ lifecycleIdentitySingleton.setThreadLifecycleIdentity(currentIdentity) ;
+ }
}
/**
@@ -75,8 +92,18 @@
public void restart()
throws ManagedLifecycleException
{
- stopInstances();
- startInstances();
+ final LifecycleIdentity lifecycleIdentitySingleton = LifecycleIdentity.getSingleton() ;
+ final String currentIdentity = lifecycleIdentitySingleton.getThreadLifecycleIdentity() ;
+ try
+ {
+ lifecycleIdentitySingleton.setThreadLifecycleIdentity(lifecycleIdentity) ;
+ stopInstances();
+ startInstances();
+ }
+ finally
+ {
+ lifecycleIdentitySingleton.setThreadLifecycleIdentity(currentIdentity) ;
+ }
}
/**
@@ -89,18 +116,29 @@
public void stop()
throws ManagedLifecycleException
{
- stopInstances();
- destroyInstances();
-
- // Cleanup resources.
- CourierFactory.releaseCouriers() ;
+ final LifecycleIdentity lifecycleIdentitySingleton = LifecycleIdentity.getSingleton() ;
+ final String currentIdentity = lifecycleIdentitySingleton.getThreadLifecycleIdentity() ;
try
{
- JmsConnectionPoolContainer.removeAllPools() ;
+ lifecycleIdentitySingleton.setThreadLifecycleIdentity(lifecycleIdentity) ;
+ stopInstances();
+ destroyInstances();
+
+ // Cleanup resources.
+ CourierFactory.releaseCouriers() ;
+ CourierFactory.destroyLifecycleIdentityMap(lifecycleIdentity) ;
+ try
+ {
+ JmsConnectionPoolContainer.removeAllPools() ;
+ }
+ catch (final JMSException jmse)
+ {
+ throw new ManagedLifecycleException("Unexpected exception clearing JMS pools", jmse) ;
+ }
}
- catch (final JMSException jmse)
+ finally
{
- throw new ManagedLifecycleException("Unexpected exception clearing JMS pools", jmse) ;
+ lifecycleIdentitySingleton.setThreadLifecycleIdentity(currentIdentity) ;
}
}
Modified: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java 2007-03-21 12:36:41 UTC (rev 10387)
+++ labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java 2007-03-21 13:05:31 UTC (rev 10388)
@@ -35,28 +35,25 @@
import org.jboss.internal.soa.esb.couriers.TwoWayCourierImpl;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.lifecycle.LifecycleIdentity;
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.
+ * Track lifecycle couriers.
*/
- private static final Map<TwoWayCourier, Exception> couriers = new HashMap<TwoWayCourier, Exception>() ;
+ private static final Map<String, Map<TwoWayCourier, Exception>> lifecycleCouriers = new HashMap<String, Map<TwoWayCourier, Exception>>() ;
+
+ static
+ {
+ lifecycleCouriers.put(null, new HashMap<TwoWayCourier, Exception>()) ;
+ }
- // private default constructor
- private CourierFactory() {}
-
- public static CourierFactory getInstance(Object obj)
- {
- return _instance;
- }
/**
* Obtain a courier which can perform deliveries only and prime it with the "to address" (toEPR).
*
@@ -98,6 +95,30 @@
}
/**
+ * Initialise the association for the current lifecycle identify.
+ * @param lifecycleIdentity The lifecycle identiy.
+ */
+ public synchronized static void initialiseLifecycleIdentityMap(final String lifecycleIdentity)
+ {
+ if (lifecycleIdentity != null)
+ {
+ lifecycleCouriers.put(lifecycleIdentity, new HashMap<TwoWayCourier, Exception>()) ;
+ }
+ }
+
+ /**
+ * Destroy the association for the current lifecycle identify.
+ * @param lifecycleIdentity The lifecycle identiy.
+ */
+ public synchronized static void destroyLifecycleIdentityMap(final String lifecycleIdentity)
+ {
+ if (lifecycleIdentity != null)
+ {
+ lifecycleCouriers.remove(lifecycleIdentity) ;
+ }
+ }
+
+ /**
* Register the courier as part of the current set.
* @param courier The current courier.
*/
@@ -112,26 +133,68 @@
{
ex = null ;
}
- couriers.put(courier, ex) ;
+ getMap().put(courier, ex) ;
}
/**
+ * Get the current map.
+ * @return The current map.
+ */
+ private static synchronized Map<TwoWayCourier, Exception> getMap()
+ {
+ final String lifecycleIdentity = LifecycleIdentity.getSingleton().getThreadLifecycleIdentity() ;
+ Map<TwoWayCourier, Exception> map = lifecycleCouriers.get(lifecycleIdentity) ;
+ if (map == null)
+ {
+ map = lifecycleCouriers.get(null) ;
+ }
+ return map ;
+ }
+
+ /**
+ * Get and clear the current map.
+ * @return The current map.
+ */
+ private static synchronized Map<TwoWayCourier, Exception> getAndClearMap()
+ {
+ final String lifecycleIdentity = LifecycleIdentity.getSingleton().getThreadLifecycleIdentity() ;
+ Map<TwoWayCourier, Exception> map = lifecycleCouriers.get(lifecycleIdentity) ;
+ final String key ;
+ if (map != null)
+ {
+ key = lifecycleIdentity ;
+ }
+ else
+ {
+ key = null ;
+ map = lifecycleCouriers.get(null) ;
+ }
+ if (map.size() > 0)
+ {
+ lifecycleCouriers.put(key, new HashMap<TwoWayCourier, Exception>()) ;
+ }
+ return map ;
+ }
+
+ /**
* Deregister the courier from the current set.
* @param courier The current courier.
*/
public static synchronized void deregisterCourier(final TwoWayCourier courier)
{
- couriers.remove(courier) ;
+ getMap().remove(courier) ;
}
/**
* Release all couriers.
*/
- public static synchronized void releaseCouriers()
+ public static void releaseCouriers()
{
+ final Map<TwoWayCourier, Exception> couriers = getAndClearMap() ;
if (couriers.size() > 0)
{
- LOGGER.warn("Calling cleanup on existing couriers") ;
+ LOGGER.warn("Calling cleanup on existing couriers for identity " +
+ LifecycleIdentity.getSingleton().getThreadLifecycleIdentity()) ;
final Iterator<Entry<TwoWayCourier, Exception>> entryIter = couriers.entrySet().iterator() ;
while(entryIter.hasNext())
{
Added: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java 2007-03-21 13:05:31 UTC (rev 10388)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.lifecycle;
+
+/**
+ * Utility to handle lifecycle identities.
+ * @author kevin
+ */
+public class LifecycleIdentity
+{
+ /**
+ * The lifecycle identity singleton.
+ */
+ private static final LifecycleIdentity SINGLETON = new LifecycleIdentity() ;
+
+ /**
+ * The lifecycle identity associated with the current thread.
+ */
+ private static final InheritableThreadLocal<String> threadLifecycleIdentiy = new InheritableThreadLocal<String>() ;
+
+ /**
+ * The identity counter.
+ */
+ private long identifyCounter ;
+
+ public String getNextLifecycleIdentity()
+ {
+ final long lifecycleIdentity ;
+ synchronized(this)
+ {
+ lifecycleIdentity = identifyCounter++ ;
+ }
+ return "LifecycleIdentity:" + Long.valueOf(lifecycleIdentity) ;
+ }
+
+ /**
+ * Set the lifecycle identity associated with the current thread.
+ * @param lifecycleIdentity The lifecycle identity or null to clear.
+ */
+ public void setThreadLifecycleIdentity(final String lifecycleIdentity)
+ {
+ threadLifecycleIdentiy.set(lifecycleIdentity) ;
+ }
+
+ /**
+ * Get the lifecycle identity associated with the current thread.
+ * @return The lifecycle identity or null if not set.
+ */
+ public String getThreadLifecycleIdentity()
+ {
+ return threadLifecycleIdentiy.get() ;
+ }
+
+
+ /**
+ * Get the lifecycle identify singleton.
+ * @return the lifecycle identity singleton.
+ */
+ public static LifecycleIdentity getSingleton()
+ {
+ return SINGLETON ;
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list