/** * <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); } }
private QuartzJobDetail makeJobDetail(CascadingClassLoadHelper cascadingClassLoadHelper, ResultSet rs) throws SQLException, ClassNotFoundException, IOException { JobDetailImpl jobDetail = new JobDetailImpl(); String groupName = rs.getString(Constants.COL_JOB_GROUP); String jobName = rs.getString(Constants.COL_JOB_NAME); jobDetail.setName(jobName); jobDetail.setGroup(groupName); jobDetail.setDescription(rs.getString(Constants.COL_DESCRIPTION)); jobDetail.setJobClass( cascadingClassLoadHelper.loadClass(rs.getString(Constants.COL_JOB_CLASS), Job.class) ); jobDetail.setDurability(rs.getBoolean(Constants.COL_IS_DURABLE)); jobDetail.setRequestsRecovery(rs.getBoolean(Constants.COL_REQUESTS_RECOVERY)); Map<?, ?> map = (Map<?, ?>) getObjectFromBlob(rs, COL_JOB_DATAMAP); if (map != null) { jobDetail.setJobDataMap(new JobDataMap(map)); } JobId jobId = new QuartzJobId(groupName, jobName, engine.getClusterName()); QuartzJobDetail quartzJobDetail = new QuartzJobDetail(engine, jobId, jobDetail, rs.getTimestamp(WinderJDBCDelegate.COL_JOB_CREATED)); return quartzJobDetail; }
@BeforeClass public void setUp() throws SchedulerException, InterruptedException { fSignaler = new SampleSignaler(); Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); hazelcastInstance = Hazelcast.newHazelcastInstance(config); ClassLoadHelper loadHelper = new CascadingClassLoadHelper(); loadHelper.initialize(); HazelcastJobStore.setHazelcastClient(hazelcastInstance); jobStore = createJobStore("AbstractJobStoreTest"); jobStore.initialize(loadHelper, this.fSignaler); jobStore.schedulerStarted(); jobDetail = JobBuilder.newJob(NoOpJob.class).withIdentity("job1", "jobGroup1").build(); jobStore.storeJob(jobDetail, false); }
@Test public void testStoreAndRetrieveJobs() throws Exception { final int nJobs = 10; SchedulerSignaler schedSignaler = new SampleSignaler(); ClassLoadHelper loadHelper = new CascadingClassLoadHelper(); loadHelper.initialize(); JobStore store = createJobStore("testStoreAndRetrieveJobs"); store.initialize(loadHelper, schedSignaler); // Store jobs. for (int i = 0; i < nJobs; i++) { JobDetail job = JobBuilder.newJob(NoOpJob.class).withIdentity("job" + i).build(); store.storeJob(job, false); } // Retrieve jobs. for (int i = 0; i < nJobs; i++) { JobKey jobKey = JobKey.jobKey("job" + i); JobDetail storedJob = store.retrieveJob(jobKey); Assert.assertEquals(storedJob.getKey(), jobKey); } }
@Test() public void testStoreAndRetrieveJobs() throws Exception { SchedulerSignaler schedSignaler = new SampleSignaler(); ClassLoadHelper loadHelper = new CascadingClassLoadHelper(); loadHelper.initialize(); JobStore store = createJobStore("testStoreAndRetrieveJobs"); store.initialize(loadHelper, schedSignaler); // Store jobs. for (int i = 0; i < 10; i++) { JobDetail job = JobBuilder.newJob(NoOpJob.class).withIdentity("job" + i) .build(); store.storeJob(job, false); } // Retrieve jobs. for (int i = 0; i < 10; i++) { JobKey jobKey = JobKey.jobKey("job" + i); JobDetail storedJob = store.retrieveJob(jobKey); Assert.assertEquals(jobKey, storedJob.getKey()); } }
@BeforeClass public void setUp() throws SchedulerException, InterruptedException { Config config = new Config(); config.setProperty("hazelcast.logging.type", "slf4j"); hazelcastInstance = Hazelcast.newHazelcastInstance(config); this.fSignaler = new SampleSignaler(); ClassLoadHelper loadHelper = new CascadingClassLoadHelper(); loadHelper.initialize(); this.jobStore = createJobStore("AbstractJobStoreTest"); this.jobStore.initialize(loadHelper, this.fSignaler); this.jobStore.schedulerStarted(); this.fJobDetail = new JobDetailImpl("job1", "jobGroup1", NoOpJob.class); this.fJobDetail.setDurability(true); this.jobStore.storeJob(this.fJobDetail, false); }
@Override public void initialize() { geemoduleClassLoader = App.get().moduleLoader().getPublicClassLoader(); // Initialize a fall back ClassLoadHelper. cascadeClassLoadHelper = new CascadingClassLoadHelper(); cascadeClassLoadHelper.initialize(); }
@Before public void setUp() throws Exception { ClassLoadHelper loadHelper = new CascadingClassLoadHelper(); loadHelper.initialize(); this.jobStore = createJobStore(); this.jobStore.start(); this.jobStore.initialize(loadHelper, new SampleSignaler()); this.jobStore.schedulerStarted(); }
@Test public void testStoreAndRetriveTriggers() throws Exception { final int nJobs = 10; SchedulerSignaler schedSignaler = new SampleSignaler(); ClassLoadHelper loadHelper = new CascadingClassLoadHelper(); loadHelper.initialize(); JobStore store = createJobStore("testStoreAndRetriveTriggers"); store.initialize(loadHelper, schedSignaler); // Store jobs and triggers. for (int i = 0; i < nJobs; i++) { JobDetail job = JobBuilder.newJob(NoOpJob.class).withIdentity("job" + i).build(); store.storeJob(job, true); OperableTrigger trigger = buildTrigger("job" + i, DEFAULT_GROUP, job); store.storeTrigger((OperableTrigger) trigger, true); } // Retrieve jobs and triggers. for (int i = 0; i < nJobs; i++) { JobKey jobKey = JobKey.jobKey("job" + i); JobDetail storedJob = store.retrieveJob(jobKey); Assert.assertEquals(storedJob.getKey(), jobKey); TriggerKey triggerKey = TriggerKey.triggerKey("job" + i); OperableTrigger storedTrigger = store.retrieveTrigger(triggerKey); Assert.assertEquals(storedTrigger.getKey(), triggerKey); } }
@Test() public void testStoreAndRetriveTriggers() throws Exception { SchedulerSignaler schedSignaler = new SampleSignaler(); ClassLoadHelper loadHelper = new CascadingClassLoadHelper(); loadHelper.initialize(); JobStore store = createJobStore("testStoreAndRetriveTriggers"); store.initialize(loadHelper, schedSignaler); // Store jobs and triggers. for (int i = 0; i < 10; i++) { JobDetail job = JobBuilder.newJob(NoOpJob.class).withIdentity("job" + i) .build(); store.storeJob(job, true); SimpleScheduleBuilder schedule = SimpleScheduleBuilder.simpleSchedule(); Trigger trigger = TriggerBuilder.newTrigger().withIdentity("job" + i) .withSchedule(schedule).forJob(job).build(); store.storeTrigger((OperableTrigger) trigger, true); } // Retrieve job and trigger. for (int i = 0; i < 10; i++) { JobKey jobKey = JobKey.jobKey("job" + i); JobDetail storedJob = store.retrieveJob(jobKey); Assert.assertEquals(jobKey, storedJob.getKey()); TriggerKey triggerKey = TriggerKey.triggerKey("job" + i); Trigger storedTrigger = store.retrieveTrigger(triggerKey); Assert.assertEquals(triggerKey, storedTrigger.getKey()); } }
@Test public void testAcquireTriggers() throws Exception { final int nJobs = 10; 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 < nJobs; i++) { Date startTime = new Date(startTime0.getTime() + i * MIN); // a min apart JobDetail job = JobBuilder.newJob(NoOpJob.class).withIdentity("job" + i).build(); SimpleScheduleBuilder schedule = SimpleScheduleBuilder.repeatMinutelyForever(2); OperableTrigger trigger = (OperableTrigger) 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.assertNotNull(fireTime); store.storeJobAndTrigger(job, trigger); } // Test acquire one trigger at a time for (int i = 0; i < nJobs; i++) { long noLaterThan = (startTime0.getTime() + i * MIN); int maxCount = 1; long timeWindow = 0; List<OperableTrigger> triggers = store.acquireNextTriggers(noLaterThan, maxCount, timeWindow); Assert.assertEquals(triggers.size(), 1); Assert.assertEquals(triggers.get(0).getKey().getName(), "job" + i); // Let's remove the trigger now. store.removeJob(triggers.get(0).getJobKey()); } }
@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(NoOpJob.class).withIdentity("job" + i).build(); SimpleScheduleBuilder schedule = SimpleScheduleBuilder.repeatMinutelyForever(2); OperableTrigger trigger = (OperableTrigger) 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.assertNotNull(fireTime); 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(triggers.size(), 7); }
@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(NoOpJob.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()); } }
@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(NoOpJob.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()); }
/** * Gets the job store class load helper used during scheduler scheduler creation to * set up the job store that is assigned in the S * @return */ protected ClassLoadHelper getJobStoreClassLoadHelper() { return new CascadingClassLoadHelper(); }