本文整理匯總了Java中org.quartz.Scheduler.getContext方法的典型用法代碼示例。如果您正苦於以下問題:Java Scheduler.getContext方法的具體用法?Java Scheduler.getContext怎麽用?Java Scheduler.getContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.quartz.Scheduler
的用法示例。
在下文中一共展示了Scheduler.getContext方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAllSchedulerInfo
import org.quartz.Scheduler; //導入方法依賴的package包/類
/**
* 獲取Scheduler基本信息
*
* @return 返回基本信息的Map
* @throws SchedulerException 異常
*/
public static List<SchedulerInfo> getAllSchedulerInfo() throws SchedulerException {
List<SchedulerInfo> schedulerInfos = new ArrayList<SchedulerInfo>();
Collection<Scheduler> allSchedulers = quartzManager.getSchedulers();
for (Scheduler scheduler : allSchedulers) {
// 獲取Job數量
List<JobDetail> allJobsOfScheduler = QuartzUtils.getAllJobsOfScheduler(scheduler);
int triggerCount = 0;
// 錯誤Trigger數量
int triggerErrorCount = 0;
// 堵塞Trigger數量
int triggerBlockedCount = 0;
// 暫停Trigger數量
int triggerPausedCount = 0;
for (JobDetail jobDetail : allJobsOfScheduler) {
List<? extends Trigger> triggersOfJob = QuartzUtils.getTriggersOfJob(jobDetail, scheduler);
for (Trigger trigger : triggersOfJob) {
triggerCount++;
boolean isError = QuartzUtils.isTriggerError(trigger, scheduler);
if (isError) {
triggerErrorCount++;
}
boolean isBlocked = QuartzUtils.isTriggerBlocked(trigger, scheduler);
if (isBlocked) {
triggerBlockedCount++;
}
boolean isPaused = QuartzUtils.isTriggerPaused(trigger, scheduler);
if (isPaused) {
triggerPausedCount++;
}
}
}
// schedulerConext中參數Map
List<Map<String, Object>> schedulerContextMapList = new ArrayList<Map<String, Object>>();
SchedulerContext context = scheduler.getContext();
Set<String> contextKeySet = context.keySet();
for (String contextKey : contextKeySet) {
Map<String, Object> contextMap = new LinkedHashMap<String, Object>();
Object contextKeyObj = context.get(contextKey);
// 是否支持json轉換
boolean support = JSONWriter.support(contextKeyObj);
if (support) {
contextMap.put("key", contextKey);
contextMap.put("value", contextKeyObj);
} else {
contextMap.put("key", contextKey);
contextMap.put("value", contextKeyObj.toString());
}
schedulerContextMapList.add(contextMap);
}
SchedulerInfo schedulerInfo = new SchedulerInfo();
schedulerInfo.setSchedulerName(scheduler.getSchedulerName());
schedulerInfo.setShutdown(scheduler.isShutdown());
schedulerInfo.setStarted(scheduler.isStarted());
schedulerInfo.setInStandbyMode(scheduler.isInStandbyMode());
// 設置job數量
schedulerInfo.setJobCount(allJobsOfScheduler.size());
// 設置數量
schedulerInfo.setTriggerCount(triggerCount);
schedulerInfo.setTriggerErrorCount(triggerErrorCount);
schedulerInfo.setTriggerBlockedCount(triggerBlockedCount);
schedulerInfo.setTriggerPausedCount(triggerPausedCount);
// 設置schedulerContext
schedulerInfo.setSchedulerContext(schedulerContextMapList);
schedulerInfos.add(schedulerInfo);
}
return schedulerInfos;
}