/** * Creates a new instance of processor. * @param injectionManager injection manager. * @param monitoringEventListener Monitoring event listener. */ MonitoringStatisticsProcessor( final InjectionManager injectionManager, final MonitoringEventListener monitoringEventListener) { this.monitoringEventListener = monitoringEventListener; final ResourceModel resourceModel = injectionManager.getInstance(ExtendedResourceContext.class).getResourceModel(); this.statisticsBuilder = new MonitoringStatisticsImpl.Builder(resourceModel); this.statisticsCallbackList = injectionManager.getAllInstances(MonitoringStatisticsListener.class); this.scheduler = injectionManager.getInstance(ScheduledExecutorService.class, BackgroundSchedulerLiteral.INSTANCE); this.interval = PropertiesHelper.getValue(injectionManager.getInstance(Configuration.class).getProperties(), ServerProperties.MONITORING_STATISTICS_REFRESH_INTERVAL, DEFAULT_INTERVAL, Collections.<String, String>emptyMap()); }
private void processRequestItems() { final Queue<MonitoringEventListener.RequestStats> requestQueuedItems = monitoringEventListener.getRequestQueuedItems(); final FloodingLogger floodingLogger = new FloodingLogger(requestQueuedItems); while (!requestQueuedItems.isEmpty()) { floodingLogger.conditionallyLogFlooding(); final MonitoringEventListener.RequestStats event = requestQueuedItems.remove(); final MonitoringEventListener.TimeStats requestStats = event.getRequestStats(); statisticsBuilder.addRequestExecution(requestStats.getStartTime(), requestStats.getDuration()); final MonitoringEventListener.MethodStats methodStat = event.getMethodStats(); if (methodStat != null) { final ResourceMethod method = methodStat.getMethod(); statisticsBuilder.addExecution(event.getRequestUri(), method, methodStat.getStartTime(), methodStat.getDuration(), requestStats.getStartTime(), requestStats.getDuration()); } } }
private void processResponseCodeEvents() { final Queue<Integer> responseEvents = monitoringEventListener.getResponseStatuses(); final FloodingLogger floodingLogger = new FloodingLogger(responseEvents); while (!responseEvents.isEmpty()) { floodingLogger.conditionallyLogFlooding(); final Integer code = responseEvents.remove(); statisticsBuilder.addResponseCode(code); } }
/** * Add execution of a resource method. * * @param uri String uri which was executed. * @param resourceMethod Resource method. * @param methodTime Time spent on execution of resource method itself (Unix timestamp format). * @param methodDuration Time of execution of the resource method. * @param requestTime Time of whole request processing (from receiving the request until writing the response). (Unix * timestamp format) * @param requestDuration Time when the request matching to the executed resource method has been received by Jersey. */ void addExecution(final String uri, final ResourceMethod resourceMethod, final long methodTime, final long methodDuration, final long requestTime, final long requestDuration) { // Uri resource stats. ResourceStatisticsImpl.Builder uriStatsBuilder = uriStatistics.get(uri); if (uriStatsBuilder == null) { uriStatsBuilder = new ResourceStatisticsImpl.Builder(resourceMethod.getParent(), methodFactory); uriStatistics.put(uri, uriStatsBuilder); } uriStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Class resource stats. final ResourceStatisticsImpl.Builder classStatsBuilder = getOrCreateResourceBuilder(resourceMethod); classStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Resource method stats. methodFactory.getOrCreate(resourceMethod) .addResourceMethodExecution(methodTime, methodDuration, requestTime, requestDuration); }
/** * Add execution of a resource method. * * @param uri String uri which was executed. * @param resourceMethod Resource method. * @param methodTime Time spent on execution of resource method itself (Unix timestamp format). * @param methodDuration Time of execution of the resource method. * @param requestTime Time of whole request processing (from receiving the request until writing the response). (Unix * timestamp format) * @param requestDuration Time when the request matching to the executed resource method has been received by Jersey. */ void addExecution(final String uri, final ResourceMethod resourceMethod, final long methodTime, final long methodDuration, final long requestTime, final long requestDuration) { // Uri resource stats. ResourceStatisticsImpl.Builder uriStatsBuilder = uriStatistics.get(uri); if (uriStatsBuilder == null) { uriStatsBuilder = new ResourceStatisticsImpl.Builder(resourceMethod.getParent(), methodFactory); uriStatistics.put(uri, uriStatsBuilder); } uriStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Class resource stats. final ResourceStatisticsImpl.Builder classStatsBuilder = getOrCreateResourceBuilder(resourceMethod); classStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Resource method stats. methodFactory.getOrCreate(resourceMethod) .addResourceMethodExecution(methodTime, methodDuration, requestTime, requestDuration); }
/** * Add execution of a resource method. * * @param uri String uri which was executed. * @param resourceMethod Resource method. * @param methodTime Time spent on execution of resource method itself (Unix timestamp format). * @param methodDuration Time of execution of the resource method. * @param requestTime Time of whole request processing (from receiving the request until writing the response). (Unix * timestamp format) * @param requestDuration Time when the request matching to the executed resource method has been received by Jersey. */ void addExecution(final String uri, final ResourceMethod resourceMethod, final long methodTime, final long methodDuration, final long requestTime, final long requestDuration) { // Uri resource stats. ResourceStatisticsImpl.Builder uriStatsBuilder = uriStatistics.get(uri); if (uriStatsBuilder == null) { uriStatsBuilder = new ResourceStatisticsImpl.Builder(resourceMethod.getParent(), methodFactory); uriStatistics.put(uri, uriStatsBuilder); } uriStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Class resource stats. final ResourceStatisticsImpl.Builder classStatsBuilder = getOrCreateResourceBuilder(resourceMethod); classStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Resource method stats. methodFactory.getOrCreate(resourceMethod) .addResourceMethodExecution(methodTime, methodDuration, requestTime, requestDuration); }
/** * Add execution of a resource method. * * @param uri String uri which was executed. * @param resourceMethod Resource method. * @param methodTime Time spent on execution of resource method itself (Unix timestamp format). * @param methodDuration Time of execution of the resource method. * @param requestTime Time of whole request processing (from receiving the request until writing the response). (Unix * timestamp format) * @param requestDuration Time when the request matching to the executed resource method has been received by Jersey. */ void addExecution(final String uri, final ResourceMethod resourceMethod, final long methodTime, final long methodDuration, final long requestTime, final long requestDuration) { // Uri resource stats. ResourceStatisticsImpl.Builder uriStatsBuilder = uriStatistics.get(uri); if (uriStatsBuilder == null) { uriStatsBuilder = new ResourceStatisticsImpl.Builder(resourceMethod.getParent(), methodFactory); uriStatistics.put(uri, uriStatsBuilder); } uriStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Class resource stats. final ResourceStatisticsImpl.Builder classStatsBuilder = getOrCreateResourceBuilder(resourceMethod); classStatsBuilder.addExecution(resourceMethod, methodTime, methodDuration, requestTime, requestDuration); // Resource method stats. methodFactory.getOrCreate(resourceMethod) .addResourceMethodExecution(methodTime, methodDuration, requestTime, requestDuration); }
@Override public void run() { try { processRequestItems(); processResponseCodeEvents(); processExceptionMapperEvents(); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); // rethrowing exception stops further task execution throw new ProcessingException(LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); } final MonitoringStatisticsImpl immutableStats = statisticsBuilder.build(); final Iterator<MonitoringStatisticsListener> iterator = statisticsCallbackList.iterator(); while (iterator.hasNext() && !Thread.currentThread().isInterrupted()) { final MonitoringStatisticsListener listener = iterator.next(); try { listener.onStatistics(immutableStats); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_LISTENER(listener.getClass()), t); iterator.remove(); } } } }, 0, interval, TimeUnit.MILLISECONDS);
@Override public void run() { try { processRequestItems(); processResponseCodeEvents(); processExceptionMapperEvents(); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); // rethrowing exception stops further task execution throw new ProcessingException(LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); } final MonitoringStatisticsImpl immutableStats = statisticsBuilder.build(); final Iterator<MonitoringStatisticsListener> iterator = statisticsCallbackList.iterator(); while (iterator.hasNext() && !Thread.currentThread().isInterrupted()) { final MonitoringStatisticsListener listener = iterator.next(); try { listener.onStatistics(immutableStats); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_LISTENER(listener.getClass()), t); iterator.remove(); } } } }, 0, interval, TimeUnit.MILLISECONDS);
@Override public void run() { try { processRequestItems(); processResponseCodeEvents(); processExceptionMapperEvents(); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); // rethrowing exception stops further task execution throw new ProcessingException(LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); } final MonitoringStatisticsImpl immutableStats = statisticsBuilder.build(); final Iterator<MonitoringStatisticsListener> iterator = statisticsCallbackList.iterator(); while (iterator.hasNext() && !Thread.currentThread().isInterrupted()) { final MonitoringStatisticsListener listener = iterator.next(); try { listener.onStatistics(immutableStats); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_LISTENER(listener.getClass()), t); iterator.remove(); } } } }, 0, interval, TimeUnit.MILLISECONDS);
@Override public void run() { try { processRequestItems(); processResponseCodeEvents(); processExceptionMapperEvents(); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); // rethrowing exception stops further task execution throw new ProcessingException(LocalizationMessages.ERROR_MONITORING_STATISTICS_GENERATION(), t); } final MonitoringStatisticsImpl immutableStats = statisticsBuilder.build(); final Iterator<MonitoringStatisticsListener> iterator = statisticsCallbackList.iterator(); while (iterator.hasNext() && !Thread.currentThread().isInterrupted()) { final MonitoringStatisticsListener listener = iterator.next(); try { listener.onStatistics(immutableStats); } catch (final Throwable t) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_MONITORING_STATISTICS_LISTENER(listener.getClass()), t); iterator.remove(); } } } }, 0, interval, TimeUnit.MILLISECONDS);
private void processRequestItems() { final Queue<MonitoringEventListener.RequestStats> requestQueuedItems = monitoringEventListener.getRequestQueuedItems(); final FloodingLogger floodingLogger = new FloodingLogger(requestQueuedItems); while (!requestQueuedItems.isEmpty()) { floodingLogger.conditionallyLogFlooding(); final MonitoringEventListener.RequestStats event = requestQueuedItems.remove(); final MonitoringEventListener.TimeStats requestStats = event.getRequestStats(); statisticsBuilder.addRequestExecution(requestStats.getStartTime(), requestStats.getDuration()); final MonitoringEventListener.MethodStats methodStat = event.getMethodStats(); if (methodStat != null) { final ResourceMethod method = methodStat.getMethod(); statisticsBuilder.addExecution(event.getRequestUri(), method, methodStat.getStartTime(), methodStat.getDuration(), requestStats.getStartTime(), requestStats.getDuration()); } } }
private void processRequestItems() { final Queue<MonitoringEventListener.RequestStats> requestQueuedItems = monitoringEventListener.getRequestQueuedItems(); final FloodingLogger floodingLogger = new FloodingLogger(requestQueuedItems); while (!requestQueuedItems.isEmpty()) { floodingLogger.conditionallyLogFlooding(); final MonitoringEventListener.RequestStats event = requestQueuedItems.remove(); final MonitoringEventListener.TimeStats requestStats = event.getRequestStats(); statisticsBuilder.addRequestExecution(requestStats.getStartTime(), requestStats.getDuration()); final MonitoringEventListener.MethodStats methodStat = event.getMethodStats(); if (methodStat != null) { final ResourceMethod method = methodStat.getMethod(); statisticsBuilder.addExecution(event.getRequestUri(), method, methodStat.getStartTime(), methodStat.getDuration(), requestStats.getStartTime(), requestStats.getDuration()); } } }
/** * Creates a new instance of processor. * @param injectionManager injection manager. * @param monitoringEventListener Monitoring event listener. */ MonitoringStatisticsProcessor( final InjectionManager injectionManager, final MonitoringEventListener monitoringEventListener) { this.monitoringEventListener = monitoringEventListener; final ResourceModel resourceModel = injectionManager.getInstance(ExtendedResourceContext.class).getResourceModel(); this.statisticsBuilder = new MonitoringStatisticsImpl.Builder(resourceModel); this.statisticsCallbackList = injectionManager.getAllInstances(MonitoringStatisticsListener.class); this.scheduler = injectionManager.getInstance(ScheduledExecutorService.class, BackgroundSchedulerLiteral.INSTANCE); this.interval = PropertiesHelper.getValue(injectionManager.getInstance(Configuration.class).getProperties(), ServerProperties.MONITORING_STATISTICS_REFRESH_INTERVAL, DEFAULT_INTERVAL, Collections.<String, String>emptyMap()); }
private void processRequestItems() { final Queue<MonitoringEventListener.RequestStats> requestQueuedItems = monitoringEventListener.getRequestQueuedItems(); final FloodingLogger floodingLogger = new FloodingLogger(requestQueuedItems); while (!requestQueuedItems.isEmpty()) { floodingLogger.conditionallyLogFlooding(); final MonitoringEventListener.RequestStats event = requestQueuedItems.remove(); final MonitoringEventListener.TimeStats requestStats = event.getRequestStats(); statisticsBuilder.addRequestExecution(requestStats.getStartTime(), requestStats.getDuration()); final MonitoringEventListener.MethodStats methodStat = event.getMethodStats(); if (methodStat != null) { final ResourceMethod method = methodStat.getMethod(); statisticsBuilder.addExecution(event.getRequestUri(), method, methodStat.getStartTime(), methodStat.getDuration(), requestStats.getStartTime(), requestStats.getDuration()); } } }
/** * Creates a new instance of processor. * @param serviceLocator Service locator. * @param monitoringEventListener Monitoring event listener. */ MonitoringStatisticsProcessor(final ServiceLocator serviceLocator, final MonitoringEventListener monitoringEventListener) { this.monitoringEventListener = monitoringEventListener; final ResourceModel resourceModel = serviceLocator.getService(ExtendedResourceContext.class).getResourceModel(); this.statisticsBuilder = new MonitoringStatisticsImpl.Builder(resourceModel); this.statisticsCallbackList = serviceLocator.getAllServices(MonitoringStatisticsListener.class); this.scheduler = serviceLocator.getService(ScheduledExecutorService.class, BackgroundSchedulerLiteral.INSTANCE); this.interval = PropertiesHelper.getValue(serviceLocator.getService(Configuration.class).getProperties(), ServerProperties.MONITORING_STATISTICS_REFRESH_INTERVAL, DEFAULT_INTERVAL, Collections.<String, String>emptyMap()); }
private void processRequestItems() { final Queue<MonitoringEventListener.RequestStats> requestQueuedItems = monitoringEventListener.getRequestQueuedItems(); final FloodingLogger floodingLogger = new FloodingLogger(requestQueuedItems); while (!requestQueuedItems.isEmpty()) { floodingLogger.conditionallyLogFlooding(); final MonitoringEventListener.RequestStats event = requestQueuedItems.remove(); final MonitoringEventListener.TimeStats requestStats = event.getRequestStats(); statisticsBuilder.addRequestExecution(requestStats.getStartTime(), requestStats.getDuration()); final MonitoringEventListener.MethodStats methodStat = event.getMethodStats(); if (methodStat != null) { final ResourceMethod method = methodStat.getMethod(); statisticsBuilder.addExecution(event.getRequestUri(), method, methodStat.getStartTime(), methodStat.getDuration(), requestStats.getStartTime(), requestStats.getDuration()); } } }
/** * Creates a new instance of processor. * @param serviceLocator Service locator. * @param monitoringEventListener Monitoring event listener. */ MonitoringStatisticsProcessor(final ServiceLocator serviceLocator, final MonitoringEventListener monitoringEventListener) { this.monitoringEventListener = monitoringEventListener; final ResourceModel resourceModel = serviceLocator.getService(ExtendedResourceContext.class).getResourceModel(); this.statisticsBuilder = new MonitoringStatisticsImpl.Builder(resourceModel); this.statisticsCallbackList = serviceLocator.getAllServices(MonitoringStatisticsListener.class); this.scheduler = serviceLocator.getService(ScheduledExecutorService.class, BackgroundSchedulerLiteral.INSTANCE); this.interval = PropertiesHelper.getValue(serviceLocator.getService(Configuration.class).getProperties(), ServerProperties.MONITORING_STATISTICS_REFRESH_INTERVAL, DEFAULT_INTERVAL, Collections.<String, String>emptyMap()); }
/** * Creates a new instance of processor. * @param serviceLocator Service locator. * @param monitoringEventListener Monitoring event listener. */ MonitoringStatisticsProcessor(final ServiceLocator serviceLocator, final MonitoringEventListener monitoringEventListener) { this.monitoringEventListener = monitoringEventListener; final ResourceModel resourceModel = serviceLocator.getService(ExtendedResourceContext.class).getResourceModel(); this.statisticsBuilder = new MonitoringStatisticsImpl.Builder(resourceModel); this.statisticsCallbackList = serviceLocator.getAllServices(MonitoringStatisticsListener.class); this.scheduler = serviceLocator.getService(ScheduledExecutorService.class, BackgroundSchedulerLiteral.INSTANCE); this.interval = PropertiesHelper.getValue(serviceLocator.getService(Configuration.class).getProperties(), ServerProperties.MONITORING_STATISTICS_REFRESH_INTERVAL, DEFAULT_INTERVAL, Collections.<String, String>emptyMap()); }
/** * Create a new builder and initialize it from resource model. * * @param resourceModel resource model. */ Builder(final ResourceModel resourceModel) { this(); for (final Resource resource : resourceModel.getRootResources()) { processResource(resource, ""); for (final Resource child : resource.getChildResources()) { final String path = resource.getPath(); processResource(child, path.startsWith("/") ? path : "/" + path); } } }