@@ -0,0 +1,2268 @@
+package com.example.sling.metrics.listener;%0A%0Aimport com.codahale.metrics.Histogram;%0Aimport com.example.sling.metrics.service.MetricService;%0Aimport org.apache.commons.lang.StringUtils;%0Aimport org.apache.felix.scr.annotations.Component;%0Aimport org.apache.felix.scr.annotations.Property;%0Aimport org.apache.felix.scr.annotations.Reference;%0Aimport org.apache.felix.scr.annotations.Service;%0Aimport org.apache.sling.event.EventUtil;%0Aimport org.apache.sling.event.jobs.JobProcessor;%0Aimport org.apache.sling.event.jobs.JobUtil;%0Aimport org.osgi.service.event.Event;%0Aimport org.osgi.service.event.EventHandler;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.util.SortedMap;%0A%0A@Component(metatype = false, immediate = true)%0A@Service(value = EventHandler.class)%0A@Property(name=%22event.topics%22, value = %22metric/histograms%22, propertyPrivate = true)%0Apublic class HistogramEventListener implements EventHandler, JobProcessor %7B%0A%0A    private static final Logger LOG = LoggerFactory.getLogger(HistogramEventListener.class);%0A%0A    @Reference%0A    protected MetricService metricService;%0A%0A    @Override%0A    public void handleEvent(final Event event) %7B%0A        if (EventUtil.isLocal(event)) %7B%0A            JobUtil.processJob(event, this);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public boolean process(final Event event) %7B%0A        final String name = (String) event.getProperty(MetricEvent.NAME);%0A        final String value = (String) event.getProperty(MetricEvent.VALUE);%0A%0A        if(metricService.isEnabled()) %7B%0A            if(StringUtils.isNotEmpty(name)) %7B%0A                final SortedMap%3CString,Histogram%3E histograms = metricService.getRegistry().getHistograms();%0A                Histogram histogram = histograms.get(name);%0A                if(histogram == null) %7B%0A                    histogram = metricService.getRegistry().histogram(name);%0A                %7D%0A                try %7B%0A                    histogram.update(Long.parseLong(value));%0A                %7D catch(NumberFormatException e) %7B%0A                    LOG.error(%22Received histogram metric event without value: %5B%7B%7D%5D - %7B%7D%22, e.getMessage(), e);%0A                %7D%0A            %7D else %7B%0A                LOG.warn(%22Received metric event without name: %5B%7B%7D%5D%22, event);%0A            %7D%0A        %7D%0A%0A        return true;%0A    %7D%0A%0A%7D%0A

add HistogramEventListener