private void createTemporaryGauge()

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


    private void createTemporaryGauge(final JobExecutionContext jobExecutionContext) {
        final JobDataMap data = jobExecutionContext.getJobDetail().getJobDataMap();
        final String jobName = data.getString(QuartzScheduler.DATA_MAP_NAME);
        final String gaugeName = QuartzScheduler.METRICS_NAME_OLDEST_RUNNING_JOB_MILLIS + ".slow."
                + MetricsHelper.asMetricsSuffix(jobName);
        TemporaryGauge tempGauge;
        synchronized (temporaryGauges) {
            tempGauge = temporaryGauges.get(gaugeName);
            if (tempGauge != null) {
                // then there is already a gauge for this job execution
                // check if it has the same jobExecutionContext
                if (tempGauge.jobExecutionContext == jobExecutionContext) {
                    // then all is fine, skip
                    return;
                }
                // otherwise the current temporary gauge is an old one, that job
                // execution has already finished
                // so we should unregister that one and create a new one

                // the unregister we want to do outside of this sync block
                // though
            }
        }
        if (tempGauge != null) {
            logger.debug("createTemporaryGauge: unregistering temporary gauge for slow job : " + gaugeName);
            tempGauge.unregister();
        }
        logger.debug("createTemporaryGauge: creating temporary gauge for slow job : " + gaugeName);
        synchronized (this.temporaryGauges) {
            temporaryGauges.put(gaugeName, new TemporaryGauge(jobExecutionContext, gaugeName));
        }
    }