@Override public void start() { overdueQueue.startQueue(); }
@Override public void stop() throws NoSuchNotificationQueue { if (nextBillingQueue != null) { nextBillingQueue.stopQueue(); notificationQueueService.deleteNotificationQueue(nextBillingQueue.getServiceName(), nextBillingQueue.getQueueName()); } }
protected NotificationQueueHandler getHandlerForActiveQueue(final String compositeName) { synchronized (queues) { final NotificationQueue queue = queues.get(compositeName); if (queue == null || !queue.isStarted()) { return null; } return queue.getHandler(); } }
queue.startQueue(); queue.stopQueue(); log.info("GOT SIZE " + Collections2.filter(expectedNotifications.values(), new Predicate<Boolean>() { @Override
@Override public Object inTransaction(final DummySqlTest transactional, final TransactionStatus status) throws Exception { queue.recordFutureNotificationFromTransaction(transactional, readyTime, eventJson, TOKEN_ID, SEARCH_KEY_1, SEARCH_KEY_2); log.info("Posted key: " + eventJson); return null; } });
private boolean scheduleRetryInternal(final UUID paymentId, final DateTime timeOfRetry, final EntitySqlDaoWrapperFactory<EntitySqlDao> transactionalDao) { final InternalCallContext context = createCallContextFromPaymentId(paymentId); try { final NotificationQueue retryQueue = notificationQueueService.getNotificationQueue(DefaultPaymentService.SERVICE_NAME, getQueueName()); final NotificationEvent key = new PaymentRetryNotificationKey(paymentId); if (retryQueue != null) { if (transactionalDao == null) { retryQueue.recordFutureNotification(timeOfRetry, key, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } else { retryQueue.recordFutureNotificationFromTransaction(transactionalDao.getSqlDao(), timeOfRetry, key, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } } } catch (NoSuchNotificationQueue e) { log.error(String.format("Failed to retrieve notification queue %s:%s", DefaultPaymentService.SERVICE_NAME, getQueueName())); return false; } catch (IOException e) { log.error(String.format("Failed to serialize notificationQueue event for paymentId %s", paymentId)); return false; } return true; }
private void recordFutureNotification(final DateTime effectiveDate, final NotificationEvent notificationEvent, final InternalCallContext context) { try { final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, DefaultEntitlementService.NOTIFICATION_QUEUE_NAME); subscriptionEventQueue.recordFutureNotification(effectiveDate, notificationEvent, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } catch (NoSuchNotificationQueue e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }
private List<NotificationEventModelDao> getReadyNotifications() { final List<NotificationEventModelDao> input = dao.getReadyEntries(); final List<NotificationEventModelDao> claimedNotifications = new ArrayList<NotificationEventModelDao>(); for (final NotificationEventModelDao cur : input) { // Skip non active queues... final NotificationQueue queue = queues.get(cur.getQueueName()); if (queue == null || !queue.isStarted()) { continue; } claimedNotifications.add(cur); } return claimedNotifications; }
queue.startQueue(); queue.stopQueue(); Assert.assertTrue(expectedNotifications.get(eventJson));
@Override public Object inTransaction(final DummySqlTest transactional, final TransactionStatus status) throws Exception { queue.recordFutureNotificationFromTransaction(transactional, now.plus((currentIteration + 1) * nextReadyTimeIncrementMs), eventJson, TOKEN_ID, SEARCH_KEY_1, SEARCH_KEY_2); return null; } });
private void recordFutureNotification(final DateTime effectiveDate, final NotificationEvent notificationEvent, final InternalCallContext context) { try { final NotificationQueue subscriptionEventQueue = notificationQueueService.getNotificationQueue(DefaultEntitlementService.ENTITLEMENT_SERVICE_NAME, DefaultEntitlementService.NOTIFICATION_QUEUE_NAME); subscriptionEventQueue.recordFutureNotification(effectiveDate, notificationEvent, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } catch (NoSuchNotificationQueue e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public void stopQueue() { if (config.isProcessingOff() || !isStarted()) { return; } // If there are no active queues left, stop the processing for the queues // (This is not intended to be robust against a system that would stop and start queues at the same time, // for a a normal shutdown sequence) // int nbQueueStarted = 0; synchronized (queues) { for (final NotificationQueue cur : queues.values()) { if (cur.isStarted()) { nbQueueStarted++; } } } if (nbQueueStarted == 0) { super.stopQueue(); } }
@Override public void stop() { if (overdueQueue != null) { overdueQueue.stopQueue(); try { notificationQueueService.deleteNotificationQueue(overdueQueue.getServiceName(), overdueQueue.getQueueName()); } catch (NoSuchNotificationQueue e) { log.error("Error deleting a queue by its own name - this should never happen", e); } } }
queueFred.startQueue(); queueFred.stopQueue(); Assert.assertTrue(expectedNotificationsFred.get(eventJsonFred)); Assert.assertFalse(expectedNotificationsFred.get(eventJsonBarney));
@Override public Object inTransaction(final DummySqlTest transactional, final TransactionStatus status) throws Exception { queueFred.recordFutureNotificationFromTransaction(transactional, readyTime, eventJsonFred, TOKEN_ID, SEARCH_KEY_1, SEARCH_KEY_2); log.info("posted key: " + eventJsonFred.toString()); queueBarney.recordFutureNotificationFromTransaction(transactional, readyTime, eventJsonBarney, TOKEN_ID, SEARCH_KEY_1, SEARCH_KEY_2); log.info("posted key: " + eventJsonBarney.toString()); return null; } });
@Override public void start() { retryQueue.startQueue(); }
@Override public void insertNextBillingNotification(final UUID accountId, final UUID subscriptionId, final DateTime futureNotificationTime, final UUID userToken) { final InternalCallContext context = createCallContext(accountId, userToken); final NotificationQueue nextBillingQueue; try { nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME, DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE); log.info("Queuing next billing date notification at {} for subscriptionId {}", futureNotificationTime.toString(), subscriptionId.toString()); nextBillingQueue.recordFutureNotification(futureNotificationTime, new NextBillingDateNotificationKey(subscriptionId), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } catch (NoSuchNotificationQueue e) { log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).", e); } catch (IOException e) { log.error("Failed to serialize notificationKey for subscriptionId {}", subscriptionId); } }
@Override @BeforeMethod(groups = "slow") public void beforeMethod() throws Exception { super.beforeMethod(); entitySqlDaoTransactionalJdbiWrapper = new EntitySqlDaoTransactionalJdbiWrapper(dbi, clock, cacheControllerDispatcher, nonEntityDao); overdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE); Assert.assertTrue(overdueQueue.isStarted()); testReferenceTime = clock.getUTCNow(); }
@Override public void stop() throws NoSuchNotificationQueue { if (retryQueue != null) { retryQueue.stopQueue(); notificationQueueService.deleteNotificationQueue(retryQueue.getServiceName(), retryQueue.getQueueName()); } }
@Override public Void inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception { // Check if we already have notifications for that key final Class<T> clazz = (Class<T>) notificationKey.getClass(); final Collection<NotificationEventWithMetadata<T>> futureNotifications = getFutureNotificationsForAccountInTransaction(entitySqlDaoWrapperFactory, overdueQueue, accountId, clazz, context); boolean shouldInsertNewNotification = cleanupFutureNotificationsFormTransaction(entitySqlDaoWrapperFactory, futureNotifications, futureNotificationTime, overdueQueue); if (shouldInsertNewNotification) { log.debug("Queuing overdue check notification. Account id: {}, timestamp: {}", accountId.toString(), futureNotificationTime.toString()); overdueQueue.recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory.getSqlDao(), futureNotificationTime, notificationKey, context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); } else { log.debug("Skipping queuing overdue check notification. Account id: {}, timestamp: {}", accountId.toString(), futureNotificationTime.toString()); } return null; } });