protected void postPaymentEvent(final BusInternalEvent ev, final UUID accountId, final InternalCallContext context) { if (ev == null) { return; } try { eventBus.post(ev); } catch (EventBusException e) { log.error("Failed to post Payment event event for account {} ", accountId, e); } }
private void postBusEvent(final BusEvent event) { try { // TODO STEPH Ideally we would like to post from transaction when we inserted the new blocking state, but new state would have to be recalculated from transaction which is // difficult without the help of BlockingChecker -- which itself relies on dao. Other alternative is duplicating the logic, or refactoring the DAO to export higher level api. eventBus.post(event); } catch (EventBusException e) { log.warn("Failed to post event {}", e); } }
private void postEvent(final BusInternalEvent event, final UUID accountId, final InternalCallContext context) { try { eventBus.post(event); } catch (EventBusException e) { log.error(String.format("Failed to post event %s for account %s", event.getBusEventType(), accountId), e); } }
@Subscribe public void handleAllInternalKillbillEvents(final BusInternalEvent event) { final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "BeatrixListener", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); try { final BusEvent externalEvent = computeExtBusEventEntryFromBusInternalEvent(event, internalContext); if (externalEvent != null) { externalBus.post(externalEvent); } } catch (EventBusException e) { log.warn("Failed to dispatch external bus events", e); } }
private void notifyBusOfInvoiceAdjustment(final UUID invoiceId, final UUID accountId, final InternalCallContext context) { try { eventBus.post(new DefaultInvoiceAdjustmentEvent(invoiceId, accountId, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken())); } catch (EventBusException e) { log.warn("Failed to post adjustment event for invoice " + invoiceId, e); } } }
public void testDifferentType() { try { final MyEventHandler handler = new MyEventHandler(1, 0); eventBus.register(handler); for (int i = 0; i < 5; i++) { eventBus.post(new MyOtherEvent("my-other-event", (double) i, "MY_EVENT_TYPE", 1L, 2L, UUID.randomUUID())); } eventBus.post(new MyEvent("my-event", 11l, "MY_EVENT_TYPE", 1L, 2L, UUID.randomUUID())); final boolean completed = handler.waitForCompletion(10000); Assert.assertEquals(completed, true); } catch (Exception e) { Assert.fail("", e); } } }
public void testSimple() { try { final int nbEvents = 5; final MyEventHandler handler = new MyEventHandler(nbEvents, 0); eventBus.register(handler); for (int i = 0; i < nbEvents; i++) { eventBus.post(new MyEvent("my-event", (long) i, "MY_EVENT_TYPE", 1L, 2L, UUID.randomUUID())); } final boolean completed = handler.waitForCompletion(10000); Assert.assertEquals(completed, true); } catch (Exception e) { Assert.fail("", e); } }
public void testSimpleWithExceptionAndRetrySuccess() { try { final MyEventHandler handler = new MyEventHandler(1, 1); eventBus.register(handler); eventBus.post(new MyEvent("my-event", 1L, "MY_EVENT_TYPE", 1L, 2L, UUID.randomUUID())); final boolean completed = handler.waitForCompletion(5000); Assert.assertEquals(completed, true); } catch (Exception ignored) { } }
public void testSimpleWithExceptionAndFail() { try { final MyEventHandler handler = new MyEventHandler(1, 4); eventBus.register(handler); eventBus.post(new MyEvent("my-event", 1L, "MY_EVENT_TYPE", 1L, 2L, UUID.randomUUID())); final boolean completed = handler.waitForCompletion(5000); Assert.assertEquals(completed, false); } catch (Exception ignored) { } }
public void clear(final Account account, final OverdueState previousOverdueState, final OverdueState clearState, final InternalCallContext context) throws OverdueException { log.debug("OverdueStateApplicator:clear : time = " + clock.getUTCNow() + ", previousState = " + previousOverdueState.getName()); storeNewState(account, clearState, context); clearFutureNotification(account, context); try { avoid_extra_credit_by_toggling_AUTO_INVOICE_OFF(account, previousOverdueState, clearState, context); } catch (OverdueApiException e) { throw new OverdueException(e); } try { bus.post(createOverdueEvent(account, previousOverdueState.getName(), clearState.getName(), isBlockBillingTransition(previousOverdueState, clearState), isUnblockBillingTransition(previousOverdueState, clearState), context)); } catch (Exception e) { log.error("Error posting overdue change event to bus", e); } }
private void processBlockingNotification(final BlockingTransitionNotificationKey key, final InternalCallContext internalCallContext) { // Check if the blocking state has been deleted since if (blockingStateDao.getById(key.getBlockingStateId(), internalCallContext) == null) { log.debug("BlockingState {} has been deleted, not sending a bus event", key.getBlockingStateId()); return; } final BusEvent event = new DefaultBlockingTransitionInternalEvent(key.getBlockableId(), key.getBlockingType(), key.isTransitionedToBlockedBilling(), key.isTransitionedToUnblockedBilling(), key.isTransitionedToBlockedEntitlement(), key.isTransitionToUnblockedEntitlement(), internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId(), internalCallContext.getUserToken()); try { eventBus.post(event); } catch (EventBusException e) { log.warn("Failed to post event {}", e); } }
bus.post(createOverdueEvent(account, previousOverdueState.getName(), nextOverdueState.getName(), isBlockBillingTransition(previousOverdueState, nextOverdueState), isUnblockBillingTransition(previousOverdueState, nextOverdueState), context)); } catch (Exception e) {
@Override public void createInvoice(final InvoiceModelDao invoice, final List<InvoiceItemModelDao> invoiceItems, final List<InvoicePaymentModelDao> invoicePayments, final boolean isRealInvoice, final Map<UUID, DateTime> callbackDateTimePerSubscriptions, final InternalCallContext context) { synchronized (monitor) { invoices.put(invoice.getId(), invoice); for (final InvoiceItemModelDao invoiceItemModelDao : invoiceItems) { items.put(invoiceItemModelDao.getId(), invoiceItemModelDao); } for (final InvoicePaymentModelDao paymentModelDao : invoicePayments) { payments.put(paymentModelDao.getId(), paymentModelDao); } accountRecordIds.put(invoice.getAccountId(), context.getAccountRecordId()); } try { eventBus.post(new DefaultInvoiceCreationEvent(invoice.getId(), invoice.getAccountId(), InvoiceModelDaoHelper.getBalance(invoice), invoice.getCurrency(), context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken())); } catch (PersistentBus.EventBusException ex) { throw new RuntimeException(ex); } }
eventBus.post(event); } catch (EventBusException e) { log.warn("Failed to post bus event for resume operation on bundle " + bundleId);
eventBus.post(event); } catch (EventBusException e) { log.warn("Failed to post bus event for pause operation on bundle " + bundleId);
public Invoice createTestInvoice(final Account account, final LocalDate targetDate, final Currency currency, final CallContext context, final InvoiceItem... items) throws EventBusException, InvoiceApiException { final Invoice invoice = new MockInvoice(account.getId(), clock.getUTCToday(), targetDate, currency); for (final InvoiceItem item : items) { if (item instanceof MockRecurringInvoiceItem) { final MockRecurringInvoiceItem recurringInvoiceItem = (MockRecurringInvoiceItem) item; invoice.addInvoiceItem(new MockRecurringInvoiceItem(invoice.getId(), account.getId(), recurringInvoiceItem.getBundleId(), recurringInvoiceItem.getSubscriptionId(), recurringInvoiceItem.getPlanName(), recurringInvoiceItem.getPhaseName(), recurringInvoiceItem.getStartDate(), recurringInvoiceItem.getEndDate(), recurringInvoiceItem.getAmount(), recurringInvoiceItem.getRate(), recurringInvoiceItem.getCurrency())); } } Mockito.when(invoiceApi.getInvoiceById(Mockito.eq(invoice.getId()), Mockito.<InternalTenantContext>any())).thenReturn(invoice); final InvoiceCreationInternalEvent event = new MockInvoiceCreationEvent(invoice.getId(), invoice.getAccountId(), invoice.getBalance(), invoice.getCurrency(), invoice.getInvoiceDate(), 1L, 2L, null); eventBus.post(event); return invoice; }