本文整理匯總了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.");
}