camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1067624 - in /camel/trunk: components/camel-quartz/src/main/java/org/apache/camel/component/quartz/ components/camel-quartz/src/test/java/org/apache/camel/component/quartz/ tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/q...
Date Sun, 06 Feb 2011 09:55:29 GMT
Author: davsclaus
Date: Sun Feb  6 09:55:29 2011
New Revision: 1067624

URL: http://svn.apache.org/viewvc?rev=1067624&view=rev
Log:
CAMEL-3633: Forced disabling Quartz update checker. CAMEL-3579: You can now use multiple QuartzScheduler
instances in the same JVM classloader. Thanks to Sergey for the patch.

Modified:
    camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java

Modified: camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java?rev=1067624&r1=1067623&r2=1067624&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
(original)
+++ camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
Sun Feb  6 09:55:29 2011
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.camel.CamelContext;
 import org.apache.camel.StartupListener;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.quartz.CronTrigger;
@@ -53,8 +54,8 @@ import org.slf4j.LoggerFactory;
  */
 public class QuartzComponent extends DefaultComponent implements StartupListener {
     private static final transient Logger LOG = LoggerFactory.getLogger(QuartzComponent.class);
-    private static final AtomicInteger JOBS = new AtomicInteger();
-    private static Scheduler scheduler;
+    private final AtomicInteger jobs = new AtomicInteger();
+    private Scheduler scheduler;
     private final List<JobToAdd> jobsToAdd = new ArrayList<JobToAdd>();
     private SchedulerFactory factory;
     private Properties properties;
@@ -186,7 +187,7 @@ public class QuartzComponent extends Def
         super.doStop();
 
         if (scheduler != null) {
-            int number = JOBS.get();
+            int number = jobs.get();
             if (number > 0) {
                 LOG.info("Cannot shutdown Quartz scheduler: " + scheduler.getSchedulerName()
+ " as there are still " + number + " jobs registered.");
             } else {
@@ -209,7 +210,7 @@ public class QuartzComponent extends Def
     }
 
     private void doAddJob(JobDetail job, Trigger trigger) throws SchedulerException {
-        JOBS.incrementAndGet();
+        jobs.incrementAndGet();
 
         Trigger existingTrigger = getScheduler().getTrigger(trigger.getName(), trigger.getGroup());
         if (existingTrigger == null) {
@@ -245,7 +246,7 @@ public class QuartzComponent extends Def
     }
 
     public void pauseJob(Trigger trigger) throws SchedulerException {
-        JOBS.decrementAndGet();
+        jobs.decrementAndGet();
 
         if (isClustered()) {
             // do not pause jobs which are clustered, as we want the jobs to continue running
on the other nodes
@@ -268,7 +269,7 @@ public class QuartzComponent extends Def
                 LOG.debug("Cannot delete job using trigger: " + group + "/" + name + " as
the JobStore is clustered.");
             }
         } else {
-            Trigger trigger = getScheduler().getTrigger(name, group);
+            Trigger trigger  = getScheduler().getTrigger(name, group);
             if (trigger != null) {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Deleting job using trigger: " + group + "/" + name);
@@ -341,7 +342,7 @@ public class QuartzComponent extends Def
         return factory;
     }
 
-    public void setFactory(final SchedulerFactory factory) {
+    public void setFactory(SchedulerFactory factory) {
         this.factory = factory;
     }
 
@@ -353,7 +354,7 @@ public class QuartzComponent extends Def
     }
 
     public void setScheduler(final Scheduler scheduler) {
-        QuartzComponent.scheduler = scheduler;
+        this.scheduler = scheduler;
     }
 
     public Properties getProperties() {
@@ -412,15 +413,54 @@ public class QuartzComponent extends Def
     }
 
     protected SchedulerFactory createSchedulerFactory() throws SchedulerException {
+        SchedulerFactory answer;
+
         Properties prop = loadProperties();
         if (prop != null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Creating SchedulerFactory with properties: " + prop);
-            }
-            return new StdSchedulerFactory(prop);
+
+            // force disabling update checker (will do online check over the internet)
+            prop.put("org.quartz.scheduler.skipUpdateCheck", "true");
+
+            answer = new StdSchedulerFactory(prop);
         } else {
-            return new StdSchedulerFactory();
+            // read default props to be able to use a single scheduler per camel context
+            // if we need more than one scheduler per context use setScheduler(Scheduler)

+            // or setFactory(SchedulerFactory) methods
+
+            // must use classloader from StdSchedulerFactory to work even in OSGi
+            InputStream is = StdSchedulerFactory.class.getClassLoader().getResourceAsStream("org/quartz/quartz.properties");
+            if (is == null) {
+                throw new SchedulerException("Quartz properties file not found in classpath:
org/quartz/quartz.properties");
+            }
+            prop = new Properties();
+            try {
+                prop.load(is);
+            } catch (IOException e) {
+                throw new SchedulerException("Error loading Quartz properties file from classpath:
org/quartz/quartz.properties", e);
+            }
+
+            // camel context name will be a suffix to use one scheduler per context
+            String identity = getCamelContext().getName();
+
+            String instName = prop.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
+            if (instName == null) {
+                instName = "scheduler-" + identity;
+            } else {
+                instName = instName + "-" + identity;
+            }
+            prop.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instName);
+
+            // force disabling update checker (will do online check over the internet)
+            prop.put("org.quartz.scheduler.skipUpdateCheck", "true");
+
+            answer = new StdSchedulerFactory(prop);
         }
+
+        if (LOG.isDebugEnabled()) {
+            String name = prop.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
+            LOG.debug("Creating SchedulerFactory: " + name + " with properties: " + prop);
+        }
+        return answer;
     }
 
     protected Scheduler createScheduler() throws SchedulerException {

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java?rev=1067624&r1=1067623&r2=1067624&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzNameCollisionTest.java
Sun Feb  6 09:55:29 2011
@@ -43,9 +43,7 @@ public class QuartzNameCollisionTest {
         });
         camel1.start();
 
-        camel2 = new DefaultCamelContext();
-        QuartzComponent component2 = new QuartzComponent(camel2);
-
+        QuartzComponent component2 = new QuartzComponent(camel1);
         try {
             component2.createEndpoint("quartz://myGroup/myTimerName");
             Assert.fail("Should have thrown an exception");
@@ -54,6 +52,22 @@ public class QuartzNameCollisionTest {
         }
     }
 
+    @Test
+    public void testDupeNameMultiContext() throws Exception {
+        camel1 = new DefaultCamelContext();
+        camel1.setName("camel-1");
+        camel1.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+            }
+        });
+        camel1.start();
+
+        camel2 = new DefaultCamelContext();
+        QuartzComponent component2 = new QuartzComponent(camel2);
+        component2.createEndpoint("quartz://myGroup/myTimerName");
+    }
 
     /**
      * Don't check for a name collision if the job is stateful.
@@ -116,32 +130,29 @@ public class QuartzNameCollisionTest {
         camel1.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+                from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").id("route-1").to("log:one",
"mock:one");
             }
         });
-        camel1.start();
 
-        camel2 = new DefaultCamelContext();
-        camel2.setName("camel-2");
-        camel2.addRoutes(new RouteBuilder() {
+        camel1.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("quartz://myGroup2/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
+                from("quartz://myGroup2/myTimerName?cron=0/1+*+*+*+*+?").id("route-2").to("log:one",
"mock:one");
             }
         });
-        camel2.start();
+
+        camel1.start();
 
         QuartzComponent component = (QuartzComponent) camel1.getComponent("quartz");
         Scheduler scheduler = component.getScheduler();
         Trigger trigger = scheduler.getTrigger("myTimerName", "myGroup");
         Assert.assertNotNull(trigger);
+        
+        camel1.stopRoute("route-1");
 
-        camel1.stop();
-
-        trigger = scheduler.getTrigger("myTimerName", "myGroup");
-        Assert.assertNull(trigger);
-
-        camel2.stop();
+        int triggerState = component.getScheduler().getTriggerState("myTimerName", "myGroup");
+        Assert.assertNotNull(trigger);
+        Assert.assertEquals(Trigger.STATE_PAUSED, triggerState);
     }
 
     @After

Modified: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java?rev=1067624&r1=1067623&r2=1067624&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java
(original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/quartz/QuartzCronRouteTest.java
Sun Feb  6 09:55:29 2011
@@ -19,7 +19,6 @@ package org.apache.camel.itest.osgi.quar
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -34,7 +33,6 @@ import static org.ops4j.pax.exam.contain
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
 
 @RunWith(JUnit4TestRunner.class)
-@Ignore("TODO: Test hangs")
 public class QuartzCronRouteTest extends OSGiIntegrationTestSupport {
 
     @Test
@@ -61,7 +59,7 @@ public class QuartzCronRouteTest extends
             // install the spring dm profile
             profile("spring.dm").version("1.2.0"),
             // this is how you set the default log level when using pax logging (logProfile)
-            org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+            org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
 
             // using the features to install the camel components
             scanFeatures(getCamelKarafFeatureUrl(),
@@ -69,7 +67,8 @@ public class QuartzCronRouteTest extends
 
             workingDirectory("target/paxrunner/"),
 
-            felix(), equinox());
+            // TODO: test hang on shutdown on equionox
+            felix());
 
         return options;
     }



Mime
View raw message