Search in sources :

Example 6 with QuartzComponent

use of org.apache.camel.component.quartz2.QuartzComponent in project wildfly-camel by wildfly-extras.

the class RouteBuilderF method configure.

@Override
public void configure() throws Exception {
    final CountDownLatch startLatch = new CountDownLatch(1);
    // verify that a component can be added manually
    getContext().addComponent("quartz2", new QuartzComponent() {

        @Override
        public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
            super.onCamelContextStarted(context, alreadyStarted);
            startLatch.countDown();
        }
    });
    from("quartz2://mytimer?trigger.repeatCount=3&trigger.repeatInterval=100").process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            if (startLatch.getCount() > 0)
                throw new IllegalStateException("onCamelContextStarted not called");
        }
    }).to(MOCK_RESULT_URI);
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) IllegalStateException(javax.resource.spi.IllegalStateException) Processor(org.apache.camel.Processor) CountDownLatch(java.util.concurrent.CountDownLatch) IllegalStateException(javax.resource.spi.IllegalStateException) QuartzComponent(org.apache.camel.component.quartz2.QuartzComponent)

Example 7 with QuartzComponent

use of org.apache.camel.component.quartz2.QuartzComponent in project wildfly-camel by wildfly-extras.

the class QuartzIntegrationTest method testScheduler.

@Test
public void testScheduler() throws Exception {
    final CountDownLatch procLatch = new CountDownLatch(3);
    ClassLoader loader = QuartzIntegrationTest.class.getClassLoader();
    Class<?> sclass = loader.loadClass("org.quartz.Scheduler");
    Assert.assertNotNull("Scheduler can be loaded", sclass);
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("quartz2://mytimer?trigger.repeatCount=3&trigger.repeatInterval=100").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    CamelContext context = exchange.getContext();
                    QuartzComponent comp = context.getComponent("quartz2", QuartzComponent.class);
                    Scheduler scheduler = comp.getScheduler();
                    Assert.assertNotNull("Scheduler not null", scheduler);
                    procLatch.countDown();
                }
            }).to("mock:result");
        }
    });
    camelctx.start();
    try {
        Assert.assertTrue("ProcLatch reached zero", procLatch.await(500, TimeUnit.MILLISECONDS));
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(org.quartz.Scheduler) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) QuartzComponent(org.apache.camel.component.quartz2.QuartzComponent) Test(org.junit.Test)

Aggregations

QuartzComponent (org.apache.camel.component.quartz2.QuartzComponent)7 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelContext (org.apache.camel.CamelContext)3 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IllegalStateException (javax.resource.spi.IllegalStateException)1 JobDataMap (org.quartz.JobDataMap)1 Scheduler (org.quartz.Scheduler)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1