[jboss-svn-commits] JBL Code SVN: r15429 - in labs/jbossesb/trunk/product/rosetta: src/org/jboss/soa/esb/couriers and 8 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Sep 28 07:42:53 EDT 2007
Author: kevin.conner at jboss.com
Date: 2007-09-28 07:42:52 -0400 (Fri, 28 Sep 2007)
New Revision: 15429
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResource.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceException.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceFactory.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/lifecycle/
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManagerTest.java
Removed:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/LifecycleResourceUtil.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolContainer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployment.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/rosetta/pooling/JmsConnectionPoolingIntegrationTest.java
Log:
New lifecycle resource management codebase: JBESB-1097
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolContainer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolContainer.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolContainer.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -27,11 +27,11 @@
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
-import javax.jms.JMSException;
-
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
-import org.jboss.soa.esb.lifecycle.LifecycleIdentity;
-import org.jboss.soa.esb.util.LifecycleResourceUtil;
+import org.jboss.soa.esb.lifecycle.LifecyclePriorities;
+import org.jboss.soa.esb.lifecycle.LifecycleResource;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceFactory;
import org.apache.log4j.Logger;
/**
@@ -46,16 +46,16 @@
private static Logger logger = Logger.getLogger(JmsConnectionPoolContainer.class);
/**
- * Contextualised container of all the pools in the system.
+ * The lifecycle resource factory.
*/
- private static Map<String, Map<Map<String, String>, JmsConnectionPool>> poolMaps;
+ private static final LifecycleResourceFactory<Map<Map<String, String>, JmsConnectionPool>> lifecycleJMSPoolFactory = new JmsConnectionPoolFactory() ;
+ /**
+ * Lifecycle JMS connection pools.
+ */
+ private static final LifecycleResource<Map<Map<String, String>, JmsConnectionPool>> lifecycleJMSPoolResource =
+ new LifecycleResource<Map<Map<String, String>, JmsConnectionPool>>(lifecycleJMSPoolFactory,
+ LifecyclePriorities.JMS_CONNECTION_POOL_PRIORITY) ;
- static {
- poolMaps = new HashMap<String, Map<Map<String, String>, JmsConnectionPool>>();
- logger.info("JMS Connection Pool successfully created.");
- LifecycleResourceUtil.activateHook() ;
- }
-
/**
* Returns the pool given a JMSEpr.
*
@@ -77,9 +77,10 @@
* @throws ConnectionException
*/
public static JmsConnectionPool getPool(Properties enviroment, String connectionFactory, String destinationType)
+ throws ConnectionException
{
Map<String,String> poolKey = createPoolKey(enviroment, connectionFactory, destinationType);
- final Map<Map<String, String>, JmsConnectionPool> poolMap = getOrCreatePoolMap() ;
+ final Map<Map<String, String>, JmsConnectionPool> poolMap = getMap() ;
if (poolMap.containsKey(poolKey)) {
return poolMap.get(poolKey);
} else {
@@ -124,11 +125,18 @@
}
/**
* Gets the number of pools in the constainer.
- *
*/
- public static int getNumberOfPools() {
- final Map<Map<String, String>, JmsConnectionPool> poolMap = getPoolMap() ;
- return (poolMap == null ? 0 : poolMap.size());
+ public static int getNumberOfPools()
+ {
+ try
+ {
+ return lifecycleJMSPoolResource.getLifecycleResource().size() ;
+ }
+ catch (final LifecycleResourceException lre)
+ {
+ // The resource has already been destroyed
+ return 0 ;
+ }
}
/**
* Removes the poolKey from the poolMap.
@@ -136,65 +144,68 @@
* @param poolKey
*/
protected static void removePool(Map<String, String> poolKey) {
- final Map<Map<String, String>, JmsConnectionPool> poolMap = getPoolMap() ;
- if ((poolMap != null) && poolMap.containsKey(poolKey)) {
+ try {
+ final Map<Map<String, String>, JmsConnectionPool> poolMap = lifecycleJMSPoolResource.getLifecycleResource() ;
poolMap.remove(poolKey);
+ } catch (final LifecycleResourceException lre) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Unexpected lifecycle resource exception removing pool", lre) ;
+ }
}
+
}
/**
* Adds this poolKey and pool to the the poolMap.
*
* @param poolKey
*/
- protected static void addToPool(Map<String, String> poolKey, JmsConnectionPool pool) {
- final Map<Map<String, String>, JmsConnectionPool> poolMap = getOrCreatePoolMap() ;
+ protected static void addToPool(Map<String, String> poolKey, JmsConnectionPool pool)
+ throws ConnectionException
+ {
+ final Map<Map<String, String>, JmsConnectionPool> poolMap = getMap() ;
if (!poolMap.containsKey(poolKey)) {
poolMap.put(poolKey, pool);
}
}
- /**
- * Removes all pools from the container.
- *
- */
- public static void removeAllPools() throws JMSException{
- final Map<Map<String, String>, JmsConnectionPool> poolMap = removePoolMap() ;
- if (poolMap != null) {
- for (Map<String,String> poolKey : poolMap.keySet()) {
- poolMap.get(poolKey).removeSessionPool();
- }
+
+ private static Map<Map<String, String>, JmsConnectionPool> getMap()
+ throws ConnectionException
+ {
+ try {
+ return lifecycleJMSPoolResource.getLifecycleResource() ;
+ } catch (final LifecycleResourceException lre) {
+ throw new ConnectionException("Unexpected lifecycle resource exception", lre) ;
}
}
- /**
- * Remove the pool map associated with the current thread.
- * @return The map being removed.
- */
- private static synchronized Map<Map<String, String>, JmsConnectionPool> removePoolMap() {
- final String lifecycleIdentity = LifecycleIdentity.getSingleton().getLifecycleIdentity() ;
- return poolMaps.remove(lifecycleIdentity) ;
- }
-
- /**
- * Get the pool map associated with the current thread.
- * @return The pool map or null if not present.
- */
- private static synchronized Map<Map<String, String>, JmsConnectionPool> getPoolMap() {
- final String lifecycleIdentity = LifecycleIdentity.getSingleton().getLifecycleIdentity() ;
- return poolMaps.get(lifecycleIdentity) ;
- }
-
- /**
- * Get or create the pool map associated with the current thread.
- * @return The pool map.
- */
- private static synchronized Map<Map<String, String>, JmsConnectionPool> getOrCreatePoolMap() {
- final String lifecycleIdentity = LifecycleIdentity.getSingleton().getLifecycleIdentity() ;
- Map<Map<String, String>, JmsConnectionPool> map = poolMaps.get(lifecycleIdentity) ;
- if (map == null)
+ private static class JmsConnectionPoolFactory implements LifecycleResourceFactory<Map<Map<String, String>, JmsConnectionPool>>
+ {
+ /**
+ * Create a resource object which will be associated with the specified lifecycle identity.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource
+ * @throws LifecycleResourceException for errors during construction.
+ */
+ public Map<Map<String, String>, JmsConnectionPool> createLifecycleResource(final String lifecycleIdentity)
+ throws LifecycleResourceException
{
- map = new ConcurrentHashMap<Map<String, String>, JmsConnectionPool>() ;
- poolMaps.put(lifecycleIdentity, map) ;
+ return new ConcurrentHashMap<Map<String, String>, JmsConnectionPool>() ;
}
- return map ;
+
+ /**
+ * Destroy a resource object which is associated with the specified lifecycle identity.
+ * @param resource The lifecycle resource.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource.
+ * @throws LifecycleResourceException for errors during destroy.
+ */
+ public void destroyLifecycleResource(final Map<Map<String, String>, JmsConnectionPool> resource,
+ final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ for (JmsConnectionPool pool : resource.values()) {
+ pool.removeSessionPool();
+ }
+ }
}
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -35,8 +35,10 @@
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;
-import org.jboss.soa.esb.util.LifecycleResourceUtil;
+import org.jboss.soa.esb.lifecycle.LifecyclePriorities;
+import org.jboss.soa.esb.lifecycle.LifecycleResource;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceFactory;
public class CourierFactory
{
@@ -44,23 +46,23 @@
* The logger for this instance.
*/
private static final Logger LOGGER = Logger.getLogger(CourierFactory.class) ;
-
+
/**
- * Track lifecycle couriers.
+ * The lifecycle resource factory.
*/
- private static final Map<String, Map<TwoWayCourier, Exception>> lifecycleCouriers = new HashMap<String, Map<TwoWayCourier, Exception>>() ;
+ private static final LifecycleResourceFactory<Map<TwoWayCourier, Exception>> lifecycleCourierFactory = new LifecycleCourierFactory() ;
+ /**
+ * Lifecycle couriers.
+ */
+ private static final LifecycleResource<Map<TwoWayCourier, Exception>> lifecycleCouriers =
+ new LifecycleResource<Map<TwoWayCourier,Exception>>(lifecycleCourierFactory,
+ LifecyclePriorities.COURIER_PRIORITY) ;
/**
* Factory singleton instance.
*/
private static CourierFactory instance = new CourierFactory();
- static
- {
- lifecycleCouriers.put(null, new HashMap<TwoWayCourier, Exception>()) ;
- LifecycleResourceUtil.activateHook() ;
- }
-
// protected default constructor
protected CourierFactory() {}
@@ -134,34 +136,11 @@
}
/**
- * 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.
*/
private static synchronized void registerCourier(final TwoWayCourier courier)
+ throws CourierException
{
final Exception ex ;
if (LOGGER.isDebugEnabled())
@@ -172,47 +151,14 @@
{
ex = null ;
}
- getMap().put(courier, ex) ;
- }
-
- /**
- * Get the current map.
- * @return The current map.
- */
- private static synchronized Map<TwoWayCourier, Exception> getMap()
- {
- final String lifecycleIdentity = LifecycleIdentity.getSingleton().getLifecycleIdentity() ;
- Map<TwoWayCourier, Exception> map = lifecycleCouriers.get(lifecycleIdentity) ;
- if (map == null)
+ try
{
- map = lifecycleCouriers.get(null) ;
+ lifecycleCouriers.getLifecycleResource().put(courier, ex) ;
}
- return map ;
- }
-
- /**
- * Get and clear the current map.
- * @return The current map.
- */
- private static synchronized Map<TwoWayCourier, Exception> getAndClearMap()
- {
- final String lifecycleIdentity = LifecycleIdentity.getSingleton().getLifecycleIdentity() ;
- Map<TwoWayCourier, Exception> map = lifecycleCouriers.get(lifecycleIdentity) ;
- final String key ;
- if (map != null)
+ catch (final LifecycleResourceException lre)
{
- key = lifecycleIdentity ;
+ throw new CourierException("Unexpected lifecycle resource exception whiel registering courier", lre) ;
}
- else
- {
- key = null ;
- map = lifecycleCouriers.get(null) ;
- }
- if (map.size() > 0)
- {
- lifecycleCouriers.put(key, new HashMap<TwoWayCourier, Exception>()) ;
- }
- return map ;
}
/**
@@ -221,37 +167,71 @@
*/
public static synchronized void deregisterCourier(final TwoWayCourier courier)
{
- getMap().remove(courier) ;
+ try
+ {
+ lifecycleCouriers.getLifecycleResource().remove(courier) ;
+ }
+ catch (final LifecycleResourceException lre)
+ {
+ LOGGER.warn("Unexpected error removing courier: " + lre.getMessage()) ;
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Unexpected error removing courier", lre) ;
+ }
+ }
}
/**
- * Release all couriers.
+ * The lifecycle resource factory
+ * @author kevin
*/
- public static void releaseCouriers()
+ private static class LifecycleCourierFactory implements LifecycleResourceFactory<Map<TwoWayCourier, Exception>>
{
- final Map<TwoWayCourier, Exception> couriers = getAndClearMap() ;
- if (couriers.size() > 0)
+ /**
+ * Create a resource object which will be associated with the specified lifecycle identity.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource
+ * @throws LifecycleResourceException for errors during construction.
+ */
+ public Map<TwoWayCourier, Exception> createLifecycleResource(final String lifecycleIdentity)
+ throws LifecycleResourceException
{
- LOGGER.warn("Calling cleanup on existing couriers for identity " +
- LifecycleIdentity.getSingleton().getLifecycleIdentity()) ;
- final Iterator<Entry<TwoWayCourier, Exception>> entryIter = couriers.entrySet().iterator() ;
- while(entryIter.hasNext())
+ return new HashMap<TwoWayCourier, Exception>() ;
+ }
+
+ /**
+ * Destroy a resource object which is associated with the specified lifecycle identity.
+ * @param resource The lifecycle resource.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource.
+ * @throws LifecycleResourceException for errors during destroy.
+ */
+ public void destroyLifecycleResource(final Map<TwoWayCourier, Exception> resource,
+ final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ if (resource.size() > 0)
{
- final Entry<TwoWayCourier, Exception> entry = entryIter.next();
- entryIter.remove() ;
- if (LOGGER.isDebugEnabled() && (entry.getValue() != null))
+ LOGGER.warn("Calling cleanup on existing couriers for identity " + lifecycleIdentity) ;
+ final Iterator<Entry<TwoWayCourier, Exception>> entryIter = resource.entrySet().iterator() ;
+ while(entryIter.hasNext())
{
- LOGGER.debug("Courier allocation stacktrace", entry.getValue()) ;
+ 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) ;
+ }
}
-
- try
- {
- entry.getKey().cleanup() ;
- }
- catch (final Exception ex)
- {
- LOGGER.warn("Unexpected exception cleaning up courier", ex) ;
- }
}
}
}
Deleted: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleIdentity.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -1,89 +0,0 @@
-/*
- * 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;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-/**
- * Utility to handle lifecycle identities.
- * @author kevin
- */
-public class LifecycleIdentity
-{
- /**
- * The lifecycle identity singleton.
- */
- private static final LifecycleIdentity SINGLETON = new LifecycleIdentity() ;
-
- /**
- * The map of classloaders to lifecycle identities.
- */
- private static final Map<ClassLoader, String> classLoaderLifecycleIdentity = Collections.synchronizedMap(new WeakHashMap<ClassLoader, String>()) ;
-
- /**
- * The identity counter.
- */
- private long identifyCounter ;
-
- public String associateLifecycleIdentity()
- {
- final long lifecycleIdentity ;
- synchronized(this)
- {
- lifecycleIdentity = identifyCounter++ ;
- }
- final String lifecycleIdentityVal = "LifecycleIdentity:" + Long.valueOf(lifecycleIdentity) ;
- setLifecycleIdentity(lifecycleIdentityVal) ;
- return lifecycleIdentityVal ;
- }
-
- /**
- * Set the lifecycle identity associated with the current context classloader.
- * @param lifecycleIdentity The lifecycle identity or null to clear.
- */
- public void setLifecycleIdentity(final String lifecycleIdentity)
- {
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader() ;
- classLoaderLifecycleIdentity.put(classLoader, lifecycleIdentity) ;
- }
-
- /**
- * Get the lifecycle identity associated with the current context classloader.
- * @return The lifecycle identity or null if not set.
- */
- public String getLifecycleIdentity()
- {
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader() ;
- return classLoaderLifecycleIdentity.get(classLoader) ;
- }
-
- /**
- * Get the lifecycle identify singleton.
- * @return the lifecycle identity singleton.
- */
- public static LifecycleIdentity getSingleton()
- {
- return SINGLETON ;
- }
-}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * Lifecycle priorities.
+ *
+ * This class contains priority values for core services. The
+ * @author kevin
+ *
+ */
+public final class LifecyclePriorities
+{
+ /**
+ * The courier priority.
+ */
+ public static final int COURIER_PRIORITY = 100000 ;
+
+ /**
+ * The JMS connection pool priority.
+ */
+ public static final int JMS_CONNECTION_POOL_PRIORITY = 200000 ;
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResource.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResource.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResource.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -0,0 +1,218 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.log4j.Logger;
+
+/**
+ * This class represents a lifecycle resource.
+ */
+public final class LifecycleResource<R>
+{
+ /**
+ * The logger for this class.
+ */
+ private static Logger logger = Logger.getLogger(LifecycleResource.class);
+
+ /**
+ * The lifecycle resource factory.
+ */
+ private final LifecycleResourceFactory<R> factory ;
+
+ /**
+ * The lifecycle resource map.
+ */
+ private final Map<String, R> lifecycleResourceMap = new HashMap<String, R>() ;
+
+ /**
+ * The lifecycle resource lock.
+ */
+ private ReadWriteLock lifecycleResourceLock = new ReentrantReadWriteLock() ;
+
+ /**
+ * The destroyed flag.
+ */
+ private boolean destroyed ;
+
+ /**
+ * Construct a lifecycle resource using the specified factory.
+ * @param factory The lifecycle resource factory.
+ * @param priority The relative priority of the resource for cleanup.
+ */
+ public LifecycleResource(final LifecycleResourceFactory<R> factory, final int priority)
+ {
+ this.factory = factory ;
+ LifecycleResourceManager.getSingleton().registerResource(this, factory.getClass().getClassLoader(), priority) ;
+ }
+
+ /**
+ * Construct a lifecycle resource using the specified factory.
+ * @param factory The lifecycle resource factory.
+ */
+ public LifecycleResource(final LifecycleResourceFactory<R> factory)
+ {
+ this.factory = factory ;
+ LifecycleResourceManager.getSingleton().registerResource(this, factory.getClass().getClassLoader()) ;
+ }
+
+ /**
+ * Get the lifecycle resource.
+ * @return The lifecycle resource.
+ */
+ public R getLifecycleResource()
+ throws LifecycleResourceException
+ {
+ final String identity = LifecycleResourceManager.getSingleton().getIdentity() ;
+ final Lock readLock = lifecycleResourceLock.readLock() ;
+ readLock.lock() ;
+ try
+ {
+ final R currentResource = lifecycleResourceMap.get(identity) ;
+ if (currentResource != null)
+ {
+ return currentResource ;
+ }
+ }
+ finally
+ {
+ readLock.unlock() ;
+ }
+
+ final Lock writeLock = lifecycleResourceLock.writeLock() ;
+ writeLock.lock() ;
+ try
+ {
+ if (destroyed)
+ {
+ throw new LifecycleResourceException("Resource already destroyed") ;
+ }
+ final R resource = lifecycleResourceMap.get(identity) ;
+ if (resource != null)
+ {
+ return resource ;
+ }
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Creating resource using factory: " + factory + " with identity " + identity) ;
+ }
+ final R newResource = factory.createLifecycleResource(identity) ;
+ lifecycleResourceMap.put(identity, newResource) ;
+ return newResource ;
+ }
+ finally
+ {
+ writeLock.unlock() ;
+ }
+ }
+
+ /**
+ * Cleanup the specified resource.
+ * @param identity The identiy of the resource.
+ */
+ void cleanupResource(final String identity)
+ {
+ final R resource ;
+
+ final Lock writeLock = lifecycleResourceLock.writeLock() ;
+ writeLock.lock() ;
+ try
+ {
+ resource = lifecycleResourceMap.remove(identity) ;
+ }
+ finally
+ {
+ writeLock.unlock() ;
+ }
+
+ cleanupLifecycleResource(factory, resource, identity) ;
+ }
+
+ /**
+ * Destroy all remaining resources.
+ */
+ synchronized void destroyResources()
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Destroying all resources for factory : " + factory) ;
+ }
+
+ final Lock writeLock = lifecycleResourceLock.writeLock() ;
+ writeLock.lock() ;
+ try
+ {
+ final Iterator<Map.Entry<String, R>> entryIter = lifecycleResourceMap.entrySet().iterator() ;
+ while(entryIter.hasNext())
+ {
+ final Map.Entry<String, R> entry = entryIter.next() ;
+ final String identity = entry.getKey() ;
+ final R resource = entry.getValue() ;
+ cleanupLifecycleResource(factory, resource, identity) ;
+ }
+ lifecycleResourceMap.clear() ;
+ destroyed = true ;
+ }
+ finally
+ {
+ writeLock.unlock() ;
+ }
+
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Destroyed all resources for factory : " + factory) ;
+ }
+ }
+
+ /**
+ * Destroy the lifecycle resource for the specific identity..
+ * @param factory The lifecycle factory.
+ * @param resource The lifecycle resource.
+ * @param identity The identity.
+ */
+ private void cleanupLifecycleResource(final LifecycleResourceFactory<R> factory,
+ final R resource, final String identity)
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Cleaning up resource using factory: " + factory + " with identity " + identity) ;
+ }
+ try
+ {
+ factory.destroyLifecycleResource(resource, identity) ;
+ }
+ catch (final Throwable th)
+ {
+ logger.warn("Unexpected error destroying lifecycle resource:" + th.getMessage()) ;
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("LifecycleResourceFactory: " + factory + ", identity: " + identity, th) ;
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResource.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceException.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceException.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceException.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -0,0 +1,71 @@
+/*
+ * 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;
+
+/**
+ * Exception class used for reporting exceptions during lifecycle resource
+ * creation/destruction.
+ *
+ * @author kevin
+ */
+public class LifecycleResourceException extends Exception
+{
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = 659413201365777924L;
+
+ /**
+ * Construct a default lifecycle resource exception.
+ */
+ public LifecycleResourceException()
+ {
+ }
+
+ /**
+ * Construct a lifecycle resource exception with a specific message.
+ * @param message the associated message.
+ */
+ public LifecycleResourceException(final String message)
+ {
+ super(message) ;
+ }
+
+ /**
+ * Construct a lifecycle resource exception with a specific cause.
+ * @param cause the associated cause.
+ */
+ public LifecycleResourceException(final Throwable cause)
+ {
+ super(cause) ;
+ }
+
+ /**
+ * Construct a lifecycle resource exception with a specific message and cause.
+ * @param message the associated message.
+ * @param cause the associated cause.
+ */
+ public LifecycleResourceException(final String message, final Throwable cause)
+ {
+ super(message, cause) ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceException.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceFactory.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceFactory.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceFactory.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+/**
+ * Interface representing a lifecycle resource.
+ *
+ * This
+ */
+public interface LifecycleResourceFactory<R>
+{
+ /**
+ * Create a resource object which will be associated with the specified lifecycle identity.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource
+ * @throws LifecycleResourceException for errors during construction.
+ */
+ public R createLifecycleResource(final String lifecycleIdentity)
+ throws LifecycleResourceException ;
+
+ /**
+ * Destroy a resource object which is associated with the specified lifecycle identity.
+ * @param resource The lifecycle resource.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource.
+ * @throws LifecycleResourceException for errors during destroy.
+ */
+ public void destroyLifecycleResource(final R resource, final String lifecycleIdentity)
+ throws LifecycleResourceException ;
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceFactory.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Copied: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java (from rev 15332, labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/LifecycleResourceUtil.java)
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManager.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -0,0 +1,440 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.NamingContext;
+
+/**
+ * Lifecycle resource manager.
+ *
+ * @author kevin
+ */
+public class LifecycleResourceManager
+{
+ /**
+ * The logger for this class.
+ */
+ private static Logger logger = Logger.getLogger(LifecycleResourceManager.class);
+
+ /**
+ * Cleanup hook for cleaning non-esb lifecycle resources.
+ */
+ private static volatile Thread cleanupHook = new Thread() {
+ public void run()
+ {
+ LifecycleResourceManager.getSingleton().cleanupAllResources() ;
+ }
+ } ;
+
+ static
+ {
+ // Initialise the shutdown hook in case we are not in an ESB.
+ Runtime.getRuntime().addShutdownHook(cleanupHook) ;
+ }
+
+ /**
+ * The singleton instance.
+ */
+ private static final LifecycleResourceManager SINGLETON = new LifecycleResourceManager() ;
+
+ /**
+ * The default identity used for unassociated requests.
+ */
+ public static final String DEFAULT_IDENTITY = "ID-DEFAULT" ;
+
+ /**
+ * The mapping of associated deployments.
+ */
+ private final Map<ClassLoader, Set<String>> associatedDeployments = new HashMap<ClassLoader, Set<String>>() ;
+ /**
+ * The classloader identities.
+ */
+ private final Map<ClassLoader, String> identities = new HashMap<ClassLoader, String>() ;
+ /**
+ * The deployment lock.
+ */
+ private ReadWriteLock deploymentLock = new ReentrantReadWriteLock() ;
+
+ /**
+ * The class loader resource map.
+ */
+ private final Map<ClassLoader, Map<Integer, Set<LifecycleResource<?>>>> classLoaderResourceMap = new HashMap<ClassLoader, Map<Integer, Set<LifecycleResource<?>>>>() ;
+ /**
+ * The resource map.
+ */
+ private final Map<Integer, Set<LifecycleResource<?>>> resourceMap = new TreeMap<Integer, Set<LifecycleResource<?>>>() ;
+
+ /**
+ * The resource lock.
+ */
+ private Lock resourceLock = new ReentrantLock() ;
+
+ /**
+ * The identity counter.
+ */
+ private long identityCounter ;
+
+ /**
+ * Associate the current thread with a specified deployment.
+ * @param deploymentName The deployment name.
+ */
+ public void associateDeployment(final String deploymentName)
+ {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader() ;
+ String identity ;
+ final Lock writeLock = deploymentLock.writeLock() ;
+ writeLock.lock() ;
+ try
+ {
+ identity = identities.get(classLoader) ;
+ if (identity != null)
+ {
+ final Set<String> currentAssociations = associatedDeployments.get(classLoader) ;
+ currentAssociations.add(deploymentName) ;
+ }
+ else
+ {
+ final Set<String> associations = new HashSet<String>() ;
+ associations.add(deploymentName) ;
+ associatedDeployments.put(classLoader, associations) ;
+
+ identity = "ID-" + Long.toString(identityCounter++) ;
+ identities.put(classLoader, identity) ;
+ }
+ }
+ finally
+ {
+ writeLock.unlock() ;
+ }
+
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Associating deploymentName " + deploymentName + " with identity: " + identity) ;
+ }
+ }
+
+ /**
+ * Disassociate the current thread with a specified deployment.
+ * @param deploymentName The deployment name.
+ */
+ public void disassociateDeployment(final String deploymentName)
+ {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader() ;
+ final String identity = identities.get(classLoader) ;
+
+ final boolean cleanContext ;
+ final Lock writeLock = deploymentLock.writeLock() ;
+ writeLock.lock() ;
+ try
+ {
+ final Set<String> currentAssociations = associatedDeployments.get(classLoader) ;
+ if (currentAssociations != null)
+ {
+ currentAssociations.remove(deploymentName) ;
+ cleanContext = (currentAssociations.size() == 0) ;
+ if (cleanContext)
+ {
+ identities.remove(classLoader) ;
+ associatedDeployments.remove(classLoader) ;
+ }
+ }
+ else
+ {
+ cleanContext = false ;
+ }
+ }
+ finally
+ {
+ writeLock.unlock() ;
+ }
+
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Disassociating deploymentName " + deploymentName + " from identity: " + identity) ;
+ }
+
+ if (cleanContext)
+ {
+ cleanContextResources(identity) ;
+ }
+ }
+
+ /**
+ * The the current classloader identity.
+ * @return The identity or null if disassociated.
+ */
+ public String getIdentity()
+ {
+ final String identity ;
+ final Lock readLock = deploymentLock.readLock() ;
+ readLock.lock() ;
+ try
+ {
+ identity = identities.get(Thread.currentThread().getContextClassLoader()) ;
+ }
+ finally
+ {
+ readLock.unlock() ;
+ }
+ return (null == identity ? DEFAULT_IDENTITY : identity) ;
+ }
+
+ /**
+ * Register a lifecycle resource with the manager.
+ * @param lifecycleResource The lifecycle resource.
+ * @param classLoader The classloader associated with the factory.
+ * @param priority The priority for cleaning.
+ *
+ * The priority dictates the order in which the resources will be asked to cleanup,
+ * lower priorities being asked to cleanup before higher priorities.
+ */
+ public void registerResource(final LifecycleResource<?> lifecycleResource,
+ final ClassLoader classLoader, final int priority)
+ {
+ try
+ {
+ resourceLock.lock() ;
+ try
+ {
+ final Map<Integer, Set<LifecycleResource<?>>> classLoaderMap = classLoaderResourceMap.get(classLoader) ;
+ if (classLoaderMap != null)
+ {
+ insertInto(classLoaderMap, priority, lifecycleResource) ;
+ }
+ else
+ {
+ final Map<Integer, Set<LifecycleResource<?>>> newMap = new TreeMap<Integer, Set<LifecycleResource<?>>>() ;
+ classLoaderResourceMap.put(classLoader, newMap) ;
+ insertInto(newMap, priority, lifecycleResource) ;
+ }
+ insertInto(resourceMap, priority, lifecycleResource) ;
+ }
+ finally
+ {
+ resourceLock.unlock() ;
+ }
+ }
+ catch (final RuntimeException re)
+ {
+ re.printStackTrace() ;
+ throw re ;
+ }
+ catch (final Error err)
+ {
+ err.printStackTrace() ;
+ throw err ;
+ }
+ }
+
+ /**
+ * Cleanup resources for the specific identity.
+ * @param identity The identity being cleaned.
+ */
+ public void cleanContextResources(final String identity)
+ {
+ resourceLock.lock();
+ try
+ {
+ // cleanup resources for this identity.
+ final Iterator<Set<LifecycleResource<?>>> resourceSetIter = resourceMap.values().iterator() ;
+ while(resourceSetIter.hasNext())
+ {
+ final Set<LifecycleResource<?>> resourceSet = resourceSetIter.next() ;
+ final Iterator<LifecycleResource<?>> resourceIter = resourceSet.iterator() ;
+ while(resourceIter.hasNext())
+ {
+ final LifecycleResource<?> resource = resourceIter.next() ;
+ resource.cleanupResource(identity) ;
+ }
+ }
+
+ // destroy all resources associated with the class loader.
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader() ;
+ final Map<Integer, Set<LifecycleResource<?>>> classLoaderMap = classLoaderResourceMap.remove(classLoader) ;
+ if (classLoaderMap != null)
+ {
+ final Iterator<Entry<Integer, Set<LifecycleResource<?>>>> entryIter = classLoaderMap.entrySet().iterator() ;
+ while(entryIter.hasNext())
+ {
+ final Map.Entry<Integer, Set<LifecycleResource<?>>> entry = entryIter.next() ;
+ final Integer priority = entry.getKey() ;
+ final Set<LifecycleResource<?>> classLoaderResourceMapSet = entry.getValue() ;
+
+ final Set<LifecycleResource<?>> resourceMapSet = resourceMap.get(priority) ;
+ final Iterator<LifecycleResource<?>> resourceIter = classLoaderResourceMapSet.iterator() ;
+ while(resourceIter.hasNext())
+ {
+ final LifecycleResource<?> resource = resourceIter.next() ;
+ resource.destroyResources() ;
+ resourceMapSet.remove(resource) ;
+ }
+
+ if (resourceMapSet.size() == 0)
+ {
+ resourceMap.remove(priority) ;
+ }
+ }
+ }
+ }
+ finally
+ {
+ resourceLock.unlock() ;
+ }
+ // Not touching this yet, needs reworking
+ NamingContext.closeAllContexts() ;
+ }
+
+ /**
+ * Cleanup all remaining resources.
+ */
+ public void cleanupAllResources()
+ {
+ resourceLock.lock();
+ try
+ {
+ // destroy resources.
+ final Iterator<Set<LifecycleResource<?>>> resourceSetIter = resourceMap.values().iterator() ;
+ while(resourceSetIter.hasNext())
+ {
+ final Set<LifecycleResource<?>> resourceSet = resourceSetIter.next() ;
+ final Iterator<LifecycleResource<?>> resourceIter = resourceSet.iterator() ;
+ while(resourceIter.hasNext())
+ {
+ final LifecycleResource<?> resource = resourceIter.next() ;
+ resource.destroyResources() ;
+ }
+ }
+
+ resourceMap.clear() ;
+ classLoaderResourceMap.clear();
+ }
+ finally
+ {
+ resourceLock.unlock() ;
+ }
+ }
+
+ /**
+ * Register a lifecycle resource using the lowest priority.
+ * @param lifecycleResource The lifecycle resource.
+ * @param classLoader The classloader associated with the factory.
+ */
+ public void registerResource(final LifecycleResource<?> lifecycleResource,
+ final ClassLoader classLoader)
+ {
+ registerResource(lifecycleResource, classLoader, Integer.MIN_VALUE) ;
+ }
+
+ /**
+ * Get the singleton instance.
+ * @return The singleton instance.
+ */
+ public static LifecycleResourceManager getSingleton()
+ {
+ return SINGLETON ;
+ }
+
+ /**
+ * Deactivate the cleanup hook.
+ */
+ public static void deactivateHook()
+ {
+ final Thread hook = cleanupHook ;
+ if (hook != null)
+ {
+ cleanupHook = null ;
+ Runtime.getRuntime().removeShutdownHook(hook) ;
+ }
+ }
+
+ /**
+ * Insert the lifecycle resource into the priority map.
+ * @param priorityMap The priority map.
+ * @param priority The resource priority.
+ * @param lifecycleResource The lifecycle resource.
+ */
+ private static void insertInto(final Map<Integer, Set<LifecycleResource<?>>> priorityMap,
+ final int priority, final LifecycleResource<?> lifecycleResource)
+ {
+ final Integer key = Integer.valueOf(priority) ;
+ final Set<LifecycleResource<?>> currentResourceSet = priorityMap.get(key) ;
+ if (currentResourceSet != null)
+ {
+ currentResourceSet.add(lifecycleResource) ;
+ }
+ else
+ {
+ final Set<LifecycleResource<?>> newResourceSet = new HashSet<LifecycleResource<?>>() ;
+ priorityMap.put(key, newResourceSet) ;
+ newResourceSet.add(lifecycleResource) ;
+ }
+ }
+
+//
+// /**
+// * Cleanup resources associated with the current lifecycle context.
+// */
+// public static void cleanupResources()
+// {
+// final String lifecycleIdentity = LifecycleIdentity.getSingleton().getLifecycleIdentity() ;
+// if (logger.isDebugEnabled())
+// {
+// if (lifecycleIdentity != null)
+// {
+// logger.debug("Cleaning up resources for lifecycle identity: " + lifecycleIdentity) ;
+// }
+// else
+// {
+// logger.debug("Cleaning up non-esb lifecycle resources") ;
+// }
+// }
+//
+// CourierFactory.releaseCouriers() ;
+// CourierFactory.destroyLifecycleIdentityMap(lifecycleIdentity) ;
+// try
+// {
+// JmsConnectionPoolContainer.removeAllPools() ;
+// }
+// catch (final JMSException jmse)
+// {
+// if (logger.isDebugEnabled())
+// {
+// logger.debug("Unexpected exception clearing JMS pools", jmse) ;
+// }
+// }
+// NamingContext.closeAllContexts();
+// }
+}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/StandAloneBootStrapper.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -29,8 +29,8 @@
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.internal.soa.esb.util.Exit;
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
import org.jboss.soa.esb.listeners.config.ConfigurationController;
-import org.jboss.soa.esb.util.LifecycleResourceUtil;
public class StandAloneBootStrapper
{
@@ -104,9 +104,10 @@
System.out.println("| |");
System.out.println("+----------------------------------------------------------+");
boot.requestEnd() ;
+ LifecycleResourceManager.getSingleton().cleanupAllResources() ;
}
} ;
- LifecycleResourceUtil.deactivateHook() ;
+ LifecycleResourceManager.deactivateHook() ;
Runtime.getRuntime().addShutdownHook(hook) ;
if (lSecondsToRun < 5) lSecondsToRun = 5;
long lRunTo = System.currentTimeMillis() + 1000 * lSecondsToRun;
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -38,6 +38,7 @@
import javax.xml.transform.stream.StreamSource;
import org.apache.log4j.Logger;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
import org.jboss.soa.esb.listeners.LifecycleUtil;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
@@ -153,6 +154,7 @@
mLogger.fatal("The name of the configuran file was null: " + mConfigFileName);
}
} finally {
+ LifecycleResourceManager.getSingleton().cleanupAllResources() ;
mLogger.info("Exiting Config Controller...");
setEnded(true) ;
}
@@ -323,7 +325,7 @@
stopController() ;
// TODO: Get rid of generating config files to disk. It's nuts. Use in memory stream buffers!!
- controller = startController(generator.getModel(), LifecycleUtil.getConfigTree(mListenerConfigFile), LifecycleUtil.getConfigTree(mGatewayConfigFile));
+ controller = startController(generator.getModel());
} else {
StringBuffer buffer = new StringBuffer("The configuration file "
+ mConfigFileName + "\n did not pass validation for the following reasons: \n");
@@ -344,6 +346,13 @@
}
}
}
+
+ public ManagedLifecycleController startController(final Generator.XMLBeansModel configModel)
+ throws ParamRepositoryException, SAXException, ManagedLifecycleException, ConfigurationException
+ {
+ LifecycleResourceManager.getSingleton().associateDeployment(mConfigFileName) ;
+ return startController(configModel, LifecycleUtil.getConfigTree(mListenerConfigFile), LifecycleUtil.getConfigTree(mGatewayConfigFile)) ;
+ }
public static ManagedLifecycleController startController(Generator.XMLBeansModel configModel, ConfigTree listenerConfig, ConfigTree gatewayConfig) throws ParamRepositoryException, SAXException, ManagedLifecycleException, ConfigurationException {
final List<ManagedLifecycle> instances = LifecycleUtil.getListeners(listenerConfig);
@@ -397,6 +406,7 @@
private void stopController()
{
stopController(controller);
+ LifecycleResourceManager.getSingleton().disassociateDeployment(mConfigFileName) ;
controller = null ;
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployer.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -39,7 +39,7 @@
import org.jboss.mx.loading.LoaderRepositoryFactory;
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.mx.util.ObjectNameConverter;
-import org.jboss.soa.esb.util.LifecycleResourceUtil;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
import org.jboss.system.ServiceControllerMBean;
import org.w3c.dom.Element;
@@ -120,8 +120,15 @@
ServiceControllerMBean.OBJECT_NAME, server);
mainDeployer.addDeployer(this);
- LifecycleResourceUtil.deactivateHook() ;
+ LifecycleResourceManager.deactivateHook() ;
}
+
+ @Override
+ protected void stopService() throws Exception
+ {
+ LifecycleResourceManager.getSingleton().cleanupAllResources() ;
+ super.stopService();
+ }
protected URL getDocumentUrl(DeploymentInfo di)
@@ -236,7 +243,7 @@
InputStream inputStream = document.openStream();
String jbossEsbXml = Configuration.getStringFromStream(inputStream);
inputStream.close();
- JBoss4ESBDeployment deployment = new JBoss4ESBDeployment(jbossEsbXml);
+ JBoss4ESBDeployment deployment = new JBoss4ESBDeployment(jbossEsbXml, di.shortName);
deployment.setClassloader(di.ucl);
String name = "jboss.esb:deployment=" + di.shortName;
ObjectName on = ObjectNameConverter.convert(name);
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployment.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployment.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/JBoss4ESBDeployment.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -21,6 +21,7 @@
*/
package org.jboss.soa.esb.listeners.config;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
import org.jboss.system.ServiceMBeanSupport;
@@ -32,14 +33,16 @@
*/
public class JBoss4ESBDeployment extends ServiceMBeanSupport implements JBoss4ESBDeploymentMBean
{
- private String jbossEsbXml;
+ private final String jbossEsbXml;
+ private final String deploymentName ;
private ManagedLifecycleController controller;
private ClassLoader classloader;
- public JBoss4ESBDeployment(String jbossEsbXml)
+ public JBoss4ESBDeployment(String jbossEsbXml, final String deploymentName)
{
this.jbossEsbXml = jbossEsbXml;
+ this.deploymentName = deploymentName ;
}
public String getJbossEsbXml()
@@ -75,6 +78,7 @@
try
{
Thread.currentThread().setContextClassLoader(classloader);
+ LifecycleResourceManager.getSingleton().associateDeployment(deploymentName) ;
controller = Configuration.create(jbossEsbXml, serviceName);
controller.start();
}
@@ -97,6 +101,7 @@
}
finally
{
+ LifecycleResourceManager.getSingleton().disassociateDeployment(deploymentName) ;
Thread.currentThread().setContextClassLoader(old);
}
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -23,11 +23,8 @@
import java.util.Collection;
-import org.jboss.soa.esb.couriers.CourierFactory;
-import org.jboss.soa.esb.lifecycle.LifecycleIdentity;
import org.jboss.soa.esb.schedule.ScheduleProvider;
import org.jboss.soa.esb.schedule.SchedulingException;
-import org.jboss.soa.esb.util.LifecycleResourceUtil;
import org.apache.log4j.Logger;
/**
@@ -43,10 +40,6 @@
* The managed lifecycle instances.
*/
private final ManagedLifecycle[] instances;
- /**
- * The lifecycle identity.
- */
- private final String lifecycleIdentity ;
private ScheduleProvider scheduleProvider;
/**
@@ -61,9 +54,6 @@
} else {
instances = lifecycles.toArray(new ManagedLifecycle[lifecycles.size()]);
}
- lifecycleIdentity = LifecycleIdentity.getSingleton().associateLifecycleIdentity() ;
-
- CourierFactory.initialiseLifecycleIdentityMap(lifecycleIdentity) ;
}
/**
@@ -251,7 +241,6 @@
throw mle;
}
}
- LifecycleResourceUtil.cleanupResources() ;
}
/**
@@ -292,7 +281,6 @@
{
} // Ignore exception
}
- LifecycleResourceUtil.cleanupResources() ;
}
/**
Deleted: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/LifecycleResourceUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/LifecycleResourceUtil.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/LifecycleResourceUtil.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -1,117 +0,0 @@
-/*
- * 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.util;
-
-import javax.jms.JMSException;
-
-import org.apache.log4j.Logger;
-import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
-import org.jboss.soa.esb.couriers.CourierFactory;
-import org.jboss.soa.esb.helpers.NamingContext;
-import org.jboss.soa.esb.lifecycle.LifecycleIdentity;
-
-/**
- * Utility methods to manage lifecycle resources.
- *
- * @author kevin
- */
-public class LifecycleResourceUtil
-{
- /**
- * The logger for this class.
- */
- private static Logger logger = Logger.getLogger(LifecycleResourceUtil.class);
-
- /**
- * Cleanup hook for cleaning non-esb lifecycle resources.
- */
- private static volatile Thread cleanupHook = new Thread() {
- public void run()
- {
- cleanupResources() ;
- }
- } ;
-
- static
- {
- // Initialise the shutdown hook in case we are not in an ESB.
- Runtime.getRuntime().addShutdownHook(cleanupHook) ;
- }
-
- /**
- * Cleanup resources associated with the current lifecycle context.
- */
- public static void cleanupResources()
- {
- final String lifecycleIdentity = LifecycleIdentity.getSingleton().getLifecycleIdentity() ;
- if (logger.isDebugEnabled())
- {
- if (lifecycleIdentity != null)
- {
- logger.debug("Cleaning up resources for lifecycle identity: " + lifecycleIdentity) ;
- }
- else
- {
- logger.debug("Cleaning up non-esb lifecycle resources") ;
- }
- }
-
- CourierFactory.releaseCouriers() ;
- CourierFactory.destroyLifecycleIdentityMap(lifecycleIdentity) ;
- try
- {
- JmsConnectionPoolContainer.removeAllPools() ;
- }
- catch (final JMSException jmse)
- {
- if (logger.isDebugEnabled())
- {
- logger.debug("Unexpected exception clearing JMS pools", jmse) ;
- }
- }
- NamingContext.closeAllContexts();
- }
-
- /**
- * Handle the activiation of the cleanup hook.
- */
- public static void activateHook()
- {
- /*
- * The real activation is handled in the static initialiser so
- * that it occurs only once.
- */
- }
-
- /**
- * Deactivate the cleanup hook.
- */
- public static void deactivateHook()
- {
- final Thread hook = cleanupHook ;
- if (hook != null)
- {
- cleanupHook = null ;
- Runtime.getRuntime().removeShutdownHook(hook) ;
- }
- }
-}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManagerTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManagerTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManagerTest.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -0,0 +1,197 @@
+/*
+* 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.junit.Test;
+
+/**
+ * @author Kevin Conner
+ *
+ */
+public class LifecycleResourceManagerTest {
+
+ @Test
+ public void testAssociation()
+ throws Exception
+ {
+ // create a lifecycle resource
+ final LifecycleResource<TestLifecycleResource1> resource = new LifecycleResource<TestLifecycleResource1>(new TestLifecycleResource1Factory()) ;
+ // get unassociated resource and check id
+ final TestLifecycleResource1 first = resource.getLifecycleResource() ;
+ assertEquals(LifecycleResourceManager.DEFAULT_IDENTITY, first.getId()) ;
+ assertNull(first.getDestroyId()) ;
+
+
+ // associate deployment
+ final String deploymentName = "deploymentName" ;
+ // get associated resource and check id
+ LifecycleResourceManager.getSingleton().associateDeployment(deploymentName) ;
+ final TestLifecycleResource1 second = resource.getLifecycleResource() ;
+ final String id = second.getId() ;
+ assertFalse(LifecycleResourceManager.DEFAULT_IDENTITY.equals(id)) ;
+ assertNull(second.getDestroyId()) ;
+ assertNull(first.getDestroyId()) ;
+
+ // disassociate deployment
+ LifecycleResourceManager.getSingleton().disassociateDeployment(deploymentName) ;
+ // check id has been cleaned
+ assertEquals(id, second.getDestroyId()) ;
+ // check other resources using this classloader have also been cleared.
+ assertEquals(LifecycleResourceManager.DEFAULT_IDENTITY, first.getDestroyId()) ;
+ }
+
+ // Check order
+ // create three resources (none, 0, 1000)
+ // disassociate deployment
+ // check id has been cleaned and resources destroyed in correct order.
+
+ @Test
+ public void testOrder()
+ throws Exception
+ {
+ // create factories and lifecycle resources
+ final TestLifecycleResource2Factory factory1 = new TestLifecycleResource2Factory() ;
+ final LifecycleResource<TestLifecycleResource2> lifecycleResource1 = new LifecycleResource<TestLifecycleResource2>(factory1) ;
+ final TestLifecycleResource2Factory factory2 = new TestLifecycleResource2Factory() ;
+ final LifecycleResource<TestLifecycleResource2> lifecycleResource2 = new LifecycleResource<TestLifecycleResource2>(factory2, 100) ;
+ final TestLifecycleResource2Factory factory3 = new TestLifecycleResource2Factory() ;
+ final LifecycleResource<TestLifecycleResource2> lifecycleResource3 = new LifecycleResource<TestLifecycleResource2>(factory3, 0) ;
+
+ // create resources
+ final TestLifecycleResource2 resource1 = lifecycleResource1.getLifecycleResource() ;
+ final TestLifecycleResource2 resource2 = lifecycleResource2.getLifecycleResource() ;
+ final TestLifecycleResource2 resource3 = lifecycleResource3.getLifecycleResource() ;
+
+ // check correct factory is used
+ assertEquals(factory1, resource1.getFactory()) ;
+ assertEquals(factory2, resource2.getFactory()) ;
+ assertEquals(factory3, resource3.getFactory()) ;
+
+ // check nothing is destroyed
+ assertEquals(0, TestLifecycleResource2Factory.getDestroyOrder().size()) ;
+
+ // cleanup all resources
+ LifecycleResourceManager.getSingleton().cleanupAllResources() ;
+
+ // check we have three resources destroyed
+ assertEquals(3, TestLifecycleResource2Factory.getDestroyOrder().size()) ;
+
+ // check order of destroy calls.
+ assertEquals(resource1, TestLifecycleResource2Factory.getDestroyOrder().get(0)) ;
+ assertEquals(resource3, TestLifecycleResource2Factory.getDestroyOrder().get(1)) ;
+ assertEquals(resource2, TestLifecycleResource2Factory.getDestroyOrder().get(2)) ;
+ }
+
+ private static class TestLifecycleResource1
+ {
+ private final String id ;
+ private String destroyId ;
+
+ TestLifecycleResource1(final String id)
+ {
+ this.id = id ;
+ }
+
+ String getId()
+ {
+ return id ;
+ }
+
+ String getDestroyId()
+ {
+ return destroyId ;
+ }
+
+ void setDestroyId(final String destroyId)
+ {
+ this.destroyId = destroyId ;
+ }
+ }
+
+ private static class TestLifecycleResource1Factory implements LifecycleResourceFactory<TestLifecycleResource1>
+ {
+ public TestLifecycleResource1 createLifecycleResource(final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ return new TestLifecycleResource1(lifecycleIdentity) ;
+ }
+
+ public void destroyLifecycleResource(final TestLifecycleResource1 resource,
+ final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ resource.setDestroyId(lifecycleIdentity) ;
+ }
+ }
+
+ private static class TestLifecycleResource2
+ {
+ private final LifecycleResourceFactory<TestLifecycleResource2> factory ;
+
+ TestLifecycleResource2(final LifecycleResourceFactory<TestLifecycleResource2> factory)
+ {
+ this.factory = factory ;
+ }
+
+ LifecycleResourceFactory<TestLifecycleResource2> getFactory()
+ {
+ return factory ;
+ }
+ }
+
+ private static class TestLifecycleResource2Factory implements LifecycleResourceFactory<TestLifecycleResource2>
+ {
+ private static final List<TestLifecycleResource2> destroyOrder = new ArrayList<TestLifecycleResource2>() ;
+
+ public TestLifecycleResource2 createLifecycleResource(final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ return new TestLifecycleResource2(this) ;
+ }
+
+ public void destroyLifecycleResource(final TestLifecycleResource2 resource,
+ final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ destroyOrder.add(resource) ;
+ }
+
+ static List<TestLifecycleResource2> getDestroyOrder()
+ {
+ return destroyOrder ;
+ }
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(LifecycleResourceManagerTest.class);
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/lifecycle/LifecycleResourceManagerTest.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/rosetta/pooling/JmsConnectionPoolingIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/rosetta/pooling/JmsConnectionPoolingIntegrationTest.java 2007-09-28 11:40:13 UTC (rev 15428)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/rosetta/pooling/JmsConnectionPoolingIntegrationTest.java 2007-09-28 11:42:52 UTC (rev 15429)
@@ -35,6 +35,7 @@
import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.helpers.NamingContext;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
import org.junit.Test;
/**
@@ -45,79 +46,71 @@
@Test
public void testPoolAndConnectionCreation()
+ throws Exception
{
JmsConnectionPool jmsConnectionPool = null;
- try {
- Properties environment = new Properties();
- environment.setProperty(Context.PROVIDER_URL, NamingContext.JBOSS_PROVIDER_URL);
- environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
- environment.setProperty(Context.URL_PKG_PREFIXES, NamingContext.JBOSS_URL_PKG_PREFIX);
-
- jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment,"ConnectionFactory", JMSEpr.QUEUE_TYPE);
- assertEquals(0, jmsConnectionPool.getSessionsInPool());
- //Open 3 concurrent sessions
- Session session1 = jmsConnectionPool.getQueueSession();
- assertEquals(1, jmsConnectionPool.getSessionsInPool());
- Session session2 = jmsConnectionPool.getQueueSession();
- assertEquals(2, jmsConnectionPool.getSessionsInPool());
- Session session3 = jmsConnectionPool.getQueueSession();
- assertEquals(3, jmsConnectionPool.getSessionsInPool());
- //Close them
- jmsConnectionPool.closeSession(session1);
- jmsConnectionPool.closeSession(session2);
- jmsConnectionPool.closeSession(session3);
- assertEquals(3, jmsConnectionPool.getSessionsInPool());
- //destroy this pool
- jmsConnectionPool.removeSessionPool();
- assertEquals(0, jmsConnectionPool.getSessionsInPool());
- assertEquals(0, JmsConnectionPoolContainer.getNumberOfPools());
-
- //Use it again and add one session
- jmsConnectionPool.getQueueSession();
- assertEquals(1, jmsConnectionPool.getSessionsInPool());
- assertEquals(1, JmsConnectionPoolContainer.getNumberOfPools());
- //I should be able to remove the entire pool and have it do closing
- //of the session.
- jmsConnectionPool.removeSessionPool();
- } catch (Exception e) {
- assertTrue(false);
- e.printStackTrace();
- }
+ Properties environment = new Properties();
+ environment.setProperty(Context.PROVIDER_URL, NamingContext.JBOSS_PROVIDER_URL);
+ environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
+ environment.setProperty(Context.URL_PKG_PREFIXES, NamingContext.JBOSS_URL_PKG_PREFIX);
+
+ jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment,"ConnectionFactory", JMSEpr.QUEUE_TYPE);
+ assertEquals(0, jmsConnectionPool.getSessionsInPool());
+ //Open 3 concurrent sessions
+ Session session1 = jmsConnectionPool.getQueueSession();
+ assertEquals(1, jmsConnectionPool.getSessionsInPool());
+ Session session2 = jmsConnectionPool.getQueueSession();
+ assertEquals(2, jmsConnectionPool.getSessionsInPool());
+ Session session3 = jmsConnectionPool.getQueueSession();
+ assertEquals(3, jmsConnectionPool.getSessionsInPool());
+ //Close them
+ jmsConnectionPool.closeSession(session1);
+ jmsConnectionPool.closeSession(session2);
+ jmsConnectionPool.closeSession(session3);
+ assertEquals(3, jmsConnectionPool.getSessionsInPool());
+ //destroy this pool
+ jmsConnectionPool.removeSessionPool();
+ assertEquals(0, jmsConnectionPool.getSessionsInPool());
+ assertEquals(0, JmsConnectionPoolContainer.getNumberOfPools());
+
+ //Use it again and add one session
+ jmsConnectionPool.getQueueSession();
+ assertEquals(1, jmsConnectionPool.getSessionsInPool());
+ assertEquals(1, JmsConnectionPoolContainer.getNumberOfPools());
+ //I should be able to remove the entire pool and have it do closing
+ //of the session.
+ jmsConnectionPool.removeSessionPool();
}
@Test
public void testCreateSecondPool()
+ throws Exception
{
- try {
- Properties environment = new Properties();
- environment.setProperty(Context.PROVIDER_URL, NamingContext.JBOSS_PROVIDER_URL);
- environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
- environment.setProperty(Context.URL_PKG_PREFIXES, NamingContext.JBOSS_URL_PKG_PREFIX);
- JmsConnectionPool jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory", JMSEpr.QUEUE_TYPE);
- jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory", JMSEpr.QUEUE_TYPE);
- //This should be the same pool
- assertEquals(1, JmsConnectionPoolContainer.getNumberOfPools());
+ Properties environment = new Properties();
+ environment.setProperty(Context.PROVIDER_URL, NamingContext.JBOSS_PROVIDER_URL);
+ environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
+ environment.setProperty(Context.URL_PKG_PREFIXES, NamingContext.JBOSS_URL_PKG_PREFIX);
+ JmsConnectionPool jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory", JMSEpr.QUEUE_TYPE);
+ jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory", JMSEpr.QUEUE_TYPE);
+ //This should be the same pool
+ assertEquals(1, JmsConnectionPoolContainer.getNumberOfPools());
+
+ jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory", JMSEpr.TOPIC_TYPE);
+ //This should be a different pool, so now we should have 2.
+ assertEquals(2, JmsConnectionPoolContainer.getNumberOfPools());
- jmsConnectionPool = JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory", JMSEpr.TOPIC_TYPE);
- //This should be a different pool, so now we should have 2.
- assertEquals(2, JmsConnectionPoolContainer.getNumberOfPools());
-
- jmsConnectionPool = JmsConnectionPoolContainer.getPool(null, "ConnectionFactory", JMSEpr.TOPIC_TYPE);
- //This should be a different pool, so now we should have 3.
- assertEquals(3, JmsConnectionPoolContainer.getNumberOfPools());
-
- //Now lets cleanup after ourselves
- jmsConnectionPool.removeSessionPool();
- assertEquals(2, JmsConnectionPoolContainer.getNumberOfPools());
-
- //Let's clean the rest up with a removeAll.
- JmsConnectionPoolContainer.removeAllPools();
- assertEquals(0, JmsConnectionPoolContainer.getNumberOfPools());
- } catch (Exception e) {
- assertTrue(false);
- e.printStackTrace();
- }
+ jmsConnectionPool = JmsConnectionPoolContainer.getPool(null, "ConnectionFactory", JMSEpr.TOPIC_TYPE);
+ //This should be a different pool, so now we should have 3.
+ assertEquals(3, JmsConnectionPoolContainer.getNumberOfPools());
+
+ //Now lets cleanup after ourselves
+ jmsConnectionPool.removeSessionPool();
+ assertEquals(2, JmsConnectionPoolContainer.getNumberOfPools());
+
+ //Let's clean the rest up with a removeAll.
+ LifecycleResourceManager.getSingleton().cleanupAllResources() ;
+ assertEquals(0, JmsConnectionPoolContainer.getNumberOfPools());
}
public static junit.framework.Test suite()
More information about the jboss-svn-commits
mailing list