[jboss-svn-commits] JBL Code SVN: r23393 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta: src/org/jboss/soa/esb/listeners and 9 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 9 09:52:21 EDT 2008


Author: kevin.conner at jboss.com
Date: 2008-10-09 09:52:20 -0400 (Thu, 09 Oct 2008)
New Revision: 23393

Added:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractScheduledManagedLifecycle.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJob.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJobListener.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerResource.java
Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ScheduleListener.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ESBAwareGenerator.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Generator.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/ScheduleMapper.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduleProvider.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/quartz.properties
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/build.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ScheduledListenerUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/scheduled-listener-config-configtree.xml
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/schedule/expected-config-01-listener.xml
Log:
Update scheduled listeners: JBESB-2046

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -37,6 +37,11 @@
     public static final int RULE_BASE_PRIORITY = 50000;
     
     /**
+     * The scheduler priority.
+     */
+    public static final int SCHEDULE_RESOURCE_PRIORITY = 70000 ;
+    
+    /**
      * The service message counter priority.
      */
     public static final int SERVICE_MESSAGE_COUNTER_PRIORITY = 75000 ;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -26,6 +26,8 @@
 package org.jboss.soa.esb.listeners;
 
 import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
+import org.jboss.soa.esb.listeners.config.ScheduleProviderFactory;
+import org.jboss.soa.esb.schedule.ScheduleProvider;
 
 public class ListenerTagNames
 {
@@ -147,4 +149,14 @@
 
     /** Reply Listener */
     public static final String REPLY_LISTENER_TIMEOUT_TAG   = "replyListenerTimeout";
+
+    /** Scheduled listeners */
+    public static final String SCHEDULE_ID_REF = "scheduleidref" ; // taken from ScheduleProviderFactory
+    public static final String SCHEDULE_FREQUENCY = "schedule-frequency" ; // taken from ScheduleProviderFactory
+    public static final String SCHEDULE_START_DATE = "scheduleStartDate" ;
+    public static final String SCHEDULE_END_DATE = "scheduleEndDate" ;
+    public static final String SCHEDULE_SIMPLE_FREQUENCY = "scheduleSimpleFrequency" ;
+    public static final String SCHEDULE_SIMPLE_EXEC = "scheduleSimpleExec" ;
+    public static final String SCHEDULE_CRON_EXPRESSION = "scheduleCronExpression" ;
+    public static final String SCHEDULE_PROPERTIES = "ScheduleProperties" ;
 }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ScheduleListener.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ScheduleListener.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/ScheduleListener.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -19,25 +19,25 @@
  */
 package org.jboss.soa.esb.listeners;
 
-import org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.Initializable;
+import org.jboss.soa.esb.common.TransactionStrategy;
+import org.jboss.soa.esb.common.TransactionStrategyException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractScheduledManagedLifecycle;
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
 import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
+import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.schedule.ScheduledEventListener;
 import org.jboss.soa.esb.schedule.SchedulingException;
-import org.jboss.soa.esb.common.TransactionStrategy;
-import org.jboss.soa.esb.common.TransactionStrategyException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.Initializable;
 import org.jboss.soa.esb.util.ClassUtil;
-import org.jboss.soa.esb.message.Message;
 
 /**
  * ESB Schedule listener.
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
-public class ScheduleListener extends AbstractManagedLifecycle implements ScheduledEventListener {
+public class ScheduleListener extends AbstractScheduledManagedLifecycle {
 
     /**
      * 
@@ -136,23 +136,8 @@
         }
     }
 
-    protected void doInitialise() throws ManagedLifecycleException {
-    }
-
-    public void initialize(ConfigTree config) throws ConfigurationException {
-        // TODO Convert lifecycle code to use the Initializable interface.
-    }
-
-    public void uninitialize() {
-    }
-
-    protected void doStart() throws ManagedLifecycleException {
-    }
-
-    protected void doStop() throws ManagedLifecycleException {
-    }
-
-    protected void doDestroy() throws ManagedLifecycleException {
+    @Override
+    protected void doScheduledDestroy() throws ManagedLifecycleException {
         eventProcessor.uninitialize();
         if(pipeline != null) {
             pipeline.destroy() ;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Configuration.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -39,7 +39,6 @@
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
 import org.jboss.soa.esb.util.ClassUtil;
-import org.jboss.soa.esb.schedule.ScheduleProvider;
 import org.xml.sax.InputSource;
 
 /**
@@ -119,8 +118,6 @@
             instances.addAll(LifecycleUtil.getGateways(gatewayConfig));
 
              ManagedLifecycleController controller = new ManagedLifecycleController(instances);
-             ScheduleProvider scheduleProvider = ScheduleProviderFactory.createInstance(instances, generator.getModel().getScheduleProvider());
-             controller.setScheduleProvider(scheduleProvider);
 
              // In parallel, create a map of the contract publication info...
              ServicePublisher.addServicePublishers(controller, generator.getModel());

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ConfigurationController.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -46,7 +46,6 @@
 import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
 import org.jboss.soa.esb.parameters.ParamRepositoryException;
 import org.jboss.soa.esb.util.ClassUtil;
-import org.jboss.soa.esb.schedule.ScheduleProvider;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.xml.sax.InputSource;
@@ -359,8 +358,6 @@
         instances.addAll(LifecycleUtil.getGateways(gatewayConfig));
 
         ManagedLifecycleController lifecycleController = new ManagedLifecycleController(instances);
-        ScheduleProvider scheduleProvider = ScheduleProviderFactory.createInstance(instances, configModel.getScheduleProvider());
-        lifecycleController.setScheduleProvider(scheduleProvider);
 
         try {
             lifecycleController.start();

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ESBAwareGenerator.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ESBAwareGenerator.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/ESBAwareGenerator.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -209,7 +209,7 @@
 		}
 
         if (listener instanceof AbstractScheduledListener) {
-            ScheduleMapper.map(listenerConfigTree, (AbstractScheduledListener) listener);
+            ScheduleMapper.map(listenerConfigTree, (AbstractScheduledListener) listener, model);
         }
 
         // Locate the Service to which the listener is bound...

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -143,7 +143,7 @@
         }
 
         if (gateway instanceof AbstractScheduledListener) {
-            ScheduleMapper.map(listenerConfig, (AbstractScheduledListener) gateway);
+            ScheduleMapper.map(listenerConfig, (AbstractScheduledListener) gateway, model);
         }
     }
 }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Generator.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Generator.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/Generator.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -349,6 +349,28 @@
 			throw new IllegalStateException("No Provider instance found for the supplied Bus config instance.  This should not be possible if the Bus instance was provided by this configuration.  Where has this Bus instance come from?");
 		}
 
+        public Schedule getSchedule(final String id) {
+            if((id == null) || (jbossesb.getProviders() == null)) {
+                return null;
+            }
+
+            List<Provider> providers = jbossesb.getProviders().getProviderList();
+
+            for(Provider provider : providers) {
+                if(provider instanceof ScheduleProvider) {
+                    final ScheduleProvider scheduleProvider = (ScheduleProvider)provider ;
+                    final List<Schedule> schedules = scheduleProvider.getScheduleList() ;
+                    for(Schedule schedule: schedules) {
+                        if (id.equals(schedule.getScheduleid())) {
+                            return schedule ;
+                        }
+                    }
+                }
+            }
+
+            return null;
+        }
+
         public ScheduleProvider getScheduleProvider() {
             if(jbossesb.getProviders() == null) {
                 return null;
@@ -364,6 +386,24 @@
 
             return null;
         }
+        
+        public int getScheduledListenerCount() {
+            int count = 0 ;
+            if (jbossesb.getServices() != null) {
+                final List<Service> services = getServices() ;
+                for(Service service: services) {
+                    final ListenersDocument.Listeners listeners = service.getListeners() ;
+                    if (listeners != null) {
+                        for (Listener listener: listeners.getListenerList()) {
+                            if (listener instanceof AbstractScheduledListener) {
+                                count++ ;
+                            }
+                        }
+                    }
+                }
+            }
+            return count ;
+        }
 
         private boolean isGateway(Listener listener)
       {

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/ScheduleMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/ScheduleMapper.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/ScheduleMapper.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -19,11 +19,23 @@
  */
 package org.jboss.soa.esb.listeners.config.mappers;
 
+import java.util.List;
+
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.dom.YADOMUtil;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
 import org.jboss.soa.esb.listeners.config.Generator;
 import org.jboss.soa.esb.listeners.config.ScheduleProviderFactory;
+import org.jboss.soa.esb.listeners.config.Generator.XMLBeansModel;
 import org.jboss.soa.esb.listeners.config.xbeanmodel.AbstractScheduledListener;
+import org.jboss.soa.esb.listeners.config.xbeanmodel.FrequencyUnit;
+import org.jboss.soa.esb.listeners.config.xbeanmodel.PropertyDocument;
+import org.jboss.soa.esb.listeners.config.xbeanmodel.Schedule;
+import org.jboss.soa.esb.listeners.config.xbeanmodel.CronScheduleDocument.CronSchedule;
+import org.jboss.soa.esb.listeners.config.xbeanmodel.ScheduleProviderDocument.ScheduleProvider;
+import org.jboss.soa.esb.listeners.config.xbeanmodel.SimpleScheduleDocument.SimpleSchedule;
+import org.jboss.soa.esb.schedule.SchedulerResource;
 import org.w3c.dom.Element;
 
 /**
@@ -39,20 +51,51 @@
 
     private static Logger logger = Logger.getLogger(ScheduleMapper.class);
 
-    public static void map(Element listenerConfig, AbstractScheduledListener scheduledListener) throws ConfigurationException {
+    public static void map(Element listenerConfig, AbstractScheduledListener scheduledListener, final XMLBeansModel model) throws ConfigurationException {
         String scheduleIdRef = scheduledListener.getScheduleidref();
         Element domElement = (Element) scheduledListener.getDomNode();
-        int frequency = scheduledListener.getScheduleFrequency();
+        int scheduleFrequency = scheduledListener.getScheduleFrequency();
         int pollFrequency = scheduledListener.getPollFrequencySeconds();
         int pollLatency = getPollLatencySeconds(scheduledListener);
 
         if(scheduleIdRef != null) {
-            listenerConfig.setAttribute(ScheduleProviderFactory.ATTR_SCHEDULE_ID_REF, scheduleIdRef);
+            listenerConfig.setAttribute(ListenerTagNames.SCHEDULE_ID_REF, scheduleIdRef);
+            final Schedule schedule = model.getSchedule(scheduleIdRef) ;
+            if (schedule.isSetStartDate()) {
+                listenerConfig.setAttribute(ListenerTagNames.SCHEDULE_START_DATE, Long.toString(schedule.getStartDate().getTimeInMillis())) ;
+            }
+            if (schedule.isSetEndDate()) {
+                listenerConfig.setAttribute(ListenerTagNames.SCHEDULE_END_DATE, Long.toString(schedule.getEndDate().getTimeInMillis())) ;
+            }
+            if (schedule instanceof SimpleSchedule) {
+                final SimpleSchedule simpleSchedule = (SimpleSchedule)schedule ;
+                final long simpleFrequency = simpleSchedule.getFrequency() ;
+                final FrequencyUnit.Enum unit = simpleSchedule.getFrequencyUnits() ;
+                final String frequencyVal ;
+                if (unit.equals(FrequencyUnit.SECONDS)) {
+                    frequencyVal = Long.toString(simpleFrequency * 1000) ;
+                } else {
+                    frequencyVal = Long.toString(simpleFrequency) ;
+                }
+                listenerConfig.setAttribute(ListenerTagNames.SCHEDULE_SIMPLE_FREQUENCY, frequencyVal) ;
+                if (simpleSchedule.isSetExecCount()) {
+                    listenerConfig.setAttribute(ListenerTagNames.SCHEDULE_SIMPLE_EXEC, Integer.toString(simpleSchedule.getExecCount())) ;
+                }
+            } else if (schedule instanceof CronSchedule) {
+                final String cronExpression = ((CronSchedule)schedule).getCronExpression() ;
+                if (cronExpression == null) {
+                    throw new ConfigurationException("Missing cron expression from configuration") ;
+                }
+                listenerConfig.setAttribute(ListenerTagNames.SCHEDULE_CRON_EXPRESSION, cronExpression) ;
+            } else {
+                throw new ConfigurationException("Unknown schedule type specified in configuration: " + schedule.getClass().getName()) ;
+            }
+            
             if(domElement.hasAttribute("poll-frequency-seconds") || domElement.hasAttribute("schedule-frequency") ) {
                 logger.warn("Schedule Listener '" + listenerConfig.getTagName() + "' defines both 'scheduleidref' and frequency attributes.  Using the 'scheduleidref'.");
             }
-        } else if(frequency > -1) {
-            listenerConfig.setAttribute(ScheduleProviderFactory.ATTR_FREQUENCY, Integer.toString(frequency));
+        } else if(scheduleFrequency > -1) {
+            listenerConfig.setAttribute(ScheduleProviderFactory.ATTR_FREQUENCY, Integer.toString(scheduleFrequency));
         } else if(pollFrequency > -1) {
             listenerConfig.setAttribute(ScheduleProviderFactory.ATTR_FREQUENCY, Integer.toString(pollFrequency));
         } else if(pollLatency > -1) {
@@ -61,6 +104,12 @@
             listenerConfig.setAttribute(ScheduleProviderFactory.ATTR_FREQUENCY, "10");
         }
 
+        final ScheduleProvider scheduleProvider = model.getScheduleProvider() ;
+        if (scheduleProvider != null) {
+            // There is only one schedule provider allowed in the configuration at present
+            copyProperties(listenerConfig, model.getScheduleProvider().getPropertyList(), model.getScheduledListenerCount()) ;
+        }
+        
         if(domElement.hasAttribute("poll-frequency-seconds")) {
             logger.warn("Attrubute 'poll-frequency-seconds' is DEPRECATED.  Please change your configuration to use 'schedule-frequency'.");
         }
@@ -69,6 +118,17 @@
         }
     }
 
+    private static void copyProperties(final Element listenerConfig, final List<PropertyDocument.Property> properties, final int numScheduledListeners)
+    {
+        final Element schedulePropertyElement = YADOMUtil.addElement(listenerConfig, ListenerTagNames.SCHEDULE_PROPERTIES) ;
+        schedulePropertyElement.setAttribute(SchedulerResource.THREAD_COUNT, Integer.toString(numScheduledListeners)) ;
+
+        if ((properties != null) && (properties.size() > 0))
+        {
+            MapperUtil.mapProperties(properties, schedulePropertyElement) ;
+        }
+    }
+    
     private static int getPollLatencySeconds(AbstractScheduledListener scheduledListener) {
         String value = Generator.XMLBeansModel.getProperty(scheduledListener.getPropertyList(), "pollLatencySeconds", "-1");
 

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -34,7 +34,6 @@
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.Service;
 import org.jboss.soa.esb.addressing.eprs.FileEpr;
-import org.jboss.soa.esb.schedule.ScheduledEventListener;
 import org.jboss.soa.esb.schedule.SchedulingException;
 import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.couriers.CourierException;
@@ -58,7 +57,7 @@
  * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
  * @since Version 4.0
  */
-public abstract class AbstractFileGateway extends AbstractManagedLifecycle implements ScheduledEventListener {
+public abstract class AbstractFileGateway extends AbstractScheduledManagedLifecycle {
 
     protected final static Logger _logger = Logger
             .getLogger(AbstractFileGateway.class);
@@ -102,22 +101,6 @@
         }
     }
 
-    public void initialize(ConfigTree config) throws ConfigurationException {
-        // TODO Convert lifecycle code to use the Initializable interface.
-    }
-
-    public void uninitialize() {
-    }
-
-    protected void doStart() throws ManagedLifecycleException {
-    }
-
-    protected void doStop() throws ManagedLifecycleException {
-    }
-
-    protected void doDestroy() throws ManagedLifecycleException {
-    }
-
     /**
      * Execute on trigger from the scheduler.
      */
@@ -270,14 +253,6 @@
         return new File(fileIn.toString() + _workingSuffix);
     }
 
-    /**
-     * Handle the threaded destroy of the managed instance.
-     *
-     * @throws ManagedLifecycleException for errors while destroying.
-     */
-    protected void doThreadedDestroy() throws ManagedLifecycleException {
-    }
-
     /*
          * Is the input suffix valid for this type of gateway?
          */

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -173,20 +173,22 @@
 	 * Stop the service and also after that stop the 
 	 * remotefileSystemStrategy in use
 	 */
+	@Override
 	protected void doStop() throws ManagedLifecycleException
 	{
+		super.doStop();
 		remotefileSystemStrategy.stop();
-		super.doStop();
 	}
 	
 	/**
 	 * Destroys the service and also after that stop the 
 	 * remotefileSystemStrategy in use
 	 */
-    protected void doThreadedDestroy() throws ManagedLifecycleException
+	@Override
+    protected void doScheduledDestroy() throws ManagedLifecycleException
     {
+		super.doScheduledDestroy();
 		remotefileSystemStrategy.destroy();
-		super.doDestroy();
     }
 	
 	private void createRemoteFileSystemStrategy() throws ConfigurationException

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractScheduledManagedLifecycle.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractScheduledManagedLifecycle.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractScheduledManagedLifecycle.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -0,0 +1,340 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.lifecycle;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.schedule.SchedulerJob;
+import org.jboss.soa.esb.schedule.SchedulerJobListener;
+import org.jboss.soa.esb.schedule.SchedulingException;
+
+
+/**
+ * This class provides threaded support for a managed instance.
+ * 
+ * @author kevin
+ */
+public abstract class AbstractScheduledManagedLifecycle extends AbstractManagedLifecycle
+{
+    /**
+     * The job associated with the scheduler.
+     */
+    private final SchedulerJob job ;
+    /**
+     * The logger for this class.
+     */
+    private static final Logger logger = Logger.getLogger(AbstractScheduledManagedLifecycle.class) ;
+
+    /**
+     * Construct the threaded managed lifecycle.
+     * @param config The configuration associated with this instance.
+     * @throws ConfigurationException for configuration errors during initialisation.
+     */
+    protected AbstractScheduledManagedLifecycle(final ConfigTree config)
+        throws ConfigurationException
+    {
+        super(config) ;
+        
+        final Properties properties = extractProperties(config) ;
+        final SchedulerJobListener listener = new SchedulerJobListener() {
+            public void onSchedule() throws SchedulingException {
+                AbstractScheduledManagedLifecycle.this.onSchedule() ;
+            }
+        } ;
+        final String scheduleIdRef = config.getAttribute(ListenerTagNames.SCHEDULE_ID_REF) ;
+        if (scheduleIdRef == null)
+        {
+            final String intervalVal = config.getAttribute(ListenerTagNames.SCHEDULE_FREQUENCY) ;
+            final long interval ;
+            if (intervalVal != null)
+            {
+                interval = parseInt(ListenerTagNames.SCHEDULE_FREQUENCY, intervalVal) ;
+            }
+            else
+            {
+                interval = 10 ;
+            }
+            
+            job = SchedulerJob.createIntervalSchedulerJob(null, listener, interval*1000, properties) ;
+        }
+        else
+        {
+            final Date scheduleStartDate = getDate(config.getAttribute(ListenerTagNames.SCHEDULE_START_DATE)) ;
+            final Date scheduleEndDate = getDate(config.getAttribute(ListenerTagNames.SCHEDULE_END_DATE)) ;
+            final String simpleFrequency = config.getAttribute(ListenerTagNames.SCHEDULE_SIMPLE_FREQUENCY) ;
+            if (simpleFrequency != null)
+            {
+                final long frequency = parseLong(ListenerTagNames.SCHEDULE_SIMPLE_FREQUENCY, simpleFrequency) ;
+                if (frequency <= 0)
+                {
+                    throw new ConfigurationException("Invalid " + ListenerTagNames.SCHEDULE_SIMPLE_FREQUENCY + " value, must be greate than zero: " + simpleFrequency) ;
+                }
+                final String simpleExecCount = config.getAttribute(ListenerTagNames.SCHEDULE_SIMPLE_EXEC) ;
+                if (simpleExecCount != null)
+                {
+                    final int execCount = parseInt(ListenerTagNames.SCHEDULE_SIMPLE_EXEC, simpleExecCount) ;
+                    if (execCount < 0)
+                    {
+                        job = SchedulerJob.createIntervalSchedulerJob(scheduleIdRef, listener, frequency, scheduleStartDate, scheduleEndDate, properties) ;
+                    }
+                    else if (execCount == 0)
+                    {
+                        logger.warn("<simple-schedule> '" + scheduleIdRef + "' has an execCount of 0 configured.  This schedule will not fire!");
+                        job = null ;
+                    }
+                    else
+                    {
+                        job = SchedulerJob.createIntervalSchedulerJob(scheduleIdRef, listener, frequency, execCount, scheduleStartDate, scheduleEndDate, properties) ;
+                    }
+                }
+                else
+                {
+                    job = SchedulerJob.createIntervalSchedulerJob(scheduleIdRef, listener, frequency, scheduleStartDate, scheduleEndDate, properties) ;
+                }
+            }
+            else
+            {
+                final String cronExpression = config.getAttribute(ListenerTagNames.SCHEDULE_CRON_EXPRESSION) ;
+                if (cronExpression == null)
+                {
+                    throw new ConfigurationException("Missing cron expression") ;
+                }
+                try
+                {
+                    job = SchedulerJob.createCronSchedulerJob(scheduleIdRef, listener, cronExpression, scheduleStartDate, scheduleEndDate, properties) ;
+                }
+                catch (final ParseException pe)
+                {
+                    throw new ConfigurationException("Invalid cron expression", pe) ;
+                }
+            }
+        }
+    }
+
+    /**
+     * Handle the initialisation of the managed instance.
+     * 
+     * @throws ManagedLifecycleException for errors while initialisation.
+     */
+    @Override
+    protected void doInitialise()
+        throws ManagedLifecycleException
+    {
+    }
+    
+    /**
+     * Handle the start of the managed instance.
+     * 
+     * @throws ManagedLifecycleException for errors while starting.
+     */
+    @Override
+    protected void doStart()
+        throws ManagedLifecycleException
+    {
+        if (job != null)
+        {
+            try
+            {
+                job.start() ;
+            }
+            catch (final SchedulingException se)
+            {
+                throw new ManagedLifecycleException("Failed to start the scheduling job", se) ;
+            }
+        }
+    }
+    
+    /**
+     * Execute the scheduled event.
+     */
+    protected abstract void onSchedule()
+        throws SchedulingException ;
+    
+    /**
+     * Handle the stop of the managed instance.
+     * 
+     * @throws ManagedLifecycleException for errors while stopping.
+     */
+    @Override
+    protected void doStop()
+        throws ManagedLifecycleException
+    {
+        if (job != null)
+        {
+            try
+            {
+                job.pause() ;
+            }
+            catch (final SchedulingException se)
+            {
+                throw new ManagedLifecycleException("Failed to pause the scheduling job", se) ;
+            }
+        }
+    }
+    
+    /**
+     * Handle the destroy of the managed instance.
+     * 
+     * @throws ManagedLifecycleException for errors while destroying.
+     */
+    @Override
+    protected final void doDestroy()
+        throws ManagedLifecycleException
+    {
+        try
+        {
+            doScheduledDestroy() ;
+        }
+        finally
+        {
+            if (job != null)
+            {
+                try
+                {
+                    job.destroy() ;
+                }
+                catch (final SchedulingException se)
+                {
+                    throw new ManagedLifecycleException("Failed to destroy the scheduling job", se) ;
+                }
+            }
+        }
+    }
+    
+    /**
+     * Handle the scheduled destroy of the managed instance.
+     * 
+     * @throws ManagedLifecycleException for errors while destroying.
+     */
+    protected void doScheduledDestroy()
+        throws ManagedLifecycleException
+    {
+    }
+    
+    /**
+     * Parse the value as an integer.
+     * @param propertyName The property name.
+     * @param value The string representation.
+     * @return the integer value.
+     * @throws ConfigurationException For failures in parsing the integer.
+     */
+    private int parseInt(final String propertyName, final String value)
+        throws ConfigurationException
+    {
+        try
+        {
+            return Integer.parseInt(value) ;
+        }
+        catch (final NumberFormatException nfe)
+        {
+            throw new ConfigurationException("Failed to parse " + propertyName + " as integer: " + value) ;
+        }
+    }
+    
+    /**
+     * Parse the value as a long.
+     * @param propertyName The property name.
+     * @param value The string representation.
+     * @return the long value.
+     * @throws ConfigurationException For failures in parsing the long.
+     */
+    private long parseLong(final String propertyName, final String value)
+        throws ConfigurationException
+    {
+        try
+        {
+            return Long.parseLong(value) ;
+        }
+        catch (final NumberFormatException nfe)
+        {
+            throw new ConfigurationException("Failed to parse " + propertyName + " as long: " + value) ;
+        }
+    }
+    
+    /**
+     * Extract any scheduler properties from the configuration.
+     * @param config The current configuration.
+     * @return The scheduler properties or null if none present.
+     * @throws ConfigurationException for errors in configuration
+     */
+    private Properties extractProperties(final ConfigTree config)
+        throws ConfigurationException
+    {
+        final ConfigTree[] children = config.getChildren(ListenerTagNames.SCHEDULE_PROPERTIES) ;
+        final int numChildren = (children == null ? 0 : children.length) ;
+        if (numChildren == 0)
+        {
+            return null ;
+        }
+        else if (numChildren > 1)
+        {
+            throw new ConfigurationException("Only one " + ListenerTagNames.SCHEDULE_PROPERTIES + " element allowed within the configuration") ;
+        }
+        
+        final List<KeyValuePair> attributeList = children[0].attributesAsList() ;
+        if ((attributeList == null) || attributeList.isEmpty())
+        {
+            return null ;
+        }
+        
+        final Properties properties = new Properties() ;
+        for(KeyValuePair pair: attributeList)
+        {
+            properties.put(pair.getKey(), pair.getValue()) ;
+        }
+        return properties ;
+    }
+    
+    /**
+     * Create a date object from the time value.
+     * @param time The time value.
+     * @return The date instance.
+     * @throws ConfigurationException for parsing errors.
+     */
+    private Date getDate(final String time)
+        throws ConfigurationException
+    {
+        if (time == null)
+        {
+            return null ;
+        }
+        
+        final long timeval ;
+        try
+        {
+            timeval = Long.parseLong(time) ;
+        }
+        catch (final NumberFormatException nfe)
+        {
+            throw new ConfigurationException("Could not create date from millisecond value: " + time) ;
+        }
+        return new Date(timeval) ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/AbstractScheduledManagedLifecycle.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -23,10 +23,6 @@
 
 import java.util.Collection;
 
-import org.jboss.soa.esb.schedule.ScheduleProvider;
-import org.jboss.soa.esb.schedule.SchedulingException;
-import org.apache.log4j.Logger;
-
 /**
  * Controller class to manage the lifecycles of a set of managed instances.
  *
@@ -34,13 +30,10 @@
  */
 public class ManagedLifecycleController
 {
-    private static Logger logger = Logger.getLogger(ManagedLifecycleController.class);   
-
    /**
     * The managed lifecycle instances.
     */
    private final ManagedLifecycle[] instances;
-    private ScheduleProvider scheduleProvider;
 
     /**
     * Construct the controller to manage the specified managed lifecycle instances.
@@ -68,14 +61,6 @@
    {
       initialiseInstances();
       startInstances();
-      try {
-         if(scheduleProvider != null) {
-             scheduleProvider.start();
-         }
-      } catch (SchedulingException e) {
-          stopAndDestroy(false);
-          throw new ManagedLifecycleException("Failed to start schedule provider.", e);
-      }
    }
 
     /**
@@ -87,25 +72,8 @@
     */
    public void restart() throws ManagedLifecycleException
    {
-      try
-      {
-          if(scheduleProvider != null) {
-              scheduleProvider.stop();
-          }
-      } catch (SchedulingException e) {
-          stopAndDestroy(false);
-          throw new ManagedLifecycleException("Failed to put schedule provider into standby.", e);
-      }
       stopInstances();
       startInstances();
-      try {
-          if(scheduleProvider != null) {
-              scheduleProvider.start();
-         }
-      } catch (SchedulingException e) {
-          stopAndDestroy(false);
-          throw new ManagedLifecycleException("Failed to restart schedule provider.", e);
-      }
    }
 
    /**
@@ -117,20 +85,7 @@
     */
    public void stop() throws ManagedLifecycleException
    {
-      try
-      {
-          stopAndDestroy(true) ;
-      }
-      finally
-      {
-          if(scheduleProvider != null) {
-              try {
-                  scheduleProvider.stop();
-              } catch (SchedulingException e) {
-                  logger.error("Failed to stop scheduling.", e);
-              }
-          }
-      }
+      stopAndDestroy(true) ;
    }
 
    /**
@@ -302,8 +257,4 @@
            destroyInstances(numInstances-1) ;
        }
    }
-
-    public void setScheduleProvider(ScheduleProvider scheduleProvider) {
-        this.scheduleProvider = scheduleProvider;
-    }
 }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleState.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -48,7 +48,7 @@
 {
     CONSTRUCTED { public boolean canTransition(final ManagedLifecycleState newState) { return (newState == INITIALISING) ;}} ,
     INITIALISING { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == INITIALISED) || (newState == DESTROYED)) ;}} ,
-    INITIALISED { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == STARTING) || (newState == DESTROYED)) ;}} ,
+    INITIALISED { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == STARTING) || (newState == DESTROYING)) ;}} ,
     STARTING { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == STARTED) || (newState == STOPPED)) ;}} ,
     STARTED { public boolean canTransition(final ManagedLifecycleState newState) { return ((newState == RUNNING) || (newState == STOPPING)) ;}} ,
     RUNNING { public boolean canTransition(final ManagedLifecycleState newState) { return (newState == STOPPING) ;}} ,

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduleProvider.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduleProvider.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduleProvider.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -41,6 +41,7 @@
  *
  * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @deprecated {@link ScheduleResource}
  */
 public class ScheduleProvider {
 

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJob.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJob.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJob.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -0,0 +1,309 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.schedule;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.quartz.CronTrigger;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.SimpleTrigger;
+import org.quartz.StatefulJob;
+import org.quartz.Trigger;
+
+/**
+ * Scheduler job tied to the lifecycle.
+ */
+public class SchedulerJob
+{
+    /**
+     * The logger for this class.
+     */
+    private static Logger LOGGER = Logger.getLogger(SchedulerJob.class);
+    
+    /**
+     * The job group used by scheduled jobs.
+     */
+    private static final String JOB_GROUP = "ESBScheduler" ;
+    
+    /**
+     * The base job name used by scheduled jobs.
+     */
+    private static final String JOB_NAME = "ESBJob" ;
+    
+    /**
+     * The job counter.
+     */
+    private static long jobCounter ;
+    
+    /**
+     * The name associated with this scheduler.
+     */
+    private final String name ;
+    /**
+     * The job details.
+     */
+    private final JobDetail jobDetail ;
+    /**
+     * The trigger associated with this job.
+     */
+    private final Trigger trigger ;
+    /**
+     * The scheduler properties.
+     */
+    private final Properties properties ;
+
+    /**
+     * Construct the job with the specified listener, trigger and properties.
+     * @param listener The job listener.
+     * @param trigger The associated trigger.
+     * @param properties Scheduler properties.
+     */
+    private SchedulerJob(final String name, final SchedulerJobListener listener,
+        final Trigger trigger, final Properties properties)
+    {
+        this.name = name ;
+        this.jobDetail = new JobDetail(trigger.getName(), JOB_GROUP, ESBScheduledJob.class) ;
+
+        final JobDataMap jobDataMap = new JobDataMap() ;
+        jobDataMap.put(SchedulerJobListener.class.getName(), listener) ;
+        jobDataMap.put(ClassLoader.class.getName(), Thread.currentThread().getContextClassLoader()) ;
+        jobDetail.setJobDataMap(jobDataMap) ;
+        
+        this.trigger = trigger ;
+        this.properties = properties ;
+    }
+
+    /**
+     * Start or resume the operation of the trigger.
+     * @throws SchedulingException for errors during the operation.
+     */
+    public void start()
+        throws SchedulingException
+    {
+        if (LOGGER.isDebugEnabled())
+        {
+            LOGGER.debug("Starting SchedulerJob " + getName()) ;
+        }
+        SchedulerResource.getSchedulerResource().start(trigger, jobDetail, properties) ;
+    }
+
+    /**
+     * Pause the operation of the trigger.
+     * @throws SchedulingException for errors during the operation.
+     */
+    public void pause()
+        throws SchedulingException
+    {
+        if (LOGGER.isDebugEnabled())
+        {
+            LOGGER.debug("Pausing SchedulerJob " + getName()) ;
+        }
+        SchedulerResource.getSchedulerResource().pause(trigger) ;
+    }
+
+    /**
+     * Destroy the trigger.
+     * @throws SchedulingException for errors during the operation.
+     */
+    public void destroy()
+        throws SchedulingException
+    {
+        if (LOGGER.isDebugEnabled())
+        {
+            LOGGER.debug("Destroying SchedulerJob " + getName()) ;
+        }
+        SchedulerResource.getSchedulerResource().destroy(trigger) ;
+    }
+    
+    /**
+     * Get a name associated with this schedule.
+     * @return a name for this schedule.
+     */
+    private String getName()
+    {
+        if (name != null)
+        {
+            return name + '/' + trigger.getName();
+        }
+        else
+        {
+            return trigger.getName() ;
+        }
+    }
+
+    /**
+     * Create a job based on an interval.
+     * @param name The name for the job.
+     * @param listener The listener to fire on schedule.
+     * @param interval The specified interval.
+     * @param properties Any scheduler properties that may be required.
+     * @return The Scheduler Job managing the schedule.
+     */
+    public static SchedulerJob createIntervalSchedulerJob(final String name, final SchedulerJobListener listener,
+        final long interval, final Properties properties)
+    {
+        final SimpleTrigger trigger = new SimpleTrigger(getJobName(), JOB_GROUP, SimpleTrigger.REPEAT_INDEFINITELY, interval) ;
+        trigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT) ;
+        return new SchedulerJob(name, listener, trigger, properties) ;
+    }
+
+    /**
+     * Create a job based on an interval.
+     * @param name The name for the job.
+     * @param listener The listener to fire on schedule.
+     * @param interval The specified interval.
+     * @param startDate The start date of the trigger or null if not constrained.
+     * @param endDate The end date of the trigger or null if not constrained.
+     * @param properties Any scheduler properties that may be required.
+     * @return The Scheduler Job managing the schedule.
+     */
+    public static SchedulerJob createIntervalSchedulerJob(final String name, final SchedulerJobListener listener,
+        final long interval, final Date startDate, final Date endDate, final Properties properties)
+    {
+        final SimpleTrigger trigger = new SimpleTrigger(getJobName(), JOB_GROUP, SimpleTrigger.REPEAT_INDEFINITELY, interval) ;
+        trigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT) ;
+        if (startDate != null)
+        {
+            trigger.setStartTime(startDate) ;
+        }
+        if (endDate != null)
+        {
+            trigger.setEndTime(endDate) ;
+        }
+        return new SchedulerJob(name, listener, trigger, properties) ;
+    }
+
+    /**
+     * Create a job based on an interval.
+     * @param name The name for the job.
+     * @param listener The listener to fire on schedule.
+     * @param interval The specified interval.
+     * #param execCount The execution count.
+     * @param startDate The start date of the trigger or null if not constrained.
+     * @param endDate The end date of the trigger or null if not constrained.
+     * @param properties Any scheduler properties that may be required.
+     * @return The Scheduler Job managing the schedule.
+     */
+    public static SchedulerJob createIntervalSchedulerJob(final String name, final SchedulerJobListener listener,
+        final long interval, final int execCount, final Date startDate, final Date endDate, final Properties properties)
+    {
+        final SimpleTrigger trigger = new SimpleTrigger(getJobName(), JOB_GROUP, execCount-1, interval) ;
+        trigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT) ;
+        if (startDate != null)
+        {
+            trigger.setStartTime(startDate) ;
+        }
+        if (endDate != null)
+        {
+            trigger.setEndTime(endDate) ;
+        }
+        return new SchedulerJob(name, listener, trigger, properties) ;
+    }
+
+    /**
+     * Create a job based on cron.
+     * @param name The name for the job.
+     * @param listener The listener to fire on schedule.
+     * @param cronExpression The cron expression.
+     * @param startDate The start date of the trigger or null if not constrained.
+     * @param endDate The end date of the trigger or null if not constrained.
+     * @param properties Any scheduler properties that may be required.
+     * @return The Scheduler Job managing the schedule.
+     * @throws ParseException for errors in the cron expression.
+     */
+    public static SchedulerJob createCronSchedulerJob(final String name, final SchedulerJobListener listener,
+        final String cronExpression, final Date startDate, final Date endDate, final Properties properties)
+        throws ParseException
+    {
+        final CronTrigger trigger = new CronTrigger(getJobName(), JOB_GROUP, cronExpression) ;
+        trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING) ;
+        if (startDate != null)
+        {
+            trigger.setStartTime(startDate) ;
+        }
+        if (endDate != null)
+        {
+            trigger.setEndTime(endDate) ;
+        }
+        return new SchedulerJob(name, listener, trigger, properties) ;
+    }
+    
+    /**
+     * Get the name of the next job.
+     * @return The job name.
+     */
+    private static String getJobName()
+    {
+        final long id ;
+        synchronized(SchedulerJob.class)
+        {
+            id = ++jobCounter ;
+        }
+        return JOB_NAME + id ;
+    }
+    
+    /**
+     * The scheduled job for executing the listener.
+     * @author kevin
+     */
+    public static class ESBScheduledJob implements StatefulJob
+    {
+        /**
+         * Execute the current job.
+         */
+        public void execute(final JobExecutionContext jobExecutionContext)
+            throws JobExecutionException
+        {
+            final JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap() ;
+            final SchedulerJobListener listener = (SchedulerJobListener) jobDataMap.get(SchedulerJobListener.class.getName()) ;
+            final ClassLoader tcc = (ClassLoader)jobDataMap.get(ClassLoader.class.getName()) ;
+            
+            final Thread thread = Thread.currentThread() ;
+            final ClassLoader currentClassLoader = thread.getContextClassLoader() ;
+            thread.setContextClassLoader(tcc) ;
+            try
+            {
+                listener.onSchedule() ;
+            }
+            catch (final SchedulingException se)
+            {
+                final JobExecutionException jobException = new JobExecutionException("Scheduling exception on " + jobExecutionContext.getTrigger().getName()) ;
+                jobException.initCause(se) ;
+                throw jobException ;
+            }
+            catch (final Throwable th)
+            {
+                final JobExecutionException jobException = new JobExecutionException("Unexpected exception on " + jobExecutionContext.getTrigger().getName()) ;
+                jobException.initCause(th) ;
+                throw jobException ;
+            }
+            finally
+            {
+                thread.setContextClassLoader(currentClassLoader) ;
+            }
+        }
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJob.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJobListener.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJobListener.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJobListener.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.schedule;
+
+/**
+ * Interface used to register scheduled resource listeners with the lifecycle.
+ *
+ * @author <a href="mailto:Kevin.Conner at jboss.com">Kevin Conner</a>
+ */
+public interface SchedulerJobListener
+{
+    /**
+     * Handle the scheduled event.
+     * 
+     * @throws SchedulingException For any errors occurring during the scheduled event.
+     */
+    public void onSchedule()
+        throws SchedulingException ;
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerJobListener.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerResource.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerResource.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerResource.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -0,0 +1,316 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.schedule;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.lifecycle.LifecyclePriorities;
+import org.jboss.soa.esb.lifecycle.LifecycleResource;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceFactory;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.quartz.JobDetail;
+import org.quartz.ObjectAlreadyExistsException;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * Scheduler resource tied to the lifecycle.
+ */
+public class SchedulerResource
+{
+    /**
+     * The logger for this class.
+     */
+    private static Logger LOGGER = Logger.getLogger(SchedulerResource.class);
+    
+    /**
+     * The lifecycle resource factory.
+     */
+    private static final LifecycleResourceFactory<SchedulerResource> lifecycleSchedulerFactory = new SchedulerFactory() ;
+    /**
+     * Lifecycle schedulers.
+     */
+    private static final LifecycleResource<SchedulerResource> lifecycleSchedulerResource =
+        new LifecycleResource<SchedulerResource>(lifecycleSchedulerFactory, LifecyclePriorities.SCHEDULE_RESOURCE_PRIORITY) ;
+    
+    /**
+     * The instance name property.
+     */
+    public static final String INSTANCE_NAME = "org.quartz.scheduler.instanceName" ;
+    /**
+     * The thread name property.
+     */
+    public static final String THREAD_NAME = "org.quartz.scheduler.threadName" ;
+    /**
+     * The thread count property.
+     */
+    public static final String THREAD_COUNT = "org.quartz.threadPool.threadCount" ;
+    
+    /**
+     * The quartz scheduler associated with this resource.
+     */
+    private Scheduler scheduler ;
+    
+    private SchedulerResource()
+    {
+    }
+
+    /**
+     * Start a trigger on the contextualised resource.
+     * @param trigger The trigger to enable.
+     * @param jobDetail The details of the job.
+     * @param properties The properties for the scheduler.
+     * @throws SchedulingException For any errors.
+     * 
+     * Note that there is only one scheduler in force per scheduled esb artifact and, therefore,
+     * the first invocation will create the scheduler.  We may support multiple schedulers at a later
+     * point in time.
+     */
+    synchronized void start(final Trigger trigger, final JobDetail jobDetail, final Properties properties)
+        throws SchedulingException
+    {
+        initScheduler(properties) ;
+        try
+        {
+            try
+            {
+                scheduler.scheduleJob(jobDetail, trigger) ;
+            }
+            catch (final ObjectAlreadyExistsException oaee)
+            {
+                scheduler.resumeTrigger(trigger.getName(), trigger.getGroup()) ;
+            }
+        }
+        catch (final SchedulerException se)
+        {
+            throw new SchedulingException("Failed to start scheduled job", se) ;
+        }
+    }
+
+    /**
+     * Pause a trigger on the contextualised resource.
+     * @param trigger The trigger to pause.
+     * @throws SchedulingException For any errors.
+     */
+    synchronized void pause(final Trigger trigger)
+        throws SchedulingException
+    {
+        if (scheduler != null)
+        {
+            try
+            {
+                if (scheduler.isShutdown())
+                {
+                    throw new SchedulingException("Scheduler has been shutdown") ;
+                }
+                scheduler.pauseTrigger(trigger.getName(), trigger.getGroup()) ;
+            }
+            catch (final SchedulerException se)
+            {
+                throw new SchedulingException("Failed to pause scheduled job", se) ;
+            }
+        }
+    }
+
+    /**
+     * Destroy a trigger on the contextualised resource.
+     * @param trigger The trigger to destroy.
+     * @throws SchedulingException For any errors.
+     */
+    synchronized void destroy(final Trigger trigger)
+        throws SchedulingException
+    {
+        if (scheduler != null)
+        {
+            try
+            {
+                if (scheduler.isShutdown())
+                {
+                    throw new SchedulingException("Scheduler has been shutdown") ;
+                }
+                scheduler.unscheduleJob(trigger.getName(), trigger.getGroup()) ;
+            }
+            catch (final SchedulerException se)
+            {
+                throw new SchedulingException("Failed to destroy scheduled job", se) ;
+            }
+        }
+    }
+
+    /**
+     * Shutdown the contextualised resource.
+     * @throws SchedulingException For any errors.
+     */
+    synchronized void shutdown()
+        throws SchedulingException
+    {
+        if (scheduler != null)
+        {
+            try
+            {
+                if (!scheduler.isShutdown())
+                {
+                    scheduler.shutdown() ;
+                }
+            }
+            catch (final SchedulerException se)
+            {
+                throw new SchedulingException("Failed to shutdown scheduler", se) ;
+            }
+        }
+    }
+    
+    /**
+     * Initialise the scheduler if necessary.
+     * @param properties The properties used to create a scheduler.
+     */
+    private void initScheduler(final Properties properties)
+        throws SchedulingException
+    {
+        if (scheduler == null)
+        {
+            final InputStream quartzProperties = ClassUtil.getResourceAsStream("quartz.properties", SchedulerResource.class) ;
+
+            if(quartzProperties == null)
+            {
+                throw new SchedulingException("Failed to locate the default scheduling properties") ;
+            }
+
+            final Properties defaultProperties = new Properties();
+            try
+            {
+                defaultProperties.load(quartzProperties) ;
+            }
+            catch (final IOException ioe)
+            {
+                throw new SchedulingException("Failed to load the default scheduling properties") ;
+            }
+            
+            if(properties != null)
+            {
+                defaultProperties.putAll(properties) ;
+            }
+            
+            final String name = "ESBScheduler:" + getDeploymentName() ;
+            defaultProperties.put(INSTANCE_NAME, name) ;
+            defaultProperties.put(THREAD_NAME, name) ;
+            if (!defaultProperties.containsKey(THREAD_COUNT))
+            {
+                defaultProperties.put(THREAD_COUNT, "1") ;
+            }
+            final Scheduler scheduler ;
+            try
+            {
+                scheduler = new StdSchedulerFactory(defaultProperties).getScheduler();
+                scheduler.start() ;
+            }
+            catch (final SchedulerException se)
+            {
+                throw new SchedulingException("Failed to initialise the scheduler", se) ;
+            }
+            this.scheduler = scheduler ;
+        }
+    }
+    
+    /**
+     * Create a name associated with this deployment.
+     * @return The deployment name.
+     */
+    private String getDeploymentName()
+    {
+        final LifecycleResourceManager lifecycleResourceManager = LifecycleResourceManager.getSingleton() ;
+        final String[] associatedDeployments = lifecycleResourceManager.getAssociatedDeployments() ;
+        final String deployment ;
+        if ((associatedDeployments != null) && (associatedDeployments.length == 1))
+        {
+            deployment = associatedDeployments[0] ;
+        }
+        else
+        {
+            deployment = lifecycleResourceManager.getIdentity() ;
+        }
+        return deployment ;
+    }
+    
+    /**
+     * Get the scheduler resource.
+     * @return The scheduler resource.
+     * @throws LifecycleResourceException for errors acquiring the resource.
+     */
+    static SchedulerResource getSchedulerResource()
+        throws SchedulingException
+    {
+        try
+        {
+            return lifecycleSchedulerResource.getLifecycleResource() ;
+        }
+        catch (final LifecycleResourceException lre)
+        {
+            throw new SchedulingException("Failed to obtain the contextualised scheduler resource", lre) ;
+        }
+    }
+    
+    /**
+     * The lifecycle resource factory
+     * @author kevin
+     */
+    private static class SchedulerFactory implements LifecycleResourceFactory<SchedulerResource>
+    {
+        /**
+         * Create a resource object which will be associated with the specified lifecycle identity.
+         * @param lifecycleIdentity The associated lifecycle identity.
+         * @return The lifecycle resource
+         * @throws LifecycleResourceException for errors during construction.
+         */
+        public SchedulerResource createLifecycleResource(final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+            return new SchedulerResource() ;
+        }
+
+        /**
+         * Destroy a resource object which is associated with the specified lifecycle identity.
+         * @param resource The lifecycle resource.
+         * @param lifecycleIdentity The associated lifecycle identity.
+         * @return The lifecycle resource.
+         * @throws LifecycleResourceException for errors during destroy.
+         */
+        public void destroyLifecycleResource(final SchedulerResource resource, final String lifecycleIdentity)
+            throws LifecycleResourceException
+        {
+            LOGGER.debug("Shutting down scheduler for identity " + lifecycleIdentity) ;
+            try
+            {
+                resource.shutdown() ;
+            }
+            catch (final SchedulingException se)
+            {
+                throw new LifecycleResourceException("Failed to shutdown the contextualised scheduler resource") ;
+            }
+        }
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/SchedulerResource.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/quartz.properties
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/quartz.properties	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/quartz.properties	2008-10-09 13:52:20 UTC (rev 23393)
@@ -1,17 +1,14 @@
 # Default ESB Quartz Properties file.
 #
 
-org.quartz.scheduler.instanceName = ScheduleProviderScheduler
 org.quartz.scheduler.rmi.export = false
 org.quartz.scheduler.rmi.proxy = false
 org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
 
 org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
-org.quartz.threadPool.threadCount = 20
 org.quartz.threadPool.threadPriority = 5
-org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
 
-org.quartz.jobStore.misfireThreshold = 60000
+org.quartz.jobStore.misfireThreshold = 1
 
 org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
 

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/build.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/build.xml	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/build.xml	2008-10-09 13:52:20 UTC (rev 23393)
@@ -135,6 +135,7 @@
                 <pathelement location="${basedir}/resources/etc"/>
         		<!-- using instrumented code for code coverage -->
                 <pathelement location="${org.jboss.esb.module.classes.instr.dir}"/>
+	        <pathelement location="${org.jboss.esb.module.src.dir}"/>
                 <pathelement location="${org.jboss.esb.tests.classes.dir}"/>
             	<!-- Need the tests src folder because there may be non-compiled test resources -->
                 <pathelement location="${org.jboss.esb.module.tests.src.dir}"/>
@@ -221,6 +222,7 @@
 	            <classpath>
 	        		<!-- using instrumented code for code coverage -->
 	                <pathelement location="${org.jboss.esb.module.classes.instr.dir}"/>
+	                <pathelement location="${org.jboss.esb.module.src.dir}"/>
 	                <pathelement location="${org.jboss.esb.tests.classes.dir}"/>
 	            	<!-- Need the tests src folder because there may be non-compiled test resources -->
 	                <pathelement location="${org.jboss.esb.module.tests.src.dir}"/>

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ScheduledListenerUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ScheduledListenerUnitTest.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ScheduledListenerUnitTest.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -75,6 +75,7 @@
     	tree.setAttribute("listenerClass", listenerClass );
     	tree.setAttribute("my-prop", "1");
     	tree.setAttribute("scheduleidref", "1-sec-trigger");
+    	tree.setAttribute("scheduleSimpleFrequency", "1000") ;
     
     	final ConfigTree action = new ConfigTree("action", tree);
     	action.setAttribute("action", "action");

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/GroovyGatewayUnitTest.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -63,20 +63,27 @@
         config.setAttribute("script", "/org/jboss/soa/esb/listeners/gateway/testgateway.groovy");
         groovyGateway = new MockGroovyGateway(config);
 
-        groovyGateway.doInitialise();
-        Thread thread = new Thread(new Runnable() {
-            public void run() {
-                groovyGateway.doRun();
-            }
-        });
-        thread.start();
-
-        Thread.sleep(2000);
-        assertTrue("Is already stopped", (courier1.message == null));
-        groovyGateway.stopped = true;
-        Thread.sleep(2000);
-        assertTrue("Is not stopped", (courier1.message != null));
-        assertEquals("Hi there!", (String) courier1.message.getBody().get());
+        groovyGateway.initialise();
+        try
+        {
+            Thread thread = new Thread(new Runnable() {
+                public void run() {
+                    groovyGateway.doRun();
+                }
+            });
+            thread.start();
+    
+            Thread.sleep(2000);
+            assertTrue("Is already stopped", (courier1.message == null));
+            groovyGateway.stopped = true;
+            Thread.sleep(2000);
+            assertTrue("Is not stopped", (courier1.message != null));
+            assertEquals("Hi there!", (String) courier1.message.getBody().get());
+        }
+        finally
+        {
+            groovyGateway.destroy() ;
+        }
     }
 
     // TODO: Fix build such that it can pick up the scripts from the src folder.

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListenerUnitTest.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -100,13 +100,10 @@
         } catch(ManagedLifecycleException e) {}
 
         // Initialise...
-        listener.doInitialise();
+        listener.initialise();
 
         // try initialising again...
-        try {
-            listener.doInitialise();
-            fail("Expected ManagedLifecycleException");
-        } catch(ManagedLifecycleException e) {}
+        listener.initialise();
 
         // try stopping without starting...
         try {
@@ -115,22 +112,16 @@
         } catch(ManagedLifecycleException e) {}
 
         // Start...
-        listener.doStart();
+        listener.start();
 
         // try starting again...
-        try {
-            listener.start();
-            fail("Expected ManagedLifecycleException");
-        } catch(ManagedLifecycleException e) {}
+        listener.start();
 
         // Stop...
-        listener.doStop();
+        listener.stop();
 
         // try stopping again...
-        try {
-            listener.doStop();
-            fail("Expected ManagedLifecycleException");
-        } catch(ManagedLifecycleException e) {}
+        listener.stop();
     }
     @Test
     public void test_http_async() throws Throwable {
@@ -188,8 +179,8 @@
             listener = new JBossRemotingGatewayListener(config);
         }
 
-        listener.doInitialise();
-        listener.doStart();
+        listener.initialise();
+        listener.start();
     }
 
     private void sendMessageToServer(String protocol, Object messagePayload, final String port) throws Throwable {
@@ -223,9 +214,9 @@
     private void stopServer() throws ManagedLifecycleException {
         if(listener != null && listener.isStarted()) {
             try {
-                listener.doStop();
+                listener.stop();
             } finally {
-                listener.doDestroy();
+                listener.destroy();
             }
         }
     }
@@ -246,7 +237,7 @@
 
         try {
             listener = new JBossRemotingGatewayListener(config);
-            listener.doInitialise();
+            listener.initialise();
             fail("Expected a ManagedLifecycleException.");
         } catch (ConfigurationException e) {
         	log.error(e);

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -115,26 +115,30 @@
 		
 		RemoteGatewayListenerMock mock = createAndStartListener ( configTree,  getCourierReturnValue );
 		
-		File inputDir =  ftpServer.getLocalInputDir();
-		String doneFileName = testFile.getName();
-		
-		//waitForFile( inputDir, doneFileName );
-		//stopdoRun( mock );
-        try {
-            mock.onSchedule();
-        } catch (SchedulingException e) {
-            fail(e.getMessage());
-        }
-		
-		File processedFile = new File ( inputDir,  doneFileName );
-		try
-		{
-			assertTrue ( processedFile.exists() );
+		try {
+			File inputDir =  ftpServer.getLocalInputDir();
+			String doneFileName = testFile.getName();
+			
+			//waitForFile( inputDir, doneFileName );
+			//stopdoRun( mock );
+			try {
+				mock.onSchedule();
+			} catch (SchedulingException e) {
+				fail(e.getMessage());
+			}
+			
+			File processedFile = new File ( inputDir,  doneFileName );
+			try
+			{
+				assertTrue ( processedFile.exists() );
+			}
+			finally
+			{
+				FtpTestUtil.deleteFile( processedFile );
+			}
+		} finally {
+			mock.destroy();
 		}
-		finally
-		{
-			FtpTestUtil.deleteFile( processedFile );
-		}
 	}
 	
 	/**
@@ -238,7 +242,7 @@
 	{
 		final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree );
         try {
-            mock.doInitialise();
+            mock.initialise();
         } catch (ManagedLifecycleException e) {
             fail(e.getMessage());
         }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -79,7 +79,6 @@
 		boolean exception = false;
 
         gateway.initialise();
-        gateway.start();
 
         try {
             try
@@ -142,7 +141,6 @@
             {
             }
         } finally {
-            gateway.stop();
             gateway.destroy();
         }
     }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java	2008-10-09 13:52:20 UTC (rev 23393)
@@ -182,7 +182,7 @@
 	 * postDir="/upload" 
 	 */
 	@Test //( timeout=3000 )
-	public void doRun_PostDir_Different_From_InputDir() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException
+	public void doRun_PostDir_Different_From_InputDir() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException, SchedulingException
 	{
 		setAbsoluteInputDir();
 		setAbsolutePostDirToUploadDir();
@@ -195,11 +195,7 @@
 		
         try {
             mock.onSchedule();
-        } catch (SchedulingException e) {
-            fail(e.getMessage());
-        }
 
-        try {
             File processedFile = new File ( done,  doneFileName );
             try
             {
@@ -221,7 +217,7 @@
 	 *	postDir="/input" 
 	 */
 	@Test ( timeout=3000 )
-	public void doRun_PostDir_Same_As_InputDir() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException
+	public void doRun_PostDir_Same_As_InputDir() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException, SchedulingException
 	{
 		setAbsoluteInputDir();
 		setAbsolutePostDirToInputDir();
@@ -234,11 +230,7 @@
 
         try {
             mock.onSchedule();
-        } catch (SchedulingException e) {
-            fail(e.getMessage());
-        }
 
-        try {
             File processedFile = new File ( inputDir,  doneFileName );
             try
             {
@@ -263,7 +255,7 @@
 	 *  Note. when this test runs a stacktrace will be displayed. This is expected.
 	 */
 	@Test ( timeout = 2000 )
-	public void doRun_Negative() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException
+	public void doRun_Negative() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException, SchedulingException
 	{
 		setAbsoluteInputDir();
 		setAbsoluteErrorDir();
@@ -271,30 +263,26 @@
 		log.error( "The following exceptions are expected: "  );
 		RemoteGatewayListenerMock mock = createAndStartListener ( configTree, getCourierReturnValue );
 		
-		File errorDir =  ftpServer.getLocalErrorDir();
-		String errorFileName = testFile.getName() + POST_ERROR_SUFFIX;
+		try {
+			File errorDir =  ftpServer.getLocalErrorDir();
+			String errorFileName = testFile.getName() + POST_ERROR_SUFFIX;
 
-        try {
-            mock.onSchedule();
-        } catch (SchedulingException e) {
-            fail(e.getMessage());
-        }
+			mock.onSchedule();
 
-        try {
-            File errorFile = new File ( errorDir,  errorFileName );
-            try
-            {
-                assertTrue ( errorFile.exists() );
-            }
-            finally
-            {
-                FtpTestUtil.deleteFile( errorFile );
-            }
-        } finally {
-            mock.stop();
-            mock.destroy();
-        }
-    }
+			File errorFile = new File ( errorDir,  errorFileName );
+			try
+			{
+				assertTrue ( errorFile.exists() );
+			}
+			finally
+			{
+				FtpTestUtil.deleteFile( errorFile );
+			}
+		} finally {
+			mock.stop();
+			mock.destroy();
+		}
+	}
 	
 	@Test
 	public void renameFile_In_Same_Directory() throws GatewayException
@@ -400,7 +388,11 @@
 		/* post error attributes */
 		configTree.setAttribute( ListenerTagNames.FILE_ERROR_DIR_TAG,  remoteErrorDirName );
 		configTree.setAttribute( ListenerTagNames.FILE_ERROR_SFX_TAG, POST_ERROR_SUFFIX);
-		
+		// Do not allow the background scheduler to fire before we run the tests.
+		// We should really be allowing it to fire so that we can test the normal operation.
+		configTree.setAttribute( ListenerTagNames.SCHEDULE_ID_REF, "idref") ;
+		configTree.setAttribute( ListenerTagNames.SCHEDULE_SIMPLE_FREQUENCY, "1000000000") ;
+		configTree.setAttribute( ListenerTagNames.SCHEDULE_SIMPLE_EXEC, "0") ;
 		return configTree;
 	}
 	
@@ -431,15 +423,11 @@
 	 * @param returnValueForCourier					the return value for the getCourier method of the RemoteGatewayListenerMock object
 	 * @return RemoteGatewayListenerMock		Mock impl of a RemoteGatewayListener.
 	 */
-	private RemoteGatewayListenerMock createAndStartListener ( ConfigTree configTree,  boolean returnValueForCourier ) throws ConfigurationException, GatewayException, RegistryException
+	private RemoteGatewayListenerMock createAndStartListener ( ConfigTree configTree,  boolean returnValueForCourier ) throws ConfigurationException, GatewayException, RegistryException, ManagedLifecycleException
 	{
 		final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree );
-        try {
-            mock.initialise();
-            mock.start();
-        } catch (ManagedLifecycleException e) {
-            fail(e.getMessage());
-        }
+        mock.initialise();
+        mock.start();
 
         if(returnValueForCourier) {
             MockCourierFactory.courierException = null;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/scheduled-listener-config-configtree.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/scheduled-listener-config-configtree.xml	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/scheduled-listener-config-configtree.xml	2008-10-09 13:52:20 UTC (rev 23393)
@@ -1,3 +1,6 @@
-<listener event-processor="org.jboss.soa.esb.schedule.MockScheduledEventMessageComposer" listenerClass="org.jboss.soa.esb.listeners.ScheduleListener" my-prop="1" name="simple-schedule-listener" scheduleidref="1-sec-trigger" service-category="ServiceCat" service-description="Test Service" service-name="ServiceName">
+<listener event-processor="org.jboss.soa.esb.schedule.MockScheduledEventMessageComposer" listenerClass="org.jboss.soa.esb.listeners.ScheduleListener" my-prop="1"
+  name="simple-schedule-listener" scheduleSimpleFrequency="1000" scheduleidref="1-sec-trigger" service-category="ServiceCat" service-description="Test Service"
+  service-name="ServiceName">
+<ScheduleProperties org.quartz.threadPool.threadCount="1"/>
 <action action="action" class="org.jboss.soa.esb.mock.MockAction"/>
-</listener>
\ No newline at end of file
+</listener>

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/schedule/expected-config-01-listener.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/schedule/expected-config-01-listener.xml	2008-10-09 13:46:26 UTC (rev 23392)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/schedule/expected-config-01-listener.xml	2008-10-09 13:52:20 UTC (rev 23393)
@@ -1,3 +1,4 @@
-<listener event-processor="org.jboss.soa.esb.schedule.MockScheduledEventMessageComposer" listenerClass="org.jboss.soa.esb.listeners.ScheduleListener" name="simple-schedule-listener" scheduleidref="1-sec-trigger" service-category="ServiceCat" service-description="Test Service" service-name="ServiceName-01">
+<listener event-processor="org.jboss.soa.esb.schedule.MockScheduledEventMessageComposer" listenerClass="org.jboss.soa.esb.listeners.ScheduleListener" name="simple-schedule-listener" scheduleSimpleExec="2" scheduleSimpleFrequency="1000" scheduleidref="1-sec-trigger" service-category="ServiceCat" service-description="Test Service" service-name="ServiceName-01">
+<ScheduleProperties org.quartz.threadPool.threadCount="2"/>
 <action action="action" class="org.jboss.soa.esb.mock.MockAction"/>
-</listener>
\ No newline at end of file
+</listener>




More information about the jboss-svn-commits mailing list