static String asMetricsSuffix()

in src/main/java/org/apache/sling/commons/scheduler/impl/MetricsHelper.java [66:107]


    static String asMetricsSuffix(String jobName) {
        if (jobName == null || jobName.length() == 0) {
            return UNKNOWN_JOBNAME_SUFFIX;
        }
        // translate org.apache.jackrabbit.oak.jcr.observation.ChangeProcessor$4
        // into oajojo.ChangeProcessor

        // this used to do go via the job class, ie
        // the job must be a Runnable or a scheduler Job,
        // so getClass().getName() should return an actual package
        // name.classname[$anonymous/inner]
        // however, the same job class could in theory be used for
        // multiple schedules - so the really unique thing with schedules
        // is its name
        // so we're also using the name here - but we're shortening it.

        final StringBuffer shortified = new StringBuffer();
        // cut off dollar
        final int dollarPos = jobName.indexOf("$");
        if (dollarPos != -1) {
            jobName = jobName.substring(0, dollarPos);
        }
        final String[] split = jobName.split("\\.");
        if (split.length <= 2) {
            // then don't shorten at all
            shortified.append(jobName);
        } else {
            for (int i = 0; i < split.length; i++) {
                final String s = split[i];
                if (i < split.length - 2) {
                    // shorten
                    if (s.length() > 0) {
                        shortified.append(s.substring(0, 1));
                    }
                } else {
                    // except for the last 2
                    shortified.append(".").append(s);
                }
            }
        }
        return shortified.toString();
    }