Java 类org.apache.camel.component.quartz2.QuartzComponent 实例源码

项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStopRoutePolicy() throws Exception {
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStopTime("*/3 * * * * ?");
            policy.setRouteStopGracePeriod(0);
            policy.setTimeUnit(TimeUnit.MILLISECONDS);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:unreachable");
        }
    });
    context.start();

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStopRoutePolicyWithExtraPolicy() throws Exception {
    final MyRoutePolicy myPolicy = new MyRoutePolicy();

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStopTime("*/3 * * * * ?");
            policy.setRouteStopGracePeriod(0);
            policy.setTimeUnit(TimeUnit.MILLISECONDS);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy, myPolicy)
                .to("mock:unreachable");
        }
    });
    context.start();

    Thread.sleep(5000);

    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
    assertTrue("Should have called onStart", myPolicy.isStart());
    assertTrue("Should have called onStop", myPolicy.isStop());
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledSuspendRoutePolicy() throws Exception {
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteSuspendTime("*/3 * * * * ?");

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:unreachable");
        } 
    });
    context.start();

    Thread.sleep(5000);

    // when suspending its only the consumer that suspends
    // there is a ticket to improve this
    Consumer consumer = context.getRoute("test").getConsumer();
    SuspendableService ss = (SuspendableService) consumer;
    assertTrue("Consumer should be suspended", ss.isSuspended());
}
项目:Camel    文件:MultiplePoliciesOnRouteTest.java   
@Test
public void testMultiplePoliciesOnRoute() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);        
    success.expectedMinimumMessageCount(size - 10);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {   
            from(url)
                .routeId("test")
                .routePolicyRef("startPolicy, throttlePolicy")
                .to("log:foo?groupSize=10")
                .to("mock:success");
        }
    });
    context.start();

    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
    for (int i = 0; i < size; i++) {
        template.sendBody(url, "Message " + i);
        Thread.sleep(3);
    }

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:wildfly-camel    文件:RouteBuilderF.java   
@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);
}
项目:openex-worker    文件:SchedulerExecutor.java   
@Override
public ImmutableMap<String, Component> components() {
    QuartzComponent quartzComponent = new QuartzComponent();
    quartzComponent.setEnableJmx(false); //Standalone scheduler, no need to register it in mbean
    HttpComponent httpComponent = new HttpComponent();
    return ImmutableMap.of("http", httpComponent, "https", httpComponent, "quartz", quartzComponent);
}
项目:Camel    文件:SimpleScheduledRoutePolicy.java   
protected void doOnInit(Route route) throws Exception {
    QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class);
    setScheduler(quartz.getScheduler());

    // Important: do not start scheduler as QuartzComponent does that automatic
    // when CamelContext has been fully initialized and started

    if (getRouteStopGracePeriod() == 0) {
        setRouteStopGracePeriod(10000);
    }

    if (getTimeUnit() == null) {
        setTimeUnit(TimeUnit.MILLISECONDS);
    }

    // validate time options has been configured
    if ((getRouteStartDate() == null) && (getRouteStopDate() == null) && (getRouteSuspendDate() == null) && (getRouteResumeDate() == null)) {
        throw new IllegalArgumentException("Scheduled Route Policy for route {} has no start/stop/suspend/resume times specified");
    }

    registerRouteToScheduledRouteDetails(route);
    if (getRouteStartDate() != null) {
        scheduleRoute(Action.START, route);
    }
    if (getRouteStopDate() != null) {
        scheduleRoute(Action.STOP, route);
    }

    if (getRouteSuspendDate() != null) {
        scheduleRoute(Action.SUSPEND, route);
    }
    if (getRouteResumeDate() != null) {
        scheduleRoute(Action.RESUME, route);
    }
}
项目:Camel    文件:ScheduledRoutePolicy.java   
public void scheduleRoute(Action action, Route route) throws Exception {
    JobDetail jobDetail = createJobDetail(action, route);
    Trigger trigger = createTrigger(action, route);
    updateScheduledRouteDetails(action, jobDetail, trigger, route);

    loadCallbackDataIntoSchedulerContext(jobDetail, action, route);

    boolean isClustered = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class).isClustered();
    if (isClustered) {
        // check to see if the same job has already been setup through another node of the cluster
        JobDetail existingJobDetail = getScheduler().getJobDetail(jobDetail.getKey());
        if (jobDetail.equals(existingJobDetail)) {
            if (LOG.isInfoEnabled()) {
                LOG.info("Skipping to schedule the job: {} for action: {} on route {} as the job: {} already existing inside the cluster",
                         new Object[] {jobDetail.getKey(), action, route.getId(), existingJobDetail.getKey()});
            }

            // skip scheduling the same job again as one is already existing for the same routeId and action
            return;
        }
    }

    getScheduler().scheduleJob(jobDetail, trigger);

    if (LOG.isInfoEnabled()) {
        LOG.info("Scheduled trigger: {} for action: {} on route {}", new Object[]{trigger.getKey(), action, route.getId()});
    }
}
项目:Camel    文件:CronScheduledRoutePolicy.java   
protected void doOnInit(Route route) throws Exception {
    QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz2", QuartzComponent.class);
    setScheduler(quartz.getScheduler());

    // Important: do not start scheduler as QuartzComponent does that automatic
    // when CamelContext has been fully initialized and started

    if (getRouteStopGracePeriod() == 0) {
        setRouteStopGracePeriod(10000);
    }

    if (getTimeUnit() == null) {
        setTimeUnit(TimeUnit.MILLISECONDS);
    }

    // validate time options has been configured
    if ((getRouteStartTime() == null) && (getRouteStopTime() == null) && (getRouteSuspendTime() == null) && (getRouteResumeTime() == null)) {
        throw new IllegalArgumentException("Scheduled Route Policy for route {} has no start/stop/suspend/resume times specified");
    }

    registerRouteToScheduledRouteDetails(route);
    if (getRouteStartTime() != null) {
        scheduleRoute(Action.START, route);
    }
    if (getRouteStopTime() != null) {
        scheduleRoute(Action.STOP, route);
    }

    if (getRouteSuspendTime() != null) {
        scheduleRoute(Action.SUSPEND, route);
    }
    if (getRouteResumeTime() != null) {
        scheduleRoute(Action.RESUME, route);
    }
}
项目:Camel    文件:QuartzComponentAutoConfiguration.java   
@Bean
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(QuartzComponent.class)
public QuartzComponent configureQuartzComponent(CamelContext camelContext,
        QuartzComponentConfiguration configuration) throws Exception {
    QuartzComponent component = new QuartzComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null,
            false);
    IntrospectionSupport.setProperties(camelContext,
            camelContext.getTypeConverter(), component, parameters);
    return component;
}
项目:Camel    文件:SimpleScheduledRoutePolicyTest.java   
@Test
public void testScheduledStartRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);        
    success.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {   
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000L;
            policy.setRouteStartDate(new Date(startTime));
            policy.setRouteStartRepeatCount(1);
            policy.setRouteStartRepeatInterval(3000);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:success");
        }
    });
    context.start();
    context.stopRoute("test", 1000, TimeUnit.MILLISECONDS);

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
    template.sendBody("direct:start", "Ready or not, Here, I come");

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:Camel    文件:SimpleScheduledRoutePolicyTest.java   
@Test
public void testScheduledStopRoutePolicy() throws Exception {
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000;
            policy.setRouteStopDate(new Date(startTime));
            policy.setRouteStopRepeatCount(1);
            policy.setRouteStopRepeatInterval(3000);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:unreachable");
        }
    });
    context.start();

    Thread.sleep(4000);

    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);

    boolean consumerStopped = false;
    try {
        template.sendBody("direct:start", "Ready or not, Here, I come");
    } catch (CamelExecutionException e) {
        consumerStopped = true;
    }    
    assertTrue(consumerStopped);
    context.getComponent("quartz2", QuartzComponent.class).stop();
}
项目:Camel    文件:SimpleScheduledRoutePolicyTest.java   
@Test
public void testScheduledSuspendRoutePolicy() throws Exception {
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000L;
            policy.setRouteSuspendDate(new Date(startTime));
            policy.setRouteSuspendRepeatCount(1);
            policy.setRouteSuspendRepeatInterval(3000);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:unreachable");
        } 
    });
    context.start();

    Thread.sleep(4000);

    boolean consumerSuspended = false;
    try {
        template.sendBody("direct:start", "Ready or not, Here, I come");
    } catch (CamelExecutionException e) {
        consumerSuspended = true;
    }        
    assertTrue(consumerSuspended);
    context.getComponent("quartz2", QuartzComponent.class).stop();
}
项目:Camel    文件:SimpleScheduledRoutePolicyTest.java   
@Test
public void testScheduledResumeRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000L;
            policy.setRouteResumeDate(new Date(startTime));
            policy.setRouteResumeRepeatCount(1);
            policy.setRouteResumeRepeatInterval(3000);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:success");
        } 
    });
    context.start();

    ServiceHelper.suspendService(context.getRoute("test").getConsumer());
    try {
        template.sendBody("direct:start", "Ready or not, Here, I come");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        LOG.debug("Consumer successfully suspended");
    } 

    Thread.sleep(4000);
    template.sendBody("direct:start", "Ready or not, Here, I come");

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:Camel    文件:SimpleScheduledRoutePolicyTest.java   
@Test
public void testScheduledSuspendAndResumeRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long suspendTime = System.currentTimeMillis() + 1000L;
            policy.setRouteSuspendDate(new Date(suspendTime));
            policy.setRouteSuspendRepeatCount(0);
            policy.setRouteSuspendRepeatInterval(3000);
            long resumeTime = System.currentTimeMillis() + 4000L;
            policy.setRouteResumeDate(new Date(resumeTime));
            policy.setRouteResumeRepeatCount(1);
            policy.setRouteResumeRepeatInterval(3000);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:success");
        } 
    });
    context.start();
    Thread.sleep(1000);

    try {
        template.sendBody("direct:start", "Ready or not, Here, I come");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        LOG.debug("Consumer successfully suspended");
    } 

    Thread.sleep(4000);
    template.sendBody("direct:start", "Ready or not, Here, I come");

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:Camel    文件:SimpleScheduledRoutePolicyTest.java   
@Test
public void testScheduledSuspendAndRestartPolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long suspendTime = System.currentTimeMillis() + 1000L;
            policy.setRouteSuspendDate(new Date(suspendTime));
            policy.setRouteSuspendRepeatCount(0);
            long startTime = System.currentTimeMillis() + 4000L;
            policy.setRouteStartDate(new Date(startTime));
            policy.setRouteResumeRepeatCount(1);
            policy.setRouteResumeRepeatInterval(3000);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:success");
        } 
    });
    context.start();
    Thread.sleep(1000);

    try {
        template.sendBody("direct:start", "Ready or not, Here, I come");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        LOG.debug("Consumer successfully suspended");
    } 

    Thread.sleep(4000);
    template.sendBody("direct:start", "Ready or not, Here, I come");

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStartRoutePolicyWithTwoRoutes() throws Exception {
    MockEndpoint success1 = context.getEndpoint("mock:success1", MockEndpoint.class);
    MockEndpoint success2 = context.getEndpoint("mock:success2", MockEndpoint.class);
    success1.expectedMessageCount(1);
    success2.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");

    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStartTime("*/3 * * * * ?");

            from("direct:start1")
                .routeId("test1")
                .routePolicy(policy)
                .to("mock:success1");

            from("direct:start2")
                .routeId("test2")
                .routePolicy(policy)
                .to("mock:success2");
        }
    });
    context.start();
    context.stopRoute("test1", 1000, TimeUnit.MILLISECONDS);
    context.stopRoute("test2", 1000, TimeUnit.MILLISECONDS);

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test1") == ServiceStatus.Started);
    assertTrue(context.getRouteStatus("test2") == ServiceStatus.Started);
    template.sendBody("direct:start1", "Ready or not, Here, I come");
    template.sendBody("direct:start2", "Ready or not, Here, I come");

    success1.assertIsSatisfied();
    success2.assertIsSatisfied();
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStopRoutePolicyWithTwoRoutes() throws Exception {
    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStopTime("*/3 * * * * ?");
            policy.setRouteStopGracePeriod(0);
            policy.setTimeUnit(TimeUnit.MILLISECONDS);

            from("direct:start1")
                .routeId("test1")
                .routePolicy(policy)
                .to("mock:unreachable");

            from("direct:start2")
                .routeId("test2")
                .routePolicy(policy)
                .to("mock:unreachable");
        }
    });
    context.start();

    Thread.sleep(5000);

    assertTrue(context.getRouteStatus("test1") == ServiceStatus.Stopped);
    assertTrue(context.getRouteStatus("test2") == ServiceStatus.Stopped);
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledStartRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");

    context.addRoutes(new RouteBuilder() {
        public void configure() {    
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStartTime("*/3 * * * * ?");

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:success");
        }
    });
    context.start();
    context.stopRoute("test", 1000, TimeUnit.MILLISECONDS);

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
    template.sendBody("direct:start", "Ready or not, Here, I come");

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:Camel    文件:CronScheduledRoutePolicyTest.java   
@Test
public void testScheduledResumeRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteResumeTime("*/3 * * * * ?");

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:success");
        } 
    });
    context.start();

    ServiceHelper.suspendService(context.getRoute("test").getConsumer());

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);

    template.sendBody("direct:start", "Ready or not, Here, I come");

    success.assertIsSatisfied();
}
项目:Camel    文件:SimpleScheduledCombinedRoutePolicyTest.java   
@Test
public void testScheduledStartAndStopRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);        
    success.expectedMessageCount(1);

    context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(new RouteBuilder() {
        public void configure() {   
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000L;
            long stopTime = System.currentTimeMillis() + 8000L;
            policy.setRouteStartDate(new Date(startTime));
            policy.setRouteStartRepeatCount(1);
            policy.setRouteStartRepeatInterval(3000);
            policy.setRouteStopDate(new Date(stopTime));
            policy.setRouteStopRepeatCount(1);
            policy.setRouteStopRepeatInterval(3000);

            from("direct:start")
                .routeId("test")
                .routePolicy(policy)
                .to("mock:success");
        }
    });
    context.start();

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
    template.sendBody("direct:start", "Ready or not, Here, I come");
    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);

    context.getComponent("quartz2", QuartzComponent.class).stop();
    success.assertIsSatisfied();
}
项目:camelinaction2    文件:ServerFoo.java   
public void boot() throws Exception {
    main = new Main();

    // setup quartz component
    QuartzComponent quartz = new QuartzComponent();
    quartz.setPropertiesFile("quartz.properties");

    // add the component to Camel
    main.bind("quartz2", quartz);

    main.addRouteBuilder(new QuartzRoute("Foo"));
    main.run();
}
项目:camelinaction2    文件:ServerBar.java   
public void boot() throws Exception {
    main = new Main();

    // setup quartz component
    QuartzComponent quartz = new QuartzComponent();
    quartz.setPropertiesFile("quartz.properties");

    // add the component to Camel
    main.bind("quartz2", quartz);

    // route which uses get/put operations
    main.addRouteBuilder(new QuartzRoute("Bar"));
    main.run();
}
项目:sample_spring-boot-camel-mongo-jdk8    文件:ProcessConfiguration.java   
@Bean
public QuartzComponent quartzComponent(
    @Value("${scheduler.startup-delay-seconds}") final int startupDelaySeconds) {
  final Properties quartzProperties = new Properties();
  quartzProperties.setProperty("org.quartz.plugin.shutdownhook.class",
      "org.quartz.plugins.management.ShutdownHookPlugin");
  quartzProperties.setProperty("org.quartz.plugin.shutdownhook.cleanShutdown", "true");

  final QuartzComponent component = new QuartzComponent();
  component.setEnableJmx(false);
  component.setStartDelayedSeconds(startupDelaySeconds);
  component.setProperties(quartzProperties);
  return component;
}
项目:wildfly-camel    文件:QuartzIntegrationTest.java   
@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();
    }
}
项目:wildfly-camel    文件:QuartzIntegrationTest.java   
@Test
public void testManualComponentConfig() throws Exception {

    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch procLatch = new CountDownLatch(3);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addComponent("quartz2", new QuartzComponent() {
        @Override
        public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
            super.onCamelContextStarted(context, alreadyStarted);
            if (!alreadyStarted) {
                startLatch.countDown();
            }
        }
    });

    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 {
                    procLatch.countDown();
                }
            }).to("mock:result");
        }
    });

    camelctx.start();
    try {
        Assert.assertEquals("StartLatch is zero", 0, startLatch.getCount());
        Assert.assertTrue("ProcLatch reached zero", procLatch.await(500, TimeUnit.MILLISECONDS));
    } finally {
        camelctx.stop();
    }
}
项目:Camel    文件:QuartzScheduledPollConsumerScheduler.java   
@Override
protected void doStart() throws Exception {
    ObjectHelper.notEmpty(cron, "cron", this);

    if (quartzScheduler == null) {
        // get the scheduler form the quartz component
        QuartzComponent quartz = getCamelContext().getComponent("quartz2", QuartzComponent.class);
        setQuartzScheduler(quartz.getScheduler());
    }

    JobDataMap map = new JobDataMap();
    // do not store task as its not serializable, if we have route id
    if (routeId != null) {
        map.put("routeId", routeId);
    } else {
        map.put("task", runnable);
    }
    map.put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
    map.put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION, getCron());
    map.put(QuartzConstants.QUARTZ_TRIGGER_CRON_TIMEZONE, getTimeZone().getID());

    job = JobBuilder.newJob(QuartzScheduledPollConsumerJob.class)
            .usingJobData(map)
            .build();

    // store additional information on job such as camel context etc
    QuartzHelper.updateJobDataMap(getCamelContext(), job, null);

    String id = triggerId;
    if (id == null) {
        id = "trigger-" + getCamelContext().getUuidGenerator().generateUuid();
    }

    trigger = TriggerBuilder.newTrigger()
            .withIdentity(id, triggerGroup)
            .withSchedule(CronScheduleBuilder.cronSchedule(getCron()).inTimeZone(getTimeZone()))
            .build();

    LOG.debug("Scheduling job: {} with trigger: {}", job, trigger.getKey());
    quartzScheduler.scheduleJob(job, trigger);
}