Java Code Examples for org.quartz.JobDataMap#getLong()

The following examples show how to use org.quartz.JobDataMap#getLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MachineMonitorJob.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public void action(JobExecutionContext context) {
    try {
        JobDataMap dataMap = context.getMergedJobDataMap();
        String ip = dataMap.getString(ConstUtils.HOST_KEY);
        long hostId = dataMap.getLong(ConstUtils.HOST_ID_KEY);

        SchedulerContext schedulerContext = context.getScheduler().getContext();
        ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
        MachineCenter machineCenter = applicationContext.getBean("machineCenter", MachineCenter.class);
        machineCenter.asyncMonitorMachineStats(hostId, ip);
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 2
Source File: FileScanJob.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
/** 
 * @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);
}
 
Example 3
Source File: SchedulerNotificationManager.java    From SO with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //
        long time = System.currentTimeMillis();
        SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String timeStr = timeFormat.format(new Date(time));

        String profileId = context.getJobDetail().getKey().getName();
        String groupName = context.getJobDetail().getKey().getGroup();

        log.debug("### Checking Time by schedule({}) :{}",profileId, timeStr);
        
        SimpleTrigger  st = (SimpleTrigger ) context.getTrigger();
        int checkRate = (int)st.getRepeatInterval()/1000;

        //ServiceProcessor 의 ProfileInjector 에 주기에 따라 profile Id 전송
//        ProfileInjector profileInJector = new ProfileIntjector();
//        profileInJector.sendProfile(profileId);

        //JobDataMap dataMap = context.getMergedJobDataMap();
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        //JobDataMap dataMap = context.getTrigger().getJobDataMap();

        ProfileForDB profileForDB = (ProfileForDB)dataMap.get("profile");
        
        //log.debug("profileForDB.getPeriod()={}", profileForDB.getPeriod());

        int period = profileForDB.getPeriod();
        //int checkRate 	= dataMap.getInt("checkRate");
     	boolean happened 	= dataMap.getBoolean("happened"); //초기값=미발생
     	long lastTimeExecutedCm = dataMap.getLong("lastTimeExecutedCm"); //마지막 CM 발생 일시
        
		//context.getJobDetail().getJobDataMap().put("lastTimeExecutedCm", lastTimeExecutedCm);
     	
        long currentTime = (new Date().getTime())/1000; //to sec
        boolean result;

        log.debug("## past={}, {} - {}", (currentTime - lastTimeExecutedCm), currentTime, lastTimeExecutedCm);
        
		if (happened) { //이미 CM을 처리했으면
			if (lastTimeExecutedCm==0 ||  (lastTimeExecutedCm + period) <= currentTime){ //시간이 경과 했으면
				result = checkCm(profileId, CHECK_AND_RUN); //CM조사해서 발생했으면 실행후 발생(실행) 여부 리턴
				lastTimeExecutedCm = currentTime; //마지막 실행시간 저장
				dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm);
			} else {
				result = checkCm(profileId, CHECK_ONLY); //CM조사해서발생여부만 리턴
			}
			if (result == false) {//발생하지 않으면
				happened = false; // 실행 여부 초기화
				dataMap.put("happened", happened);
			}
			
		} else { //CM이 실행하지 않았으면
			result = checkCm(profileId, CHECK_AND_RUN); //CM실행후 발생(실행) 여부 리턴
			if (result == true) {//처리되었으면
				happened = true; // 실행했음
				lastTimeExecutedCm = currentTime;

				dataMap.put("happened", happened);
				dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm);
			}
		}

		dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm);
     	dataMap.put("profile", profileForDB);

     	SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
     	String ctime = sdf.format(new Date());
     	log.debug("{} - result={}, happened={}, lastTimeExecutedCm={}\n", ctime, result, happened, lastTimeExecutedCm);
     	
    }
 
Example 4
Source File: SchedulerNotificationManager.java    From SO with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //
        long time = System.currentTimeMillis();
        SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String timeStr = timeFormat.format(new Date(time));

        String profileId = context.getJobDetail().getKey().getName();
        String groupName = context.getJobDetail().getKey().getGroup();

        log.debug("### Checking Time by schedule({}) :{}",profileId, timeStr);
        
        SimpleTrigger  st = (SimpleTrigger ) context.getTrigger();
        int checkRate = (int)st.getRepeatInterval()/1000;

        //ServiceProcessor 의 ProfileInjector 에 주기에 따라 profile Id 전송
//        ProfileInjector profileInJector = new ProfileIntjector();
//        profileInJector.sendProfile(profileId);

        //JobDataMap dataMap = context.getMergedJobDataMap();
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        //JobDataMap dataMap = context.getTrigger().getJobDataMap();

        ProfileForDB profileForDB = (ProfileForDB)dataMap.get("profile");
        
        //log.debug("profileForDB.getPeriod()={}", profileForDB.getPeriod());

        int period = profileForDB.getPeriod();
        //int checkRate 	= dataMap.getInt("checkRate");
     	boolean happened 	= dataMap.getBoolean("happened"); //초기값=미발생
     	long lastTimeExecutedCm = dataMap.getLong("lastTimeExecutedCm"); //마지막 CM 발생 일시
        
		//context.getJobDetail().getJobDataMap().put("lastTimeExecutedCm", lastTimeExecutedCm);
     	
        long currentTime = (new Date().getTime())/1000; //to sec
        boolean result;

        log.debug("## past={}, {} - {}", (currentTime - lastTimeExecutedCm), currentTime, lastTimeExecutedCm);
        
		if (happened) { //이미 CM을 처리했으면
			if (lastTimeExecutedCm==0 ||  (lastTimeExecutedCm + period) <= currentTime){ //시간이 경과 했으면
				result = checkCm(profileId, CHECK_AND_RUN); //CM조사해서 발생했으면 실행후 발생(실행) 여부 리턴
				lastTimeExecutedCm = currentTime; //마지막 실행시간 저장
				dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm);
			} else {
				result = checkCm(profileId, CHECK_ONLY); //CM조사해서발생여부만 리턴
			}
			if (result == false) {//발생하지 않으면
				happened = false; // 실행 여부 초기화
				dataMap.put("happened", happened);
			}
			
		} else { //CM이 실행하지 않았으면
			result = checkCm(profileId, CHECK_AND_RUN); //CM실행후 발생(실행) 여부 리턴
			if (result == true) {//처리되었으면
				happened = true; // 실행했음
				lastTimeExecutedCm = currentTime;

				dataMap.put("happened", happened);
				dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm);
			}
		}

		dataMap.put("lastTimeExecutedCm", lastTimeExecutedCm);
     	dataMap.put("profile", profileForDB);

     	SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
     	String ctime = sdf.format(new Date());
     	log.debug("{} - result={}, happened={}, lastTimeExecutedCm={}\n", ctime, result, happened, lastTimeExecutedCm);
     	
    }