项目:jaffa-framework
文件:TriggerHelper.java
/** Creates a SimpleTrigger with an interval computed from the hours,minutes and seconds.
*/
private static AbstractTrigger<?> createTrigger(ScheduledTask task,Recurrence.Often recurrence) throws FrameworkException,ApplicationExceptions {
// Compute the repeatInterval for the SimpleTrigger in milliseconds
long repeatInterval = 0;
if (recurrence.getHours() != null)
repeatInterval += recurrence.getHours() * 60 * 60 * 1000;
if (recurrence.getMinutes() != null)
repeatInterval += recurrence.getMinutes() * 60 * 1000;
if (recurrence.getSeconds() != null)
repeatInterval += recurrence.getSeconds() * 1000;
SimpleTriggerImpl trigger = new SimpleTriggerImpl();
if (repeatInterval > 0) {
trigger.setRepeatInterval(repeatInterval);
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
}
return trigger;
}
项目:quartz-scheduler-hazelcast-jobstore
文件:QuartzTest.java
@Test
public void testScheduleJobWithRepeatTime()
throws Exception {
JobDetail job1 = buildJob("Job1",DEFAULT_GROUP,MyJob.class);
final SimpleTriggerImpl o = (SimpleTriggerImpl) buildTrigger("key1",job1);
o.setRepeatInterval(100);
o.setRepeatCount(10);
scheduler.scheduleJob(job1,o);
Thread.sleep(750);
assertEquals(MyJob.count,8);
assertEquals(MyJob.triggerKeys.poll(),"key1");
}
项目:quartz-scheduler-hazelcast-jobstore
文件:QuartzTest.java
@Test
public void testScheduleJobWithnorepeatTime()
throws Exception {
JobDetail job1 = buildJob("Job11",MyJob.class);
final SimpleTriggerImpl o = (SimpleTriggerImpl) buildTrigger("key11",job1);
o.setRepeatInterval(100);
o.setRepeatCount(0);
scheduler.scheduleJob(job1,o);
// it really needs to wait to be sure that it is not found as a lost trigger
Thread.sleep(60000);
assertEquals(MyJob.count,1);
assertEquals(MyJob.triggerKeys.poll(),"key11");
}
项目:quartz-scheduler-hazelcast-jobstore
文件:QuartzTest.java
@Test
public void testScheduleJobWithRepeatTimeWithConcurrentExecutiondisallowed()
throws Exception {
JobDetail job1 = buildJob("CJob1",MyNoConcurrentJob.class);
final SimpleTriggerImpl o = (SimpleTriggerImpl) buildTrigger("Ckey1",job1);
o.setRepeatInterval(100);
o.setRepeatCount(10);
MyNoConcurrentJob.waitTime = 300;
scheduler.scheduleJob(job1,o);
Thread.sleep(850);
// since MyNoCocurrent job takes 300 ms to finish
assertEquals(MyNoConcurrentJob.count,3);
assertEquals(MyNoConcurrentJob.triggerKeys.poll(),"Ckey1");
}
项目:quartz-scheduler-hazelcast-jobstore
文件:QuartzTest.java
@Test
public void testScheduleJobWithRepeatTimeWithConcurrentExecutiondisallowedAfterEnd()
throws Exception {
JobDetail job1 = buildJob("CJob1",job1);
o.setRepeatInterval(100);
o.setRepeatCount(1);
MyNoConcurrentJob.waitTime = 200;
scheduler.scheduleJob(job1,o);
Thread.sleep(750);
// since MyNoCocurrent job takes 300 ms to finish
assertEquals(MyNoConcurrentJob.count,2);
assertEquals(MyNoConcurrentJob.triggerKeys.poll(),"Ckey1");
}
项目:quartz-scheduler-hazelcast-jobstore
文件:QuartzTest.java
@Test
public void testScheduleJobWithRepeatTimeWithConcurrentExecutiondisallowed_withFastJob()
throws Exception {
JobDetail job1 = buildJob("CJob2",MyNoConcurrentJob.class);
final SimpleTriggerImpl o = (SimpleTriggerImpl) buildTrigger("Ckey2",job1);
o.setRepeatInterval(100);
o.setRepeatCount(10);
MyNoConcurrentJob.waitTime = 10;
scheduler.scheduleJob(job1,8);
assertEquals(MyNoConcurrentJob.triggerKeys.poll(),"Ckey2");
}
@Test
public void serialization(){
SimpleTrigger trigger = TriggerBuilder.newTrigger()
.forJob("testJob","testGroup")
.withIdentity("testTrigger","testTriggerGroup")
.usingJobData("timeout",5)
.withDescription("A description!")
.withSchedule(SimpleScheduleBuilder.repeatHourlyForever())
.build();
Map<String,String> triggerMap = mapper.convertValue(trigger,new TypeReference<HashMap<String,String>>() {});
assertthat(triggerMap,hasKey("name"));
assertEquals("testTrigger",triggerMap.get("name"));
assertthat(triggerMap,hasKey("group"));
assertEquals("testTriggerGroup",triggerMap.get("group"));
assertthat(triggerMap,hasKey("jobName"));
assertEquals("testJob",triggerMap.get("jobName"));
SimpleTriggerImpl simpleTrigger = mapper.convertValue(triggerMap,SimpleTriggerImpl.class);
assertEquals(trigger.getKey().getName(),simpleTrigger.getKey().getName());
assertEquals(trigger.getKey().getGroup(),simpleTrigger.getKey().getGroup());
assertEquals(trigger.getStartTime(),simpleTrigger.getStartTime());
assertEquals(trigger.getRepeatInterval(),simpleTrigger.getRepeatInterval());
}
项目:rice
文件:DelayedAsynchronousServiceCallProxy.java
protected void scheduleMessage(PersistedMessageBO message) throws SchedulerException {
LOG.debug("Scheduling execution of a delayed asynchronous message.");
Scheduler scheduler = KSBServiceLocator.getScheduler();
JobDataMap jobData = new JobDataMap();
jobData.put(MessageServiceExecutorJob.MESSAGE_KEY,message);
JobDetailImpl jobDetail = new JobDetailImpl("Delayed_Asynchronous_Call-" + Math.random(),"Delayed_Asynchronous_Call",MessageServiceExecutorJob.class);
jobDetail.setJobDataMap(jobData);
scheduler.getListenerManager().addJobListener( new MessageServiceExecutorJobListener());
SimpleTriggerImpl trigger = new SimpleTriggerImpl("Delayed_Asynchronous_Call_Trigger-" + Math.random(),message.getQueueDate());
trigger.setJobDataMap(jobData);// 1.6 bug required or derby will choke
scheduler.scheduleJob(jobDetail,trigger);
}
项目:rice
文件:DefaultExceptionServiceImpl.java
public void scheduleExecution(Throwable throwable,PersistedMessageBO message,String description) throws Exception {
KSBServiceLocator.getMessageQueueService().delete(message);
PersistedMessageBO messagecopy = message.copy();
Scheduler scheduler = KSBServiceLocator.getScheduler();
JobDataMap jobData = new JobDataMap();
jobData.put(MessageServiceExecutorJob.MESSAGE_KEY,messagecopy);
JobDetailImpl jobDetail = new JobDetailImpl("Exception_Message_Job " + Math.random(),"Exception Messaging",MessageServiceExecutorJob.class);
jobDetail.setJobDataMap(jobData);
if (!StringUtils.isBlank(description)) {
jobDetail.setDescription(description);
}
scheduler.getListenerManager().addJobListener( new MessageServiceExecutorJobListener());
SimpleTriggerImpl trigger = new SimpleTriggerImpl("Exception_Message_Trigger " + Math.random(),messagecopy
.getQueueDate());
trigger.setJobDataMap(jobData);// 1.6 bug required or derby will choke
scheduler.scheduleJob(jobDetail,trigger);
}
项目:quartz-couchdb-store
文件:CouchDbJobStoreIT.java
@Test
public void shouldDeleteAssociatedTriggersWhenDeletingJob() throws JobPersistenceException {
final String jobId = id("job");
JobDetail job = newJob(DummyJobListener.class)
.withIdentity(jobId,"bargroup")
.build();
couchdbStore.storeJob(job,false);
final String tridderName = id("trigger");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(tridderName,"borgroup")
.forJob(JobKey.jobKey(jobId,"bargroup"))
.startAt(new Date(2010,10,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
couchdbStore.storeTrigger(trigger,false);
couchdbStore.removeJob(JobKey.jobKey(jobId,"bargroup"));
assertNull(couchdbStore.retrieveTrigger(TriggerKey.triggerKey(tridderName,"borgroup")));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldStoreAndRetrieveTrigger() throws JobPersistenceException {
final String triggerName = id("fuuid");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,"borgroup")
.forJob(JobKey.jobKey("fooid","bargroup"))
.startAt(new Date(2010,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
couchdbStore.storeTrigger(trigger,false);
assertNull(couchdbStore.retrieveTrigger(TriggerKey.triggerKey("something","something")));
assertEquals(new Date(2010,20),couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName,"borgroup")).getStartTime());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldDeleteExistingTrigger() throws JobPersistenceException {
final String triggerName = id("fuuid");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,false);
couchdbStore.removeTrigger(TriggerKey.triggerKey(triggerName,"borgroup"));
assertNull(couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName,"borgroup")));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldCheckWhetherTriggerExists() throws JobPersistenceException {
final String triggerName = id("fuuid");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
assertFalse(couchdbStore.checkExists(TriggerKey.triggerKey(triggerName,"borgroup")));
couchdbStore.storeTrigger(trigger,false);
assertTrue(couchdbStore.checkExists(TriggerKey.triggerKey(triggerName,"borgroup")));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldFireTriggers() throws JobPersistenceException {
final String triggerName = id("fuuid1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,"borgroup1")
.forJob(JobKey.jobKey("fooid","bargroup"))
.startAt(new Date(2010 - 1900,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
trigger.computeFirstFireTime(null);
couchdbStore.storeTrigger(trigger,false);
List<TriggerFiredResult> firedResults = couchdbStore.triggersFired(Arrays.<OperableTrigger>asList(trigger));
assertEquals(1,firedResults.size());
assertEquals(TriggerKey.triggerKey(triggerName,"borgroup1"),firedResults.get(0).getTriggerFiredBundle().getTrigger().getKey());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldUpdateTriggerForMisfireNowWithExistingRepeatCount() throws Exception {
String triggerName = id("fuuid");
DateTime Now = new DateTime();
DateTime startTime = Now.minusMinutes(1);
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,"bargroup"))
.startAt(startTime.toDate())
.withSchedule(simpleSchedule()
.withIntervalInMinutes(1)
.withRepeatCount(2)
.withMisfireHandlingInstructionNowWithExistingCount())
.build();
trigger.computeFirstFireTime(null);
couchdbStore.storeTrigger(trigger,false);
List<OperableTrigger> acquiredTriggers = couchdbStore.acquireNextTriggers(Now.getMillis(),1,0);
assertEquals(1,acquiredTriggers.size());
SimpleTrigger acquiredTrigger = (SimpleTrigger) acquiredTriggers.get(0);
assertTrue(acquiredTrigger.getNextFireTime().getTime() - Now.getMillis() < 5000);
assertEquals(2,acquiredTrigger.getRepeatCount());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldUpdateTriggerForMisfireNextWithRemainingRepeatCount() throws Exception {
String triggerName = id("fuuid");
DateTime Now = new DateTime();
DateTime startTime = Now.minusMinutes(1);
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,"bargroup"))
.startAt(startTime.toDate())
.withSchedule(simpleSchedule()
.withIntervalInMinutes(1)
.withRepeatCount(2)
.withMisfireHandlingInstructionNowWithRemainingCount())
.build();
trigger.computeFirstFireTime(null);
couchdbStore.storeTrigger(trigger,acquiredTriggers.size());
SimpleTrigger acquiredTrigger = (SimpleTrigger) acquiredTriggers.get(0);
assertTrue(acquiredTrigger.getNextFireTime().getTime() - Now.plusMinutes(1).getMillis() < 5000);
assertEquals(1,acquiredTrigger.getRepeatCount());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldGetTriggerState() throws Exception {
final String triggerName = id("fuuid1");
final String triggerGroup = id("borgroup1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,triggerGroup)
.forJob(JobKey.jobKey(id("fooid"),id("bargroup")))
.startAt(new Date(2010 - 1900,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.withRepeatCount(0))
.build();
trigger.computeFirstFireTime(null);
couchdbStore.storeTrigger(trigger,false);
assertEquals(Trigger.TriggerState.norMAL,couchdbStore.getTriggerState(TriggerKey.triggerKey(triggerName,triggerGroup)));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldUpdateTriggerStatetoAcquired() throws JobPersistenceException {
final String triggerName = id("fuuid1");
final String triggerGroup = id("borgroup1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,triggerGroup)
.forJob(JobKey.jobKey(id("fooid"),id("bargroup")))
.startAt(new Date(2010 - 1900,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.withRepeatCount(0))
.build();
trigger.computeFirstFireTime(null);
couchdbStore.storeTrigger(trigger,false);
CouchDbTrigger storedTrigger = new CouchDbSimpleTrigger((SimpleTriggerImpl) couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName,triggerGroup)));
assertEquals(CouchDbTriggerState.WAITING,storedTrigger.getState());
couchdbStore.acquireNextTriggers(new Date().getTime(),0);
CouchDbSimpleTrigger acquiredTrigger = (CouchDbSimpleTrigger) couchdbStore.getTriggerStore().getTriggerByKey(TriggerKey.triggerKey(triggerName,triggerGroup));
assertEquals(CouchDbTriggerState.ACQUIRED,acquiredTrigger.getState());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldReleaseAcquiredTriggers() throws JobPersistenceException {
String triggerName = id("fuuid1");
String triggerGroup = id("borgroup1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.withRepeatCount(0))
.build();
trigger.computeFirstFireTime(null);
couchdbStore.getTriggerStore().storeTrigger(new CouchDbSimpleTrigger(trigger,CouchDbTriggerState.ACQUIRED),false);
couchdbStore.releaseAcquiredTrigger(trigger);
CouchDbTrigger dbTrigger = couchdbStore.getTriggerStore().getTriggerByKey(TriggerKey.triggerKey(triggerName,triggerGroup));
assertEquals(CouchDbTriggerState.WAITING,dbTrigger.getState());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldReleaseAcquiredTriggersAfterFiring() throws JobPersistenceException {
String triggerName = id("fuuid1");
String triggerGroup = id("borgroup1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,dbTrigger.getState());
}
项目:lams
文件:DefaultClusteredJobStore.java
protected OperableTrigger createRecoveryTrigger(TriggerWrapper tw,JobWrapper jw,String name,FiredTrigger recovering) {
final SimpleTriggerImpl recoveryTrigger = new SimpleTriggerImpl(name,Scheduler.DEFAULT_RECOVERY_GROUP,new Date(recovering.getScheduledFireTime()));
recoveryTrigger.setJobName(jw.getKey().getName());
recoveryTrigger.setJobGroup(jw.getKey().getGroup());
recoveryTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_IGnorE_MISFIRE_POLICY);
recoveryTrigger.setPriority(tw.getPriority());
return recoveryTrigger;
}
项目:lams
文件:SimpleScheduleBuilder.java
/**
* Build the actual Trigger -- NOT intended to be invoked by end users,* but will rather be invoked by a TriggerBuilder which this
* ScheduleBuilder is given to.
*
* @see TriggerBuilder#withSchedule(ScheduleBuilder)
*/
@Override
public MutableTrigger build() {
SimpleTriggerImpl st = new SimpleTriggerImpl();
st.setRepeatInterval(interval);
st.setRepeatCount(repeatCount);
st.setMisfireInstruction(misfireInstruction);
return st;
}
项目:lams
文件:SimpleTriggerSupport.java
public static OperableTrigger newTrigger(CompositeData cData) throws ParseException {
SimpleTriggerImpl result = new SimpleTriggerImpl();
result.setRepeatCount(((Integer) cData.get("repeatCount")).intValue());
result.setRepeatInterval(((Long) cData.get("repeatInterval")).longValue());
result.setTimesTriggered(((Integer) cData.get("timesTriggered")).intValue());
TriggerSupport.initializeTrigger(result,cData);
return result;
}
项目:lams
文件:SimpleTriggerSupport.java
public static OperableTrigger newTrigger(Map<String,Object> attrMap) throws ParseException {
SimpleTriggerImpl result = new SimpleTriggerImpl();
if(attrMap.containsKey("repeatCount")) {
result.setRepeatCount(((Integer) attrMap.get("repeatCount")).intValue());
}
if(attrMap.containsKey("repeatInterval")) {
result.setRepeatInterval(((Long) attrMap.get("repeatInterval")).longValue());
}
if(attrMap.containsKey("timesTriggered")) {
result.setTimesTriggered(((Integer) attrMap.get("timesTriggered")).intValue());
}
TriggerSupport.initializeTrigger(result,attrMap);
return result;
}
项目:uflo
文件:SchedulerServiceImpl.java
public void addReminderJob(TaskReminder reminder,ProcessInstance processInstance,Task task) {
try {
AbstractTrigger<? extends Trigger> trigger=null;
if(reminder.getType().equals(ReminderType.Once)){
SimpleTriggerImpl simpleTrigger=new SimpleTriggerImpl();
simpleTrigger.setRepeatCount(0);
trigger=simpleTrigger;
long executeTime=reminder.getStartDate().getTime()+10000;
long Now=(new Date()).getTime();
if(executeTime<=Now){
return;
}
}else{
crontriggerImpl crontrigger=new crontriggerImpl();
crontrigger.setCronExpression(reminder.getCron());
trigger=crontrigger;
}
trigger.setName("trigger_"+reminder.getId());
trigger.setStartTime(reminder.getStartDate());
ReminderJobDetail jobDetail=new ReminderJobDetail();
jobDetail.setJobClass(ReminderJob.class);
ReminderHandler handler=(ReminderHandler)applicationContext.getBean(reminder.getReminderHandlerBean());
jobDetail.setReminderHandlerBean(handler);
if(task==null){
task=taskService.getTask(reminder.getTaskId());
}
jobDetail.setTask(task);
jobDetail.setProcessInstance(processService.getProcessInstanceById(task.getProcessInstanceId()));
jobDetail.setKey(new JobKey(JOB_NAME_PREFIX+reminder.getId(),JOB_GROUP_PREFIX));
Calendar calendar=getCalendar(reminder,processInstance,task);
if(calendar!=null){
String calendarName=REMINDER_CALENDAR_PREFIX+reminder.getId();
scheduler.addCalendar(calendarName,calendar,false,false);
trigger.setCalendarName(calendarName);
}
scheduler.scheduleJob(jobDetail,trigger);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
项目:spring4-understanding
文件:SimpleTriggerfactorybean.java
@Override
public void afterPropertiesSet() {
if (this.name == null) {
this.name = this.beanName;
}
if (this.group == null) {
this.group = Scheduler.DEFAULT_GROUP;
}
if (this.jobDetail != null) {
this.jobDataMap.put("jobDetail",this.jobDetail);
}
if (this.startDelay > 0 || this.startTime == null) {
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
}
SimpleTriggerImpl sti = new SimpleTriggerImpl();
sti.setName(this.name);
sti.setGroup(this.group);
sti.setJobKey(this.jobDetail.getKey());
sti.setJobDataMap(this.jobDataMap);
sti.setStartTime(this.startTime);
sti.setRepeatInterval(this.repeatInterval);
sti.setRepeatCount(this.repeatCount);
sti.setPriority(this.priority);
sti.setMisfireInstruction(this.misfireInstruction);
sti.setDescription(this.description);
this.simpleTrigger = sti;
}
@Test
public void testTriggerStates() throws Exception {
JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("job1","jobGroup1").storeDurably(true).build();
this.jobStore.storeJob(jobDetail,false);
OperableTrigger trigger =
new SimpleTriggerImpl("trigger1","triggerGroup1",jobDetail.getKey().getName(),jobDetail.getKey().getGroup(),new Date(System.currentTimeMillis() + 100000),new Date(System.currentTimeMillis() + 200000),2,2000);
trigger.computeFirstFireTime(null);
assertEquals(TriggerState.NONE,this.jobStore.getTriggerState(trigger.getKey()));
this.jobStore.storeTrigger(trigger,false);
assertEquals(TriggerState.norMAL,this.jobStore.getTriggerState(trigger.getKey()));
this.jobStore.pauseTrigger(trigger.getKey());
assertEquals(TriggerState.PAUSED,this.jobStore.getTriggerState(trigger.getKey()));
this.jobStore.resumeTrigger(trigger.getKey());
assertEquals(TriggerState.norMAL,this.jobStore.getTriggerState(trigger.getKey()));
trigger = this.jobStore.acquireNextTriggers(
new Date(trigger.getNextFireTime().getTime()).getTime() + 10000,1L).get(0);
assertNotNull(trigger);
this.jobStore.releaseAcquiredTrigger(trigger);
trigger = this.jobStore.acquireNextTriggers(
new Date(trigger.getNextFireTime().getTime()).getTime() + 10000,1L).get(0);
assertNotNull(trigger);
assertTrue(this.jobStore.acquireNextTriggers(
new Date(trigger.getNextFireTime().getTime()).getTime() + 10000,1L).isEmpty());
}
@Test
public void testStoreTriggerReplacesTrigger() throws Exception {
String jobName = "StoreTriggerReplacesTrigger";
String jobGroup = "StoreTriggerReplacesTriggerGroup";
JobDetailImpl detail = new JobDetailImpl(jobName,jobGroup,MyJob.class);
jobStore.storeJob(detail,false);
String trName = "StoreTriggerReplacesTrigger";
String trGroup = "StoreTriggerReplacesTriggerGroup";
OperableTrigger tr = new SimpleTriggerImpl(trName,trGroup,new Date());
tr.setJobKey(new JobKey(jobName,jobGroup));
tr.setCalendarName(null);
jobStore.storeTrigger(tr,false);
assertEquals(tr,jobStore.retrieveTrigger(tr.getKey()));
try {
jobStore.storeTrigger(tr,false);
fail("an attempt to store duplicate trigger succeeded");
}
catch (ObjectAlreadyExistsException oaee) {
// expected
}
tr.setCalendarName("QQ");
jobStore.storeTrigger(tr,true); //fails here
assertEquals(tr,jobStore.retrieveTrigger(tr.getKey()));
assertEquals("StoreJob doesn't replace triggers","QQ",jobStore.retrieveTrigger(tr.getKey()).getCalendarName());
}
private OperableTrigger toOperableTrigger(TriggerKey triggerKey,Map<String,String> trigger) {
if (TRIGGER_TYPE_SIMPLE.equals(trigger.get(TRIGGER_TYPE))) {
SimpleTriggerImpl simpleTrigger = new SimpleTriggerImpl();
setoperableTriggerFields(triggerKey,trigger,simpleTrigger);
if (trigger.get(REPEAT_COUNT) != null && !trigger.get(REPEAT_COUNT).isEmpty())
simpleTrigger.setRepeatCount(Integer.parseInt(trigger.get(REPEAT_COUNT)));
if (trigger.get(REPEAT_INTERVAL) != null && !trigger.get(REPEAT_INTERVAL).isEmpty())
simpleTrigger.setRepeatInterval(Long.parseLong(trigger.get(REPEAT_INTERVAL)));
if (trigger.get(TIMES_TRIGGERED) != null && !trigger.get(TIMES_TRIGGERED).isEmpty())
simpleTrigger.setTimesTriggered(Integer.parseInt(trigger.get(TIMES_TRIGGERED)));
return simpleTrigger;
} else if (TRIGGER_TYPE_CRON.equals(trigger.get(TRIGGER_TYPE))) {
crontriggerImpl crontrigger = new crontriggerImpl();
setoperableTriggerFields(triggerKey,crontrigger);
if (trigger.get(TIME_ZONE_ID) != null && !trigger.get(TIME_ZONE_ID).isEmpty())
crontrigger.getTimeZone().setID(trigger.get(TIME_ZONE_ID).isEmpty() ? null : trigger.get(TIME_ZONE_ID));
try {
if (trigger.get(CRON_EXPRESSION) != null && !trigger.get(CRON_EXPRESSION).isEmpty())
crontrigger.setCronExpression(trigger.get(CRON_EXPRESSION).isEmpty() ? null : trigger.get(CRON_EXPRESSION));
} catch (ParseException ex) {
log.warn("Could not parse cron_expression: " + trigger.get(CRON_EXPRESSION) + " for trigger: " + createTriggerHashKey(triggerKey.getGroup(),triggerKey.getName()));
}
return crontrigger;
} else { // other trigger types are not supported
throw new UnsupportedOperationException();
}
}
项目:rice
文件:MessagingServiceImpl.java
private void scheduleJob() {
LOG.debug("queueing processing job");
try {
Scheduler scheduler = KSBServiceLocator.getScheduler();
if (synchronous) {
LOG.debug("Invoking job synchronously in Thread " + Thread.currentThread());
MessageProcessingJob job = new MessageProcessingJob(messageId,mode,user,cause);
job.run();
} else {
String uniqueTriggerName = jobName + "-Trigger-" + System.currentTimeMillis() + Math.random();
SimpleTriggerImpl trigger = new SimpleTriggerImpl(uniqueTriggerName,jobGroup + "-Trigger");
LOG.debug("Scheduling trigger: " + trigger);
JobDataMap data = new JobDataMap();
data.put("mode",mode.name());
data.put("user",user);
data.put("cause",cause);
data.put("messageId",messageId);
trigger.setJobName(jobName);
trigger.setJobGroup(jobGroup);
trigger.setJobDataMap(data);
scheduler.scheduleJob(trigger);
}
} catch (SchedulerException se) {
throw new RuntimeException(se);
}
}
项目:quartz-hazelcast-jobstore
文件:TestHazelcastJobStore.java
@test()
public void testTriggerStates() throws Exception {
this.jobStore.storeJob(fJobDetail,false);
final OperableTrigger trigger = new SimpleTriggerImpl("trigger1",this.fJobDetail.getName(),this.fJobDetail.getGroup(),new Date(
System.currentTimeMillis() + 200000),2000);
trigger.computeFirstFireTime(null);
assertEquals(Trigger.TriggerState.NONE,this.jobStore.getTriggerState(trigger.getKey()));
this.jobStore.storeTrigger(trigger,false);
assertEquals(Trigger.TriggerState.norMAL,this.jobStore.getTriggerState(trigger.getKey()));
this.jobStore.pauseTrigger(trigger.getKey());
assertEquals(Trigger.TriggerState.PAUSED,this.jobStore.getTriggerState(trigger.getKey()));
this.jobStore.resumeTrigger(trigger.getKey());
assertEquals(Trigger.TriggerState.norMAL,this.jobStore.getTriggerState(trigger.getKey()));
final OperableTrigger rTrigger1 = this.jobStore.acquireNextTriggers(
new Date(trigger.getNextFireTime().getTime()).getTime() + 10000,1L)
.get(0);
assertNotNull(rTrigger1);
this.jobStore.releaseAcquiredTrigger(rTrigger1);
final OperableTrigger rTrigger2 = this.jobStore.acquireNextTriggers(
new Date(rTrigger1.getNextFireTime().getTime()).getTime() + 10000,1L).get(0);
assertNotNull(rTrigger2);
assertTrue(this.jobStore.acquireNextTriggers(
new Date(rTrigger2.getNextFireTime().getTime()).getTime() + 10000,1L).isEmpty());
}
项目:quartz-hazelcast-jobstore
文件:TestHazelcastJobStore.java
@test()
public void testStoreTriggerReplacesTrigger() throws Exception {
String jobName = "StoreTriggerReplacesTrigger";
String jobGroup = "StoreTriggerReplacesTriggerGroup";
JobDetailImpl detail = new JobDetailImpl(jobName,NoOpJob.class);
jobStore.storeJob(detail,false);
fail("an attempt to store duplicate trigger succeeded");
} catch (ObjectAlreadyExistsException oaee) {
// expected
}
tr.setCalendarName("QQ");
jobStore.storeTrigger(tr,true); // fails here
assertEquals(tr,jobStore.retrieveTrigger(tr.getKey()));
assertEquals("QQ",jobStore.retrieveTrigger(tr.getKey()).getCalendarName(),"StoreJob doesn't replace triggers");
}
项目:quartz-couchdb-store
文件:CouchDbStore.java
private CouchDbTrigger createCouchDbTrigger(OperableTrigger newTrigger) {
CouchDbTrigger couchdbTrigger = null;
if (newTrigger instanceof SimpleTriggerImpl) {
couchdbTrigger = new CouchDbSimpleTrigger((SimpleTriggerImpl) newTrigger);
} else if (newTrigger instanceof crontriggerImpl) {
couchdbTrigger = new CouchDbcrontrigger((crontriggerImpl) newTrigger);
} else if (newTrigger instanceof CalendarIntervalTriggerImpl) {
couchdbTrigger = new CouchDbCalendarIntervalTrigger((CalendarIntervalTriggerImpl) newTrigger);
}
return couchdbTrigger;
}
项目:quartz-couchdb-store
文件:CouchDbStoreIT.java
@Test
public void shouldDeleteallJobsTriggersAndCalendars() throws JobPersistenceException {
JobDetail job = newJob(JobListener.class)
.withIdentity(id("fooid"),id("bargroup"))
.usingJobData("foo","bar")
.build();
couchdbStore.storeJob(job,false);
Calendar testCalendar = new WeeklyCalendar();
String calendarName = id("weeklyCalendar");
couchdbStore.storeCalendar(calendarName,testCalendar,false);
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(id("fuuid"),id("borgroup"))
.forJob(JobKey.jobKey("fooid",20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.modifiedByCalendar(calendarName)
.build();
couchdbStore.storeTrigger(trigger,false);
couchdbStore.clearallSchedulingData();
assertEquals(0,couchdbStore.getNumberOfJobs());
assertEquals(0,couchdbStore.getNumberOfCalendars());
assertEquals(0,couchdbStore.getNumberOfTriggers());
assertEquals(0,couchdbStore.getJobGroupNames().size());
assertEquals(0,couchdbStore.getCalendarNames().size());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldDeleteExistingTriggers() throws JobPersistenceException {
final String triggerName = id("fuuid1");
SimpleTriggerImpl trigger1 = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
final String triggerName2 = id("fuuid2");
SimpleTriggerImpl trigger2 = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName2,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
couchdbStore.storeTrigger(trigger1,false);
couchdbStore.storeTrigger(trigger2,false);
couchdbStore.removeTriggers(asList(
TriggerKey.triggerKey(triggerName,"borgroup"),TriggerKey.triggerKey(triggerName2,"borgroup")
));
assertNull(couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName,"borgroup")));
assertNull(couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName2,"borgroup")));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldNotReplaceNonExistingTrigger() throws JobPersistenceException {
final String triggerName = id("fuuid");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
assertFalse(couchdbStore.replaceTrigger(TriggerKey.triggerKey(triggerName,trigger));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldReturnTriggerState() throws JobPersistenceException {
final String triggerName = id("fuuid1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,"borgroup1")));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldAcquireTriggersToFire() throws JobPersistenceException {
int numberOfTriggers = couchdbStore.acquireNextTriggers(new Date(2010 - 1900,21).getTime(),Integer.MAX_VALUE,0).size();
final String triggerName1 = id("fuuid1");
SimpleTriggerImpl trigger1 = (SimpleTriggerImpl) newTrigger().withIdentity(triggerName1,20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
trigger1.computeFirstFireTime(null);
couchdbStore.storeTrigger(trigger1,false);
final String triggerName2 = id("fuuid2");
SimpleTriggerImpl trigger2 = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName2,"borgroup2")
.forJob(JobKey.jobKey("fooid",22))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.repeatForever())
.build();
trigger2.computeFirstFireTime(null);
couchdbStore.storeTrigger(trigger2,false);
List<OperableTrigger> triggers = couchdbStore.acquireNextTriggers(new Date(2010 - 1900,0);
assertEquals(numberOfTriggers + 1,triggers.size());
assertEquals(TriggerKey.triggerKey(triggerName1,triggers.get(0).getKey());
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldDeleteTriggerAfterFire() throws JobPersistenceException {
final String jobName = id("job");
JobDetail job = newJob(CouchDbStoreCalendarRepeatingJobIT.TestListener.class)
.withIdentity(jobName,"bargroup")
.usingJobData("foo","bar")
.usingJobData("fuu","baz")
.build();
couchdbStore.storeJob(job,false);
final String triggerName = id("fuuid1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,"borgroup1")
.forJob(JobKey.jobKey(jobName,false);
trigger.triggered(null);
couchdbStore.triggeredJobComplete(trigger,job,null);
assertNull(couchdbStore.retrieveTrigger(TriggerKey.triggerKey(triggerName,"borgroup1")));
}
项目:quartz-couchdb-store
文件:CouchDbTriggerStoreIT.java
@Test
public void shouldAcquireWaitingTriggersOnly() throws JobPersistenceException {
String triggerName = id("fuuid1");
String triggerGroup = id("borgroup1");
SimpleTriggerImpl trigger = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName,false);
String triggerName2 = id("fuuid2");
String triggerGroup2 = id("borgroup2");
SimpleTriggerImpl trigger2 = (SimpleTriggerImpl) newTrigger()
.withIdentity(triggerName2,triggerGroup2)
.forJob(JobKey.jobKey(id("fooid"),20))
.withSchedule(simpleSchedule()
.withIntervalInMinutes(2)
.withRepeatCount(0))
.build();
trigger2.computeFirstFireTime(null);
CouchDbSimpleTrigger couchdbTrigger2 = new CouchDbSimpleTrigger(trigger2);
couchdbTrigger2.setState(CouchDbTriggerState.ACQUIRED);
couchdbStore.getTriggerStore().storeTrigger(couchdbTrigger2,true);
List<OperableTrigger> acquiredTriggers = couchdbStore.acquireNextTriggers(new Date().getTime(),acquiredTriggers.size());
assertEquals(TriggerKey.triggerKey(triggerName,triggerGroup),acquiredTriggers.get(0).getKey());
}