本文整理汇总了Java中org.quartz.JobDetail.getJobDataMap方法的典型用法代码示例。如果您正苦于以下问题:Java JobDetail.getJobDataMap方法的具体用法?Java JobDetail.getJobDataMap怎么用?Java JobDetail.getJobDataMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.JobDetail
的用法示例。
在下文中一共展示了JobDetail.getJobDataMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: execute
import org.quartz.JobDetail; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JobDetail jobDetail = jobExecutionContext.getJobDetail();
_logger.info("Cron triggered for {0}", jobDetail.getDescription());
JobDataMap dataMap = jobDetail.getJobDataMap();
try {
//Creating entry in redis to avoid duplicate job scheduling
MemcacheService cache = AppFactory.get().getMemcacheService();
String jobKey = "SJOB_" + DigestUtils.md5Hex(dataMap.getString("url"));
if (cache.get(jobKey) == null) {
HttpUtil
.connectMulti(HttpUtil.GET, ConfigUtil.get("task.url") + dataMap.getString("url"), null,
null, null, null);
cache.put(jobKey, true, 1800);
} else {
_logger.warn("Job with url {0} is already scheduled. Doing nothing!!",
dataMap.getString("url"));
}
} catch (Exception e) {
_logger.warn("Scheduled job failed for url {0} with exception {1}", dataMap.getString("url"),
e.getMessage(), e);
}
}
示例3: executeScheduleJob
import org.quartz.JobDetail; //导入方法依赖的package包/类
/**
* 执行计划任务
* @param job
* @param trigger
* @return
* @throws SchedulerException
*/
public static ScheduleJobResult executeScheduleJob(JobDetail job, Trigger trigger) throws SchedulerException {
ScheduleJobResult scheduleJobResult = new ScheduleJobResult();
//判断是否满足计划任务的创建条件
if(job.getKey() == null || trigger.getKey() == null || job.getJobDataMap() == null){
scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.FAILED);
//不满足计划任务的创建条件,返回scheduleJobResult值类
return scheduleJobResult;
}
scheduleJobResult.setJobDetail(job);
scheduleJobResult.setTrigger(trigger);
//开始分配计划任务
Scheduler scheduler = SchedulerFactory.getScheduler();
//开始判断是否存在相同的计划任务
if(scheduler.checkExists(job.getKey())){
log.info("存在相同的计划任务:{}",job.getKey());
scheduler.deleteJob(job.getKey());
scheduleJobResult.setJobKey(job.getKey());
scheduleJobResult.setTriggerKey(trigger.getKey());
scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.ISEXIST);
scheduler.scheduleJob(job,trigger);
scheduler.start();
}else{
scheduler.scheduleJob(job,trigger);
scheduler.start();
scheduleJobResult.setJobKey(job.getKey());
scheduleJobResult.setTriggerKey(trigger.getKey());
scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.SUCCESS);
}
//计划任务分配成功
return scheduleJobResult;
}
示例4: setUp
import org.quartz.JobDetail; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception
{
ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) ctx.getBean("ActivitiesFeed");
ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
feedNotifier = (FeedNotifierImpl) activitiesFeedCtx.getBean("feedNotifier");
activityService = (ActivityService) activitiesFeedCtx.getBean("activityService");
feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
ObjectFactory<ActivitiesFeedModelBuilder> feedModelBuilderFactory = (ObjectFactory<ActivitiesFeedModelBuilder>) activitiesFeedCtx.getBean("feedModelBuilderFactory");
EmailUserNotifier emailUserNotifier = (EmailUserNotifier) activitiesFeedCtx.getBean("emailUserNotifier");
tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
transactionService = (TransactionService) ctx.getBean("transactionService");
personService = (PersonService) ctx.getBean("personService");
postDAO = (ActivityPostDAO) ctx.getBean("postDAO");
nodeService = (NodeService) ctx.getBean("nodeService");
namespaceService = (NamespaceService) ctx.getBean("namespaceService");
siteService = (SiteService) ctx.getBean("siteService");
repoAdminService = (RepoAdminService) ctx.getBean("repoAdminService");
actionService = (ActionService) ctx.getBean("ActionService");
authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
EmailHelper emailHelper = (EmailHelper) ctx.getBean("emailHelper");
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
// create some users
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
{
@SuppressWarnings("synthetic-access")
public Void execute() throws Throwable
{
personNodeRef = createUser(userName1);
failingPersonNodeRef = createUser(userName2);
return null;
}
}, false, true);
// use our own user notifier for testing purposes
userNotifier = new RegisterErrorUserFeedNotifier();
userNotifier.setNodeService(nodeService);
userNotifier.setNamespaceService(namespaceService);
userNotifier.setSiteService(siteService);
userNotifier.setActivityService(activityService);
userNotifier.setRepoAdminService(repoAdminService);
userNotifier.setActionService(actionService);
userNotifier.setActivitiesFeedModelBuilderFactory(feedModelBuilderFactory);
userNotifier.setAuthenticationContext(authenticationContext);
userNotifier.setExcludedEmailSuffixes(emailUserNotifier.getExcludedEmailSuffixes());
userNotifier.setEmailHelper(emailHelper);
feedNotifier.setUserNotifier(userNotifier);
jobDetail = new JobDetail("feedNotifier", FeedNotifierJob.class);
JobDataMap jobDataMap = jobDetail.getJobDataMap();
jobDataMap.put("tenantAdminService", tenantAdminService);
jobDataMap.put("feedNotifier", feedNotifier);
feedNotifierJob = new FeedNotifierJob();
when(jobCtx.getJobDetail()).thenReturn(jobDetail);
}
示例5: showScheduledEmails
import org.quartz.JobDetail; //导入方法依赖的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");
}
示例6: getEmailProgressDates
import org.quartz.JobDetail; //导入方法依赖的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;
}
示例7: jobWasExecuted
import org.quartz.JobDetail; //导入方法依赖的package包/类
public void jobWasExecuted(JobExecutionContext context,
JobExecutionException jobException) {
JobDetail jobDetail = context.getJobDetail();
if (!(jobDetail instanceof SpringBeanJobExecutorDetail)) {
return;
}
JobDataMap map = jobDetail.getJobDataMap();
if (!map.containsKey(IJobDefinitionService.JOB_DEFINITION_ID)) {
return;
}
Date end = new Date();
String exception = getExceptionStackMessage(jobException);
JobHistory history = new JobHistory();
history.setSuccessful(exception == null ? true : false);
if (exception != null) {
history.setExceptionMessage(exception.length() > 1500 ? exception
.substring(0, 1500) : exception);
}
history.setEndDate(end);
history.setStartDate((Date)map.get(START_DATE_KEY));
history.setId(UUID.randomUUID().toString());
history.setJobId(map.getString(IJobDefinitionService.JOB_DEFINITION_ID));
Session session = getSessionFactory().openSession();
try {
session.save(history);
} finally {
session.flush();
session.close();
}
}
示例8: deleteNotification
import org.quartz.JobDetail; //导入方法依赖的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;
}
示例9: jobToBeExecuted
import org.quartz.JobDetail; //导入方法依赖的package包/类
public void jobToBeExecuted(JobExecutionContext context) {
JobDetail jobDetail = context.getJobDetail();
JobDataMap map = jobDetail.getJobDataMap();
map.put(START_DATE_KEY, new Date());
}
示例10: execute
import org.quartz.JobDetail; //导入方法依赖的package包/类
public void execute(final JobExecutionContext jobCtx)
throws JobExecutionException {
Connection conn = null;
Session sess = null;
MessageProducer producer = null;
try {
final JobDetail detail = jobCtx.getJobDetail();
final JobDataMap dataMap = detail.getJobDataMap();
final Context namingCtx = JmsHelper.getInitialContext(dataMap);
final ConnectionFactory connFactory = (ConnectionFactory) namingCtx
.lookup(dataMap
.getString(JmsHelper.JMS_CONNECTION_FACTORY_JNDI));
if (!JmsHelper.isDestinationSecure(dataMap)) {
conn = connFactory.createConnection();
} else {
final String user = dataMap.getString(JmsHelper.JMS_USER);
final String password = dataMap
.getString(JmsHelper.JMS_PASSWORD);
conn = connFactory.createConnection(user, password);
}
final boolean useTransaction = JmsHelper.useTransaction(dataMap);
final int ackMode = dataMap.getInt(JmsHelper.JMS_ACK_MODE);
sess = conn.createSession(useTransaction, ackMode);
final Destination destination = (Destination) namingCtx
.lookup(dataMap.getString(JmsHelper.JMS_DESTINATION_JNDI));
producer = sess.createProducer(destination);
final String msgFactoryClassName = dataMap
.getString(JmsHelper.JMS_MSG_FACTORY_CLASS_NAME);
final JmsMessageFactory messageFactory = JmsHelper
.getMessageFactory(msgFactoryClassName);
final Message msg = messageFactory.createMessage(dataMap, sess);
producer.send(msg);
} catch (final Exception e) {
throw new JobExecutionException(e);
} finally {
JmsHelper.closeResource(producer);
JmsHelper.closeResource(sess);
JmsHelper.closeResource(conn);
}
}