[jboss-svn-commits] JBL Code SVN: r6813 - labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Oct 15 21:50:51 EDT 2006


Author: estebanschifman
Date: 2006-10-15 21:50:48 -0400 (Sun, 15 Oct 2006)
New Revision: 6813

Modified:
   labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ActionProcessingPipeline.java
   labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/JmsQueueListener.java
   labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ListenerPropertyNames.java
Log:
Still working on them - Not ready yet

Modified: labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ActionProcessingPipeline.java	2006-10-15 23:25:08 UTC (rev 6812)
+++ labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ActionProcessingPipeline.java	2006-10-16 01:50:48 UTC (rev 6813)
@@ -23,7 +23,8 @@
          
     /**
      * public constructor
-     * @param message Message - The initial message to be run through the action class chain
+     * @param message Message - The initial message to be run through the whole action 
+     * class chain
      */
     public ActionProcessingPipeline(Message message)
     	throws ConfigurationException
@@ -45,9 +46,18 @@
      */
     public Message getMessage()     { return _message; }
 
-    /* (non-Javadoc)
-     * @see java.lang.Runnable#run()
-     */
+    /**
+     * Implement Runnable Interface
+     * <p/>Uses reflection to instantiate action classes that must have a public constructor
+     * that takes a single ConfigTree as argument
+     * <p/>Requires each action class to have a public method that takes a Message and returns a Message
+     * <br/>Default name for it is 'process'  but can optionally be defined in the 'process' attribute
+     * of the corresponding &lt;action&gt; element of the ConfigTree
+     * <p/>Each &lt;action&gt; element can optionally define a method (taking a Message argument) to be 
+     * called upon successful completion of the action class (that step of the chain)
+     * <br/>Default name for it is 'process'  but can optionally be defined in the 'process' attribute
+     * <p/>See actionClassException and actionClassFinishedOk
+     * */
     public void run()
     {
         try
@@ -58,19 +68,22 @@
             {
             	_currentIndex++;
             	_currentAction = oCurr.getAttribute("class");
+            	
+            	String sProcessMethod = obtainAttribute(oCurr,"process","process");
 
-            	Class oClass = Class.forName(_currentAction);
-            	Constructor oConst = oClass.getConstructor(new Class[] {ConfigTree.class});
-            	Object currentProcessor = oConst.newInstance(_config);            	
-            	Method method = oClass.getMethod("process",new Class[] {Message.class});
+            	_currentClass = Class.forName(_currentAction);
+            	Constructor oConst = _currentClass.getConstructor(new Class[] {ConfigTree.class});
+            	_currentProcessor = oConst.newInstance(_config);            	
+            	Method method = _currentClass.getMethod(sProcessMethod,new Class[] {Message.class});
             	
             	// The processing result of each action feeds into the processing of the next action...
                 try 
                 {
                 	// copy currentObject in Message body to 'previous' currentObject
                 	ActionUtils.copyCurrentToPrevious(_message);
-                	Message next = (Message)method.invoke(currentProcessor,new Object[] {_message} );
-                    actionClassFinishedOk(next);
+                	Message next = (Message)method.invoke(_currentProcessor,new Object[] {_message} );
+                	
+                    actionClassFinishedOk(oCurr);
                     if(next==null)
                     {
                     	_logger.error(prematureTermination("returned <null> - Cannot continue"));
@@ -86,7 +99,7 @@
                 catch (Exception e)
                 {
                 	// If action class threw exception, log and abort chain
-                    actionClassException(e);
+                    actionClassException(oCurr,e);
                     return;
                 }
             }
@@ -115,15 +128,47 @@
 		;
     }
     
-    protected void actionClassException(Throwable thr)
+    /**
+     * If 'current' action step was configured with a 'exceptionMethod' attribute
+     * that method will be called with a single argument of type Exception 
+     * @param tree ConfigTree - where to look for the exceptionMetod attribute
+     * @param thr Exception - to be used in invocation to method (if found)
+     */
+    protected void actionClassException(ConfigTree tree, Exception thr)
     {
     	thr.printStackTrace();
+    	String sMethod = obtainAttribute(tree,"exceptionMethod",null);
+    	if (null!=sMethod)
+	    	try
+	    	{
+	    		Method method = _currentClass.getMethod(sMethod,new Class[] {Exception.class});
+	    		method.invoke(_currentProcessor,new Object[] {thr} );
+	    	}
+	    	catch (NoSuchMethodException e) 	{_logger.error(e); }
+	    	catch (InvocationTargetException e) {_logger.error(e); }
+	    	catch (IllegalAccessException e) 	{_logger.error(e); }
     }
 
-    protected void actionClassFinishedOk(Message message)
+    /**
+     * If 'current' action step was configured with an 'okMethod' attribute
+     * that method will be called with no arguments 
+     * @param tree ConfigTree - where to look for the okMetod attribute
+     */
+    protected void actionClassFinishedOk(ConfigTree tree)
     {
+    	String sMethod = obtainAttribute(tree,"okMethod",null);
+    	if (null!=sMethod)
+	    	try
+	    	{
+	    		Method method = _currentClass.getMethod(sMethod,new Class[] {});
+	    		method.invoke(_currentProcessor,new Object[] {} );
+	    	}
+	    	catch (NoSuchMethodException e) 	{_logger.error(e); }
+	    	catch (InvocationTargetException e) {_logger.error(e); }
+	    	catch (IllegalAccessException e) 	{_logger.error(e); }
     }
 
+    //TODO  What do we do here ?  Is this really necessary ?  Or do we do it in the last action class ?
     protected void actionChainFinishedOk()
     {
     }
@@ -137,9 +182,17 @@
     	return sa;
     }
     
+    private static String obtainAttribute(ConfigTree tree,String p_sAtt, String p_sDefault)
+	{
+		String sVal = tree.getAttribute(p_sAtt);
+		return (null != sVal) ? sVal : p_sDefault;
+	} // ________________________________
+	
     protected ConfigTree[]	_actionList;
     protected int			_currentIndex;
     protected String		_currentAction;
+    protected Class 		_currentClass;
+    protected Object		_currentProcessor;
 	protected Message		_message;
 	protected ConfigTree	_config;
 	protected Logger		_logger = Logger.getLogger(this.getClass());		

Modified: labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/JmsQueueListener.java
===================================================================
--- labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/JmsQueueListener.java	2006-10-15 23:25:08 UTC (rev 6812)
+++ labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/JmsQueueListener.java	2006-10-16 01:50:48 UTC (rev 6813)
@@ -39,6 +39,7 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.actions.ActionUtils;
 import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+import org.jboss.soa.esb.addressing.EPR;
 
 /**
  * Esb Message aware JMS queue listener.
@@ -54,8 +55,14 @@
 
 public class JmsQueueListener implements Runnable 
 {
+	/**
+	 * public constructor
+	 * @param controller EsbListenerController - the controlling process
+	 * @param config ConfigTree - Containing 'static' configuration for this instance
+	 * @throws Exception
+	 */
     public JmsQueueListener(EsbListenerController controller, ConfigTree config) 
-    	throws Exception 
+    	throws ConfigurationException 
     {
     	_controller			= controller;
     	_config				= config;
@@ -71,7 +78,9 @@
      */
     public void run()
     {
-        while (_controller.continueLooping())
+    	// TODO  Register 'this' servicing _epr
+
+    	while (_controller.continueLooping())
         {
         	org.jboss.soa.esb.message.Message message = receiveEsbMessage(_controller.millisToWait());
         	if (null!=message)
@@ -89,6 +98,9 @@
         		new Thread(chain).start();
         	}
         }
+
+    	// TODO  UN Register 'this' servicing _epr
+
     } // _______________________________
 
     /**
@@ -98,11 +110,20 @@
      *             if mandatory atts are not right or actionClass not in
      *             classpath
      */
-    protected void checkMyParms() throws Exception 
+    protected void checkMyParms() throws ConfigurationException 
     {
-        // Third arg is null - Exception will br thrown if listenQueue is not found
-        String sQueue = obtainAttribute	(JMSEpr.DESTINATION_NAME_TAG, null);
+        // Default value of obtainAttribute is null - Exception will be thrown
+        String sQueue	= obtainAttribute(JMSEpr.DESTINATION_NAME_TAG, null);
 
+/*
+        String sEpr		= obtainAttribute(ListenerPropertyNames.EPR_NAME,null);       
+        try { _epr	= EPRManager.getInstance("myDir").loadEPR(sEpr); }
+        catch (IOException e) 
+        {
+        	_logger.error(e);
+        	throw new ConfigurationException("Problems loading EPR",e);
+        }
+*/
         // No problem if selector is null - everything in queue will be returned
         _sSelector = _config.getAttribute(ListenerPropertyNames.MESSAGE_SELECTOR);
 
@@ -115,15 +136,21 @@
         Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
 
         String sFactClass = obtainAttribute(JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
-        Object tmp = oJndiCtx.lookup(sFactClass);
-        QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+        Exception thrown = null;
+        try
+        {
+        	Object tmp = oJndiCtx.lookup(sFactClass);
+        	QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
 
-        _oQconn = qcf.createQueueConnection();
-        _oQueue = (Queue) oJndiCtx.lookup(sQueue);
-        _oQsess = _oQconn.createQueueSession(false,
-                TopicSession.AUTO_ACKNOWLEDGE);
-        _oQconn.start();
-        _receiver = _oQsess.createReceiver(_oQueue, _sSelector);
+        	_oQconn = qcf.createQueueConnection();
+        	_oQueue = (Queue) oJndiCtx.lookup(sQueue);
+        	_oQsess = _oQconn.createQueueSession(false,TopicSession.AUTO_ACKNOWLEDGE);
+        	_oQconn.start();
+        	_receiver = _oQsess.createReceiver(_oQueue, _sSelector);
+        }
+        catch (javax.naming.NamingException e)	{ thrown = e; }
+        catch (JMSException e) 					{ thrown = e; }
+        throw new ConfigurationException(thrown);
 
     } // ________________________________
 
@@ -197,6 +224,7 @@
 
 	protected EsbListenerController _controller;
     protected ConfigTree		_config;
+    protected EPR				_epr;
     protected MessageConsumer 	_receiver;
     protected boolean 			_bError = false;
     protected QueueConnection	_oQconn;

Modified: labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ListenerPropertyNames.java
===================================================================
--- labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ListenerPropertyNames.java	2006-10-15 23:25:08 UTC (rev 6812)
+++ labs/jbossesb/workspace/eschifman/trunk/product/core/listeners/src/org/jboss/soa/esb/message/listeners/ListenerPropertyNames.java	2006-10-16 01:50:48 UTC (rev 6813)
@@ -2,6 +2,7 @@
 
 public class ListenerPropertyNames 
 {
+	public static final String EPR_NAME			= "epr-name";
 	public static final String CONSUMER_TYPE	= "consumer-type";
 	public static final String JNDI_TYPE		= "jndi-type";
     public static final String JNDI_URL 		= "jndi-URL";




More information about the jboss-svn-commits mailing list