本文整理汇总了Java中org.quartz.JobDetail类的典型用法代码示例。如果您正苦于以下问题:Java JobDetail类的具体用法?Java JobDetail怎么用?Java JobDetail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JobDetail类属于org.quartz包,在下文中一共展示了JobDetail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertJobListener
import org.quartz.JobDetail; //导入依赖的package包/类
/**
* <p>
* Associate a listener with a job.
* </p>
*
* @param conn
* the DB Connection
* @param job
* the job to associate with the listener
* @param listener
* the listener to insert
* @return the number of rows inserted
*/
public int insertJobListener(Connection conn, JobDetail job, String listener)
throws SQLException {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(rtp(INSERT_JOB_LISTENER));
ps.setString(1, job.getName());
ps.setString(2, job.getGroup());
ps.setString(3, listener);
return ps.executeUpdate();
} finally {
closeStatement(ps);
}
}
示例2: prvateAddQuartz
import org.quartz.JobDetail; //导入依赖的package包/类
private boolean prvateAddQuartz(Class<? extends Job> jobClass,JobKey jobKey, CronScheduleBuilder builder, SimpleScheduleBuilder repeatForever) {
if(scheduler==null){
init();
}
//创建一个任务计划生成器 设置任务名称与分组 创建任务计划
JobDetail job = JobBuilder.newJob(jobClass).withIdentity(jobKey).build();
//创建一个触发生成器 设置触发器名称与分组 设置触发器出发条件 创建触发器
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(jobKey.getName(),jobKey.getGroup()).withSchedule(builder==null?repeatForever:builder).build();
try {
scheduler.scheduleJob(job, trigger);
outLog("添加任务计划成功!");
return true;
} catch (SchedulerException e) {
outLog("添加任务计划失败!");
}
return false;
}
示例3: insertExtendedTriggerProperties
import org.quartz.JobDetail; //导入依赖的package包/类
public int insertExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {
SimpleTrigger simpleTrigger = (SimpleTrigger)trigger;
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(Util.rtp(INSERT_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral));
ps.setString(1, trigger.getKey().getName());
ps.setString(2, trigger.getKey().getGroup());
ps.setInt(3, simpleTrigger.getRepeatCount());
ps.setBigDecimal(4, new BigDecimal(String.valueOf(simpleTrigger.getRepeatInterval())));
ps.setInt(5, simpleTrigger.getTimesTriggered());
return ps.executeUpdate();
} finally {
Util.closeStatement(ps);
}
}
示例4: updateMethodInovkeJob
import org.quartz.JobDetail; //导入依赖的package包/类
public JobDetail updateMethodInovkeJob(String schedulerName, String jobName, String jobGroup, String jobClass,
Object[] constructorArguments, String jobClassMethodName,
Object[] jobClassMethodArgs, String description) throws SchedulerException {
Assert.notNull(jobClass, "jobClass can not be null");
Assert.notEmpty(schedulerName, "schedulerName can not be empty");
Assert.notEmpty(jobName, "jobName can not be empty");
Assert.notEmpty(jobGroup, "jobGroup can not be empty");
Assert.notEmpty(jobClassMethodName, "jobClassMethodName can not be empty");
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("jobClass", jobClass);
jobDataMap.put("constructorArguments", constructorArguments);
jobDataMap.put("jobClassMethodName", jobClassMethodName);
jobDataMap.put("jobClassMethodArgs", jobClassMethodArgs);
JobDetail jobDetail = JobBuilder.newJob(MethodInvokeJob.class).withIdentity(jobName, jobGroup)
.withDescription(description).setJobData(jobDataMap).storeDurably().build();
updateJob(schedulerName, jobDetail);
return jobDetail;
}
示例5: createScheduleJob
import org.quartz.JobDetail; //导入依赖的package包/类
/**
* 创建定时任务
*/
public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
try {
//构建job信息
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getJobId())).build();
//表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
.withMisfireHandlingInstructionDoNothing();
//按新的cronExpression表达式构建一个新的trigger
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId())).withSchedule(scheduleBuilder).build();
//放入参数,运行时的方法可以获取
jobDetail.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, new Gson().toJson(scheduleJob));
scheduler.scheduleJob(jobDetail, trigger);
//暂停任务
if(scheduleJob.getStatus() == ScheduleStatus.PAUSE.getValue()){
pauseJob(scheduler, scheduleJob.getJobId());
}
} catch (SchedulerException e) {
throw new RRException("创建定时任务失败", e);
}
}
示例6: findJob
import org.quartz.JobDetail; //导入依赖的package包/类
@Transactional(readOnly = true)
public Optional<JobDescriptor> findJob(String group, String name) {
// @formatter:off
try {
JobDetail jobDetail = scheduler.getJobDetail(jobKey(name, group));
if(Objects.nonNull(jobDetail))
return Optional.of(
JobDescriptor.buildDescriptor(jobDetail,
scheduler.getTriggersOfJob(jobKey(name, group))));
} catch (SchedulerException e) {
log.error("Could not find job with key - {}.{} due to error - {}", group, name, e.getLocalizedMessage());
}
// @formatter:on
log.warn("Could not find job with key - {}.{}", group, name);
return Optional.empty();
}
示例7: wrapScheduleJob
import org.quartz.JobDetail; //导入依赖的package包/类
/**
* 封装ScheduleJob对象
*
* @param scheduleJob
* @param scheduler
* @param jobKey
* @param trigger
*/
private void wrapScheduleJob(ScheduleJobEntity scheduleJob,
Scheduler scheduler, JobKey jobKey, Trigger trigger) {
try {
scheduleJob.setJobName(jobKey.getName());
scheduleJob.setJobGroup(jobKey.getGroup());
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
scheduleJob.setJobClass(jobDetail.getJobClass());
scheduleJob.setJobDesc(jobDetail.getDescription());
Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
scheduleJob.setTriggerStatus(triggerState.name());
if (trigger instanceof CronTrigger) {
CronTrigger cronTrigger = (CronTrigger) trigger;
TriggerKey triggerKey = cronTrigger.getKey();
scheduleJob.setTriggerName(triggerKey.getName());
scheduleJob.setTriggerGroup(triggerKey.getGroup());
scheduleJob.setNextFireTime(cronTrigger.getNextFireTime());
scheduleJob.setCronExpression(cronTrigger.getCronExpression());
scheduleJob.setStartDate(cronTrigger.getStartTime());
scheduleJob.setEndDate(cronTrigger.getEndTime());
}
} catch (SchedulerException e) {
logger.error("获取触发器状态失败", e);
throw new ServiceException(e);
}
}
示例8: testCodedCronTriggerBean
import org.quartz.JobDetail; //导入依赖的package包/类
/**
* Ensures that jobs that are coded without a delay run without delay.
* @throws Exception
*/
@Test
public void testCodedCronTriggerBean() throws Exception
{
final String JOB_NAME = "codedCronJob";
List<Long> jobRuns = this.getRunList(JOB_NAME);
assertEquals(0, jobRuns.size());
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
CronTriggerBean ctBean = new CronTriggerBean();
ctBean.setBeanName("Dummy");
ctBean.setCronExpression("0/1 * * * * ? *");
ctBean.setEnabled(true);
JobDetail jobDetail = new JobDetail(JOB_NAME, "DefaultGroup", DummyJob.class);
ctBean.setJobDetail(jobDetail);
ctBean.setScheduler(scheduler);
ctBean.afterPropertiesSet();
assertJobRunsAfterInterval(jobRuns);
scheduler.shutdown();
this.assertJobStopsAfterShutdown(jobRuns);
}
示例9: updateExtendedTriggerProperties
import org.quartz.JobDetail; //导入依赖的package包/类
public int updateExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {
CronTrigger cronTrigger = (CronTrigger)trigger;
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(Util.rtp(UPDATE_CRON_TRIGGER, tablePrefix, schedNameLiteral));
ps.setString(1, cronTrigger.getCronExpression());
ps.setString(2, cronTrigger.getTimeZone().getID());
ps.setString(3, trigger.getKey().getName());
ps.setString(4, trigger.getKey().getGroup());
return ps.executeUpdate();
} finally {
Util.closeStatement(ps);
}
}
示例10: startIndexerJob
import org.quartz.JobDetail; //导入依赖的package包/类
private void startIndexerJob() throws SchedulerException {
Scheduler scheduler = Singleton.getScheduler();
// Setup the indexer which runs forever indexing
JobDetail job = newJob(IndexJob.class)
.withIdentity("indexjob")
.build();
SimpleTrigger trigger = newTrigger()
.withIdentity("indexerjob")
.withSchedule(simpleSchedule()
.withIntervalInHours(24)
.repeatForever()
)
.build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
}
示例11: updateJob
import org.quartz.JobDetail; //导入依赖的package包/类
public void updateJob(String group, String name, JobDescriptor descriptor) {
try {
JobDetail oldJobDetail = scheduler.getJobDetail(jobKey(name, group));
if(Objects.nonNull(oldJobDetail)) {
JobDataMap jobDataMap = oldJobDetail.getJobDataMap();
jobDataMap.put("subject", descriptor.getSubject());
jobDataMap.put("messageBody", descriptor.getMessageBody());
jobDataMap.put("to", descriptor.getTo());
jobDataMap.put("cc", descriptor.getCc());
jobDataMap.put("bcc", descriptor.getBcc());
JobBuilder jb = oldJobDetail.getJobBuilder();
JobDetail newJobDetail = jb.usingJobData(jobDataMap).storeDurably().build();
scheduler.addJob(newJobDetail, true);
log.info("Updated job with key - {}", newJobDetail.getKey());
return;
}
log.warn("Could not find job with key - {}.{} to update", group, name);
} catch (SchedulerException e) {
log.error("Could not find job with key - {}.{} to update due to error - {}", group, name, e.getLocalizedMessage());
}
}
示例12: selectByWhere
import org.quartz.JobDetail; //导入依赖的package包/类
/**
* 查询所有定时任务
*
* @param entity
* @return Map
* @throws SchedulerException
*/
@SuppressWarnings({ "rawtypes", "serial", "unchecked" })
@Override
public Object selectByWhere(T entity) throws SchedulerException {
List<String> groups = scheduler.getJobGroupNames();
List<HashMap<String, Object>> jobList = new ArrayList<HashMap<String, Object>>();
for (String group : groups) {
if (null != entity.getGroup() && !group.contains(entity.getGroup())) {
continue;
}
Set<JobKey> jobKeys = scheduler.getJobKeys(new GroupMatcher(group,
StringOperatorName.EQUALS) {
});
for (JobKey jobKey : jobKeys) {
if (null != entity.getName()
&& !jobKey.toString().contains(entity.getName())) {
continue;
}
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
HashMap<String, Object> jobInfoMap = new HashMap<String, Object>();
List<? extends Trigger> triggers = scheduler
.getTriggersOfJob(jobKey);
jobInfoMap.put("triggers", triggers);
jobInfoMap.put("jobDetail", jobDetail);
jobInfoMap.put("params",
JSONArray.fromObject(jobDetail.getJobDataMap())
.toString());
jobInfoMap.put("type", "Kettle");
jobList.add(jobInfoMap);
}
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("jobList", jobList);
map.put("scheduler", scheduler);
return map;
}
示例13: refreshMetadata
import org.quartz.JobDetail; //导入依赖的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
示例14: interrupt
import org.quartz.JobDetail; //导入依赖的package包/类
/**
* Interrupt all instances of the identified InterruptableJob executing in
* this Scheduler instance.
*
* <p>
* This method is not cluster aware. That is, it will only interrupt
* instances of the identified InterruptableJob currently executing in this
* Scheduler instance, not across the entire cluster.
* </p>
*
* @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
*/
public boolean interrupt(JobKey jobKey) throws UnableToInterruptJobException {
List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
JobDetail jobDetail = null;
Job job = null;
boolean interrupted = false;
for(JobExecutionContext jec : jobs) {
jobDetail = jec.getJobDetail();
if (jobKey.equals(jobDetail.getKey())) {
job = jec.getJobInstance();
if (job instanceof InterruptableJob) {
((InterruptableJob)job).interrupt();
interrupted = true;
} else {
throw new UnableToInterruptJobException(
"Job " + jobDetail.getKey() +
" can not be interrupted, since it does not implement " +
InterruptableJob.class.getName());
}
}
}
return interrupted;
}
示例15: notifySchedulerListenersJobAdded
import org.quartz.JobDetail; //导入依赖的package包/类
public void notifySchedulerListenersJobAdded(JobDetail jobDetail) {
// build a list of all scheduler listeners that are to be notified...
List<SchedulerListener> schedListeners = buildSchedulerListenerList();
// notify all scheduler listeners
for(SchedulerListener sl: schedListeners) {
try {
sl.jobAdded(jobDetail);
} catch (Exception e) {
getLog().error(
"Error while notifying SchedulerListener of JobAdded.",
e);
}
}
}