private Date getOldestRunningJobDate()

in src/main/java/org/apache/sling/commons/scheduler/impl/GaugesSupport.java [274:325]


    private Date getOldestRunningJobDate(final ConfigHolder configHolder,
            final SchedulerProxy schedulerProxy,
            final String filterNameOrNull) {
        if (schedulerProxy == null) {
            return null;
        }
        final org.quartz.Scheduler scheduler = schedulerProxy.getScheduler();
        if (scheduler == null) {
            return null;
        }
        List<JobExecutionContext> currentlyExecutingJobs = null;
        try {
            currentlyExecutingJobs = scheduler.getCurrentlyExecutingJobs();
        } catch (SchedulerException e) {
            logger.warn("getValue: could not get currently executing jobs due to Exception: " + e, e);
        }
        if (currentlyExecutingJobs == null)
            return null;
        Date oldestDate = null;
        for (JobExecutionContext jobExecutionContext : currentlyExecutingJobs) {
            if (jobExecutionContext == null) {
                continue;
            }
            if (filterNameOrNull != null) {
                // apply the filter
                JobDetail jobDetail = jobExecutionContext.getJobDetail();
                JobDataMap map = null;
                if (jobDetail != null) {
                    map = jobDetail.getJobDataMap();
                }
                String filterName = null;
                if (map != null) {
                    filterName = MetricsHelper.deriveFilterName(configHolder, map.get(QuartzScheduler.DATA_MAP_OBJECT));
                }
                if (filterName == null || !filterNameOrNull.equals(filterName)) {
                    // filter doens't match
                    continue;
                }
                // filter matches, go ahead and get the fire time
            }
            final Date fireTime = jobExecutionContext.getFireTime();
            final long elapsedMillis = System.currentTimeMillis() - fireTime.getTime();
            final long slowThresholdMillis = configHolder.slowThresholdMillis();
            if (slowThresholdMillis > 0 && elapsedMillis > slowThresholdMillis) {
                // then create a gauge for this slow job in case there isn't one
                // yet
                createTemporaryGauge(jobExecutionContext);
            }
            oldestDate = olderOf(oldestDate, fireTime);
        }
        return oldestDate;
    }