Exemplo n.º 1
0
  private void startJobs() {
    try {
      // Get a new scheduler
      scheduler = new StdSchedulerFactory().getScheduler();
      // Start it up. This won't start any jobs though.
      scheduler.start();

      for (GuanxiJobConfig gxJob : gxJobs) {
        // Need a new JobDetail to hold custom data to send to the job we're controlling
        JobDetail jobDetail =
            new JobDetail(
                gxJob.getKey(), Scheduler.DEFAULT_GROUP, Class.forName(gxJob.getJobClass()));

        // Create a new JobDataMap for custom data to be sent to the job...
        JobDataMap jobDataMap = new JobDataMap();
        // ...and add the job's custom config object
        jobDataMap.put(GuanxiJobConfig.JOB_KEY_JOB_CONFIG, gxJob);

        // Put the job's custom data in it's JobDetail
        jobDetail.setJobDataMap(jobDataMap);

        /* Tell the scheduler when this job will run. Nothing will happen
         * until the start method is called.
         */
        Trigger trigger =
            new CronTrigger(gxJob.getKey(), Scheduler.DEFAULT_GROUP, gxJob.getCronLine());

        // Start the job
        scheduler.scheduleJob(jobDetail, trigger);

        if (gxJob.isStartImmediately()) {
          scheduler.triggerJob(gxJob.getKey(), Scheduler.DEFAULT_GROUP);
        }
      }
    } catch (ClassNotFoundException cnfe) {
      logger.error("Error locating job class", cnfe);
    } catch (SchedulerException se) {
      logger.error("Job scheduling error", se);
    } catch (ParseException pe) {
      logger.error("Error parsing job cronline", pe);
    }
  }
Exemplo n.º 2
0
  protected void stopScheduler() {
    try {
      SchedulerFactory f = DefaultSchedulerFactory.getInstance();
      Scheduler s = f.getScheduler();
      s.stop(null, null);
    } catch (IOException ex) {
      // Log info:
      {
        String message = "Failure to stop scheduler!";
        log.log(Level.SEVERE, message, ex);
      }

      throw new RuntimeException(ex);
    } catch (Throwable ex) {
      // Log info:
      {
        String message = "Failure to stop scheduler!";
        log.log(Level.SEVERE, message, ex);
      }

      throw new RuntimeException(ex);
    }
  }
Exemplo n.º 3
0
  /**
   * Called by Spring when application events occur. At the moment we handle: ContextClosedEvent
   * ContextRefreshedEvent RequestHandledEvent
   *
   * <p>This is where we inject the job controllers into the application context, each one under
   * it's own key.
   *
   * @param applicationEvent Spring application event
   */
  public void onApplicationEvent(ApplicationEvent applicationEvent) {
    if (applicationEvent instanceof ContextRefreshedEvent) {
      logger.info("Bootstrap init");

      // Inject the metadata farm to handle all source of metadata
      servletContext.setAttribute(Guanxi.CONTEXT_ATTR_IDP_ENTITY_FARM, entityFarm);
    }

    if (applicationEvent instanceof ContextClosedEvent) {
      if (okToUnloadBCProvider) {
        Provider[] providers = Security.getProviders();

        /* Although addProvider() returns the ID of the newly installed provider,
         * we can't rely on this. If another webapp removes a provider from the list of
         * installed providers, all the other providers shuffle up the list by one, thus
         * invalidating the ID we got from addProvider().
         */
        try {
          for (int i = 0; i < providers.length; i++) {
            if (providers[i].getName().equalsIgnoreCase(Guanxi.BOUNCY_CASTLE_PROVIDER_NAME)) {
              Security.removeProvider(Guanxi.BOUNCY_CASTLE_PROVIDER_NAME);
            }
          }

          // Stop the jobs
          scheduler.shutdown();
        } catch (SecurityException se) {
          /* We'll end up here if a security manager is installed and it refuses us
           * permission to remove the BouncyCastle provider
           */
        } catch (SchedulerException se) {
          logger.error("Could not stop jobs", se);
        }
      }
    }

    if (applicationEvent instanceof RequestHandledEvent) {}
  }
Exemplo n.º 4
0
 public void halt() {
   scheduler.interrupt();
   listenThread.interrupt();
   Client.killAllClient();
   timer.pause();
 }