JobScheduler() throws JobSchedulerException {
   org.quartz.spi.JobFactory jobFactory = new JobFactory();
   SchedulerFactory schedulerFactory = new StdSchedulerFactory();
   try {
     scheduler = schedulerFactory.getScheduler();
     scheduler.setJobFactory(jobFactory);
   } catch (SchedulerException e) {
     throw new JobSchedulerException("An exception occurred during scheduler setup", e);
   }
 }
Example #2
0
  public Registration run() throws Exception {

    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    final Scheduler scheduler = schedulerFactory.getScheduler();
    scheduler.setJobFactory(jobFactory.get());
    for (Job j : jobProvider.get()) {

      JobDetail jobDetail =
          JobBuilder.newJob(j.getClass())
              .withIdentity(j.getClass().getSimpleName() + "Job")
              .build();

      if (shouldInstall(j.getClass())) {
        ScheduleInterval interval = j.getClass().getAnnotation(ScheduleInterval.class);
        if (interval != null) {
          Trigger trigger =
              TriggerBuilder.newTrigger()
                  .withIdentity(j.getClass().getSimpleName() + "TriggerId")
                  .withSchedule(
                      SimpleScheduleBuilder.simpleSchedule()
                          .withIntervalInSeconds(interval.value())
                          .repeatForever())
                  .build();
          System.out.println(
              "Schedule " + j.getClass().getSimpleName() + " @ " + interval.value() + "sec");
          scheduler.scheduleJob(jobDetail, trigger);
        }

        CronInterval cron = j.getClass().getAnnotation(CronInterval.class);
        if (cron != null) {
          Trigger trigger =
              TriggerBuilder.newTrigger()
                  .withIdentity(j.getClass().getSimpleName() + "TriggerId")
                  .withSchedule(CronScheduleBuilder.cronSchedule(cron.value()))
                  .build();
          System.out.println("Schedule " + j.getClass().getSimpleName() + " @ " + cron.value());
          scheduler.scheduleJob(jobDetail, trigger);
        }
      }
    }

    scheduler.start();
    return new Registration() {
      public void unregister() {
        try {
          scheduler.shutdown();
        } catch (Exception e) {
        }
        System.out.println("Schedular Stopped");
      }
    };
  }
  @Override
  protected void doConfigure() {

    String name = entity.getName();
    TrackingDriverConfiguration config = entity.getConfiguration();
    CamelContext context = entity.getContext();
    EntityCache<GroundStation> groundStationCache = EntityCache.forType(dao, GroundStation.class);
    EntityCache<Satellite> satelliteCache = EntityCache.forType(dao, Satellite.class);
    EntityCache<TleOrbitalParameters> tleCache =
        EntityCache.forType(dao, TleOrbitalParameters.class);

    ProducerTemplate producer = context.createProducerTemplate();

    Scheduler scheduler;
    try {
      scheduler = StdSchedulerFactory.getDefaultScheduler();
      JobFactory factory =
          new TrackComponentJobFactory(
              entity,
              dao,
              producer,
              TRACK_COMMAND_INJECTOR,
              satelliteCache,
              tleCache,
              idBuilder,
              config);
      scheduler.setJobFactory(factory);
      scheduler.start();
    } catch (Exception e) {
      throw new RuntimeException("Failed to start Quartz sceduler", e);
    }

    SchedulingSupport support = new SchedulingSupport();
    ArchivePoller archivePoller = new ArchivePoller(config, dao);
    TrackCommandScheduler trackCommandScheduler =
        new TrackCommandScheduler(config, scheduler, support);
    TrackCommandUnscheduler contactUnscheduler = new TrackCommandUnscheduler(scheduler, support);
    EventAnalyzer analyzer = new EventAnalyzer(scheduler, support);
    ScheduleDeltaCheck deltaCheck = new ScheduleDeltaCheck(config, support);
    NotificationEventScheduler notificationScheduler =
        new NotificationEventScheduler(scheduler, support, groundStationCache, satelliteCache);

    // @formatter:off

    from(TRACK_COMMAND_INJECTOR)
        .choice()
        .when(body().isInstanceOf(Track.class))
        .bean(notificationScheduler)
        .end()
        .bean(publisher);

    from("direct:scheduleContact")
        .filter(deltaCheck)
        .bean(trackCommandScheduler)
        .to("log:scheduledContact-log?level=DEBUG");

    from("direct:rescheduleContact")
        .choice()
        .when(deltaCheck)
        .bean(contactUnscheduler)
        .to("log:RescheduleContact-log?level=DEBUG")
        .to("direct:scheduleContact")
        .otherwise()
        .to("log:ReschedulingImpossible?level=WARN");

    from("seda:eventHandler")
        .to("log:handler-log?level=DEBUG")
        .process(analyzer)
        .choice()
        .when(
            header(EventAnalyzer.HEADER_KEY_EVENT_TYPE)
                .isEqualTo(EventAnalyzer.HEADER_VALUE_NEW_EVENT))
        .to("direct:scheduleContact")
        .when(
            header(EventAnalyzer.HEADER_KEY_EVENT_TYPE)
                .isEqualTo(EventAnalyzer.HEADER_VALUE_UPDATED_EVENT))
        .to("direct:rescheduleContact")
        .otherwise()
        .log("LocationContacEvent already scheduled");

    from(addTimer(name, config.getArchivePollInterval()))
        .bean(archivePoller)
        .split(body())
        .to("seda:eventHandler");

    // @formatter:on
  }