本文整理匯總了Java中org.quartz.Trigger類的典型用法代碼示例。如果您正苦於以下問題:Java Trigger類的具體用法?Java Trigger怎麽用?Java Trigger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Trigger類屬於org.quartz包,在下文中一共展示了Trigger類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: listAllJobs
import org.quartz.Trigger; //導入依賴的package包/類
public ResultBundle<Map<String, Triple<SpiderInfo, JobKey, Trigger>>> listAllJobs() {
Map<String, Triple<SpiderInfo, JobKey, Trigger>> result = new HashMap<>();
for(JobKey key:manager.listAll(QUARTZ_JOB_GROUP_NAME)) {
Pair<JobDetail, Trigger> pair = manager.findInfo(key);
SpiderInfo info = (SpiderInfo)pair.getLeft().getJobDataMap().get("spiderInfo");
result.put(info.getId(), Triple.of(info, key, pair.getRight()));
}
return builder.bundle(null, () -> result);
}
示例2: jobExecutionVetoed
import org.quartz.Trigger; //導入依賴的package包/類
/**
* @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
*/
public void jobExecutionVetoed(JobExecutionContext context) {
if (!getLog().isInfoEnabled()) {
return;
}
Trigger trigger = context.getTrigger();
Object[] args = {
context.getJobDetail().getKey().getName(),
context.getJobDetail().getKey().getGroup(), new java.util.Date(),
trigger.getKey().getName(), trigger.getKey().getGroup(),
trigger.getPreviousFireTime(), trigger.getNextFireTime(),
Integer.valueOf(context.getRefireCount())
};
getLog().info(MessageFormat.format(getJobWasVetoedMessage(), args));
}
示例3: addSchedule
import org.quartz.Trigger; //導入依賴的package包/類
/**
* 增加一個調度任務(cron版)
*
* @param name
* 任務名稱
* @param job
* 執行內容
* @param cronExpression
* cron表達式
* @throws SchedulerException
*/
public Trigger addSchedule(String name, Class<? extends Job> task, String cronExpression, JobDataMap param)
throws SchedulerException {
Scheduler sched = SF.getScheduler();
JobBuilder builder = JobBuilder.newJob(task);
builder.withIdentity(name, Scheduler.DEFAULT_GROUP);
if (param != null) {
builder.usingJobData(param);
}
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name, Scheduler.DEFAULT_GROUP)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
sched.scheduleJob(builder.build(), trigger);
if (!sched.isShutdown())
sched.start();
return trigger;
}
示例4: wrapScheduleJob
import org.quartz.Trigger; //導入依賴的package包/類
private void wrapScheduleJob(ScheduleJob scheduleJob,Scheduler scheduler,JobKey jobKey,Trigger trigger){
try {
scheduleJob.setJobName(jobKey.getName());
scheduleJob.setJobGroup(jobKey.getGroup());
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
ScheduleJob job = (ScheduleJob)jobDetail.getJobDataMap().get("scheduleJob");
scheduleJob.setDesc(job.getDesc());
scheduleJob.setJobId(job.getJobId());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
scheduleJob.setJobStatus(triggerState.name());
if(trigger instanceof CronTrigger){
CronTrigger cronTrigger = (CronTrigger)trigger;
String cronExpression = cronTrigger.getCronExpression();
scheduleJob.setCronExpression(cronExpression);
}
} catch (SchedulerException e) {
e.printStackTrace();
}
}
示例5: toCompositeData
import org.quartz.Trigger; //導入依賴的package包/類
public static CompositeData toCompositeData(Trigger trigger) {
try {
return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
new Object[] {
trigger.getKey().getName(),
trigger.getKey().getGroup(),
trigger.getJobKey().getName(),
trigger.getJobKey().getGroup(),
trigger.getDescription(),
JobDataMapSupport.toTabularData(trigger
.getJobDataMap()),
trigger.getCalendarName(),
((OperableTrigger)trigger).getFireInstanceId(),
trigger.getMisfireInstruction(),
trigger.getPriority(), trigger.getStartTime(),
trigger.getEndTime(), trigger.getNextFireTime(),
trigger.getPreviousFireTime(),
trigger.getFinalFireTime() });
} catch (OpenDataException e) {
throw new RuntimeException(e);
}
}
示例6: doUpdateOfMisfiredTrigger
import org.quartz.Trigger; //導入依賴的package包/類
private void doUpdateOfMisfiredTrigger(Connection conn, SchedulingContext ctxt, Trigger trig, boolean forceState, String newStateIfNotComplete, boolean recovering) throws JobPersistenceException {
Calendar cal = null;
if (trig.getCalendarName() != null) {
cal = retrieveCalendar(conn, ctxt, trig.getCalendarName());
}
schedSignaler.notifyTriggerListenersMisfired(trig);
trig.updateAfterMisfire(cal);
if (trig.getNextFireTime() == null) {
storeTrigger(conn, ctxt, trig,
null, true, STATE_COMPLETE, forceState, recovering);
} else {
storeTrigger(conn, ctxt, trig, null, true, newStateIfNotComplete,
forceState, false);
}
}
示例7: refreshMetadata
import org.quartz.Trigger; //導入依賴的package包/類
/**
* Refresh metadata. Schedules the job to retrieve metadata.
*/
@PostConstruct
public void refreshMetadata() {
final Thread thread = new Thread(new Runnable() {
@Override
public void run() {
buildMetadataResolverAggregate();
}
});
thread.start();
final JobDetail job = JobBuilder.newJob(this.getClass())
.withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString())).build();
final Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(this.getClass().getSimpleName().concat(UUID.randomUUID().toString()))
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMinutes(this.refreshIntervalInMinutes)
.repeatForever()).build();
try {
scheduler.scheduleJob(job, trigger);
} catch (final SchedulerException e) {
throw new RuntimeException(e);
}
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:28,代碼來源:StaticMetadataResolverAdapter.java
示例8: updateAfterMisfire
import org.quartz.Trigger; //導入依賴的package包/類
/**
* <p>
* Updates the <code>DailyTimeIntervalTrigger</code>'s state based on the
* MISFIRE_INSTRUCTION_XXX that was selected when the <code>DailyTimeIntervalTrigger</code>
* was created.
* </p>
*
* <p>
* If the misfire instruction is set to MISFIRE_INSTRUCTION_SMART_POLICY,
* then the following scheme will be used: <br>
* <ul>
* <li>The instruction will be interpreted as <code>MISFIRE_INSTRUCTION_FIRE_ONCE_NOW</code>
* </ul>
* </p>
*/
@Override
public void updateAfterMisfire(org.quartz.Calendar cal) {
int instr = getMisfireInstruction();
if(instr == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY)
return;
if (instr == MISFIRE_INSTRUCTION_SMART_POLICY) {
instr = MISFIRE_INSTRUCTION_FIRE_ONCE_NOW;
}
if (instr == MISFIRE_INSTRUCTION_DO_NOTHING) {
Date newFireTime = getFireTimeAfter(new Date());
while (newFireTime != null && cal != null
&& !cal.isTimeIncluded(newFireTime.getTime())) {
newFireTime = getFireTimeAfter(newFireTime);
}
setNextFireTime(newFireTime);
} else if (instr == MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) {
// fire once now...
setNextFireTime(new Date());
// the new fire time afterward will magically preserve the original
// time of day for firing for day/week/month interval triggers,
// because of the way getFireTimeAfter() works - in its always restarting
// computation from the start time.
}
}
示例9: addJob
import org.quartz.Trigger; //導入依賴的package包/類
/**
* @Description: 添加一個定時任務
* @param jobName 任務名
* @param jobGroupName 任務組名
* @param triggerName 觸發器名
* @param triggerGroupName 觸發器組名
* @param jobClass 任務
* @param time 時間設置,參考quartz說明文檔
*
*/
@SuppressWarnings("unchecked")
public static void addJob(String jobName, String jobGroupName,
String triggerName, String triggerGroupName, Class jobClass,
String time) {
try {
Scheduler sched = gSchedulerFactory.getScheduler();
JobDetail job = newJob(jobClass)
.withIdentity(jobName, jobGroupName)
.build();
// 表達式調度構建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(time);
// 按新的cronExpression表達式構建一個新的trigger
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity(triggerName, triggerGroupName)
.withSchedule(scheduleBuilder).build();
sched.scheduleJob(job, trigger);
// 啟動
if (!sched.isShutdown()) {
sched.start();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例10: schedule
import org.quartz.Trigger; //導入依賴的package包/類
@Override
public synchronized String schedule(SchedulableTask task) {
try {
JobDetail job = JobBuilder.newJob(HelperTask.class)
.withIdentity(UUID.randomUUID().toString())
.build();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(UUID.randomUUID().toString())
.withSchedule(task.getScheduleBuilder())
.forJob(job)
.build();
trigger.getJobDataMap().put("task", task);
quartz.scheduleJob(job, trigger);
return job.getKey().getName();
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
示例11: resumeJobGroup
import org.quartz.Trigger; //導入依賴的package包/類
/**
* <p>
* Resume (un-pause) all of the <code>{@link org.quartz.JobDetail}s</code>
* in the given group.
* </p>
*
* <p>
* If any of the <code>Job</code> s had <code>Trigger</code> s that
* missed one or more fire-times, then the <code>Trigger</code>'s
* misfire instruction will be applied.
* </p>
*
*/
public void resumeJobGroup(SchedulingContext ctxt, String groupName) {
synchronized (lock) {
String[] jobNames = getJobNames(ctxt, groupName);
if(pausedJobGroups.contains(groupName)) {
pausedJobGroups.remove(groupName);
}
for (int i = 0; i < jobNames.length; i++) {
Trigger[] triggers = getTriggersForJob(ctxt, jobNames[i],
groupName);
for (int j = 0; j < triggers.length; j++) {
resumeTrigger(ctxt, triggers[j].getName(),
triggers[j].getGroup());
}
}
}
}
示例12: rescheduleJob
import org.quartz.Trigger; //導入依賴的package包/類
/**
* <p>
* Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the
* given name, and store the new given one - which must be associated
* with the same job.
* </p>
* @param newTrigger
* The new <code>Trigger</code> to be stored.
*
* @return <code>null</code> if a <code>Trigger</code> with the given
* name & group was not found and removed from the store, otherwise
* the first fire time of the newly scheduled trigger.
*/
public Date rescheduleJob(TriggerKey triggerKey,
Trigger newTrigger) throws SchedulerException {
validateState();
if (triggerKey == null) {
throw new IllegalArgumentException("triggerKey cannot be null");
}
if (newTrigger == null) {
throw new IllegalArgumentException("newTrigger cannot be null");
}
OperableTrigger trig = (OperableTrigger)newTrigger;
Trigger oldTrigger = getTrigger(triggerKey);
if (oldTrigger == null) {
return null;
} else {
trig.setJobKey(oldTrigger.getJobKey());
}
trig.validate();
Calendar cal = null;
if (newTrigger.getCalendarName() != null) {
cal = resources.getJobStore().retrieveCalendar(
newTrigger.getCalendarName());
}
Date ft = trig.computeFirstFireTime(cal);
if (ft == null) {
throw new SchedulerException(
"Based on configured schedule, the given trigger will never fire.");
}
if (resources.getJobStore().replaceTrigger(triggerKey, trig)) {
notifySchedulerThread(newTrigger.getNextFireTime().getTime());
notifySchedulerListenersUnscheduled(triggerKey);
notifySchedulerListenersSchduled(newTrigger);
} else {
return null;
}
return ft;
}
示例13: getAllJobDetail
import org.quartz.Trigger; //導入依賴的package包/類
public List<TaskScheduled> getAllJobDetail() {
List<TaskScheduled> result = new LinkedList<TaskScheduled>();
try {
GroupMatcher<JobKey> matcher = GroupMatcher.jobGroupContains("");
Set<JobKey> jobKeys = scheduler.getJobKeys(matcher);
for (JobKey jobKey : jobKeys) {
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
for (Trigger trigger : triggers) {
TaskScheduled job = new TaskScheduled();
job.setTaskName(jobKey.getName());
job.setTaskGroup(jobKey.getGroup());
TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
job.setStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger)trigger;
String cronExpression = cronTrigger.getCronExpression();
job.setTaskCron(cronExpression);
}
job.setPreviousFireTime(trigger.getPreviousFireTime());
job.setNextFireTime(trigger.getNextFireTime());
JobDataMap jobDataMap = trigger.getJobDataMap();
job.setTaskType(jobDataMap.getString("taskType"));
job.setTargetSystem(jobDataMap.getString("targetSystem"));
job.setTargetObject(jobDataMap.getString("targetObject"));
job.setTargetMethod(jobDataMap.getString("targetMethod"));
job.setContactName(jobDataMap.getString("contactName"));
job.setContactEmail(jobDataMap.getString("contactEmail"));
job.setTaskDesc(jobDetail.getDescription());
String jobClass = jobDetail.getJobClass().getSimpleName();
if (jobClass.equals("StatefulJob")) {
job.setJobType("statefulJob");
} else if (jobClass.equals("DefaultJob")) {
job.setJobType("job");
}
result.add(job);
}
}
} catch (Exception e) {
logger.error("Try to load All JobDetail cause error : ", e);
}
return result;
}
示例14: scheduleAfter
import org.quartz.Trigger; //導入依賴的package包/類
/**
* Schedules an event after a specified time with the specified interval.
*
* @param event event.
* @param delay delay in milliseconds.
* @param interval interval in milliseconds.
* @return scheduled event entry.
*/
@Override
public EventSchedulerEntry scheduleAfter(Event event, long delay, long interval) {
TriggerBuilder<Trigger> builder = newTrigger();
if (delay > 0) {
builder.startAt(Date.from(Instant.now().plusMillis(delay)));
}
if (interval > 0) {
builder.withSchedule(
simpleSchedule().withIntervalInMilliseconds(interval).repeatForever().withMisfireHandlingInstructionFireNow());
}
return doSchedule(event, builder.build(), interval == 0);
}
示例15: getAllTriggers
import org.quartz.Trigger; //導入依賴的package包/類
public List<CompositeData> getAllTriggers() throws Exception {
try {
List<Trigger> triggerList = new ArrayList<Trigger>();
for (String triggerGroupName : scheduler.getTriggerGroupNames()) {
for (TriggerKey triggerKey : scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(triggerGroupName))) {
triggerList.add(scheduler.getTrigger(triggerKey));
}
}
return TriggerSupport.toCompositeList(triggerList);
} catch (Exception e) {
throw newPlainException(e);
}
}