[jboss-svn-commits] JBL Code SVN: r23019 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb: schedule and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 23 12:39:33 EDT 2008


Author: kevin.conner at jboss.com
Date: 2008-09-23 12:39:33 -0400 (Tue, 23 Sep 2008)
New Revision: 23019

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/schedule/ScheduleProvider.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/quartz.properties
Log:
Use ESB scheduler, remove standby and rework start: JBESB-2066

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-09-23 15:34:38 UTC (rev 23018)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/lifecycle/ManagedLifecycleController.java	2008-09-23 16:39:33 UTC (rev 23019)
@@ -90,7 +90,7 @@
       try
       {
           if(scheduleProvider != null) {
-              scheduleProvider.standby();
+              scheduleProvider.stop();
           }
       } catch (SchedulingException e) {
           stopAndDestroy(false);

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-09-23 15:34:38 UTC (rev 23018)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduleProvider.java	2008-09-23 16:39:33 UTC (rev 23019)
@@ -28,9 +28,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.ParseException;
-import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 /**
@@ -47,8 +48,9 @@
 
     /* Quartz scheduler instance */
     private Scheduler scheduler;
-    private List<String> scheduledJobs = new ArrayList<String>();
+    private Map<JobDetail, Trigger> scheduledJobs = new HashMap<JobDetail, Trigger>();
     private List<Schedule> schedules;
+    private boolean active ;
     
     private final ClassLoader tcc ;
     private static final String JBOSS_ESB = "JBossESB";
@@ -70,6 +72,7 @@
             } else {
                 scheduler = new StdSchedulerFactory().getScheduler();
             }
+            scheduler.start() ;
             tcc = Thread.currentThread().getContextClassLoader() ;
         } catch (SchedulerException e) {
             throw new ConfigurationException("Unable to create Scheduler instance.", e);
@@ -136,27 +139,32 @@
 
     private static volatile int nameDelta = 1; 
     private void addListener(ScheduledEventListener listener, Trigger trigger) throws SchedulingException {
+        final int id ;
         synchronized (ScheduleProvider.class) {
-            JobDataMap jobDataMap = new JobDataMap();
-            JobDetail jobDetail;
+            id = nameDelta++ ;
+        }
+        JobDataMap jobDataMap = new JobDataMap();
+        JobDetail jobDetail;
 
-            String name = trigger.getName();
+        String name = trigger.getName();
 
-            // this is just to make sure they're unique - i.e. so as 1+
-            // "things" can listen to the same schedule...
-            // This is not thread safe!
-            name += ("-" + nameDelta++);
-            trigger.setName(name);
+        name += "-" + id;
+        trigger.setName(name);
 
-            jobDetail = new JobDetail(name, JBOSS_ESB, ScheduleProvider.ESBScheduledJob.class);
-            jobDataMap.put(ScheduledEventListener.class.getName(), listener);
-            jobDataMap.put(ClassLoader.class.getName(), tcc);
-            jobDetail.setJobDataMap(jobDataMap);
-            try {
-                scheduler.scheduleJob(jobDetail, trigger);
-                scheduledJobs.add(name);
-            } catch (SchedulerException e) {
-                throw new SchedulingException("Failed to schedule job.", e);
+        jobDetail = new JobDetail(name, JBOSS_ESB, ScheduleProvider.ESBScheduledJob.class);
+        jobDataMap.put(ScheduledEventListener.class.getName(), listener);
+        jobDataMap.put(ClassLoader.class.getName(), tcc);
+        jobDetail.setJobDataMap(jobDataMap);
+        synchronized(this)
+        {
+            scheduledJobs.put(jobDetail, trigger);
+            if (active)
+            {
+                try {
+                    scheduler.scheduleJob(jobDetail, trigger);
+                } catch (SchedulerException e) {
+                    throw new SchedulingException("Failed to schedule job.", e);
+                }
             }
         }
     }
@@ -175,42 +183,36 @@
      * Start the scheduler.
      * @throws SchedulingException Start failed.
      */
-    public void start() throws SchedulingException {
-        try {
-            scheduler.start();
-        } catch (SchedulerException e) {
-            throw new SchedulingException("Failed to start scheduling.", e);
+    public synchronized void start() throws SchedulingException {
+        if (!active) {
+            try {
+                for (Map.Entry<JobDetail, Trigger> entry: scheduledJobs.entrySet()) {
+                    scheduler.scheduleJob(entry.getKey(), entry.getValue());
+                }
+            } catch (SchedulerException e) {
+                throw new SchedulingException("Failed to start scheduling.", e);
+            }
+            active = true ;
         }
     }
 
     /**
-     * Standby the scheduler.
-     * <p/>
-     * Restart the scheduler through the {@link #start()} method.
-     *
-     * @throws SchedulingException Standby failed.
-     */
-    public void standby() throws SchedulingException {
-        try {
-            scheduler.standby();
-        } catch (SchedulerException e) {
-            throw new SchedulingException("Failed to standby scheduling.", e);
-        }
-    }
-
-    /**
      * Stop the scheduler.
      * @throws SchedulingException Stop failed.
      */
-    public void stop() throws SchedulingException {
-        try {
-            for(String jobName : scheduledJobs) {
-                if(!scheduler.deleteJob(jobName, JBOSS_ESB)) {
-                    logger.info("Failed to delete scheduled Job '" + jobName + "' from job group '" + JBOSS_ESB + "'.  Job run may have already completed.");
+    public synchronized void stop() throws SchedulingException {
+        if (active) {
+            try {
+                for(Trigger trigger: scheduledJobs.values()) {
+                    final String jobName = trigger.getName() ;
+                    if(!scheduler.deleteJob(jobName, JBOSS_ESB)) {
+                        logger.info("Failed to delete scheduled Job '" + jobName + "' from job group '" + JBOSS_ESB + "'.  Job run may have already completed.");
+                    }
                 }
+            } catch (SchedulerException e) {
+                throw new SchedulingException("Failed to shutdown scheduling.", e);
             }
-        } catch (SchedulerException e) {
-            throw new SchedulingException("Failed to shutdown scheduling.", e);
+            active = false ;
         }
     }
 

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-09-23 15:34:38 UTC (rev 23018)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/schedule/quartz.properties	2008-09-23 16:39:33 UTC (rev 23019)
@@ -1,13 +1,13 @@
 # Default ESB Quartz Properties file.
 #
 
-org.quartz.scheduler.instanceName = DefaultQuartzScheduler
+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 = 2
+org.quartz.threadPool.threadCount = 20
 org.quartz.threadPool.threadPriority = 5
 org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
 




More information about the jboss-svn-commits mailing list