[jboss-svn-commits] JBL Code SVN: r8297 - labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 13 13:56:48 EST 2006
Author: kurt.stam at jboss.com
Date: 2006-12-13 13:56:47 -0500 (Wed, 13 Dec 2006)
New Revision: 8297
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
Log:
Adding logging and error handling.
Modified: 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 18:53:45 UTC (rev 8296)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2006-12-13 18:56:47 UTC (rev 8297)
@@ -24,14 +24,10 @@
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.IOException;
import java.io.StringReader;
-import java.util.List;
+import java.util.Date;
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;
@@ -39,8 +35,9 @@
{
private static int SLEEP_MILLIS = 1000; // default interval between parameter reloads
private Logger mLogger = Logger.getLogger(this.getClass());
- private boolean isEndRequested = false;
+ private boolean mIsEndRequested = false;
private String mParametersName;
+ private File mConfigDirectory;
private long mPreviousFileTimestamp;
/**
* Start the Controller externally.
@@ -67,19 +64,6 @@
{
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
@@ -87,56 +71,57 @@
*/
public void run()
{
- while (!isEndRequested && mParametersName!=null)
- {
- if (isReloadNeeded()) {
+ if (mParametersName!=null) {
+ while (!mIsEndRequested) {
+ if (isReloadNeeded()) {
+ try {
+ mLogger.info("loading configuration..");
+ String configXml = ParamRepositoryFactory.getInstance().get(mParametersName);
+ mLogger.debug("Start validation on configXml=" + configXml);
+ InputSource xmlInputSource = new InputSource(new StringReader(configXml));
+ XmlValidator validator = new MockXmlValidatorImpl();
+ if (validator.validate(xmlInputSource)) {
+ mLogger.debug("Configuration file " + mParametersName + " passed validation. Starting " +
+ " the generation process of the jbossesb-listener.xml and the jbossesb-gateway.xml.");
+ Generator generator = new Generator(new ByteArrayInputStream(configXml.getBytes()));
+ generator.generate(mConfigDirectory);
+ } else {
+ mLogger.error("The configuration file "
+ + mParametersName + " did not pass validation for the following reasons: "
+ + validator.getValidationResults());
+ mLogger.info("The current configuration is kept in place until "
+ + " validation passes.");
+ }
+ } catch (Exception e) {
+ mLogger.error("The current versions of the jbossesb-listener.xml and/or"
+ + " jbossesb-gateway.xml are kept in place until the following error is resolved: "
+ + e.getMessage(), e);
+ }
+ }
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()));
- File outputDir = new File(".");
- generator.generate(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);
+ Thread.sleep(SLEEP_MILLIS);
+ } catch (InterruptedException ie) {
+ mLogger.warn("Could not sleep." + ie.getMessage(),ie);
}
- }
- try {
- Thread.sleep(SLEEP_MILLIS);
- } catch (InterruptedException ie) {
- mLogger.log(Priority.WARN,"Could not sleep.",ie);
- }
+ }
+ } else {
+ mLogger.fatal("The name of the configuran file was null: " + mParametersName);
}
- mLogger.info("Finishing Config Controller");
+ mLogger.info("Exiting Config Controller...");
}
/**
* Getter. Returns true if the end is requested.
* @return true if the end is requested.
*/
public boolean isEndRequested() {
- return isEndRequested;
+ return mIsEndRequested;
}
/**
* Setter, to request the end of processing.
* @param isEndRequested
*/
public void setEndRequested(boolean isEndRequested) {
- this.isEndRequested = isEndRequested;
+ this.mIsEndRequested = isEndRequested;
}
/**
* Check the file timestamp and return true when it changes. In other
@@ -148,11 +133,18 @@
{
File configFile = new File(mParametersName);
if (configFile.exists()) {
+ mConfigDirectory = configFile.getParentFile();
long currentFileTimestamp = configFile.lastModified();
if (mPreviousFileTimestamp==0 || currentFileTimestamp > mPreviousFileTimestamp) {
+ if (mLogger.isDebugEnabled()) {
+ mLogger.debug("The previous timestamp on the file was: " + new Date(mPreviousFileTimestamp)
+ + " the new timestamp on the file is: " + new Date(currentFileTimestamp));
+ }
mPreviousFileTimestamp = currentFileTimestamp;
return true;
}
+ } else {
+ mLogger.error("The configuration file " + configFile + " could not be found.");
}
return false;
}
More information about the jboss-svn-commits
mailing list