[jboss-svn-commits] JBL Code SVN: r8058 - in labs/jbossesb/trunk: product/core/listeners/src/org/jboss/soa/esb/listeners/message product/samples/quickstarts/helloworld/src/quickstart product/samples/quickstarts/helloworld_action/src/quickstart product/samples/quickstarts/helloworld_embedded_reg/src/quickstart product/samples/quickstarts/more_action/src/quickstart product/samples/quickstarts/simple_cbr/src/quickstart product/samples/quickstarts/simple_transformation/src/quickstart product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util qa/junit/src/org/jboss/soa/esb/actions qa/junit/src/org/jboss/soa/esb/listeners/gateway qa/junit/src/org/jboss/soa/esb/listeners/message qa/junit/src/org/jboss/soa/esb/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Dec 5 04:27:43 EST 2006


Author: tfennelly
Date: 2006-12-05 04:27:27 -0500 (Tue, 05 Dec 2006)
New Revision: 8058

Added:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerFactory.java
Removed:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerService.java
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld/src/quickstart/Launcher.java
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_action/src/quickstart/Launcher.java
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_embedded_reg/src/quickstart/Launcher.java
   labs/jbossesb/trunk/product/samples/quickstarts/more_action/src/quickstart/Launcher.java
   labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/quickstart/Launcher.java
   labs/jbossesb/trunk/product/samples/quickstarts/simple_transformation/src/quickstart/Launcher.java
   labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/Launcher.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/NewListenerUtils.java
Log:
First part of a fix for http://jira.jboss.com/jira/browse/JBESB-256.

Factory class is now implements and the runnability of the controller is hidden.  Need to implement the blocking factory methods now (Vs a dubious Thread.sleep and hope for the best).

Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -1,600 +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.listeners.message;
-
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.jboss.internal.soa.esb.command.CommandQueue;
-import org.jboss.internal.soa.esb.command.CommandQueueException;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.util.EPRManager;
-import org.jboss.soa.esb.common.Environment;
-import org.jboss.soa.esb.common.ModulePropertyManager;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.parameters.ParamRepositoryException;
-import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
-import org.jboss.soa.esb.services.registry.Registry;
-import org.jboss.soa.esb.services.registry.RegistryException;
-import org.jboss.soa.esb.services.registry.RegistryFactory;
-import org.jboss.soa.esb.util.Util;
-import org.xml.sax.SAXException;
-
-import com.arjuna.common.util.propertyservice.PropertyManager;
-
-/**
- * Controlling class that will launch 'message aware' listener child threads for supported
- * transport listener classes, as indicated in the configuration XML tree used in the constructor
- * If you use the 'main' method, configuration file is expected in arg[0]
- * 
- * <p />
- * Can be launched as uppermost controller (it has a main(args) method)
- * <p />
- * Also implements Runnable, and can thus be launched in a child thread from an
- * upper controlling process
- * <p />
- * Listens on a JMS queue (with an optional message selector) for commands (e.g.
- * Quiesce, Reload Parameters, Set End Time, etc.)
- * <p />
- * Parameter reloading can also be set using the PARM_RELOAD_SECS attribute
- * <p />
- * End time for this instance can also be set using the PARM_END_TIME attribute
- * <p />
- * 
- * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- * @since Version 4.0
- */
-public class EsbListenerController implements Runnable {
-
-	private static Logger _logger = Logger.getLogger(EsbListenerController.class);
-
-	public static void main(String[] args) throws Exception {
-		EsbListenerController oProc = new EsbListenerController(args[0]);
-		oProc.run();
-		EsbListenerController.State oS = oProc.getState();
-
-		if (null != oS.getException()) {
-			_logger.error("EsbListenerController <" + args[0] + "> FAILED\n", oS
-					.getException());
-		}
-		System.exit(oS.getCompletionCode());
-	} // ________________________________
-
-	protected int m_iDfltReloadMillis = 180000 // default interval between
-												// parameter reloads
-	;
-
-	public static final String PARM_RELOAD_SECS = "parameterReloadSecs";
-	public static final String PARM_END_TIME = "endTime";
-
-	// Attribute name that denotes listener class to be instantiated in a child
-	// thread
-	// This attribute is not in the root node but in first level child
-	// ConfigTrees
-	public static final String PARM_LISTENER_CLASS = "listenerClass";
-
-	private String m_sParmsName;
-	private ConfigTree m_oParms;
-	private Object _registrySynch = new Object();
-
-	private HashMap<String, Object> m_oAtts;
-
-	/**
-	 * Obtain a shallow copy of needed atributes in this object's last loaded
-	 * parameter tree <p/>The local bject is cloned so child threads can use it
-	 * as they choose to without interfering with the environment
-	 * <p />
-	 * Listener processes controlled by this object should keep a reference to
-	 * this object at construction time, and not call this method again unless
-	 * they specifically need updated values. Parameter reload could have
-	 * happened since last call
-	 * 
-	 * @return Map - a shallow copy of the attributes Map
-	 */
-	@SuppressWarnings("unchecked")
-	public Map<String, Object> getControllerAttributes() {
-		return (Map<String, Object>) m_oAtts.clone();
-	}
-
-	private boolean m_bReloadRequested, m_bEndRequested;
-
-	private long m_lNextReload = Long.MAX_VALUE;
-
-	private long m_lEndTime = Long.MAX_VALUE;
-
-	public static final SimpleDateFormat s_oDateParse = new SimpleDateFormat(
-			"yyyyMMdd hh:mm:ss");
-
-	private State m_oState = null;
-
-	public State getState() {
-		return m_oState;
-	}
-
-	public static enum State {
-		Loading_parameters, Running, Shutting_down, Done_OK, Exception_thrown;
-		int m_iCompletionCode = 0;
-
-		Exception m_oException = null;
-
-		public int getCompletionCode() {
-			return m_iCompletionCode;
-		};
-
-		public Exception getException() {
-			return m_oException;
-		}
-	};
-
-	private CommandQueue commandQueue;
-	private static CommandQueue defaultCommandQueue = null;
-
-	/**
-	 * No default constructor - only for child classes 
-	 */
-	protected EsbListenerController() { }
-	
-	/**
-	 * Construct a Listener Manager from the named repository based
-	 * configuration.
-	 * 
-	 * @param p_sParameterName
-	 *            Name of the Repository entry containing the configuration.
-	 * @throws Exception
-	 *             Unable to load/use the named configuration.
-	 */
-	public EsbListenerController(String p_sParameterName) throws Exception {		
-		this(EsbListenerController.getListenerConfig(p_sParameterName));
-		m_sParmsName = p_sParameterName;
-	}
-
-	/**
-	 * Construct a Listener Controller using the specified listener configuration.
-	 * 
-	 * @param config
-	 *            The configuration.
-	 * @throws Exception
-	 *             Unable to load/use the supplied configuration.
-	 */
-	public EsbListenerController(ConfigTree config) throws Exception {
-		m_oParms = config;
-		m_oState = State.Loading_parameters;
-
-		try {	checkParms(m_oParms); }
-		catch (Exception e) 
-		{
-			String configSource = config.getAttribute("configSource");
-
-			m_oState = State.Exception_thrown;
-			m_oState.m_oException = e;
-			_logger.fatal("Listener configuration and startup error.  Config Source: "
-									+ (configSource != null ? configSource
-											: "unknown"), e);
-
-			throw e;
-		}
-	}
-
-	/**
-	 * Load the named listener configuration from the configured parameter
-	 * repository.
-	 * 
-	 * @param reposParam
-	 *            The name of the repository entry containing the Listener
-	 *            configuration.
-	 * @return Listener Configuration as {@link ConfigTree}.
-	 * @throws IOException
-	 *             Unable to access the repository.
-	 * @throws ParamRepositoryException
-	 *             Unable to access the configuration in the repository.
-	 * @throws SAXException
-	 *             Unable to parse the configuration.
-	 */
-	private static ConfigTree getListenerConfig(String reposParam)
-			throws IOException, ParamRepositoryException, SAXException {		
-		String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
-		ConfigTree config = ConfigTree.fromXml(sXml);
-
-		config.setAttribute("configSource", "param-repository:" + reposParam);
-
-		return config;
-	}
-
-	/**
-	 * Check to see if all needed parameters are there, and assign default
-	 * values to some of them
-	 * 
-	 * @param p_oP
-	 *            ConfigTree - Where to look for the mandatory/optional
-	 *            configuration attributes
-	 * @throws Exception -
-	 *             If attributes are wrong or not enough for a proper runtime
-	 *             configuration
-	 */
-	public void checkParms(ConfigTree p_oP) throws Exception {
-		// We've just loaded - set to false until next reload requested
-		m_bReloadRequested = false;
-		commandQueue = createCommandQueue(p_oP);
-
-		// Open the command queue...
-		if (null!=commandQueue)
-			commandQueue.open(p_oP);
-
-		// if PARM_RELOAD_SECS not set, and no command queue
-		// then reload every 10 minutes
-		// If there is a command queue, run until command is received
-		String sRldSecs = p_oP.getAttribute(PARM_RELOAD_SECS);
-		m_lNextReload = (null != sRldSecs) 
-				? System.currentTimeMillis() + 1000 * Long.parseLong(sRldSecs)
-				: (null == commandQueue) 
-						? Long.MAX_VALUE 
-						: System.currentTimeMillis() + m_iDfltReloadMillis;
-
-		// if PARM_END_TIME not set try to run forever
-		// not a good practice if command queue is not set
-		// Expected date format is "yyyyMMdd hh:mm:ss"
-		String sEndT = p_oP.getAttribute(PARM_END_TIME);
-		m_lEndTime = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
-				sEndT).getTime();
-          
-	} // ________________________________
-
-    /**
-     * Factory method for creating the command queue.
-     * @param config EsbListenerController config.
-     * @return EsbListenerController CommandQueue instance.
-     */
-	private CommandQueue createCommandQueue(ConfigTree config) {
-		String commandQueueClass = config.getAttribute("command-queue-class");
-		
-		if(commandQueueClass != null) {
-			try {
-				return (CommandQueue) Class.forName(commandQueueClass).newInstance();
-			} catch (Exception e) {
-				_logger.error("Failed to instantiate CommandQueue ["+ commandQueueClass + "].  Defaulting to no Command Queue", e);
-			}
-		}
-			
-		return defaultCommandQueue;
-	}
-
-	/**
-	 * Allows a default command queue to be set statically for all EsbListenerController instances.
-	 * @param defaultCommandQueue The defaultCommandQueue to set.
-	 */
-	public static void setDefaultCommandQueue(CommandQueue defaultCommandQueue) {
-		EsbListenerController.defaultCommandQueue = defaultCommandQueue;
-	}
-
-	/**
-	 * Main execution loop <p/> Will continue to run until either <p/>a) run
-	 * time is expired <p/>b) quiesce command is received in command queue
-	 * <p/>For every child element that contains a PARM_LISTENER_CLASS
-	 * attribute, this method will try to launch a child thread instantiating an
-	 * object of that class, and will call it's run() method <p/>Once all child
-	 * processes are trigered, the main thread will either <p/>1) wait for a
-	 * message in the command queue (if one was configured) until next reload or
-	 * end of run period expired <p/>or 2) Just sleep if there's no command
-	 * queue to listen on
-	 */
-	public void run() {
-		while (endNotRequested()) {
-			m_oState = State.Running;
-			for (ConfigTree oCurr : m_oParms.getAllChildren()) {
-				String sClass = oCurr.getAttribute(PARM_LISTENER_CLASS);
-				if (Util.isNullString(sClass))
-					continue;
-				tryToLaunchChildListener(oCurr, sClass);
-			}
-
-			waitForCmdOrSleep();
-
-			if (endRequested()) {
-				break;
-			}
-			if (m_sParmsName != null && timeToReload()) {
-				try {
-					m_oState = State.Loading_parameters;
-					_logger
-							.info("Reloading parameters _____________________________________________________");
-					ConfigTree oNew = EsbListenerController.getListenerConfig(m_sParmsName);
-					checkParms(oNew);
-					m_oParms = oNew;
-				} catch (Exception e) {
-					_logger.error("Failed to reload parameters"
-							+ " - Continuing with cached version", e);
-				}
-			}
-		}
-		// m_oState = State.Shutting_down;
-
-		m_oState = State.Done_OK;
-		m_oState.m_iCompletionCode = 0;
-		_logger
-				.info("Finishing_____________________________________________________");
-
-		// Close the command queue...
-		try {
-			if (null != commandQueue)
-				commandQueue.close();
-		} catch (CommandQueueException e) {
-			_logger.error("Error closing Command Queue.", e);
-		}
-	} // ________________________________
-
-	private void tryToLaunchChildListener(ConfigTree p_oP, String p_sClassName) {
-		try 
-		{
-			Class oListener = Class.forName(p_sClassName);
-			Constructor oConst = oListener.getConstructor(new Class[] {this.getClass(), ConfigTree.class});
-			Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this,p_oP});
-			new Thread(oRun).start();
-		}
-		catch (Exception e) 
-		{
-			_logger.error("Cannot launch <" + p_sClassName + ">\n", e);
-		}
-	} // ________________________________
-
-	long millisToWait() {
-		return Math.min(m_lNextReload, m_lEndTime) - System.currentTimeMillis();
-	} // ________________________________
-
-	private void waitForCmdOrSleep() {
-		long lToGo = millisToWait();
-
-		if (null == commandQueue) {
-			_logger.debug("About to sleep " + lToGo);
-			// No command queue nor topic - Just sleep until time
-			// exhausted, or thread interrupted
-			try {
-				while ((lToGo=millisToWait()) > 0)
-					Thread.sleep(500);
-			} catch (InterruptedException e) {
-				m_lEndTime = 0; // mark as end requested and return
-			}
-			return;
-		}
-
-		// Wait for commands until time exhausted or command received
-		// Note that received commands might change time variables (reload/end)
-		// that's why time to go is recalculated on each cycle
-		while ((lToGo = millisToWait()) > 0) {
-			try {
-				_logger.info("Waiting for command ... timeout=" + lToGo + " millis");
-
-				String oM = commandQueue.receiveCommand(lToGo);
-				if (null == oM) {
-					return;
-				}
-				processCommand(oM);
-				if (endRequested() || timeToReload()) {
-					break;
-				}
-			} catch (CommandQueueException eJ) {
-				_logger.info("receive on command queue failed", eJ);
-			}
-		}
-	} // ________________________________
-
-	/**
-	 * Processes the command that has been received in the command queue (or
-	 * topic) <p/>m_bEndRequested, m_bReloadRequested, and m_lEndTime could be
-	 * changed
-	 * 
-	 * <p/> <p/><TABLE border="1"> <COLGROUP> <COL width="200"/> <COL
-	 * width="400"/> </COLGROUP>
-	 * <TR>
-	 * <TD align="center">message text</TD>
-	 * <TD align="center">effect</TD>
-	 * </TR>
-	 * <TR>
-	 * <TD>shutdown*</TD>
-	 * <TD>End time will be immediately set to 'now' - quiesce process will
-	 * start - Child threads will be allowed to finish normally</TD>
-	 * </TR>
-	 * <TR>
-	 * <TD>reload param*</TD>
-	 * <TD>Parameters will be immediately reloaded, and listener reconfigured
-	 * with new values</TD>
-	 * </TR>
-	 * <TR>
-	 * <TD>endTime yyyyMMdd hh:mm:ss</TD>
-	 * <TD>End time will be set to new value. If hh:mm:ss is not supplied =>
-	 * end of day assumed (23:59:59)</TD>
-	 * </TR>
-	 * </TABLE> * startsWith() <p/>
-	 * 
-	 * @param p_oMsg
-	 *            Message received from the command queue.
-	 * 
-	 */
-	private void processCommand(String sTxt) {
-		if (null == sTxt)
-			return;
-		
-		String sLow = sTxt.trim().toLowerCase();
-		if (sLow.startsWith("shutdown")) {
-			m_bEndRequested = true;
-			_logger.info("Shutdown has been requested");
-			return;
-		}
-		if (sLow.startsWith("reload param")) {
-			m_bReloadRequested = true;
-			_logger
-					.info("Request for parameter reload has been received");
-			return;
-		}
-		String[] sa = sLow.split("\\s+");
-		if (sa.length > 1 && "endtime".equals(sa[0])) {
-			try {
-				String sDate = sa[1];
-				String sTime = (sa.length < 3 || null == sa[2]) ? "23:59:59"
-						: sa[2];
-				Date oEnd = s_oDateParse.parse(sDate + " " + sTime);
-				_logger.info("New end date set to : " + oEnd);
-				m_lEndTime = oEnd.getTime();
-			} catch (Exception eDat) {
-				_logger.info("Problems with endTime command", eDat);
-			}
-		}
-	} // ________________________________
-
-	public void requestEnd() {
-		m_bEndRequested=true;
-		m_lEndTime = 0;
-	}
-	
-	/**
-	 * Accessor to determine if execution time is expired or shutdown requested
-	 * 
-	 * @return boolean if processing has to stop (all child threads will be
-	 *         allowed to finish)
-	 */
-	public boolean endRequested() {
-		return m_bEndRequested || System.currentTimeMillis() >= m_lEndTime;
-	}
-
-	/**
-	 * Accessor to determine if execution time is not expired, and no shutdown
-	 * request received
-	 * 
-	 * @return boolean - true if run time has not expired and quiesce has not
-	 *         been requested
-	 */
-	public boolean endNotRequested() {
-		return !endRequested();
-	}
-
-	/**
-	 * Provide a common accessor to determine if parameters have to be reloaded
-	 * <p/> For child threads this means thread execution has to end
-	 * </p>
-	 * Child processes should only call this method when they are idle (as
-	 * opposed to in the middle of executing a unit of work)
-	 * 
-	 * @return boolean - true if it's time to reload parameters
-	 */
-	public boolean timeToReload() {
-		return m_bReloadRequested
-				|| System.currentTimeMillis() >= m_lNextReload;
-	}
-
-	/**
-	 * Helper accessor for child processes that provides info to determine if
-	 * they can continue with yet another execution cycle
-	 * 
-	 * @return boolean - true if runtime is not expired and not time yet to
-	 *         reload parameters
-	 */
-	public boolean continueLooping() {
-		return (endNotRequested() && !timeToReload());
-	} // ________________________________
-	
-	public static EPRManager getEprManager()
-	{
-		PropertyManager manager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE);
-		String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,".");	
-		return EPRManager.getInstance(sDir);
-	}
-	
-	/**
-	 * @deprecated use register (ConfigTree config, EPR address) instead.
-	 * @param name
-	 * @param address
-	 */
-	public void register (String name, EPR address)
-	{
-		try { getEprManager().saveEPR(name,address); }
-		catch (IOException e)
-		{
-			_logger.fatal("Cannot register service",e);
-		}
-	} // ________________________________
-	/**
-	 * @deprecated use unRegister (String serviceCategoryName, String serviceName, EPR epr) instead.
-	 * @param name
-	 */
-	public void unRegister (String name)
-	{
-		try { getEprManager().removeEPR(name); }
-		catch (IOException e)
-		{
-			_logger.fatal("Cannot un-register service",e);
-		}
-	} // ________________________________
-	/**
-	 * Register an EPR in the registry.
-	 * 
-	 * @param config - a config tree containing the deployment-configuration of the service.
-	 * @param epr - the epr (EndPoint Reference) of the service.
-	 * 
-	 * @throws RegistryException
-	 */
-	public void register(ConfigTree config , EPR epr) throws RegistryException
-	{
-		String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
-		String serviceName         = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
-		if ("eprManager".equalsIgnoreCase(serviceCategoryName))
-		{
-				register(serviceName,epr);
-				return;
-		}
-		String serviceDescription  = config.getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
-		String eprDescription      = config.getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
-		Registry registry = RegistryFactory.getRegistry();
-		synchronized (_registrySynch)
-		{
-			registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription);
-		}
-	}
-	/**
-	 * Unregister the EPR from the registry.
-	 * 
-	 * @param serviceCategoryName - name of the category of the service ('Content Based Routing')
-	 * @param serviceName         - name of the service ("
-	 * @param epr
-	 * @throws RegistryException
-	 */
-	public void unRegister(String serviceCategoryName, String serviceName , EPR epr) throws RegistryException
-	{
-		if ("eprManager".equalsIgnoreCase(serviceCategoryName))
-		{
-				unRegister(serviceName);
-				return;
-		}
-		Registry registry = RegistryFactory.getRegistry();
-		synchronized (_registrySynch)
-		{
-			registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
-		}
-	}
-
-
-} // ____________________________________________________________________________

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerFactory.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerFactory.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -0,0 +1,556 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.soa.esb.listeners.message;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.command.CommandQueue;
+import org.jboss.internal.soa.esb.command.CommandQueueException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.util.EPRManager;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXException;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+/**
+ * {@link org.jboss.soa.esb.listeners.message.EsbListenerController} Factory class.
+ * <p/>
+ * Control construction and launching of the {@link org.jboss.soa.esb.listeners.message.EsbListenerController}
+ * implementation.  The factory methods will not return until the controller is up and running completely, with
+ * all managed listeners fully initalised.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class EsbListenerControllerFactory {
+
+	/**
+	 * Create an instance of EsbListenerController from a named configuration stored in the
+	 * paramater repository.
+	 * @param parameterName The parameter name.
+	 * @return The controller instance.
+	 * @throws Exception Failed to create controller instance.
+	 */
+	public static EsbListenerController getInstance(String parameterName) throws Exception {
+		EsbListenerControllerImpl controller =  new EsbListenerControllerImpl(parameterName);
+		new Thread(controller).start();
+		Thread.sleep(15000); // TODO: Replace with proper sync code!
+		return controller;
+	}
+	
+	/**
+	 * Create an instance of EsbListenerController directly from a configuration tree.
+	 * @param config The configuration tree from which to construct the controller instance.
+	 * @return The controller instance.
+	 * @throws Exception Failed to create controller instance.
+	 */
+	public static EsbListenerController getInstance(ConfigTree config) throws Exception {
+		EsbListenerControllerImpl controller =  new EsbListenerControllerImpl(config);
+		new Thread(controller).start();
+		Thread.sleep(15000); // TODO: Replace with proper sync code!
+		return controller;
+	}
+
+	/**
+	 * Controlling class that will launch 'message aware' listener child threads for supported
+	 * transport listener classes, as indicated in the configuration XML tree used in the constructor
+	 * If you use the 'main' method, configuration file is expected in arg[0]
+	 * 
+	 * <p />
+	 * Can be launched as uppermost controller (it has a main(args) method)
+	 * <p />
+	 * Also implements Runnable, and can thus be launched in a child thread from an
+	 * upper controlling process
+	 * <p />
+	 * Listens on a JMS queue (with an optional message selector) for commands (e.g.
+	 * Quiesce, Reload Parameters, Set End Time, etc.)
+	 * <p />
+	 * Parameter reloading can also be set using the PARM_RELOAD_SECS attribute
+	 * <p />
+	 * End time for this instance can also be set using the PARM_END_TIME attribute
+	 * <p />
+	 * 
+	 * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+	 * @since Version 4.0
+	 */
+	public static class EsbListenerControllerImpl implements Runnable, EsbListenerController {
+	
+		private static Logger _logger = Logger.getLogger(EsbListenerControllerImpl.class);
+	
+		public static void main(String[] args) throws Exception {
+			EsbListenerControllerImpl oProc = new EsbListenerControllerImpl(args[0]);
+			oProc.run();
+			EsbListenerControllerImpl.State oS = oProc.getState();
+	
+			if (null != oS.getException()) {
+				_logger.error("EsbListenerControllerImpl <" + args[0] + "> FAILED\n", oS
+						.getException());
+			}
+			System.exit(oS.getCompletionCode());
+		} // ________________________________
+	
+		protected int m_iDfltReloadMillis = 180000 // default interval between
+													// parameter reloads
+		;
+	
+		private String m_sParmsName;
+		private ConfigTree m_oParms;
+		private Object _registrySynch = new Object();
+	
+		private HashMap<String, Object> m_oAtts;
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#getControllerAttributes()
+		 */
+		@SuppressWarnings("unchecked")
+		public Map<String, Object> getControllerAttributes() {
+			return (Map<String, Object>) m_oAtts.clone();
+		}
+	
+		private boolean m_bReloadRequested, m_bEndRequested;
+	
+		private long m_lNextReload = Long.MAX_VALUE;
+	
+		private long m_lEndTime = Long.MAX_VALUE;
+	
+		private State m_oState = null;
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#getState()
+		 */
+		public State getState() {
+			return m_oState;
+		}
+	
+		private CommandQueue commandQueue;
+		private static CommandQueue defaultCommandQueue = null;
+		
+		/**
+		 * Construct a Listener Manager from the named repository based
+		 * configuration.
+		 * 
+		 * @param p_sParameterName
+		 *            Name of the Repository entry containing the configuration.
+		 * @throws Exception
+		 *             Unable to load/use the named configuration.
+		 */
+		private EsbListenerControllerImpl(String p_sParameterName) throws Exception {		
+			this(EsbListenerControllerImpl.getListenerConfig(p_sParameterName));
+			m_sParmsName = p_sParameterName;
+		}
+	
+		/**
+		 * Construct a Listener Controller using the specified listener configuration.
+		 * 
+		 * @param config
+		 *            The configuration.
+		 * @throws Exception
+		 *             Unable to load/use the supplied configuration.
+		 */
+		private EsbListenerControllerImpl(ConfigTree config) throws Exception {
+			m_oParms = config;
+			m_oState = State.Loading_parameters;
+	
+			try {	checkParms(m_oParms); }
+			catch (Exception e) 
+			{
+				String configSource = config.getAttribute("configSource");
+	
+				m_oState = State.Exception_thrown;
+				m_oState.m_oException = e;
+				_logger.fatal("Listener configuration and startup error.  Config Source: "
+										+ (configSource != null ? configSource
+												: "unknown"), e);
+	
+				throw e;
+			}
+		}
+	
+		/**
+		 * Load the named listener configuration from the configured parameter
+		 * repository.
+		 * 
+		 * @param reposParam
+		 *            The name of the repository entry containing the Listener
+		 *            configuration.
+		 * @return Listener Configuration as {@link ConfigTree}.
+		 * @throws IOException
+		 *             Unable to access the repository.
+		 * @throws ParamRepositoryException
+		 *             Unable to access the configuration in the repository.
+		 * @throws SAXException
+		 *             Unable to parse the configuration.
+		 */
+		private static ConfigTree getListenerConfig(String reposParam)
+				throws IOException, ParamRepositoryException, SAXException {		
+			String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
+			ConfigTree config = ConfigTree.fromXml(sXml);
+	
+			config.setAttribute("configSource", "param-repository:" + reposParam);
+	
+			return config;
+		}
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#checkParms(org.jboss.soa.esb.helpers.ConfigTree)
+		 */
+		public void checkParms(ConfigTree p_oP) throws Exception {
+			// We've just loaded - set to false until next reload requested
+			m_bReloadRequested = false;
+			commandQueue = createCommandQueue(p_oP);
+	
+			// Open the command queue...
+			if (null!=commandQueue)
+				commandQueue.open(p_oP);
+	
+			// if PARM_RELOAD_SECS not set, and no command queue
+			// then reload every 10 minutes
+			// If there is a command queue, run until command is received
+			String sRldSecs = p_oP.getAttribute(PARM_RELOAD_SECS);
+			m_lNextReload = (null != sRldSecs) 
+					? System.currentTimeMillis() + 1000 * Long.parseLong(sRldSecs)
+					: (null == commandQueue) 
+							? Long.MAX_VALUE 
+							: System.currentTimeMillis() + m_iDfltReloadMillis;
+	
+			// if PARM_END_TIME not set try to run forever
+			// not a good practice if command queue is not set
+			// Expected date format is "yyyyMMdd hh:mm:ss"
+			String sEndT = p_oP.getAttribute(PARM_END_TIME);
+			m_lEndTime = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
+					sEndT).getTime();
+	          
+		} // ________________________________
+	
+	    /**
+	     * Factory method for creating the command queue.
+	     * @param config EsbListenerControllerImpl config.
+	     * @return EsbListenerControllerImpl CommandQueue instance.
+	     */
+		private CommandQueue createCommandQueue(ConfigTree config) {
+			String commandQueueClass = config.getAttribute("command-queue-class");
+			
+			if(commandQueueClass != null) {
+				try {
+					return (CommandQueue) Class.forName(commandQueueClass).newInstance();
+				} catch (Exception e) {
+					_logger.error("Failed to instantiate CommandQueue ["+ commandQueueClass + "].  Defaulting to no Command Queue", e);
+				}
+			}
+				
+			return defaultCommandQueue;
+		}
+	
+		/**
+		 * Allows a default command queue to be set statically for all EsbListenerControllerImpl instances.
+		 * @param defaultCommandQueue The defaultCommandQueue to set.
+		 */
+		public static void setDefaultCommandQueue(CommandQueue defaultCommandQueue) {
+			EsbListenerControllerImpl.defaultCommandQueue = defaultCommandQueue;
+		}
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#run()
+		 */
+		public void run() {
+			while (endNotRequested()) {
+				m_oState = State.Running;
+				for (ConfigTree oCurr : m_oParms.getAllChildren()) {
+					String sClass = oCurr.getAttribute(PARM_LISTENER_CLASS);
+					if (Util.isNullString(sClass))
+						continue;
+					tryToLaunchChildListener(oCurr, sClass);
+				}
+	
+				waitForCmdOrSleep();
+	
+				if (endRequested()) {
+					break;
+				}
+				if (m_sParmsName != null && timeToReload()) {
+					try {
+						m_oState = State.Loading_parameters;
+						_logger
+								.info("Reloading parameters _____________________________________________________");
+						ConfigTree oNew = EsbListenerControllerImpl.getListenerConfig(m_sParmsName);
+						checkParms(oNew);
+						m_oParms = oNew;
+					} catch (Exception e) {
+						_logger.error("Failed to reload parameters"
+								+ " - Continuing with cached version", e);
+					}
+				}
+			}
+			// m_oState = State.Shutting_down;
+	
+			m_oState = State.Done_OK;
+			m_oState.m_iCompletionCode = 0;
+			_logger
+					.info("Finishing_____________________________________________________");
+	
+			// Close the command queue...
+			try {
+				if (null != commandQueue)
+					commandQueue.close();
+			} catch (CommandQueueException e) {
+				_logger.error("Error closing Command Queue.", e);
+			}
+		} // ________________________________
+	
+		private void tryToLaunchChildListener(ConfigTree p_oP, String p_sClassName) {
+			try 
+			{
+				Class oListener = Class.forName(p_sClassName);
+				Constructor oConst = oListener.getConstructor(new Class[] {EsbListenerController.class, ConfigTree.class});
+				Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this,p_oP});
+				new Thread(oRun).start();
+			}
+			catch (Exception e) 
+			{
+				_logger.error("Cannot launch <" + p_sClassName + ">\n", e);
+			}
+		} // ________________________________
+	
+		public long millisToWait() {
+			return Math.min(m_lNextReload, m_lEndTime) - System.currentTimeMillis();
+		} // ________________________________
+	
+		private void waitForCmdOrSleep() {
+			long lToGo = millisToWait();
+	
+			if (null == commandQueue) {
+				_logger.debug("About to sleep " + lToGo);
+				// No command queue nor topic - Just sleep until time
+				// exhausted, or thread interrupted
+				try {
+					while ((lToGo=millisToWait()) > 0)
+						Thread.sleep(500);
+				} catch (InterruptedException e) {
+					m_lEndTime = 0; // mark as end requested and return
+				}
+				return;
+			}
+	
+			// Wait for commands until time exhausted or command received
+			// Note that received commands might change time variables (reload/end)
+			// that's why time to go is recalculated on each cycle
+			while ((lToGo = millisToWait()) > 0) {
+				try {
+					_logger.info("Waiting for command ... timeout=" + lToGo + " millis");
+	
+					String oM = commandQueue.receiveCommand(lToGo);
+					if (null == oM) {
+						return;
+					}
+					processCommand(oM);
+					if (endRequested() || timeToReload()) {
+						break;
+					}
+				} catch (CommandQueueException eJ) {
+					_logger.info("receive on command queue failed", eJ);
+				}
+			}
+		} // ________________________________
+	
+		/**
+		 * Processes the command that has been received in the command queue (or
+		 * topic) <p/>m_bEndRequested, m_bReloadRequested, and m_lEndTime could be
+		 * changed
+		 * 
+		 * <p/> <p/><TABLE border="1"> <COLGROUP> <COL width="200"/> <COL
+		 * width="400"/> </COLGROUP>
+		 * <TR>
+		 * <TD align="center">message text</TD>
+		 * <TD align="center">effect</TD>
+		 * </TR>
+		 * <TR>
+		 * <TD>shutdown*</TD>
+		 * <TD>End time will be immediately set to 'now' - quiesce process will
+		 * start - Child threads will be allowed to finish normally</TD>
+		 * </TR>
+		 * <TR>
+		 * <TD>reload param*</TD>
+		 * <TD>Parameters will be immediately reloaded, and listener reconfigured
+		 * with new values</TD>
+		 * </TR>
+		 * <TR>
+		 * <TD>endTime yyyyMMdd hh:mm:ss</TD>
+		 * <TD>End time will be set to new value. If hh:mm:ss is not supplied =>
+		 * end of day assumed (23:59:59)</TD>
+		 * </TR>
+		 * </TABLE> * startsWith() <p/>
+		 * 
+		 * @param p_oMsg
+		 *            Message received from the command queue.
+		 * 
+		 */
+		private void processCommand(String sTxt) {
+			if (null == sTxt)
+				return;
+			
+			String sLow = sTxt.trim().toLowerCase();
+			if (sLow.startsWith("shutdown")) {
+				m_bEndRequested = true;
+				_logger.info("Shutdown has been requested");
+				return;
+			}
+			if (sLow.startsWith("reload param")) {
+				m_bReloadRequested = true;
+				_logger
+						.info("Request for parameter reload has been received");
+				return;
+			}
+			String[] sa = sLow.split("\\s+");
+			if (sa.length > 1 && "endtime".equals(sa[0])) {
+				try {
+					String sDate = sa[1];
+					String sTime = (sa.length < 3 || null == sa[2]) ? "23:59:59"
+							: sa[2];
+					Date oEnd = s_oDateParse.parse(sDate + " " + sTime);
+					_logger.info("New end date set to : " + oEnd);
+					m_lEndTime = oEnd.getTime();
+				} catch (Exception eDat) {
+					_logger.info("Problems with endTime command", eDat);
+				}
+			}
+		} // ________________________________
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#requestEnd()
+		 */
+		public void requestEnd() {
+			m_bEndRequested=true;
+			m_lEndTime = 0;
+		}
+		
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#endRequested()
+		 */
+		public boolean endRequested() {
+			return m_bEndRequested || System.currentTimeMillis() >= m_lEndTime;
+		}
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#endNotRequested()
+		 */
+		public boolean endNotRequested() {
+			return !endRequested();
+		}
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#timeToReload()
+		 */
+		public boolean timeToReload() {
+			return m_bReloadRequested
+					|| System.currentTimeMillis() >= m_lNextReload;
+		}
+	
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#continueLooping()
+		 */
+		public boolean continueLooping() {
+			return (endNotRequested() && !timeToReload());
+		} // ________________________________
+		
+		public static EPRManager getEprManager()
+		{
+			PropertyManager manager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE);
+			String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,".");	
+			return EPRManager.getInstance(sDir);
+		}
+		
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#register(java.lang.String, org.jboss.soa.esb.addressing.EPR)
+		 */
+		public void register (String name, EPR address)
+		{
+			try { getEprManager().saveEPR(name,address); }
+			catch (IOException e)
+			{
+				_logger.fatal("Cannot register service",e);
+			}
+		} // ________________________________
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#unRegister(java.lang.String)
+		 */
+		public void unRegister (String name)
+		{
+			try { getEprManager().removeEPR(name); }
+			catch (IOException e)
+			{
+				_logger.fatal("Cannot un-register service",e);
+			}
+		} // ________________________________
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#register(org.jboss.soa.esb.helpers.ConfigTree, org.jboss.soa.esb.addressing.EPR)
+		 */
+		public void register(ConfigTree config , EPR epr) throws RegistryException
+		{
+			String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+			String serviceName         = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+			if ("eprManager".equalsIgnoreCase(serviceCategoryName))
+			{
+					register(serviceName,epr);
+					return;
+			}
+			String serviceDescription  = config.getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
+			String eprDescription      = config.getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
+			Registry registry = RegistryFactory.getRegistry();
+			synchronized (_registrySynch)
+			{
+				registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription);
+			}
+		}
+		/* (non-Javadoc)
+		 * @see org.jboss.soa.esb.listeners.message.EsbListenerController#unRegister(java.lang.String, java.lang.String, org.jboss.soa.esb.addressing.EPR)
+		 */
+		public void unRegister(String serviceCategoryName, String serviceName , EPR epr) throws RegistryException
+		{
+			if ("eprManager".equalsIgnoreCase(serviceCategoryName))
+			{
+					unRegister(serviceName);
+					return;
+			}
+			Registry registry = RegistryFactory.getRegistry();
+			synchronized (_registrySynch)
+			{
+				registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
+			}
+		}
+	
+	
+	} // ____________________________________________________________________________
+}

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerService.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerService.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerService.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -19,8 +19,7 @@
 		confDir = uri.getPath();
 		String configFile = confDir + messageAwareConfigFile;
 		System.setProperty("juddi.propertiesFile", confDir + "juddi.properties");
-		_esbListController = new EsbListenerController(configFile);
-		new Thread(_esbListController).start();
+		_esbListController = EsbListenerControllerFactory.getInstance(configFile);
 	}
 
 	protected void stopService() throws Exception 

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld/src/quickstart/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld/src/quickstart/Launcher.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld/src/quickstart/Launcher.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -5,6 +5,7 @@
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 
 
 public class Launcher {	
@@ -38,11 +39,7 @@
     		if (null != messageAwareConfigFile) {
     			_logger.info("starting message aware listener with config file - " + 
     					messageAwareConfigFile);
-    			_esbListController = new EsbListenerController(messageAwareConfigFile);
-
-    			new Thread(_esbListController).start();
-    			Thread.sleep(2000);
-
+    			_esbListController = EsbListenerControllerFactory.getInstance(messageAwareConfigFile);
     		}
     		if (null != gatewayConfigFile) {
     			_logger.info("starting gateway listener with config file - " + 

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_action/src/quickstart/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_action/src/quickstart/Launcher.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_action/src/quickstart/Launcher.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -5,6 +5,7 @@
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 
 
 public class Launcher {	
@@ -38,19 +39,12 @@
     		if (null != messageAwareConfigFile) {
     			_logger.info("starting message aware listener with config file - " + 
     					messageAwareConfigFile);
-    			_esbListController = new EsbListenerController(messageAwareConfigFile);
-
-    			new Thread(_esbListController).start();
-    			Thread.sleep(2000);
-
+    			_esbListController = EsbListenerControllerFactory.getInstance(messageAwareConfigFile);
     		}
     		if (null != gatewayConfigFile) {
     			_logger.info("starting gateway listener with config file - " + 
     					gatewayConfigFile);
     			_gatewayController = new GatewayListenerController(gatewayConfigFile);
-    			new Thread(_gatewayController).start();
-    			
-    			Thread.sleep(2000);
     		}
     		
     		System.out.println("**Listener Ready**");

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_embedded_reg/src/quickstart/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_embedded_reg/src/quickstart/Launcher.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_embedded_reg/src/quickstart/Launcher.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -6,6 +6,7 @@
 import org.jboss.soa.esb.common.Configuration;
 import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 
 
 public class Launcher {	
@@ -46,12 +47,7 @@
     		if (null != messageAwareConfigFile) {
     			_logger.info("starting message aware listener with config file - " + 
     					messageAwareConfigFile);
-    			_esbListController = new EsbListenerController(messageAwareConfigFile);
-
-    			new Thread(_esbListController).start();
-    			
-    			Thread.sleep(10000);
-
+    			_esbListController = EsbListenerControllerFactory.getInstance(messageAwareConfigFile);
     		}
     		if (null != gatewayConfigFile) {
     			_logger.info("starting gateway listener with config file - " + 

Modified: labs/jbossesb/trunk/product/samples/quickstarts/more_action/src/quickstart/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/more_action/src/quickstart/Launcher.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/samples/quickstarts/more_action/src/quickstart/Launcher.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -5,6 +5,7 @@
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 
 
 public class Launcher {	
@@ -38,11 +39,7 @@
     		if (null != messageAwareConfigFile) {
     			_logger.info("starting message aware listener with config file - " + 
     					messageAwareConfigFile);
-    			_esbListController = new EsbListenerController(messageAwareConfigFile);
-
-    			new Thread(_esbListController).start();
-    			Thread.sleep(2000);
-
+    			_esbListController = EsbListenerControllerFactory.getInstance(messageAwareConfigFile);
     		}
     		if (null != gatewayConfigFile) {
     			_logger.info("starting gateway listener with config file - " + 

Modified: labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/quickstart/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/quickstart/Launcher.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/quickstart/Launcher.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -5,6 +5,7 @@
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 
 
 public class Launcher {	
@@ -38,11 +39,7 @@
     		if (null != messageAwareConfigFile) {
     			_logger.info("starting message aware listener with config file - " + 
     					messageAwareConfigFile);
-    			_esbListController = new EsbListenerController(messageAwareConfigFile);
-
-    			new Thread(_esbListController).start();
-    			Thread.sleep(2000);
-
+    			_esbListController = EsbListenerControllerFactory.getInstance(messageAwareConfigFile);
     		}
     		if (null != gatewayConfigFile) {
     			_logger.info("starting gateway listener with config file - " + 

Modified: labs/jbossesb/trunk/product/samples/quickstarts/simple_transformation/src/quickstart/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/simple_transformation/src/quickstart/Launcher.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/samples/quickstarts/simple_transformation/src/quickstart/Launcher.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -5,6 +5,7 @@
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 
 
 public class Launcher {	
@@ -38,11 +39,7 @@
     		if (null != messageAwareConfigFile) {
     			_logger.info("starting message aware listener with config file - " + 
     					messageAwareConfigFile);
-    			_esbListController = new EsbListenerController(messageAwareConfigFile);
-
-    			new Thread(_esbListController).start();
-    			Thread.sleep(2000);
-
+    			_esbListController = EsbListenerControllerFactory.getInstance(messageAwareConfigFile);
     		}
     		if (null != gatewayConfigFile) {
     			_logger.info("starting gateway listener with config file - " + 

Modified: labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/Launcher.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/Launcher.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/Launcher.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -10,6 +10,7 @@
 import org.jboss.soa.esb.common.Configuration;
 import org.jboss.soa.esb.listeners.gateway.GatewayListenerController;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 import org.jboss.soa.esb.testutils.HsqldbUtil;
 import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
 
@@ -67,9 +68,7 @@
 			
     		if (null != messageAwareConfigFile) {
     			_logger.info("starting message aware listener with config file - " + messageAwareConfigFile);
-    			_esbListController = new EsbListenerController(messageAwareConfigFile);
-    			new Thread(_esbListController).start();
-    			Thread.sleep(2000);
+    			_esbListController = EsbListenerControllerFactory.getInstance(messageAwareConfigFile);
     		}
     		
     		if (null != gatewayConfigFile) {

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -41,6 +41,7 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.format.MessageFactory;
 import org.jboss.soa.esb.services.routing.MessageRouter;
@@ -177,10 +178,7 @@
 			logger.info("Testing to see if we can instantiate one");
 			String deploymentConfigFile = TestEnvironmentUtil.getUserDir("qa") 
 				+ "junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml";
-			_proc = new EsbListenerController(deploymentConfigFile);
-			new Thread(_proc).start();
-			// give the listener time to register
-			Thread.sleep(5000);
+			_proc = EsbListenerControllerFactory.getInstance(deploymentConfigFile);
 			
 		} catch (Throwable e) {
 			e.printStackTrace();

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -41,6 +41,7 @@
 import org.apache.log4j.xml.DOMConfigurator;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.testutils.FileUtil;
 import org.jboss.soa.esb.testutils.HsqldbUtil;
@@ -111,9 +112,7 @@
     {
 		InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
 		ConfigTree tree = ConfigTree.fromInputStream(inStream);
-		_esbListController = new EsbListenerController(tree);
-		new Thread(_esbListController).start();
-		Thread.sleep(15000);
+		_esbListController = EsbListenerControllerFactory.getInstance(tree);
 
 		inStream = getClass().getResourceAsStream(_gatewayConfig);
 		tree = ConfigTree.fromInputStream(inStream);

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -50,6 +50,7 @@
 import org.jboss.soa.esb.helpers.AppServerContext;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.testutils.FileUtil;
 import org.jboss.soa.esb.testutils.HsqldbUtil;
@@ -112,9 +113,7 @@
     {
 		InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
 		ConfigTree tree = ConfigTree.fromInputStream(inStream);
-		_esbListController = new EsbListenerController(tree);
-		new Thread(_esbListController).start();
-		Thread.sleep(15000);
+		_esbListController = EsbListenerControllerFactory.getInstance(tree);
 
 		inStream = getClass().getResourceAsStream(_gatewayConfig);
 		tree = ConfigTree.fromInputStream(inStream);

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -168,11 +168,7 @@
 			logger.info("Testing to see if we can instantiate one");
 			String deploymentConfigFile = TestEnvironmentUtil.getUserDir("qa") 
 				+ "junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.xml";
-			_proc = new EsbListenerController(deploymentConfigFile);
-			new Thread(_proc).start();
-			// give the listener time to register
-			Thread.sleep(5000);
-			
+			_proc = EsbListenerControllerFactory.getInstance(deploymentConfigFile);
 		} catch (Throwable e) {
 			e.printStackTrace();
 			System.out.println("We should stop testing, since we don't have a db.");

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -41,7 +41,7 @@
  */
 public class HttpListenerTest extends TestCase  {
 
-    private NewListenerUtils.ListenersManagerExecThread listenersMgr;
+    private NewListenerUtils.ListenersManagerTestWrapper listenersMgr;
 
     protected void setUp() throws Exception {
         // Start the listener...

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/NewListenerUtils.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/NewListenerUtils.java	2006-12-04 23:34:18 UTC (rev 8057)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/NewListenerUtils.java	2006-12-05 09:27:27 UTC (rev 8058)
@@ -31,6 +31,8 @@
 import org.jboss.internal.soa.esb.command.JmsCommandQueue;
 import org.jboss.internal.soa.esb.parameters.ParamFileRepository;
 import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory.EsbListenerControllerImpl;
 import org.jboss.soa.esb.parameters.ParamRepositoryException;
 import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
 
@@ -50,13 +52,12 @@
 	 * @param paramName Config classpath.
 	 * @return Thread of execution for this Listener configs.
 	 */
-	public static ListenersManagerExecThread startListeners(String paramName) throws Exception {
-		ListenersManagerExecThread manager;
+	public static ListenersManagerTestWrapper startListeners(String paramName) throws Exception {
+		ListenersManagerTestWrapper manager;
 		
-		manager = new ListenersManagerExecThread(createEsbListenerController(paramName));
+		manager = new ListenersManagerTestWrapper(createEsbListenerController(paramName));
 		
 		logger.info("Waiting on Listener Manager the start...");
-		manager.start();
 		while(manager.listenersManager.getState() != EsbListenerController.State.Running) {
 			Thread.sleep(50);
 			if(manager.listenersManager.getState() == EsbListenerController.State.Exception_thrown) {
@@ -65,7 +66,7 @@
 				TestCase.fail(e.getMessage());
 			}
 		}
-		logger.info("Listener Manager running (Thread: " + manager.getName() + ")!  Note this does not mean all the Listeners are up and running!");
+		logger.info("Listener Manager running (Thread: " + manager + ")!  Note this does not mean all the Listeners are up and running!");
 		
 		return manager;
 	}
@@ -80,8 +81,8 @@
 	 */
 	public static EsbListenerController createEsbListenerController(String paramName) throws Exception {		
 		//fixUpConfig(paramName);
-		EsbListenerController.setDefaultCommandQueue(new JmsCommandQueue());
-		return new EsbListenerController(paramName);
+		EsbListenerControllerImpl.setDefaultCommandQueue(new JmsCommandQueue());
+		return EsbListenerControllerFactory.getInstance(paramName);
 	}
 	
 	/**
@@ -118,16 +119,11 @@
 	}
 	
 
-	/**
-	 * Execution thread for the Listener Manager. 
-	 * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
-	 */
-	public static class ListenersManagerExecThread extends Thread {
+	public static class ListenersManagerTestWrapper {
 		
 		private EsbListenerController listenersManager;
 
-		private ListenersManagerExecThread(EsbListenerController listenersManager) {
-			super(listenersManager);
+		private ListenersManagerTestWrapper(EsbListenerController listenersManager) {
 			this.listenersManager = listenersManager;
 		}
 
@@ -144,7 +140,7 @@
 		 */
 		public void asserttInException() {
 			if(listenersManager.getState() != EsbListenerController.State.Exception_thrown) {
-				String errorMsg = "ListenerManager not in Exception state.  Listener Manager Thread: " + this.getName();
+				String errorMsg = "ListenerManager not in Exception state.  Listener Manager Thread: " + listenersManager;
 				logger.error(errorMsg);
 				TestCase.fail(errorMsg);
 			}
@@ -155,7 +151,7 @@
 		 */
 		public void assertNotInException() {
 			if(listenersManager.getState() == EsbListenerController.State.Exception_thrown) {
-				String errorMsg = "ListenerManager in Exception state.  See log.  Listener Manager Thread: " + this.getName();
+				String errorMsg = "ListenerManager in Exception state.  See log.  Listener Manager Thread: " + listenersManager;
 				logger.error(errorMsg, listenersManager.getState().getException());
 				TestCase.fail(errorMsg);
 			}
@@ -170,7 +166,7 @@
 			
 			while(System.currentTimeMillis() < endTime) {
 				if(listenersManager.getState() == EsbListenerController.State.Done_OK) {
-					logger.info("Shutdown was successful.  Listener Manager Thread: " + this.getName());
+					logger.info("Shutdown was successful.  Listener Manager Thread: " + listenersManager);
 					return;
 				}
 				try {
@@ -179,7 +175,7 @@
 					logger.error("Thread interupt...", e);
 				}
 			}
-			String errorMsg = "ListenerManager failed to shutdown as requested.  Waited for " + maxWait + "ms.  Listener Manager Thread: " + this.getName();
+			String errorMsg = "ListenerManager failed to shutdown as requested.  Waited for " + maxWait + "ms.  Listener Manager Thread: " + listenersManager;
 			logger.error(errorMsg);
 			TestCase.fail(errorMsg);
 		}




More information about the jboss-svn-commits mailing list