[jboss-svn-commits] JBL Code SVN: r8683 - 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
Thu Jan 4 08:39:58 EST 2007
Author: kevin.conner at jboss.com
Date: 2007-01-04 08:39:56 -0500 (Thu, 04 Jan 2007)
New Revision: 8683
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
Log:
Make first process of configuration file synchronous: JBESB-319
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 2007-01-04 13:33:55 UTC (rev 8682)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2007-01-04 13:39:56 UTC (rev 8683)
@@ -45,15 +45,15 @@
*/
public class ConfigurationController implements Runnable
{
- private static int SLEEP_MILLIS = 1000; // default interval between parameter reloads
- private static String JBOSSESB_XSD = "/jbossesb-1.0.xsd";
- private Logger mLogger = Logger.getLogger(this.getClass());
- private boolean mIsEndRequested = false;
- private String mConfigFileName;
- private String mValidationFileName;
- private File mConfigDirectory;
+ private static final int SLEEP_MILLIS = 1000; // default interval between parameter reloads
+ private static final String JBOSSESB_XSD = "/jbossesb-1.0.xsd";
+ private final Logger mLogger = Logger.getLogger(this.getClass());
+ private final String mConfigFileName;
+ private final String mValidationFileName;
+ private final File mConfigDirectory;
private long mPreviousFileTimestamp;
- private boolean ended = false;
+ private volatile boolean mIsEndRequested;
+ private volatile boolean ended;
/**
* Start the Controller externally.
@@ -66,10 +66,6 @@
configurationController.run();
}
/**
- * Private default constructor.
- */
- private ConfigurationController() {}
- /**
* Construct a Configuration Manager from the named repository based
* configuration. The default jbossesb-1.0.xsd will be used for validation.
*
@@ -91,6 +87,8 @@
public ConfigurationController(String configFileName, String validationFileName)
{
mConfigFileName = configFileName;
+ File configFile = new File(configFileName);
+ mConfigDirectory = configFile.getParentFile();
//Try to obtain a handle to the validation file (xsd)
if (validationFileName==null) {
mValidationFileName=JBOSSESB_XSD;
@@ -98,6 +96,7 @@
mValidationFileName = validationFileName;
}
+ processConfiguration() ;
}
/**
* Thread that observes the configuration (file). If the configuration is updated it is
@@ -110,58 +109,7 @@
try {
if (mConfigFileName!=null) {
while (!mIsEndRequested) {
- if (isReloadNeeded()) {
- try {
- StreamSource validationInputSource=null;
- InputStream validationInputStream = this.getClass().getResourceAsStream(mValidationFileName);
- //if this fails try using the
- if (validationInputStream==null) {
- File validationFile = new File(mValidationFileName);
- mLogger.debug("Validation file " + mValidationFileName + " exists?:" + validationFile.exists());
- try {
- validationInputStream = new FileInputStream(validationFile);
- } catch (FileNotFoundException e) {
- mLogger.error(e.getMessage(),e);
- throw new IllegalStateException("ESB validation file [" + (new File(mValidationFileName)).getAbsolutePath() + "] not found.", e);
- }
- }
- if (validationInputStream==null) {
- mLogger.warn("Could not obtain validation file " + mValidationFileName);
- } else {
- mLogger.debug("Reading validation info from " + mValidationFileName);
- validationInputSource = new StreamSource(validationInputStream);
- }
-
- mLogger.info("loading configuration..");
- String configXml = ParamRepositoryFactory.getInstance().get(mConfigFileName);
- mLogger.debug("Start validation on configXml=" + configXml);
- InputSource xmlInputSource = new InputSource(new StringReader(configXml));
- XmlValidator validator = new XmlValidatorImpl();
- if (validator.validate(xmlInputSource, validationInputSource)) {
- mLogger.debug("Configuration file " + mConfigFileName + " 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 {
- StringBuffer buffer = new StringBuffer("The configuration file "
- + mConfigFileName + "\n did not pass validation for the following reasons: \n");
- int i=0;
- for (String error: validator.getValidationResults())
- {
- buffer.append("** " + ++i + ". "+ error + "\n");
- }
- System.out.println(buffer);
- mLogger.error(buffer);
- 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);
- System.out.println(e.getMessage());
- }
- }
+ processConfiguration() ;
try {
Thread.sleep(SLEEP_MILLIS);
} catch (InterruptedException ie) {
@@ -192,7 +140,67 @@
public void requestEnd() {
mIsEndRequested = true;
}
+
/**
+ * Process the configuration.
+ */
+ private void processConfiguration()
+ {
+ if (isReloadNeeded()) {
+ try {
+ StreamSource validationInputSource=null;
+ InputStream validationInputStream = this.getClass().getResourceAsStream(mValidationFileName);
+ //if this fails try using the
+ if (validationInputStream==null) {
+ File validationFile = new File(mValidationFileName);
+ mLogger.debug("Validation file " + mValidationFileName + " exists?:" + validationFile.exists());
+ try {
+ validationInputStream = new FileInputStream(validationFile);
+ } catch (FileNotFoundException e) {
+ mLogger.error(e.getMessage(),e);
+ throw new IllegalStateException("ESB validation file [" + (new File(mValidationFileName)).getAbsolutePath() + "] not found.", e);
+ }
+ }
+ if (validationInputStream==null) {
+ mLogger.warn("Could not obtain validation file " + mValidationFileName);
+ } else {
+ mLogger.debug("Reading validation info from " + mValidationFileName);
+ validationInputSource = new StreamSource(validationInputStream);
+ }
+
+ mLogger.info("loading configuration..");
+ String configXml = ParamRepositoryFactory.getInstance().get(mConfigFileName);
+ mLogger.debug("Start validation on configXml=" + configXml);
+ InputSource xmlInputSource = new InputSource(new StringReader(configXml));
+ XmlValidator validator = new XmlValidatorImpl();
+ if (validator.validate(xmlInputSource, validationInputSource)) {
+ mLogger.debug("Configuration file " + mConfigFileName + " 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 {
+ StringBuffer buffer = new StringBuffer("The configuration file "
+ + mConfigFileName + "\n did not pass validation for the following reasons: \n");
+ int i=0;
+ for (String error: validator.getValidationResults())
+ {
+ buffer.append("** " + ++i + ". "+ error + "\n");
+ }
+ System.out.println(buffer);
+ mLogger.error(buffer);
+ 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 error is resolved: "
+ + e.getMessage(), e);
+ System.out.println(e.getMessage());
+ }
+ }
+ }
+
+ /**
* Check the file timestamp and return true when it changes. In other
* words this only works for files for now.
*
@@ -202,7 +210,6 @@
{
File configFile = new File(mConfigFileName);
if (configFile.exists()) {
- mConfigDirectory = configFile.getParentFile();
long currentFileTimestamp = configFile.lastModified();
if (mPreviousFileTimestamp==0 || currentFileTimestamp > mPreviousFileTimestamp) {
if (mLogger.isDebugEnabled()) {
More information about the jboss-svn-commits
mailing list