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();
}
};
}
Aggregations