camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1345933 - in /camel/branches/camel-2.9.x: ./ components/camel-quartz/src/main/java/org/apache/camel/component/quartz/ components/camel-quartz/src/test/java/org/apache/camel/component/quartz/ components/camel-quartz/src/test/resources/org/a...
Date Mon, 04 Jun 2012 12:06:07 GMT
Author: davsclaus
Date: Mon Jun  4 12:06:06 2012
New Revision: 1345933

URL: http://svn.apache.org/viewvc?rev=1345933&view=rev
Log:
CAMEL-5259: Fixed quartz component need to use unique management name for CamelContext, on
jobs to pickup correct context, in case multiple Camel apps with same name is running in the
JVM.

Added:
    camel/branches/camel-2.9.x/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzTwoCamelContextSameNameClashTest.java
      - copied unchanged from r1345931, camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzTwoCamelContextSameNameClashTest.java
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
    camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConstants.java
    camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
    camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartTest.xml
    camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreTest.xml

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1345931

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java?rev=1345933&r1=1345932&r2=1345933&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
Mon Jun  4 12:06:06 2012
@@ -53,7 +53,6 @@ import org.slf4j.LoggerFactory;
  */
 public class QuartzComponent extends DefaultComponent implements StartupListener {
     private static final transient Logger LOG = LoggerFactory.getLogger(QuartzComponent.class);
-    private final AtomicInteger jobs = new AtomicInteger();
     private Scheduler scheduler;
     private final List<JobToAdd> jobsToAdd = new ArrayList<JobToAdd>();
     private SchedulerFactory factory;
@@ -165,7 +164,8 @@ public class QuartzComponent extends Def
     public void onCamelContextStarted(CamelContext camelContext, boolean alreadyStarted)
throws Exception {
         if (scheduler != null) {
             // register current camel context to scheduler so we can look it up when jobs
is being triggered
-            scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + getCamelContext().getName(),
getCamelContext());
+            // must use management name as it should be unique in the same JVM
+            scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + getCamelContext().getManagementName(),
getCamelContext());
         }
 
         // if not configure to auto start then don't start it
@@ -191,9 +191,9 @@ public class QuartzComponent extends Def
         super.doStop();
 
         if (scheduler != null) {
-            int number = jobs.get();
-            if (number > 0) {
-                LOG.info("Cannot shutdown Quartz scheduler: " + scheduler.getSchedulerName()
+ " as there are still " + number + " jobs registered.");
+            AtomicInteger number = (AtomicInteger) scheduler.getContext().get("CamelJobs");
+            if (number != null && number.get() > 0) {
+                LOG.info("Cannot shutdown Quartz scheduler: " + scheduler.getSchedulerName()
+ " as there are still " + number.get() + " jobs registered.");
             } else {
                 // no more jobs then shutdown the scheduler
                 LOG.info("There are no more jobs registered, so shutting down Quartz scheduler:
" + scheduler.getSchedulerName());
@@ -214,7 +214,7 @@ public class QuartzComponent extends Def
     }
 
     private void doAddJob(JobDetail job, Trigger trigger) throws SchedulerException {
-        jobs.incrementAndGet();
+        incrementJobCounter(getScheduler());
 
         Trigger existingTrigger = getScheduler().getTrigger(trigger.getName(), trigger.getGroup());
         if (existingTrigger == null) {
@@ -254,7 +254,7 @@ public class QuartzComponent extends Def
     }
 
     public void pauseJob(Trigger trigger) throws SchedulerException {
-        jobs.decrementAndGet();
+        decrementJobCounter(getScheduler());
 
         if (isClustered()) {
             // do not pause jobs which are clustered, as we want the jobs to continue running
on the other nodes
@@ -470,8 +470,31 @@ public class QuartzComponent extends Def
         }
 
         // register current camel context to scheduler so we can look it up when jobs is
being triggered
-        scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + getCamelContext().getName(),
getCamelContext());
+        // must use management name as it should be unique in the same JVM
+        scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + getCamelContext().getManagementName(),
getCamelContext());
+
+        // store Camel job counter
+        AtomicInteger number = (AtomicInteger) scheduler.getContext().get("CamelJobs");
+        if (number == null) {
+            number = new AtomicInteger(0);
+            scheduler.getContext().put("CamelJobs", number);
+        }
+
         return scheduler;
     }
 
+    private static void decrementJobCounter(Scheduler scheduler) throws SchedulerException
{
+        AtomicInteger number = (AtomicInteger) scheduler.getContext().get("CamelJobs");
+        if (number != null) {
+            number.decrementAndGet();
+        }
+    }
+
+    private static void incrementJobCounter(Scheduler scheduler) throws SchedulerException
{
+        AtomicInteger number = (AtomicInteger) scheduler.getContext().get("CamelJobs");
+        if (number != null) {
+            number.incrementAndGet();
+        }
+    }
+
 }

Modified: camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConstants.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConstants.java?rev=1345933&r1=1345932&r2=1345933&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConstants.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConstants.java
Mon Jun  4 12:06:06 2012
@@ -23,6 +23,7 @@ public final class QuartzConstants {
 
     public static final String QUARTZ_ENDPOINT_URI = "CamelQuartzEndpoint";
 
+    // Note: using the CamelContext management name to ensure its unique in the JVM
     public static final String QUARTZ_CAMEL_CONTEXT_NAME = "CamelQuartzCamelContextName";
 
     public static final String QUARTZ_CAMEL_CONTEXT = "CamelQuartzCamelContext";

Modified: camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java?rev=1345933&r1=1345932&r2=1345933&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
Mon Jun  4 12:06:06 2012
@@ -70,7 +70,8 @@ public class QuartzEndpoint extends Defa
             trigger.setStartTime(new Date());
         }
         detail.getJobDataMap().put(QuartzConstants.QUARTZ_ENDPOINT_URI, getEndpointUri());
-        detail.getJobDataMap().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME, getCamelContext().getName());
+        // must use management name as it should be unique in the same JVM
+        detail.getJobDataMap().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME, getCamelContext().getManagementName());
         if (detail.getJobClass() == null) {
             detail.setJobClass(isStateful() ? StatefulCamelJob.class : CamelJob.class);
         }

Modified: camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartTest.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartTest.xml?rev=1345933&r1=1345932&r2=1345933&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartTest.xml
(original)
+++ camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartTest.xml
Mon Jun  4 12:06:06 2012
@@ -56,7 +56,7 @@
     </property>
   </bean>
 
-  <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
+  <camelContext id="camelContext" managementNamePattern="#name#" xmlns="http://camel.apache.org/schema/spring">
     <route>
       <from uri="quartz://app/test?trigger.repeatInterval=1000&amp;trigger.repeatCount=-1&amp;stateful=true"/>
       <to uri="log:trigger"/>

Modified: camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreTest.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreTest.xml?rev=1345933&r1=1345932&r2=1345933&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreTest.xml
(original)
+++ camel/branches/camel-2.9.x/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/SpringQuartzPersistentStoreTest.xml
Mon Jun  4 12:06:06 2012
@@ -56,7 +56,7 @@
     </property>
   </bean>
 
-  <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
+  <camelContext id="camelContext" managementNamePattern="#name#" xmlns="http://camel.apache.org/schema/spring">
     <route id="myRoute">
       <from uri="quartz://app/test?trigger.repeatInterval=1000&amp;trigger.repeatCount=-1&amp;stateful=true"/>
       <to uri="log:trigger"/>



Mime
View raw message