当前位置: 首页>>代码示例>>Java>>正文


Java JobDataMap类代码示例

本文整理汇总了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;
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:27,代码来源:SchedulerUtil.java

示例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.");  
    }  
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:23,代码来源:QuartzSessionValidationJob.java

示例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);
    }
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:25,代码来源:ErrorHandlingJob.java

示例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;
}
 
开发者ID:quartzweb,项目名称:quartz-web,代码行数:19,代码来源:QuartzManager.java

示例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;
}
 
开发者ID:quartzweb,项目名称:quartz-web,代码行数:19,代码来源:QuartzManager.java

示例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()));
	}
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:33,代码来源:ScheduleTask.java

示例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);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:37,代码来源:QuartzScheduler.java

示例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);
        }
    }
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:26,代码来源:MessageListener.java

示例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();
        }
    }
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:17,代码来源:ConsumerLoop.java

示例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();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:SharedFolderPatch.java

示例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)
    );
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:18,代码来源:HistorianEntryMapper.java

示例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());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:JobExecutionContextImpl.java

示例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;
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:10,代码来源:ErrorHandlingJob.java

示例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);
	}
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:24,代码来源:BaseJob.java

示例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.");
}
 
开发者ID:javabypatel,项目名称:spring-boot-quartz-demo,代码行数:19,代码来源:CronJob.java


注:本文中的org.quartz.JobDataMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。