[jboss-svn-commits] JBL Code SVN: r6095 - labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 6 11:11:16 EDT 2006


Author: tfennelly
Date: 2006-09-06 11:11:11 -0400 (Wed, 06 Sep 2006)
New Revision: 6095

Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/GpListener.java
Log:
Formatted code so you could read it

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/GpListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/GpListener.java	2006-09-06 15:09:15 UTC (rev 6094)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/GpListener.java	2006-09-06 15:11:11 UTC (rev 6095)
@@ -1,24 +1,24 @@
 /*
-* 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.
-*/
+ * 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;
 
@@ -42,219 +42,262 @@
 import org.xml.sax.SAXException;
 
 /**
- * Controlling class that will launch listener child threads 
- * for supported transport listener classes, as indicated
- * in the configuration XML tree pointed by arg[0]
+ * Controlling class that will launch listener child threads for supported
+ * transport listener classes, as indicated in the configuration XML tree
+ * pointed by 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 />
+ * 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 Esteban
- *
+ * 
  */
-public class GpListener implements Runnable
-{
-	public static void main(String[] args) throws Exception
-	{
+public class GpListener implements Runnable {
+	public static void main(String[] args) throws Exception {
 		GpListener oProc = new GpListener(args[0]);
 		oProc.run();
 		GpListener.State oS = oProc.getState();
 
-		if (null!=oS.getException())
-		{
-			oProc.m_oLogger.error
-			  ("GpListener <"+args[0]+"> FAILED\n",oS.getException());
+		if (null != oS.getException()) {
+			oProc.m_oLogger.error("GpListener <" + args[0] + "> FAILED\n", oS
+					.getException());
 		}
 		System.exit(oS.getCompletionCode());
-	} //________________________________
-	
-	protected int	m_iDfltReloadMillis= 180000 // default interval between parameter reloads
+	} // ________________________________
+
+	protected int m_iDfltReloadMillis = 180000 // default interval between
+												// parameter reloads
 	;
-	public static final String COMMAND_CONN_FACTORY	= "commandConnFactoryClass";
-	public static final String COMMAND_JNDI_TYPE	= "commandJndiType";
-	public static final String COMMAND_JNDI_URL 	= "commandJndiURL";
-	public static final String COMMAND_IS_TOPIC		= "commandIsTopic";
-	public static final String COMMAND_JNDI_NAME	= "commandJndiName";
-	public static final String COMMAND_MSG_SELECTOR	= "messageSelector";
-	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 DomElements
-	public static final String PARM_LISTENER_CLASS	= "listenerClass";
-	
-    public static final String PARM_ACTION_CLASS	= "actionClass";
-    public static final String PARM_MAX_THREADS		= "maxThreads";
-    
-    public static final String CHLD_EMAIL_PARMS		= "EmailProperties";
 
+	public static final String COMMAND_CONN_FACTORY = "commandConnFactoryClass";
 
-	private static Logger	m_oLogger = Logger.getLogger(GpListener.class);
+	public static final String COMMAND_JNDI_TYPE = "commandJndiType";
 
-	private String			m_sParmsName;
-	private DomElement		m_oParms;
+	public static final String COMMAND_JNDI_URL = "commandJndiURL";
 
-	private HashMap<String,Object>	m_oAtts;
+	public static final String COMMAND_IS_TOPIC = "commandIsTopic";
+
+	public static final String COMMAND_JNDI_NAME = "commandJndiName";
+
+	public static final String COMMAND_MSG_SELECTOR = "messageSelector";
+
+	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
+	// DomElements
+	public static final String PARM_LISTENER_CLASS = "listenerClass";
+
+	public static final String PARM_ACTION_CLASS = "actionClass";
+
+	public static final String PARM_MAX_THREADS = "maxThreads";
+
+	public static final String CHLD_EMAIL_PARMS = "EmailProperties";
+
+	private static Logger m_oLogger = Logger.getLogger(GpListener.class);
+
+	private String m_sParmsName;
+
+	private DomElement m_oParms;
+
+	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
-	 *
+	 * 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");
+	public Map<String, Object> getControllerAttributes() {
+		return (Map<String, Object>) m_oAtts.clone();
+	}
 
-	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 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 MessageConsumer m_oCmdSrc;
-    private Session			m_oJmsSess;
-    private Connection		m_oJmsConn;
-    
-    /**
-     * 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 GpListener(String p_sParameterName) throws Exception {	
+
+	private MessageConsumer m_oCmdSrc;
+
+	private Session m_oJmsSess;
+
+	private Connection m_oJmsConn;
+
+	/**
+	 * 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 GpListener(String p_sParameterName) throws Exception {
 		this(GpListener.getListenerConfig(p_sParameterName));
 		m_sParmsName = p_sParameterName;
 	}
-	
+
 	/**
 	 * Construct a Listener Manager using the specified listener configuration.
-	 * @param config The configuration.
-     * @throws Exception Unable to load/use the supplied configuration.
+	 * 
+	 * @param config
+	 *            The configuration.
+	 * @throws Exception
+	 *             Unable to load/use the supplied configuration.
 	 */
 	public GpListener(DomElement config) throws Exception {
-		m_oParms	= config; 
-		m_oState	= State.Loading_parameters;
+		m_oParms = config;
+		m_oState = State.Loading_parameters;
 
-		try {   
+		try {
 			checkParms(m_oParms);
 			setEmailSystemProperties();
-		} catch (Exception e) {	
+		} catch (Exception e) {
 			String configSource = config.getAttr("configSource");
 
 			m_oState = State.Exception_thrown;
-			m_oState.m_oException	= e;
-			m_oLogger.fatal("Listener configuration and startup error.  Config Source: " + (configSource != null?configSource:"unknown"), e);
-			
+			m_oState.m_oException = e;
+			m_oLogger
+					.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 DomElement}.
-	 * @throws IOException Unable to access the repository.
-	 * @throws ParamRepositoryException Unable to access the configuration in the repository.
-	 * @throws SAXException Unable to parse the configuration.
+	 * 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 DomElement}.
+	 * @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 DomElement getListenerConfig(String reposParam) throws IOException, ParamRepositoryException, SAXException {
+	private static DomElement getListenerConfig(String reposParam)
+			throws IOException, ParamRepositoryException, SAXException {
 		String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
 		DomElement config = DomElement.fromXml(sXml);
-		
+
 		config.setAttr("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  DomElement - Where to look for the mandatory/optional 
-	 * 							configuration attributes
-	 * @throws Exception  -  If attributes are wrong or not enough for a proper
-	 * runtime configuration
+	 * @param p_oP
+	 *            DomElement - 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(DomElement p_oP) throws Exception
-	{
+	public void checkParms(DomElement p_oP) throws Exception {
 		// We've just loaded - set to false until next reload requested
 		m_bReloadRequested = false;
-		m_oCmdSrc	= null;
-		
-		Map<String,Object> oNewAtts = new HashMap<String,Object>();
+		m_oCmdSrc = null;
 
+		Map<String, Object> oNewAtts = new HashMap<String, Object>();
+
 		// Only check for JMS attributes if a queue JNDI name was specified
 		String sJndiName = p_oP.getAttr(COMMAND_JNDI_NAME);
-		if (! Util.isNullString(sJndiName))
-		{
-			oNewAtts.put(COMMAND_JNDI_NAME,sJndiName);
+		if (!Util.isNullString(sJndiName)) {
+			oNewAtts.put(COMMAND_JNDI_NAME, sJndiName);
 
-			String sJndiType = obtainAtt(p_oP,COMMAND_JNDI_TYPE,"jboss");
-			oNewAtts.put(COMMAND_JNDI_TYPE,sJndiType);
-			String sJndiURL = obtainAtt(p_oP,COMMAND_JNDI_URL,"localhost");
-			oNewAtts.put(COMMAND_JNDI_URL,sJndiURL);	
-			Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
-			
-			String sFactClass = obtainAtt(p_oP,COMMAND_CONN_FACTORY,"ConnectionFactory");
-			oNewAtts.put(COMMAND_CONN_FACTORY,sFactClass);
+			String sJndiType = obtainAtt(p_oP, COMMAND_JNDI_TYPE, "jboss");
+			oNewAtts.put(COMMAND_JNDI_TYPE, sJndiType);
+			String sJndiURL = obtainAtt(p_oP, COMMAND_JNDI_URL, "localhost");
+			oNewAtts.put(COMMAND_JNDI_URL, sJndiURL);
+			Context oJndiCtx = AppServerContext.getServerContext(sJndiType,
+					sJndiURL);
+
+			String sFactClass = obtainAtt(p_oP, COMMAND_CONN_FACTORY,
+					"ConnectionFactory");
+			oNewAtts.put(COMMAND_CONN_FACTORY, sFactClass);
 			if (Util.isNullString(sFactClass))
-	    	  sFactClass = "ConnectionFactory";
+				sFactClass = "ConnectionFactory";
 			Object oFactCls = oJndiCtx.lookup(sFactClass);
 
 			String sMsgSelector = p_oP.getAttr(COMMAND_MSG_SELECTOR);
-			if (null!=sMsgSelector)
-				oNewAtts.put(COMMAND_MSG_SELECTOR,sMsgSelector);
+			if (null != sMsgSelector)
+				oNewAtts.put(COMMAND_MSG_SELECTOR, sMsgSelector);
 
-			boolean bIsTopic = Boolean.parseBoolean
-				(obtainAtt(p_oP,COMMAND_IS_TOPIC,"false"));	
-			if (bIsTopic)
-			{
-				TopicConnectionFactory tcf = (TopicConnectionFactory)oFactCls;
+			boolean bIsTopic = Boolean.parseBoolean(obtainAtt(p_oP,
+					COMMAND_IS_TOPIC, "false"));
+			if (bIsTopic) {
+				TopicConnectionFactory tcf = (TopicConnectionFactory) oFactCls;
 				TopicConnection oTC = tcf.createTopicConnection();
 				Topic oTopic = (Topic) oJndiCtx.lookup(sJndiName);
-				TopicSession oSess = oTC.createTopicSession
-	      			(false,TopicSession.AUTO_ACKNOWLEDGE);
+				TopicSession oSess = oTC.createTopicSession(false,
+						TopicSession.AUTO_ACKNOWLEDGE);
 				m_oJmsConn = oTC;
 				m_oJmsSess = oSess;
 				oTC.start();
-				m_oCmdSrc = oSess.createSubscriber(oTopic, sMsgSelector,true);
-			}
-			else
-			{
-				QueueConnectionFactory qcf = (QueueConnectionFactory)oFactCls;
+				m_oCmdSrc = oSess.createSubscriber(oTopic, sMsgSelector, true);
+			} else {
+				QueueConnectionFactory qcf = (QueueConnectionFactory) oFactCls;
 				QueueConnection oQC = qcf.createQueueConnection();
-				javax.jms.Queue oQ = (javax.jms.Queue) oJndiCtx.lookup(sJndiName);
-				QueueSession oSess = oQC.createQueueSession
-	      			(false,TopicSession.AUTO_ACKNOWLEDGE);
+				javax.jms.Queue oQ = (javax.jms.Queue) oJndiCtx
+						.lookup(sJndiName);
+				QueueSession oSess = oQC.createQueueSession(false,
+						TopicSession.AUTO_ACKNOWLEDGE);
 				oQC.start();
 				m_oJmsConn = oQC;
 				m_oJmsSess = oSess;
@@ -266,404 +309,413 @@
 		// then reload every 10 minutes
 		// If there is a command queue, run until command is received
 		String sRldSecs = p_oP.getAttr(PARM_RELOAD_SECS);
-		m_lNextReload = (null!=sRldSecs)
-			? System.currentTimeMillis() + 1000 * Long.parseLong(sRldSecs)
-			: (null==m_oCmdSrc)	? Long.MAX_VALUE
-			: System.currentTimeMillis() + m_iDfltReloadMillis
-		;
+		m_lNextReload = (null != sRldSecs) ? System.currentTimeMillis() + 1000
+				* Long.parseLong(sRldSecs)
+				: (null == m_oCmdSrc) ? 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.getAttr(PARM_END_TIME);
-		m_lEndTime	= (null==sEndT) ? Long.MAX_VALUE
-				: s_oDateParse.parse(sEndT).getTime();		
+		// Expected date format is "yyyyMMdd hh:mm:ss"
+		String sEndT = p_oP.getAttr(PARM_END_TIME);
+		m_lEndTime = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
+				sEndT).getTime();
 
-	} //________________________________
+	} // ________________________________
 
-/**
- * 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 (DomElement oCurr : m_oParms.getAllElemChildren())
-			{	String sClass = oCurr.getAttr(PARM_LISTENER_CLASS);
+	/**
+	 * 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 (DomElement oCurr : m_oParms.getAllElemChildren()) {
+				String sClass = oCurr.getAttr(PARM_LISTENER_CLASS);
 				if (Util.isNullString(sClass))
 					continue;
-				tryToLaunchChildListener(oCurr,sClass);
+				tryToLaunchChildListener(oCurr, sClass);
 			}
 
 			waitForCmdOrSleep();
-			
-			if (endRequested())
+
+			if (endRequested()) {
 				break;
-			if (m_sParmsName != null && timeToReload())
-			try
-			{
-				m_oState	= State.Loading_parameters;
-				m_oLogger.info("Reloading parameters _____________________________________________________");
-				DomElement oNew	= GpListener.getListenerConfig(m_sParmsName); 
-				checkParms(oNew);
-				m_oParms	= oNew;
-				setEmailSystemProperties();
 			}
-			catch (Exception e)
-			{
-				m_oLogger.error
-						("Failed to reload parameters"
-						+" - Continuing with cached version",e);
+			if (m_sParmsName != null && timeToReload()) {
+				try {
+					m_oState = State.Loading_parameters;
+					m_oLogger
+							.info("Reloading parameters _____________________________________________________");
+					DomElement oNew = GpListener.getListenerConfig(m_sParmsName);
+					checkParms(oNew);
+					m_oParms = oNew;
+					setEmailSystemProperties();
+				} catch (Exception e) {
+					m_oLogger.error("Failed to reload parameters"
+							+ " - Continuing with cached version", e);
+				}
 			}
 		}
-//		m_oState	= State.Shutting_down;
-		
-		m_oState	= State.Done_OK;
+		// m_oState = State.Shutting_down;
+
+		m_oState = State.Done_OK;
 		m_oState.m_iCompletionCode = 0;
-		m_oLogger.info("Finishing_____________________________________________________");
-		
-		if (null!=m_oJmsSess)
-			try { m_oJmsSess.close(); }
-			catch (JMSException eS) {/* Tried my best - Just continue */}
-		if (null!=m_oJmsConn)
-			try { m_oJmsConn.close(); }
-			catch (JMSException eC) {/* Tried my best - Just continue */}
-	} //________________________________
-	
-	private void tryToLaunchChildListener(DomElement p_oP,String p_sClassName)
-	{
-		try
-		{	Class oListener		= Class.forName(p_sClassName);
-			Constructor oConst	= oListener.getConstructor
-				(new Class[] {this.getClass(),DomElement.class});
-			Runnable oRun = (Runnable)oConst.newInstance(new Object[] {this,p_oP});
+		m_oLogger
+				.info("Finishing_____________________________________________________");
+
+		if (null != m_oJmsSess)
+			try {
+				m_oJmsSess.close();
+			} catch (JMSException eS) {/* Tried my best - Just continue */
+			}
+		if (null != m_oJmsConn)
+			try {
+				m_oJmsConn.close();
+			} catch (JMSException eC) {/* Tried my best - Just continue */
+			}
+	} // ________________________________
+
+	private void tryToLaunchChildListener(DomElement p_oP, String p_sClassName) {
+		try {
+			Class oListener = Class.forName(p_sClassName);
+			Constructor oConst = oListener.getConstructor(new Class[] {
+					this.getClass(), DomElement.class });
+			Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this,
+					p_oP });
 			new Thread(oRun).start();
+		} catch (Exception e) {
+			m_oLogger.error("Cannot launch <" + p_sClassName + ">\n", e);
 		}
-		catch (Exception e)
-		{
-			m_oLogger.error("Cannot launch <"+p_sClassName+">\n",e);
-		}
-	} //________________________________
+	} // ________________________________
 
-	long millisToWait()
-	{
-		return Math.min(m_lNextReload,m_lEndTime)
-					- System.currentTimeMillis();
-	} //________________________________
+	long millisToWait() {
+		return Math.min(m_lNextReload, m_lEndTime) - System.currentTimeMillis();
+	} // ________________________________
 
-	private void waitForCmdOrSleep()
-	{
-		long lToGo = millisToWait(); 
+	private void waitForCmdOrSleep() {
+		long lToGo = millisToWait();
 
-		if (null==m_oCmdSrc)
-		{
-			m_oLogger.debug("About to sleep "+lToGo);
+		if (null == m_oCmdSrc) {
+			m_oLogger.debug("About to sleep " + lToGo);
 			// No command queue nor topic - Just sleep until time
 			// exhausted, or thread interrupted
-			try { Thread.sleep(lToGo); }
-			catch (InterruptedException e)
-			{
-				m_lEndTime = 0;	// mark as end requested and return
+			try {
+				Thread.sleep(lToGo);
+			} 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
-			{	
-				m_oLogger.info("Waiting for command ... timeout="+lToGo+" millis");
+		while ((lToGo = millisToWait()) > 0) {
+			try {
+				m_oLogger.info("Waiting for command ... timeout=" + lToGo
+						+ " millis");
 				// for the time being, only text messages allowed
 				// THIS WILL CHANGE !!
-				Message oM  = m_oCmdSrc.receive(lToGo);
-				if (null==oM)
+				Message oM = m_oCmdSrc.receive(lToGo);
+				if (null == oM)
 					return;
-				if (! (oM instanceof TextMessage))
-				{
-					m_oLogger.warn("Message in command queue IGNORED - should be instanceof TextMessage");
+				if (!(oM instanceof TextMessage)) {
+					m_oLogger
+							.warn("Message in command queue IGNORED - should be instanceof TextMessage");
 					return;
 				}
-				processCommand((TextMessage)oM);
+				processCommand((TextMessage) oM);
 				if (endRequested() || timeToReload())
 					break;
+			} catch (JMSException eJ) {
+				m_oLogger.info("receive on command queue failed", eJ);
 			}
-			catch (JMSException eJ)
-			{
-				m_oLogger.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 TextMessage - Received in command queue/topic
- *  
- */
-	private void processCommand (TextMessage p_oMsg)
-	{
-		try
-		{
+	/**
+	 * 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
+	 *            TextMessage - Received in command queue/topic
+	 * 
+	 */
+	private void processCommand(TextMessage p_oMsg) {
+		try {
 			String sTxt = p_oMsg.getText();
-			if (null==sTxt)
+			if (null == sTxt)
 				return;
 			String sLow = sTxt.trim().toLowerCase();
-			if (sLow.startsWith("shutdown"))
-			{	m_bEndRequested = true;
+			if (sLow.startsWith("shutdown")) {
+				m_bEndRequested = true;
 				m_oLogger.info("Shutdown has been requested");
 				return;
 			}
-			if (sLow.startsWith("reload param"))
-			{	m_bReloadRequested = true;
-				m_oLogger.info("Request for parameter reload has been received");
+			if (sLow.startsWith("reload param")) {
+				m_bReloadRequested = true;
+				m_oLogger
+						.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);
-					m_oLogger.info("New end date set to : "+oEnd);
+			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);
+					m_oLogger.info("New end date set to : " + oEnd);
 					m_lEndTime = oEnd.getTime();
+				} catch (Exception eDat) {
+					m_oLogger.info("Problems with endTime command", eDat);
 				}
-				catch (Exception eDat)
-				{
-					m_oLogger.info("Problems with endTime command",eDat);
-				}
+		} catch (JMSException eJ) {
+			m_oLogger.info("Problems with command queue", eJ);
 		}
-		catch (JMSException eJ)
-		{
-			m_oLogger.info("Problems with command queue",eJ);
-		}
-	} //________________________________
+	} // ________________________________
 
-/**
- * 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 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();
+
+	/**
+	 * 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; 
+	/**
+	 * 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());
-	} //________________________________
 
-	private static final String[] s_saMailProps=
-			{SystemProperties.SMTP_HOST
-			,SystemProperties.SMTP_USERNAME
-			,SystemProperties.SMTP_PASSWORD
-			,SystemProperties.SMTP_PORT
-			,SystemProperties.SMTP_FROM
-			,SystemProperties.SMTP_AUTH
-			};
-	private void setEmailSystemProperties()
-	{
+	/**
+	 * 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());
+	} // ________________________________
+
+	private static final String[] s_saMailProps = { SystemProperties.SMTP_HOST,
+			SystemProperties.SMTP_USERNAME, SystemProperties.SMTP_PASSWORD,
+			SystemProperties.SMTP_PORT, SystemProperties.SMTP_FROM,
+			SystemProperties.SMTP_AUTH };
+
+	private void setEmailSystemProperties() {
 		DomElement oEmail = m_oParms.getFirstElementChild(CHLD_EMAIL_PARMS);
-		if (null!=oEmail)
-			for (String sCurr : s_saMailProps)
-			{	String sProp	= oEmail.getAttr(sCurr);
-				if (null!=sProp)
-					System.setProperty(sCurr,sProp);
+		if (null != oEmail)
+			for (String sCurr : s_saMailProps) {
+				String sProp = oEmail.getAttr(sCurr);
+				if (null != sProp)
+					System.setProperty(sCurr, sProp);
 			}
-	} //________________________________
-	
-/**
- * Find an attribute in the tree (arg 0) or assign default value (arg 2)
- * 
- * @param p_oP 		DomElement - look for attributes in this Element only
- * @param p_sAtt 	String - Name of attribute to find
- * @param p_sDefault String -default value if requested attribute is not there 
- * @return 			String - value of attribute, or default value (if null) 
- * @throws Exception - If requested attribute not found and no default value
- * supplied by invoker
- */
-    static String obtainAtt
-    	(DomElement p_oP, String p_sAtt, String p_sDefault)
-	throws Exception
-	{
-	  String sVal	= p_oP.getAttr(p_sAtt);
-	  if ((null==sVal) && (null==p_sDefault))
-		  throw new Exception("Missing or invalid <"+p_sAtt+"> attribute");
-	
-	  return (null!=sVal) ? sVal : p_sDefault;
-	} //________________________________
-	
-    private static Class[] s_oaActionConstr = {DomElement.class, Object.class};
-    public static Class[] getActionClassArgs() { return s_oaActionConstr; }
+	} // ________________________________
 
-    /**
-     * Check to see if an object of the class (arg 0) can be instantiated
-     * in this context
-     * 
-     * @param p_sName String - class name to instantiate 
-     * - Must implement org.jboss.soa.esb.listeners.AbstractActionClass
-     * @return Class - 
-     * @throws Exception - if class not found in path or no appropriate constructor
-     */
-     protected static Class checkActionClass(String p_sName) throws Exception
-     {
-	   	Class oCls;
-	   	try	
-	   	{	oCls = Class.forName(p_sName);
-	   	}
-	   	catch (ClassNotFoundException e)
-	   	{ throw new Exception("Class "+p_sName
-	   			+" not found in classpath");
-	   	}
-	
-	   	try	
-	   	{	oCls.getConstructor(s_oaActionConstr);
-	   	}
-	   	catch (NoSuchMethodException eN)
-	   	{ throw new Exception("No appropriate constructor "
-	   			+p_sName+"(DomElement,Object) found for class ");
-	   	}
-	   	try { oCls.asSubclass(AbstractAction.class); }
-	   	catch (ClassCastException eCC)
-	   		{	throw new Exception("class "+p_sName
-	   				+ " does not extend "+AbstractAction.class.getName());
-	   		}
-	   	return oCls;
-     } //_________________________________________
+	/**
+	 * Find an attribute in the tree (arg 0) or assign default value (arg 2)
+	 * 
+	 * @param p_oP
+	 *            DomElement - look for attributes in this Element only
+	 * @param p_sAtt
+	 *            String - Name of attribute to find
+	 * @param p_sDefault
+	 *            String -default value if requested attribute is not there
+	 * @return String - value of attribute, or default value (if null)
+	 * @throws Exception -
+	 *             If requested attribute not found and no default value
+	 *             supplied by invoker
+	 */
+	static String obtainAtt(DomElement p_oP, String p_sAtt, String p_sDefault)
+			throws Exception {
+		String sVal = p_oP.getAttr(p_sAtt);
+		if ((null == sVal) && (null == p_sDefault))
+			throw new Exception("Missing or invalid <" + p_sAtt + "> attribute");
 
-/**
- * Find child nodes named "NotificationList" that contain an attribute 'type' that
- * starts with "ok" (case insensitive)
- * @param p_oP - DomElement to search for "NotificationList" child Elements
- * @param p_oSer Serializable - Will constitute the body of the notification
- */
- 	public static void notifyOK(DomElement p_oP, Serializable p_oSer)
-	{ try
-	  { 
-		Serializable oNotif = p_oSer;
-		for (DomElement oCurr : p_oP.getElementChildren(NotificationList.ELEMENT))
-		{ NotificationList oNL = new NotificationList(oCurr);
-		  if (! oNL.isOK())    continue;
-	        getNotifHandler().sendNotifications(oCurr,oNotif);
+		return (null != sVal) ? sVal : p_sDefault;
+	} // ________________________________
+
+	private static Class[] s_oaActionConstr = { DomElement.class, Object.class };
+
+	public static Class[] getActionClassArgs() {
+		return s_oaActionConstr;
+	}
+
+	/**
+	 * Check to see if an object of the class (arg 0) can be instantiated in
+	 * this context
+	 * 
+	 * @param p_sName
+	 *            String - class name to instantiate - Must implement
+	 *            org.jboss.soa.esb.listeners.AbstractActionClass
+	 * @return Class -
+	 * @throws Exception -
+	 *             if class not found in path or no appropriate constructor
+	 */
+	protected static Class checkActionClass(String p_sName) throws Exception {
+		Class oCls;
+		try {
+			oCls = Class.forName(p_sName);
+		} catch (ClassNotFoundException e) {
+			throw new Exception("Class " + p_sName + " not found in classpath");
 		}
-	   }
-	   catch (Exception e) {}
-	} //__________________________________
 
- 	/**
- 	 * Find child nodes named "NotificationList" that contain an attribute 'type' that
- 	 * starts with "err" (case insensitive) or no 'type' attribute set
- 	 * @param p_oP - DomElement to search for "NotificationList" child Elements
- 	 * @param p_e  - Exception if not null, will be appended to the body
- 	 * @param p_oSer Serializable - Will be included at the beginning of the body 
- 	 * of the notification
- 	 */
-	public static void notifyError(DomElement p_oP,Exception p_e, Serializable p_oSer)
-	{ 
+		try {
+			oCls.getConstructor(s_oaActionConstr);
+		} catch (NoSuchMethodException eN) {
+			throw new Exception("No appropriate constructor " + p_sName
+					+ "(DomElement,Object) found for class ");
+		}
+		try {
+			oCls.asSubclass(AbstractAction.class);
+		} catch (ClassCastException eCC) {
+			throw new Exception("class " + p_sName + " does not extend "
+					+ AbstractAction.class.getName());
+		}
+		return oCls;
+	} // _________________________________________
+
+	/**
+	 * Find child nodes named "NotificationList" that contain an attribute
+	 * 'type' that starts with "ok" (case insensitive)
+	 * 
+	 * @param p_oP -
+	 *            DomElement to search for "NotificationList" child Elements
+	 * @param p_oSer
+	 *            Serializable - Will constitute the body of the notification
+	 */
+	public static void notifyOK(DomElement p_oP, Serializable p_oSer) {
+		try {
+			Serializable oNotif = p_oSer;
+			for (DomElement oCurr : p_oP
+					.getElementChildren(NotificationList.ELEMENT)) {
+				NotificationList oNL = new NotificationList(oCurr);
+				if (!oNL.isOK())
+					continue;
+				getNotifHandler().sendNotifications(oCurr, oNotif);
+			}
+		} catch (Exception e) {
+		}
+	} // __________________________________
+
+	/**
+	 * Find child nodes named "NotificationList" that contain an attribute
+	 * 'type' that starts with "err" (case insensitive) or no 'type' attribute
+	 * set
+	 * 
+	 * @param p_oP -
+	 *            DomElement to search for "NotificationList" child Elements
+	 * @param p_e -
+	 *            Exception if not null, will be appended to the body
+	 * @param p_oSer
+	 *            Serializable - Will be included at the beginning of the body
+	 *            of the notification
+	 */
+	public static void notifyError(DomElement p_oP, Exception p_e,
+			Serializable p_oSer) {
 		Serializable oNotif = p_oSer;
 		ByteArrayOutputStream oBO = new ByteArrayOutputStream();
-	    PrintStream oPS = new PrintStream(oBO);
-	    try
-	    { oPS.println(oNotif.toString());
-	      if (null != p_e) p_e.printStackTrace(oPS);
-	      oPS.close();
+		PrintStream oPS = new PrintStream(oBO);
+		try {
+			oPS.println(oNotif.toString());
+			if (null != p_e)
+				p_e.printStackTrace(oPS);
+			oPS.close();
 
-	      String sMsg = oBO.toString();
-	      for (DomElement oCurr : p_oP.getElementChildren(NotificationList.ELEMENT))
-	      { NotificationList oNL = new NotificationList(oCurr);
-	        if (! oNL.isErr())    continue;
-	        getNotifHandler().sendNotifications(oNL,sMsg);
-	      }
-	    }
-	    catch (Exception e) { }
-	} //________________________________
-	  
-	  private static InotificationHandler s_oNH;
-	  private static final Object s_oSync = new Integer(0); 
-/**
- * Lazy instantiator of a InotificationHandler
- * @return - a reference to an implementation of the interface or null if it
- *   can't be instantiated
- */
-	  protected static InotificationHandler getNotifHandler()
-	  {
-		if (null!=s_oNH)
+			String sMsg = oBO.toString();
+			for (DomElement oCurr : p_oP
+					.getElementChildren(NotificationList.ELEMENT)) {
+				NotificationList oNL = new NotificationList(oCurr);
+				if (!oNL.isErr())
+					continue;
+				getNotifHandler().sendNotifications(oNL, sMsg);
+			}
+		} catch (Exception e) {
+		}
+	} // ________________________________
+
+	private static InotificationHandler s_oNH;
+
+	private static final Object s_oSync = new Integer(0);
+
+	/**
+	 * Lazy instantiator of a InotificationHandler
+	 * 
+	 * @return - a reference to an implementation of the interface or null if it
+	 *         can't be instantiated
+	 */
+	protected static InotificationHandler getNotifHandler() {
+		if (null != s_oNH)
 			return s_oNH;
-		synchronized (s_oSync)
-		{	if (null==s_oNH)
-			try {	s_oNH = NotificationHandlerFactory.getNotifHandler
-			  			("remote"
-			  			,SystemProperties.getJndiServerType()
-			  			,SystemProperties.getJndiServerURL()
-			  			);
+		synchronized (s_oSync) {
+			if (null == s_oNH)
+				try {
+					s_oNH = NotificationHandlerFactory.getNotifHandler(
+							"remote", SystemProperties.getJndiServerType(),
+							SystemProperties.getJndiServerURL());
+				} catch (Exception e) {
+					Logger.getLogger(GpListener.class).error(
+							"Notification FAILED", e);
 				}
-			catch (Exception e)
-				{	Logger.getLogger(GpListener.class).error("Notification FAILED",e);
-				}
 		}
 		return s_oNH;
-	  } //______________________________
-	  
-} //____________________________________________________________________________
+	} // ______________________________
+
+} // ____________________________________________________________________________




More information about the jboss-svn-commits mailing list