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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Dec 10 12:10:32 EST 2006


Author: kurt.stam at jboss.com
Date: 2006-12-10 12:10:29 -0500 (Sun, 10 Dec 2006)
New Revision: 8179

Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerFactory.java
Log:
Checking for the timestamp on the config files. If the file is not changed, then don't reload.

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java	2006-12-10 16:23:27 UTC (rev 8178)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java	2006-12-10 17:10:29 UTC (rev 8179)
@@ -22,6 +22,7 @@
 
 package org.jboss.soa.esb.listeners.gateway;
 
+import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.text.SimpleDateFormat;
@@ -30,6 +31,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.command.CommandQueue;
@@ -53,7 +55,9 @@
 
 public class GatewayListenerController implements Runnable
 {
-
+	private static Map<String,String> _paramFileTimeStamps=new ConcurrentHashMap<String,String>();
+	private static String _sRldSecs=null;
+	
 	public static void main(String[] args) throws Exception 
 	{
 		GatewayListenerController oProc = new GatewayListenerController(args[0]);
@@ -201,16 +205,16 @@
 		// if RELOAD_SECONDS_TAG 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(RELOAD_SECONDS_TAG);
-		_nextReload = (null != sRldSecs) 
-				? System.currentTimeMillis() + 1000 * Long.parseLong(sRldSecs)
+		_sRldSecs = p_oP.getAttribute(RELOAD_SECONDS_TAG);
+		_nextReload = (null != _sRldSecs) 
+				? System.currentTimeMillis() + 1000 * Long.parseLong(_sRldSecs)
 				: (null == _commandQueue) 
 						? Long.MAX_VALUE 
 						: System.currentTimeMillis() + _defaultReloadMillis;
-	    if (null==sRldSecs)
+	    if (null==_sRldSecs)
 	    {
 	    	String sMsg = (null==_commandQueue)
-	    		? " -  Using default of "+sRldSecs
+	    		? " -  Using default of "+_sRldSecs
 	    		: " - Listener will run until stopped by command sent to queue";
 	    	_logger.warn("No value specified for: "+RELOAD_SECONDS_TAG + sMsg);
 	    }
@@ -283,18 +287,36 @@
 			}
 			if (_sParametersName != null && timeToReload()) 
 			{
-				try 
-				{
-					_status = State.Loading_parameters;
-					_logger
-							.info("Reloading parameters _____________________________________________________");
-					ConfigTree oNew = GatewayListenerController.getListenerConfig(_sParametersName);
-					checkParms(oNew);
-					_config = oNew;
-				} catch (Exception e) {
-					_logger.error("Failed to reload parameters"
-							+ " - Continuing with cached version", e);
+//				check the TS on the file.
+				boolean reloadNeeded=true;
+				File paramFile = new File(_sParametersName);
+				if (paramFile.exists()) {
+					String currentTimeStamp = String.valueOf(paramFile.lastModified());
+					String previousTimeStamp = _paramFileTimeStamps.get(_sParametersName);
+					_paramFileTimeStamps.put(_sParametersName, currentTimeStamp);
+					if (previousTimeStamp==null || previousTimeStamp.equals(currentTimeStamp)) {
+						reloadNeeded=false;
+						_nextReload = (null != _sRldSecs) 
+						? System.currentTimeMillis() + 1000 * Long.parseLong(_sRldSecs)
+						: (null == _commandQueue) 
+								? Long.MAX_VALUE 
+								: System.currentTimeMillis() + _defaultReloadMillis;
+					}
 				}
+				if (reloadNeeded) {
+					try 
+					{
+						_status = State.Loading_parameters;
+						_logger
+								.info("Reloading parameters _____________________________________________________");
+						ConfigTree oNew = GatewayListenerController.getListenerConfig(_sParametersName);
+						checkParms(oNew);
+						_config = oNew;
+					} catch (Exception e) {
+						_logger.error("Failed to reload parameters"
+								+ " - Continuing with cached version", e);
+					}
+				}
 			}
 		}
 		// _status = State.Shutting_down;

Modified: 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-10 16:23:27 UTC (rev 8178)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerControllerFactory.java	2006-12-10 17:10:29 UTC (rev 8179)
@@ -21,11 +21,13 @@
 
 package org.jboss.soa.esb.listeners.message;
 
+import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.command.CommandQueue;
@@ -56,8 +58,10 @@
  * 
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
-public abstract class EsbListenerControllerFactory {
-
+public abstract class EsbListenerControllerFactory 
+{
+	private static Map<String,String> _paramFileTimeStamps=new ConcurrentHashMap<String,String>();
+	private static String _sRldSecs=null;
 	/**
 	 * Create an instance of EsbListenerController from a named configuration stored in the
 	 * paramater repository.
@@ -249,9 +253,9 @@
 			// 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)
+			_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;
@@ -312,17 +316,35 @@
 					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);
+					//check the TS on the file.
+					boolean reloadNeeded=true;
+					File paramFile = new File(m_sParmsName);
+					if (paramFile.exists()) {
+						String currentTimeStamp = String.valueOf(paramFile.lastModified());
+						String previousTimeStamp = _paramFileTimeStamps.get(m_sParmsName);
+						_paramFileTimeStamps.put(m_sParmsName, currentTimeStamp);
+						if (previousTimeStamp==null || previousTimeStamp.equals(currentTimeStamp)) {
+							reloadNeeded=false;
+							m_lNextReload = (null != _sRldSecs) 
+							? System.currentTimeMillis() + 1000 * Long.parseLong(_sRldSecs)
+							: (null == commandQueue) 
+									? Long.MAX_VALUE 
+									: System.currentTimeMillis() + m_iDfltReloadMillis;
+						}
 					}
+					if (reloadNeeded) {
+						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;




More information about the jboss-svn-commits mailing list