本文整理汇总了Java中org.quartz.Scheduler.getTrigger方法的典型用法代码示例。如果您正苦于以下问题:Java Scheduler.getTrigger方法的具体用法?Java Scheduler.getTrigger怎么用?Java Scheduler.getTrigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.Scheduler
的用法示例。
在下文中一共展示了Scheduler.getTrigger方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modifyJobTime
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* @Description: 修改一个任务的触发时间(使用默认的任务组名,触发器名,触发器组名)
* @param jobName
* @param time
*
*/
@SuppressWarnings("unchecked")
public static void modifyJobTime(String jobName, String time) {
TriggerKey triggerKey = TriggerKey.triggerKey(
jobName, TRIGGER_GROUP_NAME);
try {
Scheduler sched = gSchedulerFactory.getScheduler();
CronTrigger trigger =(CronTrigger) sched.getTrigger(triggerKey);
if (trigger == null) {
return;
}
String oldTime = trigger.getCronExpression();
if (!oldTime.equalsIgnoreCase(time)) {
CronScheduleBuilder scheduleBuilder =CronScheduleBuilder.cronSchedule(time);
//按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey)
.withSchedule(scheduleBuilder).build();
//按新的trigger重新设置job执行
sched.rescheduleJob(triggerKey, trigger);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: removeJob
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* @Description 移除一个任务(使用默认的任务组名,触发器名,触发器组名)
* @param jobName
*
*
*/
public static void removeJob(String jobName) {
TriggerKey triggerKey = TriggerKey.triggerKey(
jobName, TRIGGER_GROUP_NAME);
JobKey jobKey = JobKey.jobKey(jobName, JOB_GROUP_NAME);
try {
Scheduler sched = gSchedulerFactory.getScheduler();
Trigger trigger = (Trigger) sched.getTrigger(triggerKey);
if (trigger == null) {
return;
}
sched.pauseTrigger(triggerKey);;// 停止触发器
sched.unscheduleJob(triggerKey);// 移除触发器
sched.deleteJob(jobKey);// 删除任务
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: updateJobCron
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* 更新job时间表达式
*
* @param scheduleJob
* @throws SchedulerException
*/
public void updateJobCron(ScheduleJob scheduleJob) throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
scheduler.rescheduleJob(triggerKey, trigger);
}
示例4: showScheduledEmails
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* Renders a page listing all scheduled emails.
*/
public ActionForward showScheduledEmails(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException, SchedulerException {
getUserManagementService();
Scheduler scheduler = getScheduler();
TreeSet<EmailScheduleMessageJobDTO> scheduleList = new TreeSet<EmailScheduleMessageJobDTO>();
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true);
boolean isLessonNotifications = (lessonId != null);
Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true);
if (isLessonNotifications) {
if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(),
"show scheduled lesson email notifications", false)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson");
return null;
}
} else {
if (!getSecurityService().isGroupMonitor(organisationId, getCurrentUser().getUserID(),
"show scheduled course email notifications", false)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the organisation");
return null;
}
}
Set<TriggerKey> triggerKeys = scheduler
.getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
for (TriggerKey triggerKey : triggerKeys) {
String triggerName = triggerKey.getName();
if (triggerName.startsWith(EmailNotificationsAction.TRIGGER_PREFIX_NAME)) {
Trigger trigger = scheduler.getTrigger(triggerKey);
JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
JobDataMap jobDataMap = jobDetail.getJobDataMap();
// filter triggers
if (isLessonNotifications) {
Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID);
if ((jobLessonId == null) || (!lessonId.equals(jobLessonId))) {
continue;
}
} else {
Object jobOrganisationId = jobDataMap.get(AttributeNames.PARAM_ORGANISATION_ID);
if ((jobOrganisationId == null) || (!organisationId.equals(jobOrganisationId))) {
continue;
}
}
Date triggerDate = trigger.getNextFireTime();
String emailBody = WebUtil.convertNewlines((String) jobDataMap.get("emailBody"));
int searchType = (Integer) jobDataMap.get("searchType");
EmailScheduleMessageJobDTO emailScheduleJobDTO = new EmailScheduleMessageJobDTO();
emailScheduleJobDTO.setTriggerName(triggerName);
emailScheduleJobDTO.setTriggerDate(triggerDate);
emailScheduleJobDTO.setEmailBody(emailBody);
emailScheduleJobDTO.setSearchType(searchType);
scheduleList.add(emailScheduleJobDTO);
}
}
request.setAttribute("scheduleList", scheduleList);
request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId);
request.setAttribute(AttributeNames.PARAM_ORGANISATION_ID, organisationId);
return mapping.findForward("scheduledEmailList");
}
示例5: getEmailProgressDates
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* Gets learners or monitors of the lesson and organisation containing it.
*
* @throws SchedulerException
*/
public ActionForward getEmailProgressDates(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, JSONException, SchedulerException {
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(), "get class members", false)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson");
return null;
}
HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
JSONObject responseJSON = new JSONObject();
JSONArray datesJSON = new JSONArray();
// find all the current dates set up to send the emails
Scheduler scheduler = getScheduler();
String triggerPrefix = getTriggerPrefix(lessonId);
SortedSet<Date> currentDatesSet = new TreeSet<Date>();
Set<TriggerKey> triggerKeys = scheduler
.getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
for (TriggerKey triggerKey : triggerKeys) {
String triggerName = triggerKey.getName();
if (triggerName.startsWith(triggerPrefix)) {
Trigger trigger = scheduler.getTrigger(triggerKey);
JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
JobDataMap jobDataMap = jobDetail.getJobDataMap();
// get only the trigger for the current lesson
Object jobLessonId = jobDataMap.get(AttributeNames.PARAM_LESSON_ID);
if (lessonId.equals(jobLessonId)) {
Date triggerDate = trigger.getNextFireTime();
currentDatesSet.add(triggerDate);
}
}
}
for (Date date : currentDatesSet) {
datesJSON.put(createDateJSON(request.getLocale(), user, date, null));
}
responseJSON.put("dates", datesJSON);
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(responseJSON.toString());
return null;
}
示例6: getScheduleJobEntity
import org.quartz.Scheduler; //导入方法依赖的package包/类
@Override
public ScheduleJobEntity getScheduleJobEntity(ScheduleJobEntity job){
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
JobKey jobKey = JobKey.jobKey(job.getJobName(), job.getJobGroup());
TriggerKey triggerKey = job.getTriggerKey();
Trigger trigger = scheduler.getTrigger(triggerKey);
this.wrapScheduleJob(job, scheduler, jobKey, trigger);
} catch (SchedulerException e) {
logger.error("获取job失败", e);
throw new ServiceException("获取job失败", e);
}
return job;
}
示例7: updateJobTrigger
import org.quartz.Scheduler; //导入方法依赖的package包/类
@Transactional
@Override
public boolean updateJobTrigger(ScheduleJobEntity job) {
try {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
// 获取触发器标识
TriggerKey triggerKey = job.getTriggerKey();
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// Trigger已存在,更新相应的定时设置
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
.cronSchedule(job.getCronExpression());
// 按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder()
.forJob(job.getJobKey())
.withIdentity(triggerKey)
.startAt(job.getStartDate()) // job开始日期
.endAt(job.getEndDate())// job结束日期
.withSchedule(scheduleBuilder).build();
// 按新的trigger重新设置job执行
scheduler.rescheduleJob(triggerKey, trigger);
return Boolean.TRUE;
} catch (Exception e) {
throw new ServiceException(e);
}
}
示例8: getCronTrigger
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* 获取表达式触发器
*/
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId) {
try {
return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
} catch (SchedulerException e) {
throw new RRException("获取定时任务CronTrigger出现异常", e);
}
}
示例9: updateTrigger
import org.quartz.Scheduler; //导入方法依赖的package包/类
public void updateTrigger(String jobDefId,String companyId,String cronExpression) throws SchedulerException {
Scheduler scheduler=schedulerService.retrieveScheduler();
CronTriggerImpl trigger=(CronTriggerImpl)scheduler.getTrigger(new TriggerKey(TRIGGER_PREFIX+jobDefId,companyId));
try {
trigger.setCronExpression(cronExpression);
} catch (ParseException e) {
e.printStackTrace();
throw new SchedulerException(e);
}
scheduler.scheduleJob(trigger);
}
示例10: deleteNotification
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* Delete a scheduled emails.
*
* @throws JSONException
*/
public ActionForward deleteNotification(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException, SchedulerException, JSONException {
String inputTriggerName = WebUtil.readStrParam(request, "triggerName");
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true);
Integer userId = getCurrentUser().getUserID();
boolean isLessonNotifications = (lessonId != null);
Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true);
IMonitoringService monitoringService = MonitoringServiceProxy
.getMonitoringService(getServlet().getServletContext());
getUserManagementService();
Scheduler scheduler = getScheduler();
JSONObject jsonObject = new JSONObject();
String error = null;
try {
// if this method throws an Exception, there will be no deleteNotification=true in the JSON reply
if (isLessonNotifications) {
if (!getSecurityService().isLessonMonitor(lessonId, userId, "show scheduled lesson email notifications",
false)) {
error = "Unable to delete notification: the user is not a monitor in the lesson";
}
} else {
if (!getSecurityService().isGroupMonitor(organisationId, userId,
"show scheduled course course email notifications", false)) {
error = "Unable to delete notification: the user is not a monitor in the organisation";
}
}
if (error == null) {
Set<TriggerKey> triggerKeys = scheduler
.getTriggerKeys(GroupMatcher.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
for (TriggerKey triggerKey : triggerKeys) {
String triggerName = triggerKey.getName();
if (triggerName.equals(inputTriggerName)) {
Trigger trigger = scheduler.getTrigger(triggerKey);
JobKey jobKey = trigger.getJobKey();
JobDetail jobDetail = scheduler.getJobDetail(trigger.getJobKey());
JobDataMap jobDataMap = jobDetail.getJobDataMap();
getAuditService().log(MonitoringConstants.MONITORING_MODULE_NAME,
"Deleting unsent scheduled notification " + jobKey + " "
+ jobDataMap.getString("emailBody"));
scheduler.deleteJob(jobKey);
}
}
}
} catch (Exception e) {
String[] msg = new String[1];
msg[0] = e.getMessage();
error = monitoringService.getMessageService().getMessage("error.system.error", msg);
}
jsonObject.put("deleteNotification", error == null ? "true" : error);
response.setContentType("application/json;charset=utf-8");
response.getWriter().print(jsonObject);
return null;
}
示例11: updateEmailProgressDate
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* Add or remove a date for the email progress
*/
public ActionForward updateEmailProgressDate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException, JSONException {
Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID);
if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(), "get class members", false)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson");
return null;
}
HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
// as we are using ms since UTC 0 calculated on the client, this will be correctly set up as server date
// and does not need changing (assuming the user's LAMS timezone matches the user's computer timezone).
long dateId = WebUtil.readLongParam(request, "id");
Date newDate = new Date(dateId);
boolean add = WebUtil.readBooleanParam(request, "add");
// calculate scheduleDate
String scheduledTriggerName = getTriggerName(lessonId, newDate);
JSONObject dateJSON = null;
try {
Scheduler scheduler = getScheduler();
Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher
.triggerGroupEquals(Scheduler.DEFAULT_GROUP));
Trigger trigger = null;
for (TriggerKey triggerKey : triggerKeys) {
if (scheduledTriggerName.equals(triggerKey.getName())) {
trigger = scheduler.getTrigger(triggerKey);
break;
}
}
if (add) {
if (trigger == null) {
String desc = new StringBuilder("Send progress email. Lesson ")
.append(lessonId).append(" on ").append(newDate).toString();
// build job detail based on the bean class
JobDetail EmailProgressMessageJob = JobBuilder.newJob(EmailProgressMessageJob.class)
.withIdentity(getJobName(lessonId, newDate))
.withDescription(desc)
.usingJobData(AttributeNames.PARAM_LESSON_ID, lessonId).build();
// create customized triggers
Trigger startLessonTrigger = TriggerBuilder.newTrigger().withIdentity(scheduledTriggerName)
.startAt(newDate).build();
// start the scheduling job
scheduler.scheduleJob(EmailProgressMessageJob, startLessonTrigger);
dateJSON = createDateJSON(request.getLocale(), user, newDate, "added");
} else {
dateJSON = createDateJSON(request.getLocale(), user, newDate, "none");
}
} else if (!add) {
if (trigger != null) {
// remove trigger
scheduler.deleteJob(trigger.getJobKey());
dateJSON = createDateJSON(request.getLocale(), user, null, "deleted");
} else {
dateJSON = createDateJSON(request.getLocale(), user, null, "none");
}
}
} catch (SchedulerException e) {
LamsDispatchAction.log.error("Error occurred at " + "[EmailProgressAction]- fail to email scheduling", e);
}
if (dateJSON != null) {
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(dateJSON.toString());
}
return null;
}
示例12: getTrigger
import org.quartz.Scheduler; //导入方法依赖的package包/类
public Trigger getTrigger(String schedulerName,String triggerName,String triggerGroup) throws SchedulerException {
Assert.notEmpty(triggerName, "triggerName can not be empty");
Assert.notEmpty(triggerGroup, "triggerGroup can not be empty");
Scheduler scheduler = this.getAssertScheduler(schedulerName);
TriggerKey triggerKey = QuartzUtils.getTriggerKey(triggerName, triggerGroup);
Trigger trigger = scheduler.getTrigger(triggerKey);
return trigger;
}
示例13: updateJobCron
import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
* 更新job时间表达式
*
* @param scheduleJob
* @throws SchedulerException
*/
public void updateJobCron(ScheduleJob scheduleJob) throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getName(), scheduleJob.getGroup());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCron());
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
scheduler.rescheduleJob(triggerKey, trigger);
}