[jboss-svn-commits] JBL Code SVN: r8882 - in labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss: soa/esb/actions and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 17 09:47:16 EST 2007
Author: mark.little at jboss.com
Date: 2007-01-17 09:47:16 -0500 (Wed, 17 Jan 2007)
New Revision: 8882
Modified:
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayException.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
Log:
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/internal/soa/esb/listeners/DefaultListenerManager.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
+import java.text.ParseException;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -89,10 +90,10 @@
*
* @param parametersName
* Name of the Repository entry containing the configuration.
- * @throws Exception
+ * @throws ConfigurationException
* Unable to load/use the named configuration.
*/
- public DefaultListenerManager(String parametersName) throws Exception
+ public DefaultListenerManager(String parametersName) throws ConfigurationException, CommandQueueException
{
this(DefaultListenerManager.getListenerConfig(parametersName));
_parametersName = parametersName;
@@ -104,10 +105,10 @@
*
* @param config
* The configuration.
- * @throws Exception
+ * @throws ConfigurationException
* Unable to load/use the supplied configuration.
*/
- public DefaultListenerManager(ConfigTree config) throws Exception
+ public DefaultListenerManager(ConfigTree config) throws ConfigurationException, CommandQueueException
{
// default sleep time when waiting for events to happen in other threads
_pauseTimeMillis = 50;
@@ -122,7 +123,7 @@
{
checkParms(_config);
}
- catch (Exception e)
+ catch (CommandQueueException e)
{
String configSource = config.getAttribute("configSource");
@@ -136,6 +137,20 @@
throw e;
}
+ catch (ConfigurationException e)
+ {
+ String configSource = config.getAttribute("configSource");
+
+ _status = State.Exception_thrown;
+ _status.setThrowable(e);
+ _logger
+ .fatal(
+ "Listener configuration and startup error. Config Source: "
+ + (configSource != null ? configSource
+ : "unknown"), e);
+
+ throw e;
+ }
} // ____________________________
/*
@@ -157,29 +172,39 @@
* @throws SAXException
* Unable to parse the configuration.
*/
- private static ConfigTree getListenerConfig(String reposParam)
- throws IOException, ParamRepositoryException, SAXException
+ private static ConfigTree getListenerConfig(String reposParam) throws ConfigurationException
{
- String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
- if (sXml != null)
+ try
{
- ConfigTree config = ConfigTree.fromXml(sXml);
-
- config.setAttribute("configSource", "param-repository:" + reposParam);
-
- return config;
+ String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
+ if (sXml != null)
+ {
+ ConfigTree config = ConfigTree.fromXml(sXml);
+
+ config.setAttribute("configSource", "param-repository:" + reposParam);
+
+ return config;
+ }
+ else
+ {
+ return null ;
+ }
}
- else
+ catch (ParamRepositoryException ex)
{
- return null ;
+ throw new ConfigurationException(ex);
}
+ catch (SAXException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
} // ____________________________
/*
* (non-Javadoc)
*
*/
- public void checkParms(ConfigTree p_oP) throws Exception
+ public void checkParms(ConfigTree p_oP) throws ConfigurationException, CommandQueueException
{
// We've just loaded - set to false until next reload requested
_reloadRequested = false;
@@ -207,8 +232,16 @@
// not a good practice if command queue is not set
// Expected date format is "yyyyMMdd hh:mm:ss"
String sEndT = p_oP.getAttribute(PARM_END_TIME);
- _endTimeStamp = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
- sEndT).getTime();
+
+ try
+ {
+ _endTimeStamp = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
+ sEndT).getTime();
+ }
+ catch (ParseException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
for (ConfigTree tree : p_oP.getAllChildren())
{
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -79,7 +79,7 @@
* the EPRs of the Content Based Router.
*
* @param config
- * @throws Exception
+ * @throws RegistryException
*/
public CbrProxyAction(ConfigTree config) throws RegistryException
{
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -27,6 +27,8 @@
*/
package org.jboss.soa.esb.actions;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@@ -34,75 +36,101 @@
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.addressing.Call;
import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.services.registry.RegistryFactory;
-public class StaticRouter
+public class StaticRouter
{
- public static final String DESTINATION_LIST_TAG="destinations";
- public static final String ROUTE_TO_TAG="route-to";
-
- private StaticRouter() {}
- public StaticRouter (ConfigTree config) throws Exception
+ public static final String DESTINATION_LIST_TAG = "destinations";
+
+ public static final String ROUTE_TO_TAG = "route-to";
+
+ private StaticRouter()
{
- _config = config;
+ }
+
+ public StaticRouter(ConfigTree config) throws ConfigurationException, RegistryException
+ {
+ _config = config;
checkMyParms();
_registry = RegistryFactory.getRegistry();
- } //________________________________
-
- public Message process(Message message) throws Exception
+ } // ________________________________
+
+ public Message process(Message message) throws MalformedEPRException, RegistryException, CourierException
{
- Call call = message.getHeader().getCall();
- if (null==call || null==call.getMessageID())
- throw new IllegalArgumentException("Null message ID");
-
- for (String[] curr : _destinations)
+ try
{
- EPR epr = _registry.findEPR(curr[0], curr[1]);
- if (epr instanceof FileEpr)
+ Call call = message.getHeader().getCall();
+ if (null == call || null == call.getMessageID())
+ throw new IllegalArgumentException("Null message ID");
+
+ for (String[] curr : _destinations)
{
- FileEpr fpr = (FileEpr)epr;
- FileEpr newEpr = new FileEpr(fpr.getURL());
- newEpr.setPostDelete(false);
- newEpr.setPostDirectory(fpr.getURL().getFile());
- newEpr.setPostSuffix(fpr.getInputSuffix());
- epr = newEpr;
+ EPR epr = _registry.findEPR(curr[0], curr[1]);
+ if (epr instanceof FileEpr)
+ {
+ FileEpr fpr = (FileEpr) epr;
+ FileEpr newEpr = new FileEpr(fpr.getURL());
+ newEpr.setPostDelete(false);
+ newEpr.setPostDirectory(fpr.getURL().getFile());
+ newEpr.setPostSuffix(fpr.getInputSuffix());
+ epr = newEpr;
+ }
+ CourierFactory.getCourier(epr).deliver(message);
}
- CourierFactory.getCourier(epr).deliver(message);
+ return message;
}
- return message;
- } //________________________________
-
+ catch (MalformedURLException ex)
+ {
+ throw new MalformedEPRException(ex);
+ }
+ catch (URISyntaxException ex)
+ {
+ throw new MalformedEPRException(ex);
+ }
+ } // ________________________________
+
protected void checkMyParms() throws ConfigurationException
{
_destinations = new ArrayList<String[]>();
ConfigTree[] destList = _config.getChildren(ROUTE_TO_TAG);
- if (null==destList || destList.length<1)
+ if (null == destList || destList.length < 1)
{
- _logger.warn("Missing or empty destination list - This action class won't have any effect");
+ _logger
+ .warn("Missing or empty destination list - This action class won't have any effect");
return;
}
- for(ConfigTree curr : destList)
+ for (ConfigTree curr : destList)
try
{
- String category = curr.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG,"");
- String name = curr.getAttribute(ListenerTagNames.SERVICE_NAME_TAG,null);
- _destinations.add(new String[] {category,name});
+ String category = curr.getAttribute(
+ ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, "");
+ String name = curr.getAttribute(
+ ListenerTagNames.SERVICE_NAME_TAG, null);
+ _destinations.add(new String[]
+ { category, name });
}
catch (Exception e)
{
- throw new ConfigurationException("Problems with destination list",e);
+ throw new ConfigurationException(
+ "Problems with destination list", e);
}
- } //________________________________
+ } // ________________________________
- protected ConfigTree _config;
- protected List<String[]> _destinations;
- protected Registry _registry;
- protected static Logger _logger=Logger.getLogger(StaticRouter.class);
-
+ protected ConfigTree _config;
+
+ protected List<String[]> _destinations;
+
+ protected Registry _registry;
+
+ protected static Logger _logger = Logger.getLogger(StaticRouter.class);
+
}
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -58,9 +58,9 @@
/**
* Start the Controller externally.
* @param args - arg[0] - the parameter file name
- * @throws Exception
*/
- public static void main(String[] args) throws Exception
+
+ public static void main(String[] args)
{
ConfigurationController configurationController = new ConfigurationController(args[0],null);
configurationController.run();
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -27,6 +27,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Collection;
@@ -73,7 +74,7 @@
}
protected AbstractFileGateway(GatewayListenerController commandListener,
- ConfigTree config) throws Exception
+ ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
{
_config = config;
_controller = commandListener;
@@ -318,11 +319,11 @@
/**
* Check for mandatory and optional attributes in parameter tree
*
- * @throws Exception -
+ * @throws ConfigurationException -
* if mandatory atts are not right or actionClass not in
* classpath
*/
- protected void checkMyParms() throws Exception
+ protected void checkMyParms() throws ConfigurationException, RegistryException, GatewayException
{
// Third arg is null - Exception will be thrown if attribute is not
// found
@@ -361,99 +362,133 @@
resolveComposerClass();
- // INPUT directory and suffix (used for FileFilter)
- String url = _config.getAttribute(ListenerTagNames.URL_TAG);
- String sInpDir = (null != url) ? new URL(url).getFile() : _controller
- .obtainAtt(_config, ListenerTagNames.FILE_INPUT_DIR_TAG, null);
- _inputDirectory = fileFromString(sInpDir);
- seeIfOkToWorkOnDir(_inputDirectory);
-
- _inputSuffix = _controller.obtainAtt(_config,
- ListenerTagNames.FILE_INPUT_SFX_TAG, null);
- _inputSuffix = _inputSuffix.trim();
- if (_inputSuffix.length() < 1)
- throw new Exception("Invalid "
- + ListenerTagNames.FILE_INPUT_SFX_TAG + " attribute");
-
- // WORK suffix (will rename in input directory)
- _workingSuffix = _controller.obtainAtt(_config,
- ListenerTagNames.FILE_WORK_SFX_TAG, ".esbWork").trim();
- if (_workingSuffix.length() < 1)
- throw new Exception("Invalid " + ListenerTagNames.FILE_WORK_SFX_TAG
- + " attribute");
- if (_inputSuffix.equals(_workingSuffix))
- throw new Exception("Work suffix must differ from input suffix <"
- + _workingSuffix + ">");
-
- // ERROR directory and suffix (defaults to input dir and ".esbError"
- // suffix)
- String sErrDir = _controller.obtainAtt(_config,
- ListenerTagNames.FILE_ERROR_DIR_TAG, sInpDir);
- _errorDirectory = fileFromString(sErrDir);
- seeIfOkToWorkOnDir(_errorDirectory);
-
- _errorSuffix = _controller.obtainAtt(_config,
- ListenerTagNames.FILE_ERROR_SFX_TAG, ".esbError").trim();
- if (_errorSuffix.length() < 1)
- throw new Exception("Invalid "
- + ListenerTagNames.FILE_ERROR_SFX_TAG + " attribute");
- if (_errorDirectory.equals(_inputDirectory)
- && _inputSuffix.equals(_errorSuffix))
- throw new Exception("Error suffix must differ from input suffix <"
- + _errorSuffix + ">");
-
- // Do users wish to delete files that were processed OK ?
- String sPostDel = _controller.obtainAtt(_config,
- ListenerTagNames.FILE_POST_DEL_TAG, "false").trim();
- _deleteAfterOK = Boolean.parseBoolean(sPostDel);
- if (_deleteAfterOK)
- return;
-
- // POST (done) directory and suffix (defaults to input dir and
- // ".esbDone" suffix)
- String sPostDir = _controller.obtainAtt(_config,
- ListenerTagNames.FILE_POST_DIR_TAG, sInpDir);
- _postProcessDirectory = fileFromString(sPostDir);
- seeIfOkToWorkOnDir(_postProcessDirectory);
- _postProcessSuffix = _controller.obtainAtt(_config,
- ListenerTagNames.FILE_POST_SFX_TAG, ".esbDone").trim();
- if (_postProcessDirectory.equals(_inputDirectory))
+ try
{
- if (_postProcessSuffix.length() < 1)
- throw new Exception("Invalid "
- + ListenerTagNames.FILE_POST_SFX_TAG + " attribute");
- if (_postProcessSuffix.equals(_inputSuffix))
- throw new Exception(
- "Post process suffix must differ from input suffix <"
- + _postProcessSuffix + ">");
+ // INPUT directory and suffix (used for FileFilter)
+ String url = _config.getAttribute(ListenerTagNames.URL_TAG);
+ String sInpDir = (null != url) ? new URL(url).getFile() : _controller
+ .obtainAtt(_config, ListenerTagNames.FILE_INPUT_DIR_TAG, null);
+ _inputDirectory = fileFromString(sInpDir);
+ seeIfOkToWorkOnDir(_inputDirectory);
+
+ _inputSuffix = _controller.obtainAtt(_config,
+ ListenerTagNames.FILE_INPUT_SFX_TAG, null);
+ _inputSuffix = _inputSuffix.trim();
+ if (_inputSuffix.length() < 1)
+ throw new ConfigurationException("Invalid "
+ + ListenerTagNames.FILE_INPUT_SFX_TAG + " attribute");
+
+ // WORK suffix (will rename in input directory)
+ _workingSuffix = _controller.obtainAtt(_config,
+ ListenerTagNames.FILE_WORK_SFX_TAG, ".esbWork").trim();
+ if (_workingSuffix.length() < 1)
+ throw new ConfigurationException("Invalid " + ListenerTagNames.FILE_WORK_SFX_TAG
+ + " attribute");
+ if (_inputSuffix.equals(_workingSuffix))
+ throw new ConfigurationException("Work suffix must differ from input suffix <"
+ + _workingSuffix + ">");
+
+ // ERROR directory and suffix (defaults to input dir and ".esbError"
+ // suffix)
+ String sErrDir = _controller.obtainAtt(_config,
+ ListenerTagNames.FILE_ERROR_DIR_TAG, sInpDir);
+ _errorDirectory = fileFromString(sErrDir);
+ seeIfOkToWorkOnDir(_errorDirectory);
+
+ _errorSuffix = _controller.obtainAtt(_config,
+ ListenerTagNames.FILE_ERROR_SFX_TAG, ".esbError").trim();
+ if (_errorSuffix.length() < 1)
+ throw new ConfigurationException("Invalid "
+ + ListenerTagNames.FILE_ERROR_SFX_TAG + " attribute");
+ if (_errorDirectory.equals(_inputDirectory)
+ && _inputSuffix.equals(_errorSuffix))
+ throw new ConfigurationException("Error suffix must differ from input suffix <"
+ + _errorSuffix + ">");
+
+ // Do users wish to delete files that were processed OK ?
+ String sPostDel = _controller.obtainAtt(_config,
+ ListenerTagNames.FILE_POST_DEL_TAG, "false").trim();
+ _deleteAfterOK = Boolean.parseBoolean(sPostDel);
+ if (_deleteAfterOK)
+ return;
+
+ // POST (done) directory and suffix (defaults to input dir and
+ // ".esbDone" suffix)
+ String sPostDir = _controller.obtainAtt(_config,
+ ListenerTagNames.FILE_POST_DIR_TAG, sInpDir);
+ _postProcessDirectory = fileFromString(sPostDir);
+ seeIfOkToWorkOnDir(_postProcessDirectory);
+ _postProcessSuffix = _controller.obtainAtt(_config,
+ ListenerTagNames.FILE_POST_SFX_TAG, ".esbDone").trim();
+ if (_postProcessDirectory.equals(_inputDirectory))
+ {
+ if (_postProcessSuffix.length() < 1)
+ throw new ConfigurationException("Invalid "
+ + ListenerTagNames.FILE_POST_SFX_TAG + " attribute");
+ if (_postProcessSuffix.equals(_inputSuffix))
+ throw new ConfigurationException(
+ "Post process suffix must differ from input suffix <"
+ + _postProcessSuffix + ">");
+ }
}
+ catch (GatewayException ex)
+ {
+ throw ex;
+ }
+ catch (MalformedURLException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
} // ________________________________
- protected void resolveComposerClass() throws Exception
+ protected void resolveComposerClass() throws ConfigurationException, GatewayException
{
- // Look for first "action" element - only first one will be used
- String tagName = ListenerTagNames.ACTION_ELEMENT_TAG;
- ConfigTree actionElement = _config.getFirstChild(tagName);
- String sProcessMethod = null;
- if (null != actionElement)
- { // class attribute
- _composerName = _controller.obtainAtt(actionElement,
- ListenerTagNames.ACTION_CLASS_TAG, null);
- _composerClass = Class.forName(_composerName);
- Constructor oConst = _composerClass.getConstructor(new Class[]
- { ConfigTree.class });
- _composer = oConst.newInstance(_config);
- tagName = ListenerTagNames.PROCESS_METHOD_TAG;
- sProcessMethod = _controller.obtainAtt(_config, tagName, tagName);
+ try
+ {
+ // Look for first "action" element - only first one will be used
+ String tagName = ListenerTagNames.ACTION_ELEMENT_TAG;
+ ConfigTree actionElement = _config.getFirstChild(tagName);
+ String sProcessMethod = null;
+ if (null != actionElement)
+ { // class attribute
+ _composerName = _controller.obtainAtt(actionElement,
+ ListenerTagNames.ACTION_CLASS_TAG, null);
+ _composerClass = Class.forName(_composerName);
+ Constructor oConst = _composerClass.getConstructor(new Class[]
+ { ConfigTree.class });
+ _composer = oConst.newInstance(_config);
+ tagName = ListenerTagNames.PROCESS_METHOD_TAG;
+ sProcessMethod = _controller.obtainAtt(_config, tagName, tagName);
+ }
+ else
+ {
+ getDefaultComposer();
+ sProcessMethod = "process";
+ }
+
+ _processMethod = _composerClass.getMethod(sProcessMethod, new Class[]
+ { Object.class });
}
- else
+ catch (InvocationTargetException ex)
{
- getDefaultComposer();
- sProcessMethod = "process";
+ throw new ConfigurationException(ex);
}
-
- _processMethod = _composerClass.getMethod(sProcessMethod, new Class[]
- { Object.class });
+ catch (IllegalAccessException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
+ catch (InstantiationException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
+ catch (NoSuchMethodException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
} // ________________________________
private File fileFromString(String file)
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -29,207 +29,229 @@
import java.io.FileOutputStream;
import java.io.IOException;
+import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.util.Util;
-public class FileGatewayListener extends AbstractFileGateway
+public class FileGatewayListener extends AbstractFileGateway
{
- protected FileGatewayListener() {}
- public FileGatewayListener(GatewayListenerController commandListener, ConfigTree config)
- throws Exception
- {
- super(commandListener,config);
- _fileFilter = new FileEndsWith(_inputSuffix);
- }
+ protected FileGatewayListener()
+ {
+ }
- protected void checkMyParms() throws Exception
- {
- super.checkMyParms();
- }
+ public FileGatewayListener(GatewayListenerController commandListener,
+ ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
+ {
+ super(commandListener, config);
+ _fileFilter = new FileEndsWith(_inputSuffix);
+ }
+ protected void checkMyParms() throws ConfigurationException, RegistryException, GatewayException
+ {
+ super.checkMyParms();
+ }
+
@Override
- protected void seeIfOkToWorkOnDir (File p_oDir) throws GatewayException
+ protected void seeIfOkToWorkOnDir(File p_oDir) throws GatewayException
{
- if (! p_oDir.exists())
- throw new GatewayException ("Directory "+p_oDir.toString()+" not found");
- if (!p_oDir.isDirectory())
- throw new GatewayException(p_oDir.toString()+" is not a directory");
- if (!p_oDir.canRead())
- throw new GatewayException("Can't read directory "+p_oDir.toString());
- if (! p_oDir.canWrite())
- throw new GatewayException ("Can't write/rename in directory "+p_oDir.toString());
- } //________________________________
+ if (!p_oDir.exists())
+ throw new GatewayException("Directory " + p_oDir.toString()
+ + " not found");
+ if (!p_oDir.isDirectory())
+ throw new GatewayException(p_oDir.toString()
+ + " is not a directory");
+ if (!p_oDir.canRead())
+ throw new GatewayException("Can't read directory "
+ + p_oDir.toString());
+ if (!p_oDir.canWrite())
+ throw new GatewayException("Can't write/rename in directory "
+ + p_oDir.toString());
+ } // ________________________________
@Override
- boolean deleteFile(File file) throws GatewayException
+ boolean deleteFile(File file) throws GatewayException
{
return file.delete();
}
-
@Override
- byte[] getFileContents(File file) throws GatewayException
+ byte[] getFileContents(File file) throws GatewayException
{
try
{
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] ba = new byte[1000];
- int iQread;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] ba = new byte[1000];
+ int iQread;
FileInputStream inp = new FileInputStream(file);
- while (-1!= (iQread=inp.read(ba)))
+ while (-1 != (iQread = inp.read(ba)))
if (iQread > 0)
- out.write(ba,0,iQread);
+ out.write(ba, 0, iQread);
inp.close();
- out.close();
- return out.toByteArray();
+ out.close();
+ return out.toByteArray();
}
- catch (IOException e) { throw new GatewayException(e); }
+ catch (IOException e)
+ {
+ throw new GatewayException(e);
+ }
}
-
@Override
- File[] getFileList(String suffix) throws GatewayException
+ File[] getFileList(String suffix) throws GatewayException
{
return _inputDirectory.listFiles(_fileFilter);
}
-
@Override
- boolean renameFile(File from, File to) throws GatewayException
+ boolean renameFile(File from, File to) throws GatewayException
{
if (to.exists() && !to.delete())
{
- throw new GatewayException("Cannot delete target file: " + to.getAbsolutePath()) ;
+ throw new GatewayException("Cannot delete target file: "
+ + to.getAbsolutePath());
}
-
+
if (!from.renameTo(to))
{
- copyFile(from, to) ;
- from.delete() ;
+ copyFile(from, to);
+ from.delete();
}
- return true ;
+ return true;
}
-
+
@Override
- void getDefaultComposer() throws GatewayException
+ void getDefaultComposer() throws GatewayException
{
- _composerName = PackageFileContents.class.getName();
- _composerClass= PackageFileContents.class;
- _composer = new PackageFileContents();
- _logger.warn("No <"+ListenerTagNames.ACTION_ELEMENT_TAG+"> element found in cofiguration"
- +" - Using default composer class : "+_composerName);
+ _composerName = PackageFileContents.class.getName();
+ _composerClass = PackageFileContents.class;
+ _composer = new PackageFileContents();
+ _logger.warn("No <" + ListenerTagNames.ACTION_ELEMENT_TAG
+ + "> element found in cofiguration"
+ + " - Using default composer class : " + _composerName);
}
-
+
protected void copyFile(final File from, final File to)
- throws GatewayException
+ throws GatewayException
{
- final FileInputStream fis ;
+ final FileInputStream fis;
try
{
- fis = new FileInputStream(from) ;
+ fis = new FileInputStream(from);
}
catch (final IOException ioe)
{
- throw new GatewayException("Could not open input file for reading", ioe) ;
+ throw new GatewayException("Could not open input file for reading",
+ ioe);
}
try
{
- final FileOutputStream fos ;
+ final FileOutputStream fos;
try
{
- fos = new FileOutputStream(to) ;
+ fos = new FileOutputStream(to);
}
catch (final IOException ioe)
{
- throw new GatewayException("Could not open output file for writing", ioe) ;
+ throw new GatewayException(
+ "Could not open output file for writing", ioe);
}
-
+
try
{
- final long filesize = from.length() ;
- final byte[] buffer = (filesize > 256 ? new byte[256] : new byte[(int)filesize]) ;
- while(true)
+ final long filesize = from.length();
+ final byte[] buffer = (filesize > 256 ? new byte[256]
+ : new byte[(int) filesize]);
+ while (true)
{
- final int count = fis.read(buffer) ;
+ final int count = fis.read(buffer);
if (count < 0)
{
- break ;
+ break;
}
- fos.write(buffer, 0, count) ;
+ fos.write(buffer, 0, count);
}
}
catch (final IOException ioe)
{
- throw new GatewayException("Error copying file", ioe) ;
+ throw new GatewayException("Error copying file", ioe);
}
finally
{
try
{
- fos.close() ;
+ fos.close();
}
- catch (final IOException ioe) {} // ignore
+ catch (final IOException ioe)
+ {
+ } // ignore
}
}
finally
{
try
{
- fis.close() ;
+ fis.close();
}
- catch (final IOException ioe) {} // ignore
+ catch (final IOException ioe)
+ {
+ } // ignore
}
}
-
-//______________________________________________________________________________
- /**
- * Default gateway action for files
- * <p/>It will just drop the file contents into a Message
- * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- * @since Version 4.0
- *
- */
- public class PackageFileContents
- {
- public Message process (Object obj) throws Exception
- {
- if (! (obj instanceof File))
- throw new Exception ("Object must be instance of File");
- Message message = MessageFactory.getInstance().getMessage();
- message.getBody().setContents(getFileContent((File)obj));
- return message;
- }
-
- private byte[] getFileContent(File file) throws Exception
- { return getFileContents(file); }
- } //____________________________________________________
-
- /**
- * Simple file filter for local filesystem
- * Will accept only files that end with the String supplied at constructor time
- *
- */
- private class FileEndsWith implements FileFilter
- {
- String m_sSuffix;
- FileEndsWith(String p_sEnd) throws Exception
- {
- m_sSuffix = p_sEnd;
- if (Util.isNullString(m_sSuffix))
- throw new Exception("Must specify file extension");
- } //______________________________
+ // ______________________________________________________________________________
+ /**
+ * Default gateway action for files <p/>It will just drop the file contents
+ * into a Message
+ *
+ * @author <a
+ * href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ *
+ */
+ public class PackageFileContents
+ {
+ public Message process(Object obj) throws ConfigurationException, GatewayException
+ {
+ if (!(obj instanceof File))
+ throw new ConfigurationException("Object must be instance of File");
- public boolean accept(File p_f)
- { return (p_f.isFile())
- ? p_f.toString().endsWith(m_sSuffix)
- : false;
- } //______________________________
- } //____________________________________________________
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().setContents(getFileContent((File) obj));
+ return message;
+ }
- private FileFilter _fileFilter;
+ private byte[] getFileContent(File file) throws ConfigurationException, GatewayException
+ {
+ return getFileContents(file);
+ }
+ } // ____________________________________________________
+ /**
+ * Simple file filter for local filesystem Will accept only files that end
+ * with the String supplied at constructor time
+ *
+ */
+ private class FileEndsWith implements FileFilter
+ {
+ String m_sSuffix;
+
+ FileEndsWith(String p_sEnd) throws ConfigurationException
+ {
+ m_sSuffix = p_sEnd;
+ if (Util.isNullString(m_sSuffix))
+ throw new ConfigurationException("Must specify file extension");
+ } // ______________________________
+
+ public boolean accept(File p_f)
+ {
+ return (p_f.isFile()) ? p_f.toString().endsWith(m_sSuffix) : false;
+ } // ______________________________
+ } // ____________________________________________________
+
+ private FileFilter _fileFilter;
+
}
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayException.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayException.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayException.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -25,7 +25,7 @@
import org.jboss.soa.esb.BaseException;
/**
- * Dispatch Exception.
+ * Gateway Exception.
* @author b_georges
* @since Version 4.0
*/
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -55,29 +55,34 @@
public class GatewayListenerController implements Runnable
{
- private static Map<String,Long> _paramFileTimeStamps=new ConcurrentHashMap<String,Long>();
- private static String _sRldSecs=null;
-
- public static void main(String[] args) throws Exception
+ private static Map<String, Long> _paramFileTimeStamps = new ConcurrentHashMap<String, Long>();
+
+ private static String _sRldSecs = null;
+
+ public static void main(String[] args) throws Exception
{
GatewayListenerController oProc = new GatewayListenerController(args[0]);
oProc.run();
GatewayListenerController.State oS = oProc.getState();
- if (null != oS.getException()) {
+ if (null != oS.getException())
+ {
_logger.error("GatewayListener <" + args[0] + "> FAILED\n", oS
.getException());
}
System.exit(oS.getCompletionCode());
} // ________________________________
- public static final String RELOAD_SECONDS_TAG = "parameterReloadSecs";
- public static final String END_TIME_TAG = "endTime";
+ public static final String RELOAD_SECONDS_TAG = "parameterReloadSecs";
- // 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 ConfigTrees
- public static final String GATEWAY_CLASS_TAG = "gatewayClass";
+ public static final String END_TIME_TAG = "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
+ // ConfigTrees
+ public static final String GATEWAY_CLASS_TAG = "gatewayClass";
+
/**
* 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
@@ -91,33 +96,41 @@
* @return Map - a shallow copy of the attributes Map
*/
@SuppressWarnings("unchecked")
- public Map<String, Object> getControllerAttributes()
+ public Map<String, Object> getControllerAttributes()
{
return (Map<String, Object>) _attributes.clone();
}
- public State getState() { return _status; }
+ public State getState()
+ {
+ return _status;
+ }
- public static enum State
+ public static enum State
{
Loading_parameters, Running, Shutting_down, Done_OK, Exception_thrown;
int m_iCompletionCode = 0;
Exception m_oException = null;
- public int getCompletionCode() {
+ public int getCompletionCode()
+ {
return m_iCompletionCode;
};
- public Exception getException() {
+ public Exception getException()
+ {
return m_oException;
}
};
+
/**
- * Package private default constructor.
+ * Package private default constructor.
*/
- protected GatewayListenerController() { }
-
+ protected GatewayListenerController()
+ {
+ }
+
/**
* Construct a Listener Manager from the named repository based
* configuration.
@@ -127,7 +140,8 @@
* @throws Exception
* Unable to load/use the named configuration.
*/
- public GatewayListenerController(String p_sParameterName) throws Exception {
+ public GatewayListenerController(String p_sParameterName) throws Exception
+ {
this(GatewayListenerController.getListenerConfig(p_sParameterName));
_sParametersName = p_sParameterName;
}
@@ -140,17 +154,23 @@
* @throws Exception
* Unable to load/use the supplied configuration.
*/
- public GatewayListenerController(ConfigTree config) throws Exception {
+ public GatewayListenerController(ConfigTree config) throws Exception
+ {
_config = config;
_status = State.Loading_parameters;
- try { checkParms(_config); }
- catch (Exception e)
+ try
{
+ checkParms(_config);
+ }
+ catch (Exception e)
+ {
String configSource = config.getAttribute("configSource");
_status = State.Exception_thrown;
_status.m_oException = e;
- _logger.fatal("Listener configuration and startup error. Config Source: "
+ _logger
+ .fatal(
+ "Listener configuration and startup error. Config Source: "
+ (configSource != null ? configSource
: "unknown"), e);
throw e;
@@ -173,7 +193,8 @@
* Unable to parse the configuration.
*/
private static ConfigTree getListenerConfig(String reposParam)
- throws IOException, ParamRepositoryException, SAXException {
+ throws IOException, ParamRepositoryException, SAXException
+ {
String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
ConfigTree config = ConfigTree.fromXml(sXml);
@@ -193,21 +214,21 @@
* If attributes are wrong or not enough for a proper runtime
* configuration
*/
- public void checkParms(ConfigTree p_oP) throws Exception
+ public void checkParms(ConfigTree p_oP) throws Exception
{
// We've just loaded - set to false until next reload requested
_reloadRequested = false;
- if (null!=_sParametersName)
+ if (null != _sParametersName)
{
File file = new File(_sParametersName);
if (file.exists())
_paramFileTimeStamps.put(_sParametersName, file.lastModified());
}
-
+
_commandQueue = createCommandQueue(p_oP);
// Open the command queue...
- if (null!=_commandQueue)
+ if (null != _commandQueue)
_commandQueue.open(p_oP);
setNextReloadTime(p_oP);
@@ -215,68 +236,83 @@
// not a good practice if command queue is not set
// Expected date format is "yyyyMMdd hh:mm:ss"
String sEndT = p_oP.getAttribute(END_TIME_TAG);
- _endTime = (null == sEndT) ? Long.MAX_VALUE : _dateFormat.parse(
- sEndT).getTime();
-
- if (null==sEndT)
- {
- String sMsg = (null==_commandQueue)
- ? " - Listener will run until parent container/process terminates."
- : " - Listener will run until stopped by command sent to queue.";
- _logger.info("No value specified for: "+END_TIME_TAG + sMsg);
- }
+ _endTime = (null == sEndT) ? Long.MAX_VALUE : _dateFormat.parse(sEndT)
+ .getTime();
+
+ if (null == sEndT)
+ {
+ String sMsg = (null == _commandQueue) ? " - Listener will run until parent container/process terminates."
+ : " - Listener will run until stopped by command sent to queue.";
+ _logger.info("No value specified for: " + END_TIME_TAG + sMsg);
+ }
} // ________________________________
-
+
private void setNextReloadTime(ConfigTree tree)
{
// 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
_sRldSecs = tree.getAttribute(RELOAD_SECONDS_TAG);
-
- synchronized (_synchReload)
+
+ synchronized (_synchReload)
{
- _nextReload = (null != _sRldSecs)
- ? System.currentTimeMillis() + 1000 * Long.parseLong(_sRldSecs)
- : (null == _commandQueue)
- ? Long.MAX_VALUE
- : System.currentTimeMillis() + _defaultReloadMillis;
+ _nextReload = (null != _sRldSecs) ? System.currentTimeMillis()
+ + 1000 * Long.parseLong(_sRldSecs)
+ : (null == _commandQueue) ? Long.MAX_VALUE : System
+ .currentTimeMillis()
+ + _defaultReloadMillis;
}
-
- if (null==_sRldSecs)
- {
- String sMsg = (null==_commandQueue)
- ? " - Using default of "+_sRldSecs
- : " - Listener will run until stopped by command sent to queue";
- _logger.warn("No value specified for: "+RELOAD_SECONDS_TAG + sMsg);
- }
- } //________________________________
+ if (null == _sRldSecs)
+ {
+ String sMsg = (null == _commandQueue) ? " - Using default of "
+ + _sRldSecs
+ : " - Listener will run until stopped by command sent to queue";
+ _logger
+ .warn("No value specified for: " + RELOAD_SECONDS_TAG
+ + sMsg);
+ }
- /**
- * Factory method for creating the command queue.
- * @param config GatewayListener config.
- * @return GatewayListener CommandQueue instance.
- */
- private CommandQueue createCommandQueue(ConfigTree config) {
+ } // ________________________________
+
+ /**
+ * Factory method for creating the command queue.
+ *
+ * @param config
+ * GatewayListener config.
+ * @return GatewayListener CommandQueue instance.
+ */
+ private CommandQueue createCommandQueue(ConfigTree config)
+ {
String commandQueueClass = config.getAttribute("command-queue-class");
-
- if(commandQueueClass != null) {
- try {
- return (CommandQueue) Class.forName(commandQueueClass).newInstance();
- } catch (Exception e) {
- _logger.error("Failed to instantiate CommandQueue ["+ commandQueueClass + "]. Defaulting to no Command Queue", e);
+
+ if (commandQueueClass != null)
+ {
+ try
+ {
+ return (CommandQueue) Class.forName(commandQueueClass)
+ .newInstance();
}
+ catch (Exception e)
+ {
+ _logger.error("Failed to instantiate CommandQueue ["
+ + commandQueueClass
+ + "]. Defaulting to no Command Queue", e);
+ }
}
-
+
return _defaultCommandQueue;
}
/**
- * Allows a default command queue to be set statically for all GatewayListener instances.
- * @param defaultCommandQueue The defaultCommandQueue to set.
+ * Allows a default command queue to be set statically for all
+ * GatewayListener instances.
+ *
+ * @param defaultCommandQueue
+ * The defaultCommandQueue to set.
*/
- public static void setDefaultCommandQueue(CommandQueue defaultCommandQueue) {
+ public static void setDefaultCommandQueue(CommandQueue defaultCommandQueue)
+ {
GatewayListenerController._defaultCommandQueue = defaultCommandQueue;
}
@@ -291,10 +327,10 @@
* end of run period expired <p/>or 2) Just sleep if there's no command
* queue to listen on
*/
- public void run()
+ public void run()
{
boolean relaunch = true;
- while (endNotRequested())
+ while (endNotRequested())
{
_status = State.Running;
@@ -304,28 +340,30 @@
waitForCmdOrSleep();
- if (endRequested()) {
+ if (endRequested())
+ {
break;
}
relaunch = false;
- if (isReloadNeeded())
- try
+ if (isReloadNeeded())
+ try
{
if (_sParametersName != null)
{
_status = State.Loading_parameters;
_logger
- .info("Reloading parameters _____________________________________________________");
- ConfigTree oNew = GatewayListenerController.getListenerConfig(_sParametersName);
+ .info("Reloading parameters _____________________________________________________");
+ ConfigTree oNew = GatewayListenerController
+ .getListenerConfig(_sParametersName);
checkParms(oNew);
_config = oNew;
relaunch = true;
}
else
checkParms(_config);
- }
- catch (Exception e)
+ }
+ catch (Exception e)
{
_logger.error("Failed to reload parameters"
+ " - Continuing with cached version", e);
@@ -339,28 +377,34 @@
.info("Finishing_____________________________________________________");
// Close the command queue...
- try
+ try
{
- if (null!=_commandQueue)
+ if (null != _commandQueue)
_commandQueue.close();
- } catch (CommandQueueException e) {
+ }
+ catch (CommandQueueException e)
+ {
_logger.error("Error closing Command Queue.", e);
}
} // ________________________________
- private void tryToLaunchGateway(ConfigTree p_oP)
+ private void tryToLaunchGateway(ConfigTree p_oP)
{
String sClass = p_oP.getAttribute(GATEWAY_CLASS_TAG);
if (Util.isNullString(sClass))
return;
- try {
+ try
+ {
Class oListener = Class.forName(sClass);
Constructor oConst = oListener.getConstructor(new Class[]
- {this.getClass(), ConfigTree.class});
- Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this, p_oP});
+ { this.getClass(), ConfigTree.class });
+ Runnable oRun = (Runnable) oConst.newInstance(new Object[]
+ { this, p_oP });
new Thread(oRun).start();
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
_logger.error("Cannot launch <" + sClass + ">\n", e);
e.printStackTrace();
}
@@ -374,18 +418,23 @@
}
} // ________________________________
- private void waitForCmdOrSleep() {
+ private void waitForCmdOrSleep()
+ {
long lToGo = millisToWait();
- if (null == _commandQueue) {
+ if (null == _commandQueue)
+ {
_logger.debug("About to sleep " + lToGo);
// No command queue nor topic - Just sleep until time
// exhausted, or thread interrupted
- try {
- while ((lToGo=millisToWait()) > 0)
+ try
+ {
+ while ((lToGo = millisToWait()) > 0)
Thread.sleep(500);
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e)
+ {
_endTime = 0; // mark as end requested and return
}
return;
@@ -393,19 +442,26 @@
// 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 {
- _logger.info("Waiting for command ... timeout=" + lToGo + " millis");
+ while ((lToGo = millisToWait()) > 0)
+ {
+ try
+ {
+ _logger.info("Waiting for command ... timeout=" + lToGo
+ + " millis");
String oM = _commandQueue.receiveCommand(lToGo);
- if (null == oM) {
+ if (null == oM)
+ {
return;
}
processCommand(oM);
- if (endRequested() || isReloadNeeded()) {
+ if (endRequested() || isReloadNeeded())
+ {
break;
}
- } catch (CommandQueueException eJ) {
+ }
+ catch (CommandQueueException eJ)
+ {
_logger.info("receive on command queue failed", eJ);
}
}
@@ -413,8 +469,7 @@
/**
* Processes the command that has been received in the command queue (or
- * topic) <p/>_endRequested, _reloadRequested, and _endTime could be
- * changed
+ * topic) <p/>_endRequested, _reloadRequested, and _endTime could be changed
*
* <p/> <p/><TABLE border="1"> <COLGROUP> <COL width="200"/> <COL
* width="400"/> </COLGROUP>
@@ -443,32 +498,38 @@
* Message received from the command queue.
*
*/
- private void processCommand(String sTxt) {
+ private void processCommand(String sTxt)
+ {
if (null == sTxt)
return;
-
+
String sLow = sTxt.trim().toLowerCase();
- if (sLow.startsWith("shutdown")) {
+ if (sLow.startsWith("shutdown"))
+ {
_endRequested = true;
_logger.info("Shutdown has been requested");
return;
}
- if (sLow.startsWith("reload param")) {
+ if (sLow.startsWith("reload param"))
+ {
_reloadRequested = true;
- _logger
- .info("Request for parameter reload has been received");
+ _logger.info("Request for parameter reload has been received");
return;
}
String[] sa = sLow.split("\\s+");
- if (sa.length > 1 && "endtime".equals(sa[0])) {
- try {
+ 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 = _dateFormat.parse(sDate + " " + sTime);
_logger.info("New end date set to : " + oEnd);
_endTime = oEnd.getTime();
- } catch (Exception eDat) {
+ }
+ catch (Exception eDat)
+ {
_logger.info("Problems with endTime command", eDat);
}
}
@@ -480,14 +541,17 @@
* @return boolean if processing has to stop (all child threads will be
* allowed to finish)
*/
- public boolean endRequested() {
+ public boolean endRequested()
+ {
return _endRequested || System.currentTimeMillis() >= _endTime;
}
- public void requestEnd() {
- _endRequested=true;
+ public void requestEnd()
+ {
+ _endRequested = true;
_endTime = 0;
}
+
/**
* Accessor to determine if execution time is not expired, and no shutdown
* request received
@@ -495,7 +559,8 @@
* @return boolean - true if run time has not expired and quiesce has not
* been requested
*/
- public boolean endNotRequested() {
+ public boolean endNotRequested()
+ {
return !endRequested();
}
@@ -517,28 +582,27 @@
// Still not time to reload
if (System.currentTimeMillis() < _nextReload)
return false;
-
- if (null==_sParametersName)
+
+ if (null == _sParametersName)
return refreshNextReload();
-
+
File paramFile = new File(_sParametersName);
- if (! paramFile.exists())
+ if (!paramFile.exists())
return refreshNextReload();
-
-// check the TS on the file.
- Long previousTimeStamp = _paramFileTimeStamps.get(_sParametersName);
- if (null==previousTimeStamp)
+
+ // check the TS on the file.
+ Long previousTimeStamp = _paramFileTimeStamps.get(_sParametersName);
+ if (null == previousTimeStamp)
return refreshNextReload();
-
- Long currentTimeStamp = paramFile.lastModified();
- if (! previousTimeStamp.equals(currentTimeStamp))
+ Long currentTimeStamp = paramFile.lastModified();
+ if (!previousTimeStamp.equals(currentTimeStamp))
return refreshNextReload();
setNextReloadTime(_config);
return false;
}
-
+
private boolean refreshNextReload()
{
setNextReloadTime(_config);
@@ -552,7 +616,8 @@
* @return boolean - true if runtime is not expired and not time yet to
* reload parameters
*/
- public boolean continueLooping() {
+ public boolean continueLooping()
+ {
return (endNotRequested() && !isReloadNeeded());
} // ________________________________
@@ -571,136 +636,183 @@
* supplied by invoker
*/
public String obtainAtt(ConfigTree p_oP, String p_sAtt, String p_sDefault)
- throws ConfigurationException {
+ throws ConfigurationException
+ {
String sVal = p_oP.getAttribute(p_sAtt);
if ((null == sVal) && (null == p_sDefault))
- throw new ConfigurationException("Missing or invalid <" + p_sAtt + "> attribute");
+ throw new ConfigurationException("Missing or invalid <" + p_sAtt
+ + "> attribute");
return (null != sVal) ? sVal : p_sDefault;
} // ________________________________
private static EPRManager getEprManager()
{
- PropertyManager manager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE);
- String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,".");
+ PropertyManager manager = ModulePropertyManager
+ .getPropertyManager(ModulePropertyManager.CORE_MODULE);
+ String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,
+ ".");
return EPRManager.getInstance(sDir);
}
-
- public Collection<EPR> getEprs (String category, String name) throws RegistryException
+
+ public Collection<EPR> getEprs(String category, String name)
+ throws RegistryException
{
if ("eprManager".equals(category))
{
- Collection<EPR>ret = new ArrayList<EPR>();
- try
- {
- ret.add(getEprManager().loadEPR(name));
+ Collection<EPR> ret = new ArrayList<EPR>();
+ try
+ {
+ ret.add(getEprManager().loadEPR(name));
return ret;
}
- catch(IOException e) {throw new RegistryException("No EPRs found for <"+category+"><"+name+">");}
+ catch (IOException e)
+ {
+ throw new RegistryException("No EPRs found for <" + category
+ + "><" + name + ">");
+ }
}
-
+
Registry reg = RegistryFactory.getRegistry();
RegistryException eReg = null;
- for (int i1=0; i1<5; i1++)
+ for (int i1 = 0; i1 < 5; i1++)
{
- try { return reg.findEPRs(category, name); }
- catch(RegistryException e)
+ try
{
- if (null==eReg)
+ return reg.findEPRs(category, name);
+ }
+ catch (RegistryException e)
+ {
+ if (null == eReg)
eReg = e;
- try { Thread.sleep(500); }
- catch (InterruptedException eInt) { break; }
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException eInt)
+ {
+ break;
+ }
}
}
throw eReg;
}
-
+
/**
* @deprecated use register (ConfigTree config, EPR address) instead.
* @param name
* @param address
*/
- public void register (String name, EPR address)
+ public void register(String name, EPR address)
{
- try { getEprManager().saveEPR(name,address); }
+ try
+ {
+ getEprManager().saveEPR(name, address);
+ }
catch (IOException e)
{
- _logger.fatal("Cannot register service",e);
+ _logger.fatal("Cannot register service", e);
}
} // ________________________________
+
/**
- * @deprecated use unRegister (String serviceCategoryName, String serviceName, EPR epr) instead.
+ * @deprecated use unRegister (String serviceCategoryName, String
+ * serviceName, EPR epr) instead.
* @param name
*/
- public void unRegister (String name)
+ public void unRegister(String name)
{
- try { getEprManager().removeEPR(name); }
+ try
+ {
+ getEprManager().removeEPR(name);
+ }
catch (IOException e)
{
- _logger.fatal("Cannot un-register service",e);
+ _logger.fatal("Cannot un-register service", e);
}
} // ________________________________
+
/**
* Register an EPR in the registry.
*
- * @param config - a config tree containing the deployment-configuration of the service.
- * @param epr - the epr (EndPoint Reference) of the service.
+ * @param config -
+ * a config tree containing the deployment-configuration of the
+ * service.
+ * @param epr -
+ * the epr (EndPoint Reference) of the service.
*
* @throws RegistryException
*/
- public void register(ConfigTree config , EPR epr) throws RegistryException
+ public void register(ConfigTree config, EPR epr) throws RegistryException
{
- String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
- String serviceName = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ String serviceCategoryName = config
+ .getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+ String serviceName = config
+ .getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
if ("eprManager".equalsIgnoreCase(serviceCategoryName))
{
- register(serviceName,epr);
- return;
+ register(serviceName, epr);
+ return;
}
- String serviceDescription = config.getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
- String eprDescription = config.getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
+ String serviceDescription = config
+ .getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
+ String eprDescription = config
+ .getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
Registry registry = RegistryFactory.getRegistry();
- registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription);
+ registry.registerEPR(serviceCategoryName, serviceName,
+ serviceDescription, epr, eprDescription);
}
+
/**
* Unregister the EPR from the registry.
*
- * @param serviceCategoryName - name of the category of the service ('Content Based Routing')
- * @param serviceName - name of the service ("
+ * @param serviceCategoryName -
+ * name of the category of the service ('Content Based Routing')
+ * @param serviceName -
+ * name of the service ("
* @param epr
* @throws RegistryException
*/
- public void unRegister(String serviceCategoryName, String serviceName , EPR epr) throws RegistryException
+ public void unRegister(String serviceCategoryName, String serviceName,
+ EPR epr) throws RegistryException
{
if ("eprManager".equalsIgnoreCase(serviceCategoryName))
{
- unRegister(serviceName);
- return;
+ unRegister(serviceName);
+ return;
}
Registry registry = RegistryFactory.getRegistry();
registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
}
+ private CommandQueue _commandQueue;
- private CommandQueue _commandQueue;
- private static CommandQueue _defaultCommandQueue = null;
+ private static CommandQueue _defaultCommandQueue = null;
- private static Logger _logger = Logger.getLogger(GatewayListenerController.class);
- private String _sParametersName;
- private ConfigTree _config;
- private boolean _reloadRequested;
- private boolean _endRequested;
- private long _nextReload = Long.MAX_VALUE;
- private long _endTime = Long.MAX_VALUE;
- protected int _defaultReloadMillis = 180000; // default interval between parameter reloads
+ private static Logger _logger = Logger
+ .getLogger(GatewayListenerController.class);
+ private String _sParametersName;
- public static final SimpleDateFormat _dateFormat
- = new SimpleDateFormat("yyyyMMdd hh:mm:ss");
+ private ConfigTree _config;
+ private boolean _reloadRequested;
+
+ private boolean _endRequested;
+
+ private long _nextReload = Long.MAX_VALUE;
+
+ private long _endTime = Long.MAX_VALUE;
+
+ protected int _defaultReloadMillis = 180000; // default interval between
+ // parameter reloads
+
+ public static final SimpleDateFormat _dateFormat = new SimpleDateFormat(
+ "yyyyMMdd hh:mm:ss");
+
private State _status = null;
- private Object _synchReload = new Short((short)0);
+ private Object _synchReload = new Short((short) 0);
private HashMap<String, Object> _attributes;
} // ____________________________________________________________________________
Modified: labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java 2007-01-17 14:41:14 UTC (rev 8881)
+++ labs/jbossesb/workspace/mlittle/harden/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java 2007-01-17 14:47:16 UTC (rev 8882)
@@ -23,11 +23,15 @@
package org.jboss.soa.esb.listeners.gateway;
import java.io.File;
+import java.io.IOException;
+import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.util.FtpClientUtil;
import org.jboss.soa.esb.util.RemoteFileSystem;
+import org.jboss.soa.esb.util.RemoteFileSystemException;
import org.jboss.soa.esb.util.RemoteFileSystemFactory;
public class RemoteGatewayListener extends FileGatewayListener
@@ -37,25 +41,37 @@
}
public RemoteGatewayListener(GatewayListenerController commandListener,
- ConfigTree config) throws Exception
+ ConfigTree config) throws ConfigurationException, RegistryException, GatewayException
{
super(commandListener, config);
}
- protected void checkMyParms() throws Exception
+ protected void checkMyParms() throws RegistryException, GatewayException, ConfigurationException
{
super.checkMyParms();
- File temp = File.createTempFile("FTPdown", ".tmp");
- temp.delete();
- String localDir = temp.getParent();
- if (null==localDir)
- localDir=new File("").getAbsolutePath();
- _config.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, localDir);
- final String remoteDir = _config.getAttribute(ListenerTagNames.FILE_INPUT_DIR_TAG) ;
- _config.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR, remoteDir);
- RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(
- _config, true);
- rfs.quit();
+
+ try
+ {
+ File temp = File.createTempFile("FTPdown", ".tmp");
+ temp.delete();
+ String localDir = temp.getParent();
+ if (null==localDir)
+ localDir=new File("").getAbsolutePath();
+ _config.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, localDir);
+ final String remoteDir = _config.getAttribute(ListenerTagNames.FILE_INPUT_DIR_TAG) ;
+ _config.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR, remoteDir);
+ RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(
+ _config, true);
+ rfs.quit();
+ }
+ catch (IOException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
+ catch (RemoteFileSystemException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
}
@Override
More information about the jboss-svn-commits
mailing list