private void handleNotificationWithMetrics(final NotificationQueueHandler handler, final NotificationEventModelDao notification, final NotificationEvent key) throws NotificationQueueException { // Create specific metric name because: // - ':' is not allowed for metric name // - name would be too long (e.g entitlement-service:subscription-events-process-time -> ent-subscription-events-process-time) // final String[] parts = notification.getQueueName().split(":"); final String metricName = new StringBuilder(parts[0].substring(0, 3)) .append("-") .append(parts[1]) .append("-process-time").toString(); final Histogram perQueueHistogramProcessingTime; synchronized (perQueueProcessingTime) { if (!perQueueProcessingTime.containsKey(notification.getQueueName())) { perQueueProcessingTime.put(notification.getQueueName(), metricRegistry.histogram(MetricRegistry.name(NotificationQueueDispatcher.class, metricName))); } perQueueHistogramProcessingTime = perQueueProcessingTime.get(notification.getQueueName()); } final DateTime beforeProcessing = clock.getUTCNow(); try { handler.handleReadyNotification(key, notification.getEffectiveDate(), notification.getFutureUserToken(), notification.getSearchKey1(), notification.getSearchKey2()); } catch (RuntimeException e) { throw new NotificationQueueException(e); } finally { // Unclear if those stats should include failures final DateTime afterProcessing = clock.getUTCNow(); perQueueHistogramProcessingTime.update(afterProcessing.getMillis() - beforeProcessing.getMillis()); processedNotificationsSinceStart.inc(); } }
private int doProcessEventsForQueue(final MockNotificationQueue queue) { int result = 0; final List<NotificationEventModelDao> processedNotifications = new ArrayList<NotificationEventModelDao>(); final List<NotificationEventModelDao> oldNotifications = new ArrayList<NotificationEventModelDao>(); List<NotificationEventModelDao> readyNotifications = queue.getReadyNotifications(); for (final NotificationEventModelDao cur : readyNotifications) { final NotificationEvent key = deserializeEvent(cur.getClassName(), objectMapper, cur.getEventJson()); queue.getHandler().handleReadyNotification(key, cur.getEffectiveDate(), cur.getFutureUserToken(), cur.getSearchKey1(), cur.getSearchKey2()); final NotificationEventModelDao processedNotification = new NotificationEventModelDao(cur.getRecordId(), Hostname.get(), Hostname.get(), clock.getUTCNow(), getClock().getUTCNow().plus(CLAIM_TIME_MS), PersistentQueueEntryLifecycleState.PROCESSED, cur.getClassName(), cur.getEventJson(), 0L, cur.getUserToken(), cur.getSearchKey1(), cur.getSearchKey2(), cur.getFutureUserToken(), cur.getEffectiveDate(), "MockQueue"); oldNotifications.add(cur); processedNotifications.add(processedNotification); result++; } queue.markProcessedNotifications(oldNotifications, processedNotifications); return result; }