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


Java JobExecutionContext.getMergedJobDataMap方法代码示例

本文整理汇总了Java中org.quartz.JobExecutionContext.getMergedJobDataMap方法的典型用法代码示例。如果您正苦于以下问题:Java JobExecutionContext.getMergedJobDataMap方法的具体用法?Java JobExecutionContext.getMergedJobDataMap怎么用?Java JobExecutionContext.getMergedJobDataMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.quartz.JobExecutionContext的用法示例。


在下文中一共展示了JobExecutionContext.getMergedJobDataMap方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
public void execute(JobExecutionContext context)
    throws JobExecutionException {

    JobDataMap data = context.getMergedJobDataMap();
    
    String command = data.getString(PROP_COMMAND);

    String parameters = data.getString(PROP_PARAMETERS);

    if (parameters == null) {
        parameters = "";
    }

    boolean wait = true;
    if(data.containsKey(PROP_WAIT_FOR_PROCESS)) {
        wait = data.getBooleanValue(PROP_WAIT_FOR_PROCESS);
    }
    boolean consumeStreams = false;
    if(data.containsKey(PROP_CONSUME_STREAMS)) {
        consumeStreams = data.getBooleanValue(PROP_CONSUME_STREAMS);
    }
        
    Integer exitCode = this.runNativeCommand(command, parameters, wait, consumeStreams);
    context.setResult(exitCode);
    
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:27,代码来源:NativeJob.java

示例2: executeInternal

import org.quartz.JobExecutionContext; //导入方法依赖的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

示例3: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap dataMap = context.getMergedJobDataMap();
    String keys = dataMap.getString("keys");
    if (keys == null) {
        throw new JobExecutionException("Data map key 'keys' is missing");
    }

    Set<Long> checked = new LinkedHashSet<>();

    for (String key : keys.split(";")) {
        Long id = gameQueryService.getSteamId64(key).exceptionally(t -> {
            log.warn("Could not get profile ID from key {}", key, t);
            return null;
        }).join();
        if (id != null) {
            report(id, getPlayerProfile(id));
            checked.add(id);
        }
    }

    // clean up removed ids
    metricRegistry.removeMatching((name, metric) -> name.startsWith("steam.profile") && !checked.contains(extractId(name)));
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:25,代码来源:SteamProfilePoller.java

示例4: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
/**
 * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
 */
public void execute(JobExecutionContext context)
    throws JobExecutionException {

    JobDataMap data = context.getMergedJobDataMap();

    MailInfo mailInfo = populateMailInfo(data, createMailInfo());
    
    getLog().info("Sending message " + mailInfo);

    try {
        MimeMessage mimeMessage = prepareMimeMessage(mailInfo);
        
        Transport.send(mimeMessage);
    } catch (MessagingException e) {
        throw new JobExecutionException("Unable to send mail: " + mailInfo,
                e, false);
    }

}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:23,代码来源:SendMailJob.java

示例5: execute

import org.quartz.JobExecutionContext; //导入方法依赖的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

示例6: convert

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
public CronyxExecutionContext convert(JobExecutionContext context) {
    String contextKey = context.get(CONTEXT_KEY).toString();
    JobDefinition jobDef = (JobDefinition) context.getMergedJobDataMap().get(JOB_DEFINITION);
    TriggerDefinition triggerDef = quartzToCronyxSelector.convert(context.getTrigger());
    Instant scheduledTime = context.getScheduledFireTime().toInstant();
    Instant actualTime = context.getFireTime().toInstant();
    Map<String, Object> jobData = new HashMap<>(context.getMergedJobDataMap());
    Throwable jobException = (Throwable) context.get(JOB_EXCEPTION);
    Object jobResult = context.getResult();
    int attemptNumber = context.getRefireCount() + 1;
    return new CronyxExecutionContext(contextKey, jobDef, triggerDef, attemptNumber, scheduledTime,
            actualTime, jobData, jobResult, jobException, FIRED);
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:14,代码来源:JobExecutionContextToFiringContext.java

示例7: execute

import org.quartz.JobExecutionContext; //导入方法依赖的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

示例8: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    Date startDate = new Date();
    LOG.debug("methodInvokeJob start : " + DateUtils.formart(startDate));
    long startTime = startDate.getTime();

    JobDataMap jobDataMap = context.getMergedJobDataMap();
    //Object methodInvokerObj = jobDataMap.get("methodInvoker");
    Object jobClassObj = jobDataMap.get("jobClass");
    Object constructorArgumentsObj = jobDataMap.get("constructorArguments");
    Object jobClassMethodNameObj = jobDataMap.get("jobClassMethodName");
    Object jobClassMethodArgsObj = jobDataMap.get("jobClassMethodArgs");
    try {
        String jobClass = (String) jobClassObj;
        Object[] constructorArguments = (Object[]) constructorArgumentsObj;
        String jobClassMethodName = (String) jobClassMethodNameObj;
        Object[] jobClassMethodArgs = (Object[]) jobClassMethodArgsObj;
        Object jobBean;

        LOG.debug("methodInvokeJob jobClass:" + jobClass);
        LOG.debug("methodInvokeJob jobClassMethodName:" + jobClassMethodName);

        QuartzBeanManagerFacade quartzBeanManagerFacade = QuartzBeanManagerFacade.getInstance();

        if (constructorArguments != null && constructorArguments.length > 0) {
            jobBean = quartzBeanManagerFacade.getBean(jobClass, constructorArguments);
        } else {
            jobBean = quartzBeanManagerFacade.getBean(jobClass);
        }

        MethodInvoker methodInvoker = new MethodInvoker();
        methodInvoker.setTargetMethod(jobClassMethodName);
        methodInvoker.setArguments(jobClassMethodArgs);

        methodInvoker.setTargetObject(jobBean);

        boolean prepared = methodInvoker.isPrepared();
        if (!prepared) {
            methodInvoker.prepare();
        }
        Object result = methodInvoker.invoke();
        context.setResult(result);
        Date endDate = new Date();
        long endTime = endDate.getTime();
        LOG.debug("methodInvokeJob end : " + DateUtils.formart(endDate) + "," + (endTime - startTime));

    } catch (Exception e) {
        LOG.error("MethodInvokeJob exception message:" + e.getMessage(), e);
        e.printStackTrace();
        throw new JobExecutionException(e);
    }
}
 
开发者ID:quartzweb,项目名称:quartz-web,代码行数:53,代码来源:MethodInvokeJob.java

示例9: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    try {
        JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
        message = (Message)jobDataMap.get(JobConstants.JOB_PARAM_MESSAGE);
        MessageProcessor.processMessage(message);
    } catch( Exception e) {
        throw new JobExecutionException(e);
    }
}
 
开发者ID:sjsucohort6,项目名称:amigo-chatbot,代码行数:11,代码来源:ChatbotMessageProcessorJob.java

示例10: executeInternal

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
	JobKey key = jobExecutionContext.getJobDetail().getKey();
	System.out.println("Simple Job started with key :" + key.getName() + ", Group :"+key.getGroup() + " , Thread Name :"+Thread.currentThread().getName());
	
	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);

	//*********** For retrieving stored object, It will try to deserialize the bytes Object. ***********/
	/*
	SchedulerContext schedulerContext = null;
       try {
           schedulerContext = jobExecutionContext.getScheduler().getContext();
       } catch (SchedulerException e1) {
           e1.printStackTrace();
       }
       YourClass yourClassObject = (YourClass) schedulerContext.get("storedObjectKey");
	 */

	while(toStopFlag){
		try {
			System.out.println("Test Job Running... Thread Name :"+Thread.currentThread().getName());
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	System.out.println("Thread: "+ Thread.currentThread().getName() +" stopped.");
}
 
开发者ID:javabypatel,项目名称:spring-boot-quartz-demo,代码行数:38,代码来源:SimpleJob.java

示例11: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap jobDataMap = context.getMergedJobDataMap();
    String botId = jobDataMap.getString("bot");
    String channelId = jobDataMap.getString("channel");
    String content = jobDataMap.getString("content");

    if (botId != null && channelId != null && content != null) {
        Optional<IDiscordClient> client = clientRegistry.getClients().entrySet().stream()
            .filter(entry -> botId.equals(entry.getKey().getId())
                || botId.equals(entry.getKey().getName())
                || (entry.getValue().isReady() && botId.equals(entry.getValue().getOurUser().getStringID())))
            .map(Map.Entry::getValue)
            .findAny();
        if (client.isPresent()) {
            IChannel channel = client.get().getChannelByID(snowflake(channelId));
            if (channel != null) {
                sendMessage(channel, content);
            } else {
                throw new JobExecutionException("Channel " + channelId + " is not known by the bot");
            }
        } else {
            throw new JobExecutionException("No bot exists with identifier: " + botId);
        }
    } else {
        throw new JobExecutionException("Job requires bot, channel and content parameters");
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:29,代码来源:DiscordMessenger.java

示例12: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap dataMap = context.getMergedJobDataMap();
    StreamerService.Config config = new StreamerService.Config();
    config.setEventsPerSecond(Math.max(0.1, doubleOrDefault(dataMap, "events_per_second", EVENTS_PER_SECOND)));
    config.setExpireMinutes(Math.max(1, longOrDefault(dataMap, "expire_minutes", EXPIRE_MINUTES)));
    config.setGracePeriod(Math.max(0, longOrDefault(dataMap, "grace_period", GRACE_PERIOD)));
    streamerService.publishStreams(config);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:10,代码来源:StreamPoller.java

示例13: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
	log.info("Job triggered to send emails");
	JobDataMap map = context.getMergedJobDataMap();
	sendEmail(map);
	log.info("Job completed");
}
 
开发者ID:juliuskrah,项目名称:quartz-manager,代码行数:8,代码来源:EmailJob.java

示例14: execute

import org.quartz.JobExecutionContext; //导入方法依赖的package包/类
/** 
 * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
 */
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
    SchedulerContext schedCtxt = null;
    try {
        schedCtxt = context.getScheduler().getContext();
    } catch (SchedulerException e) {
        throw new JobExecutionException("Error obtaining scheduler context.", e, false);
    }
    
    String fileName = mergedJobDataMap.getString(FILE_NAME);
    String listenerName = mergedJobDataMap.getString(FILE_SCAN_LISTENER_NAME);
    
    if(fileName == null) {
        throw new JobExecutionException("Required parameter '" + 
                FILE_NAME + "' not found in merged JobDataMap");
    }
    if(listenerName == null) {
        throw new JobExecutionException("Required parameter '" + 
                FILE_SCAN_LISTENER_NAME + "' not found in merged JobDataMap");
    }

    FileScanListener listener = (FileScanListener)schedCtxt.get(listenerName);
    
    if(listener == null) {
        throw new JobExecutionException("FileScanListener named '" + 
                listenerName + "' not found in SchedulerContext");
    }
    
    long lastDate = -1;
    if(mergedJobDataMap.containsKey(LAST_MODIFIED_TIME)) {
        lastDate = mergedJobDataMap.getLong(LAST_MODIFIED_TIME);
    }
    
    long newDate = getLastModifiedDate(fileName);

    if(newDate < 0) {
        log.warn("File '"+fileName+"' does not exist.");
        return;
    }
    
    if(lastDate > 0 && (newDate != lastDate)) {
        // notify call back...
        log.info("File '"+fileName+"' updated, notifying listener.");
        listener.fileUpdated(fileName); 
    } else if (log.isDebugEnabled()) {
        log.debug("File '"+fileName+"' unchanged.");
    }
    
    // It is the JobDataMap on the JobDetail which is actually stateful
    context.getJobDetail().getJobDataMap().put(LAST_MODIFIED_TIME, newDate);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:55,代码来源:FileScanJob.java


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