本文整理汇总了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);
}
}