當前位置: 首頁>>代碼示例>>Java>>正文


Java Scheduler.getTrigger方法代碼示例

本文整理匯總了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);    
    }    
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:31,代碼來源:MicroQuartzManager.java

示例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);    
    }    
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:24,代碼來源:MicroQuartzManager.java

示例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);
}
 
開發者ID:handexing,項目名稱:frameworkAggregate,代碼行數:15,代碼來源:ScheduleJobService.java

示例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");
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:66,代碼來源:EmailNotificationsAction.java

示例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;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:53,代碼來源:EmailProgressAction.java

示例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;
}
 
開發者ID:wjggwm,項目名稱:webside,代碼行數:15,代碼來源:ScheduleJobServiceImpl.java

示例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);
	}
}
 
開發者ID:wjggwm,項目名稱:webside,代碼行數:29,代碼來源:ScheduleJobServiceImpl.java

示例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);
    }
}
 
開發者ID:gyp220203,項目名稱:renren-msg,代碼行數:11,代碼來源:ScheduleUtils.java

示例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);
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:12,代碼來源:JobServiceImpl.java

示例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;

   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:72,代碼來源:EmailNotificationsAction.java

示例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;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:79,代碼來源:EmailProgressAction.java

示例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;
}
 
開發者ID:quartzweb,項目名稱:quartz-web,代碼行數:9,代碼來源:QuartzManager.java

示例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);
}
 
開發者ID:Zigin,項目名稱:MonitorPlatform,代碼行數:20,代碼來源:JobConfigService.java


注:本文中的org.quartz.Scheduler.getTrigger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。