[jboss-svn-commits] JBL Code SVN: r10268 - in labs/jbossesb/trunk/product/core/listeners: src/org/jboss/soa/esb/actions/converters and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Mar 16 12:04:37 EDT 2007


Author: tfennelly
Date: 2007-03-16 12:04:37 -0400 (Fri, 16 Mar 2007)
New Revision: 10268

Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ActionLifecycle.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java
Log:
Added action lifecycle management to the SmooksTransformer.  Fixes http://jira.jboss.com/jira/browse/JBESB-475

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ActionLifecycle.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ActionLifecycle.java	2007-03-16 15:39:10 UTC (rev 10267)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ActionLifecycle.java	2007-03-16 16:04:37 UTC (rev 10268)
@@ -26,7 +26,7 @@
  * <p/>
  * Actions implementing this interface will participate in the application
  * lifecycle and should not contain any state specific to a particular message
- * instance.  Each {@link ActionProcessingPipeline} will instantiate a single
+ * instance.  Each {@link org.jboss.soa.esb.listeners.message.ActionProcessingPipeline} will instantiate a single
  * instance of the action to process all messages passing through the pipeline.  
  *  
  * @author kevin

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java	2007-03-16 15:39:10 UTC (rev 10267)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java	2007-03-16 16:04:37 UTC (rev 10268)
@@ -46,9 +46,7 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.actions.ActionProcessor;
-import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.*;
 import org.jboss.soa.esb.common.Configuration;
 import org.jboss.soa.esb.common.ModulePropertyManager;
 import org.jboss.soa.esb.helpers.ConfigTree;
@@ -103,7 +101,7 @@
  * @since Version 4.0
  */
 
-public class SmooksTransformer implements TransformationService, ActionProcessor {
+public class SmooksTransformer implements TransformationService, ActionPipelineProcessor {
 
 	/**
 	 * Configuration section key.
@@ -126,20 +124,19 @@
 	public static final String TO_TYPE = "to-type";
 	
     private static Logger logger = Logger.getLogger(SmooksTransformer.class);
-    private static volatile SmooksStandalone smooks;
-    @SuppressWarnings("unused")
-	private static ConfigurationUpdateListener updateListener = new ConfigurationUpdateListener();
+    private SmooksStandalone smooks;
+	private ConfigurationUpdateListener updateListener;
     private String defaultMessageFromType;
     private String defaultMessageFrom;
     private String defaultMessageToType;
     private String defaultMessageTo;
     private boolean setPayloadToBeanHash = false;
-    
+    private List<KeyValuePair> properties;
+
     /**
      * Public constructor.
-     * @param actionName Action name.
+     * @param name Action name.
      * @param propertiesTree Action Properties.
-     * @throws ConfigurationException 
      * @throws ConfigurationException Action not properly configured.
      */
 	public SmooksTransformer(String name, ConfigTree propertiesTree) throws ConfigurationException {
@@ -153,7 +150,7 @@
      * @throws ConfigurationException Action not properly configured.
      */
 	public SmooksTransformer(ConfigTree propertiesTree) throws ConfigurationException {
-		List<KeyValuePair> properties = propertiesTree.attributesAsList();
+		properties = propertiesTree.attributesAsList();
 
 		// Get the message flow properties...
 		defaultMessageFromType = KeyValuePair.getValue(FROM_TYPE, properties);
@@ -176,9 +173,7 @@
 		// Get the set-beanhash-to-payload property...
 		setPayloadToBeanHash = KeyValuePair.getBooleanValue(SET_BEANHASH_TO_PAYLOAD, properties, false);
         
-        if(smooks == null) {
-        	initSmooks(properties);
-        }
+        updateListener = new ConfigurationUpdateListener(this);
 	}
 
 	/* (non-Javadoc)
@@ -259,7 +254,7 @@
     	return message;
     }
 
-	/**
+    /**
 	 * Register the Message Exchange as a useragent within Smooks.
 	 * @param message The message.
 	 * @return The Smooks "usragent" string that uniquely identifies the message flow associated
@@ -362,81 +357,66 @@
 		return string.toString();
 	}
 
-	/* (non-Javadoc)
-     * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
-     */
-    public Serializable getOkNotification(Message message) {
-        return null;
+    public void processException(final Message message, final Exception ex) {
     }
 
-    /* (non-Javadoc)
-     * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
-     */
-    public Serializable getErrorNotification(Message message) {
-        return null;
+    public void processSuccess(final Message message) {
     }
 
     /**
-     * Initialise the static SmooksStandalone instance.
+     * Initialise the SmooksStandalone instance.
      * <p/>
      * We may need to write a Smooks Container implementation specifically for JBossESB's needs.  SmooksStandalone is
      * fine for a start though.
-     * @param properties Action configuration properties.
-     * @throws ConfigurationException Failed to load Smooks configurations.
+     * @throws ActionLifecycleException Failed to load Smooks configurations.
      */
-    protected void initSmooks(List<KeyValuePair> properties) throws ConfigurationException {
-        synchronized (SmooksTransformer.class) {
-            if(smooks == null) {
-                String smooksCdrlFile;
-                SmooksStandalone localSmooksRef;
-                InputStream configListStream;
+    public void initialise() throws ActionLifecycleException {
+        String smooksCdrlFile;
+        InputStream configListStream;
 
-                // Get the configuration list file - can be overridden through a system property...
-                smooksCdrlFile = ModulePropertyManager.getPropertyManager(CONFIGURATION_SECTION).getProperty("configuration.list.file.uri", "classpath:/smooks-cdr.lst");
-                try {
-					configListStream = (new URIResourceLocator()).getResource(smooksCdrlFile);
-				} catch (IOException e) {
-                    throw new ConfigurationException("Failed to locate Tranformation configuration list file [" + smooksCdrlFile + "].  This resource must be made available at the specified URI.", e);
-				}
-                if(configListStream == null) {
-                    throw new ConfigurationException("Failed to locate Tranformation configuration list file [" + smooksCdrlFile + "].  This resource must be made available at the specified URI.");
-                }
-           
-                // Initialise the local SmooksStandalone instance.  This "local" reference is
-                // used because we are using on the "global" smooks variable reference to controll
-                // access to this synchronisation block ...
-                localSmooksRef = new SmooksStandalone("UTF-8");
-                
-                try {
-                    BufferedReader configReader = new BufferedReader(new InputStreamReader(configListStream));
-                    localSmooksRef.getContext().getStore().load(configReader);
-                } catch (Exception e) {
-                	localSmooksRef = null;
-                    throw new ConfigurationException("Smooks configuration load failed.", e);
-                } finally {
-                	try {
-						configListStream.close();
-					} catch (IOException e) {
-						logger.error("Error while closing transformation list config stream [" + smooksCdrlFile + "].", e);
-					}
-                }
-                
-                logger.info("All Smooks configurations are now loaded.");
-                
-                // Purposely not initialising the "smooks" static member until the very end.  This will stop other threads
-                // falling through this classes constructor while the Smooks configurations are still being
-                // loaded.  See the constructor.
-                smooks = localSmooksRef;
+        // Get the configuration list file - can be overridden through a system property...
+        smooksCdrlFile = ModulePropertyManager.getPropertyManager(CONFIGURATION_SECTION).getProperty("configuration.list.file.uri", "classpath:/smooks-cdr.lst");
+        try {
+            configListStream = (new URIResourceLocator()).getResource(smooksCdrlFile);
+        } catch (IOException e) {
+            throw new ActionLifecycleException("Failed to locate Tranformation configuration list file [" + smooksCdrlFile + "].  This resource must be made available at the specified URI.", e);
+        }
+        if(configListStream == null) {
+            throw new ActionLifecycleException("Failed to locate Tranformation configuration list file [" + smooksCdrlFile + "].  This resource must be made available at the specified URI.");
+        }
+
+        // Initialise the local SmooksStandalone instance.  This "local" reference is
+        // used because we are using on the "global" smooks variable reference to controll
+        // access to this synchronisation block ...
+        smooks = new SmooksStandalone("UTF-8");
+
+        try {
+            BufferedReader configReader = new BufferedReader(new InputStreamReader(configListStream));
+            smooks.getContext().getStore().load(configReader);
+        } catch (Exception e) {
+            smooks = null;
+            throw new ActionLifecycleException("Smooks configuration load failed.", e);
+        } finally {
+            try {
+                configListStream.close();
+            } catch (IOException e) {
+                logger.error("Error while closing transformation list config stream [" + smooksCdrlFile + "].", e);
             }
         }
+
+        logger.info("All Smooks configurations are now loaded.");
     }
+
+    public void destroy() throws ActionLifecycleException {
+        updateListener.close();
+    }
     
     /**
      * Reset the transformer.
      * <p/>
      * Clears the internal static smooks instance.
      */
-    public static void reset() {
+    public void reset() {
     	SmooksStandalone instance = smooks;
     	
         synchronized (SmooksTransformer.class) {
@@ -445,7 +425,7 @@
         	}
         }
     }
-    
+
     /**
      * JMS Listener for receiving configuration update notifications.
      * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
@@ -455,8 +435,13 @@
     	private TopicConnection conn = null;
     	private TopicSession session = null;
     	private Topic topic = null;
+        private SmooksTransformer transformer;
 
-    	/**
+        public ConfigurationUpdateListener(SmooksTransformer transformer) {
+            this.transformer = transformer;
+        }
+
+        /**
     	 * Private constructor.
     	 * <p/>
     	 * Connects the listener to the topic.
@@ -477,7 +462,7 @@
 		public void onMessage(javax.jms.Message message) {
 			// Reset the transformer instance so as to force a config reload.
 			logger.info("Transformation configuration update notification received.  Resetting SmooksTransformer in order to force a configuration re-read.");
-			SmooksTransformer.reset();
+			transformer.reset();
 		}    	
 
 		/**

Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java	2007-03-16 15:39:10 UTC (rev 10267)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/SmooksTransformerUnitTest.java	2007-03-16 16:04:37 UTC (rev 10268)
@@ -29,6 +29,7 @@
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.actions.ActionProcessingException;
 import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.ActionLifecycleException;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.format.MessageFactory;
@@ -40,11 +41,6 @@
  */
 public class SmooksTransformerUnitTest extends TestCase {
 
-    @Override
-    protected void setUp() throws Exception {
-        SmooksTransformer.reset();
-    }
-
     public void test_bad_config() {
     	ConfigTree properties = new ConfigTree("name");
 
@@ -56,7 +52,7 @@
         assertConfigException(properties, "Empty '" + SmooksTransformer.TO_TYPE + "' config attribute supplied.");
     }
 
-    public void test_trans() throws ActionProcessingException, ConfigurationException, URISyntaxException {
+    public void test_trans() throws ActionProcessingException, ConfigurationException, URISyntaxException, ActionLifecycleException {
         String stringMessage;
         String transRes;
         
@@ -75,7 +71,7 @@
         assertEquals("<x><c>value</c></x>", transRes);
     }
     
-    private String transform(String stringMessage, String fromType, String from, String to, String toType) throws ActionProcessingException, ConfigurationException, URISyntaxException {
+    private String transform(String stringMessage, String fromType, String from, String to, String toType) throws ActionProcessingException, ConfigurationException, URISyntaxException, ActionLifecycleException {
         ConfigTree properties = new ConfigTree("name");
 
         // Set the message properties in order to trigger the appropriate transformations
@@ -89,7 +85,9 @@
         // test src folder.  You need to look at these to see how this works...
         SmooksTransformer transformer = new SmooksTransformer(properties);
         Message message;
-        
+
+        transformer.initialise();
+
         // Perform the transformation by setting the payload on the task object.
         message = createNewMessage(fromType, from, to, toType);
         ActionUtils.setTaskObject(message, stringMessage);




More information about the jboss-svn-commits mailing list