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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Dec 12 20:56:40 EST 2006


Author: kurt.stam at jboss.com
Date: 2006-12-12 20:56:37 -0500 (Tue, 12 Dec 2006)
New Revision: 8275

Added:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/MockXmlValidatorImpl.java
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/ConfigurationControlerUnitTest.java
Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/Generator.java
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/GeneratorUnitTest.java
Log:
Adding ConfigController

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java	2006-12-13 00:01:35 UTC (rev 8274)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java	2006-12-13 01:56:37 UTC (rev 8275)
@@ -0,0 +1,162 @@
+/*
+ * 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.config;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.xml.sax.InputSource;
+
+public class ConfigurationController implements Runnable
+{
+	private static int SLEEP_MILLIS       = 1000; // default interval between parameter reloads
+	private Logger mLogger = Logger.getLogger(this.getClass());
+	private boolean isEndRequested = false;
+	private String mParametersName;
+	private long mPreviousFileTimestamp;
+	/**
+	 * Start the Controller externally.
+	 * @param args - arg[0] - the parameter file name
+	 * @throws Exception
+	 */
+	public static void main(String[] args) throws Exception 
+	{
+		ConfigurationController configurationController = new ConfigurationController(args[0]);
+		configurationController.run();
+	}
+	/**
+	 * Private default constructor. 
+	 */
+	private ConfigurationController() {}
+	/**
+	 * Construct a Configuration Manager from the named repository based
+	 * configuration.
+	 * 
+	 * @param p_sParameterName
+	 *            Name of the Repository entry containing the configuration.
+	 */
+	public ConfigurationController(String p_sParameterName)
+	{
+		mParametersName = p_sParameterName;
+	}
+	/**
+	 * Load the named configuration from the configured parameter repository.
+	 * 
+	 * @param reposParam
+	 *            The name of the repository entry containing the Listener
+	 *            configuration.
+	 */
+	private String getConfiguration(String reposParam)
+			throws ParamRepositoryException 
+	{
+		String xml = ParamRepositoryFactory.getInstance().get(reposParam);
+		return xml;
+	}
+    /**
+     * Thread that observes the configuration (file). If the configuration is updated it is
+     * validated and new set jbossesb-listener.xml and jbossesb-gateway.xml is created for the
+     * current server.
+     */
+	public void run() 
+	{
+		while (!isEndRequested && mParametersName!=null) 
+		{
+			if (isReloadNeeded()) { 
+				try {
+					mLogger.info("loading configuration..");
+					@SuppressWarnings("unused")
+					String configXml = getConfiguration(mParametersName);
+					mLogger.info("configXml=" + configXml);
+					//Validation
+					
+					InputSource xmlInputSource = new InputSource(new StringReader(configXml));
+					XmlValidator validator = new MockXmlValidatorImpl();
+					if (validator.validate(xmlInputSource)) {
+						Generator generator = new Generator(new ByteArrayInputStream(configXml.getBytes()));
+						List<String> servers = generator.getServers();
+						mLogger.log(Priority.INFO, servers);
+						String firstServer = servers.iterator().next();
+						File outputDir = new File(".");
+						generator.generate(firstServer, outputDir);
+					} else {
+						mLogger.log(Priority.ERROR, "Could not validate.");
+					}
+				} catch (ParamRepositoryException pe) {
+					mLogger.log(Priority.ERROR, pe.getMessage(), pe);
+				} catch (XmlValidatorException ve) {
+					mLogger.log(Priority.ERROR, ve.getMessage(), ve);
+				} catch (IOException io) {
+					mLogger.log(Priority.ERROR, io.getMessage(), io);
+				} catch (ConfigurationException ce) {
+					mLogger.log(Priority.ERROR, ce.getMessage(), ce);
+				}
+			}
+			try {
+				Thread.sleep(SLEEP_MILLIS);
+			} catch (InterruptedException ie) {
+				mLogger.log(Priority.WARN,"Could not sleep.",ie);
+			}
+		}
+		mLogger.info("Finishing Config Controller");
+	}
+	/**
+	 * Getter. Returns true if the end is requested.
+	 * @return true if the end is requested.
+	 */
+	public boolean isEndRequested() {
+		return isEndRequested;
+	}
+	/**
+	 * Setter, to request the end of processing.
+	 * @param isEndRequested
+	 */
+	public void setEndRequested(boolean isEndRequested) {
+		this.isEndRequested = isEndRequested;
+	}
+	/**
+	 * Check the file timestamp and return true when it changes. In other
+	 * words this only works for files for now.
+	 * 
+	 * @return true if the file timestamp changed.
+	 */
+	private boolean isReloadNeeded() 
+	{
+		File configFile = new File(mParametersName);
+		if (configFile.exists()) {
+			long currentFileTimestamp = configFile.lastModified();
+			if (mPreviousFileTimestamp==0 || currentFileTimestamp > mPreviousFileTimestamp) {
+				mPreviousFileTimestamp = currentFileTimestamp;
+				return true;
+			}
+		}
+		return false;
+	}
+}

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/Generator.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/Generator.java	2006-12-13 00:01:35 UTC (rev 8274)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/Generator.java	2006-12-13 01:56:37 UTC (rev 8275)
@@ -108,11 +108,13 @@
 
 		// Generate the configuration for the ESB Aware listeners...
 		ESBAwareGenerator awareGenerator = new ESBAwareGenerator(model, serverName);
+		@SuppressWarnings("unused")
 		Document awareConfig = awareGenerator.generate();
 		// TODO: serialise config to outDir...
 
 		// Generate the configuration for the ESB Aware listeners...
 		GatewayGenerator gatewayGenerator = new GatewayGenerator(model, serverName);
+		@SuppressWarnings("unused")
 		Document gatewayConfig = gatewayGenerator.generate();
 		// TODO: serialise config to outDir...
 	}

Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/MockXmlValidatorImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/MockXmlValidatorImpl.java	2006-12-13 00:01:35 UTC (rev 8274)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/MockXmlValidatorImpl.java	2006-12-13 01:56:37 UTC (rev 8275)
@@ -0,0 +1,31 @@
+package org.jboss.soa.esb.listeners.config;
+
+import java.util.Collection;
+
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+public class MockXmlValidatorImpl implements XmlValidator
+{
+
+	public Collection<String> getValidationResults() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public Document getXMLDocument() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public boolean validate(InputSource xmlInputSource) throws XmlValidatorException {
+		// TODO Auto-generated method stub
+		return true;
+	}
+
+	public boolean validate(InputSource xmlInputSource, InputSource validationSource) throws XmlValidatorException {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+}

Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/ConfigurationControlerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/ConfigurationControlerUnitTest.java	2006-12-13 00:01:35 UTC (rev 8274)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/ConfigurationControlerUnitTest.java	2006-12-13 01:56:37 UTC (rev 8275)
@@ -0,0 +1,57 @@
+/*
+* 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.config;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.junit.Test;
+/**
+ * Testing configuration controller.
+ * 
+ * @author kurt.stam at redhat.com
+ *
+ */
+public class ConfigurationControlerUnitTest 
+{
+	//private static Logger logger = Logger.getLogger(ConfigurationControlerUnitTest.class);
+	
+	/**
+	 * Testing the Content Based Router.
+	 */
+	@Test
+	public void readConfig() throws Exception
+	{
+		String fileName = TestEnvironmentUtil.getUserDir("product") 
+			+ "core/listeners/tests/src/org/jboss/soa/esb/listeners/config/jbossesb_config_01.xml";
+		ConfigurationController configurationController = new ConfigurationController(fileName);
+		Thread controller = new Thread(configurationController);
+		controller.start();
+		Thread.sleep(4000);
+		configurationController.setEndRequested(true);
+	}
+	
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(ConfigurationControlerUnitTest.class);
+	}
+
+}

Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/GeneratorUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/GeneratorUnitTest.java	2006-12-13 00:01:35 UTC (rev 8274)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/config/GeneratorUnitTest.java	2006-12-13 01:56:37 UTC (rev 8275)
@@ -62,6 +62,7 @@
 	public void test_generate() throws ConfigurationException, IOException {
 		test_generate_badargs(null, outdir, "");
 
+		@SuppressWarnings("unused")
 		Generator generator = new Generator(getClass().getResourceAsStream("jbossesb_config_01.xml"));
 	}
 




More information about the jboss-svn-commits mailing list