Search in sources :

Example 1 with TimeSeriesRecorder

use of org.apache.jackrabbit.stats.TimeSeriesRecorder in project jackrabbit by apache.

the class ListenerTracker method getTrackedListener.

public EventListener getTrackedListener() {
    return new EventListener() {

        @Override
        public void onEvent(EventIterator events) {
            eventDeliveries.incrementAndGet();
            final long start = nanoTime();
            try {
                beforeEventDelivery();
                listener.onEvent(new EventIteratorAdapter(events) {

                    long t0 = start;

                    private void recordTime(TimeSeriesRecorder recorder) {
                        recorder.getCounter().addAndGet(-(t0 - (t0 = nanoTime())));
                    }

                    @Override
                    public Object next() {
                        recordTime(eventConsumerTime);
                        eventsDelivered.incrementAndGet();
                        eventCount.getCounter().incrementAndGet();
                        Object object = super.next();
                        if (object instanceof JackrabbitEvent) {
                            object = new JackrabbitEventTracker(ListenerTracker.this, (JackrabbitEvent) object);
                        } else if (object instanceof Event) {
                            object = new EventTracker(ListenerTracker.this, (Event) object);
                        }
                        recordTime(eventProducerTime);
                        return object;
                    }

                    @Override
                    public boolean hasNext() {
                        recordTime(eventConsumerTime);
                        boolean result = super.hasNext();
                        recordTime(eventProducerTime);
                        return result;
                    }
                });
            } finally {
                afterEventDelivery();
                eventDeliveryTime.addAndGet(nanoTime() - start);
            }
        }

        @Override
        public String toString() {
            return ListenerTracker.this.toString();
        }
    };
}
Also used : EventIteratorAdapter(org.apache.jackrabbit.commons.iterator.EventIteratorAdapter) JackrabbitEvent(org.apache.jackrabbit.api.observation.JackrabbitEvent) Event(javax.jcr.observation.Event) JackrabbitEvent(org.apache.jackrabbit.api.observation.JackrabbitEvent) TimeSeriesRecorder(org.apache.jackrabbit.stats.TimeSeriesRecorder) EventListener(javax.jcr.observation.EventListener) EventIterator(javax.jcr.observation.EventIterator)

Aggregations

Event (javax.jcr.observation.Event)1 EventIterator (javax.jcr.observation.EventIterator)1 EventListener (javax.jcr.observation.EventListener)1 JackrabbitEvent (org.apache.jackrabbit.api.observation.JackrabbitEvent)1 EventIteratorAdapter (org.apache.jackrabbit.commons.iterator.EventIteratorAdapter)1 TimeSeriesRecorder (org.apache.jackrabbit.stats.TimeSeriesRecorder)1