[jboss-svn-commits] JBL Code SVN: r27738 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration: timer and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 8 08:37:51 EDT 2009


Author: kevin.conner at jboss.com
Date: 2009-07-08 08:37:51 -0400 (Wed, 08 Jul 2009)
New Revision: 27738

Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/RetryExecutor.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerService.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerServiceFactory.java
Log:
Added maximum refire count to quartz scheduler: JBESB-2719

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/RetryExecutor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/RetryExecutor.java	2009-07-08 12:10:33 UTC (rev 27737)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/msg/RetryExecutor.java	2009-07-08 12:37:51 UTC (rev 27738)
@@ -108,7 +108,8 @@
                 {
                     final Set<Long> monitoredJobs = new HashSet<Long>() ;
                     final long now = System.currentTimeMillis() ;
-                    for(int count = 0 ; count < maxRetryJobs ; count++)
+                    int count = 0 ;
+                    do
                     {
                         final Job job = jobSession.getFirstDueJob(RETRY_EXECUTOR, monitoredJobs) ;
                         if ((job == null) || (job.getDueDate().getTime() > now))
@@ -118,6 +119,7 @@
                         monitoredJobs.add(Long.valueOf(job.getId())) ;
                         if (RETRY_EXECUTOR.equals(job.getLockOwner()))
                         {
+                            count++ ;
                             job.setLockOwner(null) ;
                             if (job instanceof Timer)
                             {
@@ -136,6 +138,7 @@
                             }
                         }
                     }
+                    while(count < maxRetryJobs) ;
                 }
             }
             catch (final Throwable th)

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerService.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerService.java	2009-07-08 12:10:33 UTC (rev 27737)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerService.java	2009-07-08 12:37:51 UTC (rev 27738)
@@ -42,12 +42,20 @@
      * Name of the timer id within the quartz map.
      */
     private static final String TIMER_ID = "id" ;
+    /**
+     * Name of the max refire count within the quartz map.
+     */
+    private static final String MAX_REFIRE_COUNT = "maxRefireCount" ;
     
     /**
      * The associated quartz scheduler.
      */
     private final Scheduler scheduler ;
     /**
+     * The maximum refire count.
+     */
+    private final int maxRefireCount ;
+    /**
      * The associated jBPM job session.
      */
     private final JobSession jobSession ;
@@ -57,9 +65,10 @@
      * @param jbpmContext The associated jBPM context.
      * @param scheduler The quartz scheduler.
      */
-    public QuartzSchedulerService(final JbpmContext jbpmContext, final Scheduler scheduler)
+    public QuartzSchedulerService(final JbpmContext jbpmContext, final Scheduler scheduler, final int maxRefireCount)
     {
         this.scheduler = scheduler ;
+        this.maxRefireCount = maxRefireCount ;
         jobSession = jbpmContext.getJobSession();
     }
     
@@ -76,6 +85,7 @@
 
         final JobDataMap jobDataMap = new JobDataMap() ;
         jobDataMap.put(TIMER_ID, new Long(timer.getId())) ;
+        jobDataMap.put(MAX_REFIRE_COUNT, Integer.valueOf(maxRefireCount)) ;
         jobDetail.setJobDataMap(jobDataMap) ;
         
         try
@@ -214,9 +224,10 @@
                     if (jobId != null)
                     {
                         final JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext() ;
+                        Job job = null ;
                         try
                         {
-                            final Job job = jbpmContext.getJobSession().loadJob(jobId) ;
+                            job = jbpmContext.getJobSession().loadJob(jobId) ;
                             if (job != null)
                             {
                                 jbpmContext.getServices().getMessageService().send(job) ;
@@ -229,9 +240,22 @@
                         }
                         catch (final RuntimeException re)
                         {
-                            final JobExecutionException jobEx = new JobExecutionException(re, true);
-                            jobEx.setErrorCode(JobExecutionException.ERR_JOB_EXECUTION_THREW_EXCEPTION);
-                            throw jobEx ;
+                            final Integer maxRefireCount = (Integer) jobDataMap.get(MAX_REFIRE_COUNT) ;
+                            if ((maxRefireCount != null) && (maxRefireCount > context.getRefireCount()))
+                            {
+                                final JobExecutionException jobEx = new JobExecutionException(re, true);
+                                jobEx.setErrorCode(JobExecutionException.ERR_JOB_EXECUTION_THREW_EXCEPTION);
+                                throw jobEx ;
+                            }
+                            else
+                            {
+                                if (job != null)
+                                {
+                                    // zero the retries to remove from the list of outstanding jobs.
+                                    job.setRetries(0) ;
+                                }
+                                throw re ;
+                            }
                         }
                         finally
                         {

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerServiceFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerServiceFactory.java	2009-07-08 12:10:33 UTC (rev 27737)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/integration/timer/QuartzSchedulerServiceFactory.java	2009-07-08 12:37:51 UTC (rev 27738)
@@ -55,12 +55,20 @@
      * The thread count property.
      */
     public static final String THREAD_COUNT = "org.quartz.threadPool.threadCount" ;
+    /**
+     * The default maximum refire count.
+     */
+    public static final int DEFAULT_MAX_REFIRE_COUNT = 5 ;
     
     /**
      * Quartz configuration.
      */
     String quartzConfiguration = "jbpm-quartz.properties" ;
     /**
+     * Quartz maximum refire count.
+     */
+    int maxRefireCount = DEFAULT_MAX_REFIRE_COUNT ;
+    /**
      * The quartz scheduler associated with this factory.
      */
     private Scheduler scheduler ;
@@ -107,6 +115,10 @@
             throw new JbpmException("Failed to initialise the scheduler", se) ;
         }
         this.scheduler = scheduler ;
+        if (maxRefireCount < 0)
+        {
+            maxRefireCount = DEFAULT_MAX_REFIRE_COUNT ;
+        }
     }
 
     /**
@@ -114,7 +126,7 @@
      */
     public Service openService()
     {
-        return new QuartzSchedulerService(JbpmConfiguration.getInstance().getCurrentJbpmContext(), scheduler) ;
+        return new QuartzSchedulerService(JbpmConfiguration.getInstance().getCurrentJbpmContext(), scheduler, maxRefireCount) ;
     }
 
     /**




More information about the jboss-svn-commits mailing list