org.quartz.simpl.CascadingClassLoadHelper Java Examples

The following examples show how to use org.quartz.simpl.CascadingClassLoadHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XMLSchedulingDataProcessorPlugin.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Called during creation of the <code>Scheduler</code> in order to give
 * the <code>SchedulerPlugin</code> a chance to initialize.
 * </p>
 * 
 * @throws org.quartz.SchedulerConfigException
 *           if there is an error initializing.
 */
public void initialize(String name, final Scheduler scheduler)
    throws SchedulerException {
    super.initialize(name, scheduler);
    
    classLoadHelper = new CascadingClassLoadHelper();
    classLoadHelper.initialize();
    
    getLog().info("Registering Quartz Job Initialization Plug-in.");
    
    // Create JobFile objects
    StringTokenizer stok = new StringTokenizer(fileNames, FILE_NAME_DELIMITERS);
    while (stok.hasMoreTokens()) {
        final String fileName = stok.nextToken();
        final JobFile jobFile = new JobFile(fileName);
        jobFiles.put(fileName, jobFile);         
    }
}
 
Example #2
Source File: AutoProvisionJobs.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void init() throws ParserConfigurationException, XPathException, ParseException, IOException, ValidationException, SchedulerException, SAXException, ClassNotFoundException {

        boolean noFiles = files == null || files.isEmpty();
        if (noFiles || !schedulerManager.isAutoProvisioning()) {
            log.info("Not auto provisioning jobs: "+ ((noFiles)?"no files.":String.join(", ", files)));
            return;
        }

        Scheduler scheduler = schedulerManager.getScheduler();
        ClassLoadHelper clh = new CascadingClassLoadHelper();
        clh.initialize();

        for (String file : files ) {
            XMLSchedulingDataProcessor proc = new XMLSchedulingDataProcessor(clh);
            InputStream in = getClass().getResourceAsStream(file);
            if (in == null) {
                throw new IllegalArgumentException("Couldn't find resource on classpath: "+ file);
            }
            try {
                proc.processStreamAndScheduleJobs(in, file, scheduler);
                log.info("Successfully provisioned jobs/triggers from :"+ file);
            } catch (ObjectAlreadyExistsException e) {
                log.info("Not fully processing: "+ file+ " because some parts already exist");
            }
        }
    }
 
Example #3
Source File: AutoProvisionJobs.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void init() throws ParserConfigurationException, XPathException, ParseException, IOException, ValidationException, SchedulerException, SAXException, ClassNotFoundException {

        boolean noFiles = files == null || files.isEmpty();
        if (noFiles || !schedulerManager.isAutoProvisioning()) {
            log.info("Not auto provisioning jobs: "+ ((noFiles)?"no files.":String.join(", ", files)));
            return;
        }

        Scheduler scheduler = schedulerManager.getScheduler();
        ClassLoadHelper clh = new CascadingClassLoadHelper();
        clh.initialize();

        for (String file : files ) {
            XMLSchedulingDataProcessor proc = new XMLSchedulingDataProcessor(clh);
            InputStream in = getClass().getResourceAsStream(file);
            if (in == null) {
                throw new IllegalArgumentException("Couldn't find resource on classpath: "+ file);
            }
            try {
                proc.processStreamAndScheduleJobs(in, file, scheduler);
                log.info("Successfully provisioned jobs/triggers from :"+ file);
            } catch (ObjectAlreadyExistsException e) {
                log.info("Not fully processing: "+ file+ " because some parts already exist");
            }
        }
    }
 
Example #4
Source File: JobStoreImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ClassLoadHelper loadHelper = new CascadingClassLoadHelper();

  nodeAccess = mock(NodeAccess.class);

  loadHelper.initialize();
  this.jobStore = createJobStore();
  this.jobStore.start();
  this.jobStore.initialize(loadHelper, new SampleSignaler());
  this.jobStore.schedulerStarted();
}
 
Example #5
Source File: AbstractJobStoreTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
  this.fSignaler = new SampleSignaler();
  ClassLoadHelper loadHelper = new CascadingClassLoadHelper();
  loadHelper.initialize();
  this.fJobStore = createJobStore("AbstractJobStoreTest");
  this.fJobStore.initialize(loadHelper, this.fSignaler);
  this.fJobStore.schedulerStarted();

  this.fJobDetail = new JobDetailImpl("job1", "jobGroup1", MyJob.class);
  this.fJobDetail.setDurability(true);
  this.fJobStore.storeJob(this.fJobDetail, false);
}
 
Example #6
Source File: AbstractJobStoreTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAcquireTriggers() throws Exception {
  SchedulerSignaler schedSignaler = new SampleSignaler();
  ClassLoadHelper loadHelper = new CascadingClassLoadHelper();
  loadHelper.initialize();

  JobStore store = createJobStore("testAcquireTriggers");
  store.initialize(loadHelper, schedSignaler);

  // Setup: Store jobs and triggers.
  long MIN = 60 * 1000L;
  Date startTime0 = new Date(System.currentTimeMillis() + MIN); // a min from now.
  for (int i=0; i < 10; i++) {
    Date startTime = new Date(startTime0.getTime() + i * MIN); // a min apart
    JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("job" + i).build();
    SimpleScheduleBuilder schedule = SimpleScheduleBuilder.repeatMinutelyForever(2);
    OperableTrigger trigger = (OperableTrigger)TriggerBuilder.newTrigger().withIdentity("job" + i).withSchedule(schedule).forJob(job).startAt(startTime).build();

    // Manually trigger the first fire time computation that scheduler would do. Otherwise
    // the store.acquireNextTriggers() will not work properly.
    Date fireTime = trigger.computeFirstFireTime(null);
    Assert.assertEquals(true, fireTime != null);

    store.storeJobAndTrigger(job, trigger);
  }

  // Test acquire one trigger at a time
  for (int i=0; i < 10; i++) {
    long noLaterThan = (startTime0.getTime() + i * MIN);
    int maxCount = 1;
    long timeWindow = 0;
    List<OperableTrigger> triggers = store.acquireNextTriggers(noLaterThan, maxCount, timeWindow);
    Assert.assertEquals(1, triggers.size());
    Assert.assertEquals("job" + i, triggers.get(0).getKey().getName());

    // Let's remove the trigger now.
    store.removeJob(triggers.get(0).getJobKey());
  }
}
 
Example #7
Source File: AbstractJobStoreTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAcquireTriggersInBatch() throws Exception {
  SchedulerSignaler schedSignaler = new SampleSignaler();
  ClassLoadHelper loadHelper = new CascadingClassLoadHelper();
  loadHelper.initialize();

  JobStore store = createJobStore("testAcquireTriggersInBatch");
  store.initialize(loadHelper, schedSignaler);

  // Setup: Store jobs and triggers.
  long MIN = 60 * 1000L;
  Date startTime0 = new Date(System.currentTimeMillis() + MIN); // a min from now.
  for (int i=0; i < 10; i++) {
    Date startTime = new Date(startTime0.getTime() + i * MIN); // a min apart
    JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("job" + i).build();
    SimpleScheduleBuilder schedule = SimpleScheduleBuilder.repeatMinutelyForever(2);
    OperableTrigger trigger = (OperableTrigger)TriggerBuilder.newTrigger().withIdentity("job" + i).withSchedule(schedule).forJob(job).startAt(startTime).build();

    // Manually trigger the first fire time computation that scheduler would do. Otherwise
    // the store.acquireNextTriggers() will not work properly.
    Date fireTime = trigger.computeFirstFireTime(null);
    Assert.assertEquals(true, fireTime != null);

    store.storeJobAndTrigger(job, trigger);
  }

  // Test acquire batch of triggers at a time
  long noLaterThan = startTime0.getTime() + 10 * MIN;
  int maxCount = 7;
  // time window needs to be big to be able to pick up multiple triggers when they are a minute apart
  long timeWindow = 8 * MIN;
  List<OperableTrigger> triggers = store.acquireNextTriggers(noLaterThan, maxCount, timeWindow);
  Assert.assertEquals(7, triggers.size());
  for (int i=0; i < 7; i++) {
    Assert.assertEquals("job" + i, triggers.get(i).getKey().getName());
  }
}
 
Example #8
Source File: AbstractJobStoreTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testMatchers() throws Exception {
  SchedulerSignaler schedSignaler = new SampleSignaler();
  ClassLoadHelper loadHelper = new CascadingClassLoadHelper();
  loadHelper.initialize();

  JobStore store = createJobStore("testMatchers");
  store.initialize(loadHelper, schedSignaler);

  JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("job1", "aaabbbccc").build();
  store.storeJob(job, true);
  SimpleScheduleBuilder schedule = SimpleScheduleBuilder.simpleSchedule();
  Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trig1", "aaabbbccc").withSchedule(schedule).forJob(job).build();
  store.storeTrigger((OperableTrigger) trigger, true);

  job = JobBuilder.newJob(MyJob.class).withIdentity("job1", "xxxyyyzzz").build();
  store.storeJob(job, true);
  schedule = SimpleScheduleBuilder.simpleSchedule();
  trigger = TriggerBuilder.newTrigger().withIdentity("trig1", "xxxyyyzzz").withSchedule(schedule).forJob(job).build();
  store.storeTrigger((OperableTrigger)trigger, true);

  job = JobBuilder.newJob(MyJob.class).withIdentity("job2", "xxxyyyzzz").build();
  store.storeJob(job, true);
  schedule = SimpleScheduleBuilder.simpleSchedule();
  trigger = TriggerBuilder.newTrigger().withIdentity("trig2", "xxxyyyzzz").withSchedule(schedule).forJob(job).build();
  store.storeTrigger((OperableTrigger)trigger, true);

  Set<JobKey> jkeys = store.getJobKeys(GroupMatcher.anyJobGroup());
  Assert.assertEquals("Wrong number of jobs found by anything matcher", 3, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupEquals("xxxyyyzzz"));
  Assert.assertEquals("Wrong number of jobs found by equals matcher", 2, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupEquals("aaabbbccc"));
  Assert.assertEquals("Wrong number of jobs found by equals matcher", 1, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupStartsWith("aa"));
  Assert.assertEquals("Wrong number of jobs found by starts with matcher", 1, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupStartsWith("xx"));
  Assert.assertEquals("Wrong number of jobs found by starts with matcher", 2, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupEndsWith("cc"));
  Assert.assertEquals("Wrong number of jobs found by ends with matcher", 1, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupEndsWith("zzz"));
  Assert.assertEquals("Wrong number of jobs found by ends with matcher", 2, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupContains("bc"));
  Assert.assertEquals("Wrong number of jobs found by contains with matcher", 1, jkeys.size());

  jkeys = store.getJobKeys(GroupMatcher.jobGroupContains("yz"));
  Assert.assertEquals("Wrong number of jobs found by contains with matcher", 2, jkeys.size());

  Set<TriggerKey> tkeys = store.getTriggerKeys(GroupMatcher.anyTriggerGroup());
  Assert.assertEquals("Wrong number of triggers found by anything matcher", 3, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupEquals("xxxyyyzzz"));
  Assert.assertEquals("Wrong number of triggers found by equals matcher", 2, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupEquals("aaabbbccc"));
  Assert.assertEquals("Wrong number of triggers found by equals matcher", 1, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupStartsWith("aa"));
  Assert.assertEquals("Wrong number of triggers found by starts with matcher", 1, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupStartsWith("xx"));
  Assert.assertEquals("Wrong number of triggers found by starts with matcher", 2, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupEndsWith("cc"));
  Assert.assertEquals("Wrong number of triggers found by ends with matcher", 1, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupEndsWith("zzz"));
  Assert.assertEquals("Wrong number of triggers found by ends with matcher", 2, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupContains("bc"));
  Assert.assertEquals("Wrong number of triggers found by contains with matcher", 1, tkeys.size());

  tkeys = store.getTriggerKeys(GroupMatcher.triggerGroupContains("yz"));
  Assert.assertEquals("Wrong number of triggers found by contains with matcher", 2, tkeys.size());

}