本文整理汇总了Java中org.quartz.JobDataMap类的典型用法代码示例。如果您正苦于以下问题:Java JobDataMap类的具体用法?Java JobDataMap怎么用?Java JobDataMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JobDataMap类属于org.quartz包,在下文中一共展示了JobDataMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSchedule
import org.quartz.JobDataMap; //导入依赖的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;
}
示例2: execute
import org.quartz.JobDataMap; //导入依赖的package包/类
/**
* Called when the job is executed by quartz. This method delegates to the <tt>validateSessions()</tt> method on the
* associated session manager.
*
* @param context
* the Quartz job execution context for this execution.
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
ValidatingSessionManager sessionManager = (ValidatingSessionManager) jobDataMap.get(SESSION_MANAGER_KEY);
if (log.isDebugEnabled()) {
log.debug("Executing session validation Quartz job...");
}
sessionManager.validateSessions();
if (log.isDebugEnabled()) {
log.debug("Session validation Quartz job complete.");
}
}
示例3: execute
import org.quartz.JobDataMap; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
final int numberOfRetries;
JobDataMap jobDataMap = context.getMergedJobDataMap();
numberOfRetries = jobDataMap.containsKey(NUMBER_OF_RETRIES_PARAM) ?
jobDataMap.getIntValue(NUMBER_OF_RETRIES_PARAM) : DEFAULT_NUMBER_OF_RETRIES;
//check if running job class has the "NonRetryable" annotation
boolean isRetryable = jobDataMap.containsKey(Constants.JOB_DEFINITION) ?
((JobDefinition)jobDataMap.get(Constants.JOB_DEFINITION)).isRetryable() : true;
try {
job.execute(context);
//reset retry param, just in case
jobDataMap.putAsString(NUMBER_OF_RETRIES_PARAM, 0);
} catch (Exception e) {
//do not retry if job is not retryable or no more retries left
if (!isRetryable || numberOfRetries <= 0) {
throwAndFinish(jobDataMap, context, e);
}
triggerRefire(jobDataMap, numberOfRetries, context, e);
} catch (Throwable t) {
//do not retry on throwable
throwAndFinish(jobDataMap, context, t);
}
}
示例4: addMethodInovkeJob
import org.quartz.JobDataMap; //导入依赖的package包/类
public JobDetail addMethodInovkeJob(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();
addJob(schedulerName, jobDetail);
return jobDetail;
}
示例5: addStatefulMethodJob
import org.quartz.JobDataMap; //导入依赖的package包/类
public JobDetail addStatefulMethodJob(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(StatefulMethodInvokeJob.class).withIdentity(jobName, jobGroup)
.withDescription(description).setJobData(jobDataMap).storeDurably().build();
addJob(schedulerName, jobDetail);
return jobDetail;
}
示例6: execute
import org.quartz.JobDataMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void execute(JobExecutionContext job) throws JobExecutionException {
TriggerScheduleServiceCenterToProviderServiceCenterMessage msg = new TriggerScheduleServiceCenterToProviderServiceCenterMessage();
String jobName = job.getJobDetail().getKey().getName();
JobDataMap jobDataMap = job.getJobDetail().getJobDataMap();
ConcurrentHashMap<Integer, ServiceXServerSession> rpcServers = (ConcurrentHashMap<Integer, ServiceXServerSession>) jobDataMap
.get(RPCSERVERS);
ConcurrentHashMap<String, ConcurrentHashSet<Integer>> schedules = (ConcurrentHashMap<String, ConcurrentHashSet<Integer>>) jobDataMap
.get(SCHEDULES);
ConcurrentHashSet<Integer> providerList = schedules.get(jobName);
if (providerList == null) {
log.error("Job:" + jobName + "找不到Provider");
return;
}
msg.setJobName(jobName);
// 查看是否是最有一次执行,并且移除此job
if (!job.getTrigger().mayFireAgain()) {
msg.setEnd(true);
schedules.remove(jobName);
log.info("任务生命终结,执行删除:" + jobName);
}
// 选举式触发
ArrayList<Integer> arrayList = new ArrayList<>(providerList);
int providerId = arrayList.get(RandomUtil.randomInt(0, arrayList.size() - 1));
ServiceXServerSession serviceXServerSession = rpcServers.get(providerId);
if (serviceXServerSession != null) {
serviceXServerSession.getSession().writeAndFlush(msg);
log.info(jobName + "触发!分配的ProviderId为:" + providerId + ",下次触发时间:"
+ TimeUtil.date2Str(job.getTrigger().getNextFireTime().getTime()));
}
}
示例7: triggerJobWithVolatileTrigger
import org.quartz.JobDataMap; //导入依赖的package包/类
/**
* <p>
* Trigger the identified <code>{@link org.quartz.Job}</code> (execute it
* now) - with a volatile trigger.
* </p>
*/
public void triggerJobWithVolatileTrigger(SchedulingContext ctxt,
String jobName, String groupName, JobDataMap data) throws SchedulerException {
validateState();
if(groupName == null) {
groupName = Scheduler.DEFAULT_GROUP;
}
Trigger trig = new org.quartz.SimpleTrigger(newTriggerId(),
Scheduler.DEFAULT_MANUAL_TRIGGERS, jobName, groupName,
new Date(), null, 0, 0);
trig.setVolatility(true);
trig.computeFirstFireTime(null);
if(data != null) {
trig.setJobDataMap(data);
}
boolean collision = true;
while (collision) {
try {
resources.getJobStore().storeTrigger(ctxt, trig, false);
collision = false;
} catch (ObjectAlreadyExistsException oaee) {
trig.setName(newTriggerId());
}
}
notifySchedulerThread(trig.getNextFireTime().getTime());
notifySchedulerListenersSchduled(trig);
}
示例8: processUserMessage
import org.quartz.JobDataMap; //导入依赖的package包/类
private void processUserMessage(String messageContent, SlackUser messageSender, SlackSession session, SlackChannel channel) {
// TODO change it to be processed asynchronously
// Parse the message content
String parsedMessage = parseMessage(messageContent);
if (parsedMessage != null) {
logger.info("=> Received message from amigo bot:" + parsedMessage);
try {
// Some unique job name
String jobName = "SLACK-MESG-JOB-" + UUID.randomUUID().toString();
String groupName = JOB_GRP_SLACKBOT;
JobDataMap params = new JobDataMap();
params.put(JOB_PARAM_MESSAGE, parsedMessage);
params.put(JOB_PARAM_MSG_SENDER, messageSender);
params.put(JOB_PARAM_SLACK_SESSION, session);
params.put(JOB_PARAM_SLACK_CHANNEL, channel);
params.put(JOB_PARAM_BOT_TOK, System.getenv("SLACK_BOT_TOKEN"));
logger.info("Processing message async with params: " + params);
JobManager.getInstance().scheduleJob(SlackMessageProcessorJob.class, jobName, groupName, params);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error in processing message", e);
}
}
}
示例9: processMessageAsync
import org.quartz.JobDataMap; //导入依赖的package包/类
private void processMessageAsync(String value) {
if (value != null && !value.trim().isEmpty()) {
try {
// Some unique job name
String jobName = "CP-MESG-JOB-" + UUID.randomUUID().toString();
String groupName = JOB_GRP_CP;
JobDataMap params = new JobDataMap();
params.put(JOB_PARAM_MESSAGE, value);
params.put(JOB_PARAM_DBCLIENT, dbClient);
JobManager.getInstance().scheduleJob(MessageProcessorJob.class, jobName, groupName, params);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例10: execute
import org.quartz.JobDataMap; //导入依赖的package包/类
/**
* Calls the cleaner to do its work
*/
public void execute(JobExecutionContext context) throws JobExecutionException
{
JobDataMap jobData = context.getJobDetail().getJobDataMap();
// extract the content cleaner to use
Object sharedFolderPatchObj = jobData.get("sharedFolderPatch");
if (sharedFolderPatchObj == null || !(sharedFolderPatchObj instanceof SharedFolderPatch))
{
throw new AlfrescoRuntimeException(
"'sharedFolderPatch' data must contain valid 'SharedFolderPatch' reference");
}
// Job Lock Here - should probably move into the patch service at some time.
SharedFolderPatch sharedFolderPatch = (SharedFolderPatch) sharedFolderPatchObj;
sharedFolderPatch.executeAsync();
}
示例11: mapRow
import org.quartz.JobDataMap; //导入依赖的package包/类
@Override
public HistorianEntry mapRow(ResultSet resultSet, int i) throws SQLException {
return new HistorianEntry(
resultSet.getString("SCHED_NAME"),
resultSet.getString("SCHED_INSTANCE_ID"),
resultSet.getString("CONTEXT_KEY"),
resultSet.getString("FIRE_KEY"),
new NameAndGroup(resultSet.getString("TRIGGER_NAME"), resultSet.getString("TRIGGER_GROUP")),
resultSet.getString("PREV_TRIGGERS_FIRE_KEYS") == null ? null : Arrays.asList(resultSet.getString("PREV_TRIGGERS_FIRE_KEYS").split(",")),
resultSet.getTimestamp("START_TIME").toInstant(),
resultSet.getTimestamp("END_TIME") == null ? null : resultSet.getTimestamp("END_TIME").toInstant(),
readByteValue(resultSet.getBytes("INPUT"), JobDataMap.class),
readByteValue(resultSet.getBytes("OUTPUT"), Object.class),
ExecutionStatus.valueOf(resultSet.getString("RUN_STATUS")),
readByteValue(resultSet.getBytes("EXCEPTION"), String.class)
);
}
示例12: JobExecutionContextImpl
import org.quartz.JobDataMap; //导入依赖的package包/类
/**
* <p>
* Create a JobExcecutionContext with the given context data.
* </p>
*/
public JobExecutionContextImpl(Scheduler scheduler,
TriggerFiredBundle firedBundle, Job job) {
this.scheduler = scheduler;
this.trigger = firedBundle.getTrigger();
this.calendar = firedBundle.getCalendar();
this.jobDetail = firedBundle.getJobDetail();
this.job = job;
this.recovering = firedBundle.isRecovering();
this.fireTime = firedBundle.getFireTime();
this.scheduledFireTime = firedBundle.getScheduledFireTime();
this.prevFireTime = firedBundle.getPrevFireTime();
this.nextFireTime = firedBundle.getNextFireTime();
this.jobDataMap = new JobDataMap();
this.jobDataMap.putAll(jobDetail.getJobDataMap());
this.jobDataMap.putAll(trigger.getJobDataMap());
}
示例13: throwAndFinish
import org.quartz.JobDataMap; //导入依赖的package包/类
private void throwAndFinish(JobDataMap jobDataMap, JobExecutionContext context, Throwable t)
throws JobExecutionException {
context.put(Constants.JOB_EXCEPTION, t);
//reset retry param, just in case
jobDataMap.putAsString(NUMBER_OF_RETRIES_PARAM, 0);
JobExecutionException e = new JobExecutionException("This trigger has thrown a terminal exception. " +
"Retries exceeded or job not retryable", t);
throw e;
}
示例14: execute
import org.quartz.JobDataMap; //导入依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException {
long start = System.currentTimeMillis();
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
String taskType = jobDataMap.getString("taskType");
String targetObject = jobDataMap.getString("targetObject");
String targetMethod = jobDataMap.getString("targetMethod");
try {
ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext()
.get("applicationContext");
if (TaskType.local.equals(taskType)) {
Object refer = applicationContext.getBean(targetObject);
refer.getClass().getDeclaredMethod(targetMethod).invoke(refer);
} else if (TaskType.dubbo.equals(taskType)) {
String system = "org.ibase4j.provider.I" + jobDataMap.getString("targetSystem");
BaseProvider provider = (BaseProvider) DubboUtil.refer(applicationContext, system);
provider.execute(new Parameter(targetObject, targetMethod));
}
double time = (System.currentTimeMillis() - start) / 1000.0;
logger.info("定时任务[{}.{}]用时:{}s", targetObject, targetMethod, time);
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
示例15: executeInternal
import org.quartz.JobDataMap; //导入依赖的package包/类
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
JobKey key = jobExecutionContext.getJobDetail().getKey();
System.out.println("Cron Job started with key :" + key.getName() + ", Group :"+key.getGroup() + " , Thread Name :"+Thread.currentThread().getName() + " ,Time now :"+new Date());
System.out.println("======================================");
System.out.println("Accessing annotation example: "+jobService.getAllJobs());
List<Map<String, Object>> list = jobService.getAllJobs();
System.out.println("Job list :"+list);
System.out.println("======================================");
//*********** For retrieving stored key-value pairs ***********/
JobDataMap dataMap = jobExecutionContext.getMergedJobDataMap();
String myValue = dataMap.getString("myKey");
System.out.println("Value:" + myValue);
System.out.println("Thread: "+ Thread.currentThread().getName() +" stopped.");
}