@Override public void broadcast(final String serviceName, final String type, final String event, final DateTime createdDate, final String createdBy, final boolean localNodeOnly) { // If localNodeOnly, this is not really a broadcast api anymore, but we still rely on that broadcast bus event to notify the local node if (localNodeOnly) { final BroadcastInternalEvent busEvent = new DefaultBroadcastInternalEvent(serviceName, type, event); try { eventBus.post(busEvent); } catch (final EventBusException e) { logger.warn("Failed to post event {}", event, e); } } else { final BroadcastModelDao modelDao = new BroadcastModelDao(serviceName, type, event, createdDate, createdBy); dao.create(modelDao); } } }
@Override public void run() { if (parent.isStopped) { return; } final List<BroadcastModelDao> entries = broadcastDao.getLatestEntriesFrom(parent.getLatestRecordIdProcessed().get()); for (BroadcastModelDao cur : entries) { if (parent.isStopped()) { return; } final BroadcastInternalEvent event = new DefaultBroadcastInternalEvent(cur.getServiceName(), cur.getType(), cur.getEvent()); try { eventBus.post(event); } catch (final EventBusException e) { logger.warn("Failed to post event {}", event, e); } finally { parent.setLatestRecordIdProcessed(cur.getRecordId()); } } } }
public void clear(final DateTime effectiveDate, final ImmutableAccountData account, final OverdueState previousOverdueState, final OverdueState clearState, final InternalCallContext context) throws OverdueException { log.debug("OverdueStateApplicator:clear : time = " + effectiveDate + ", previousState = " + previousOverdueState.getName()); storeNewState(effectiveDate, account, clearState, context); clearFutureNotification(account, context); try { avoid_extra_credit_by_toggling_AUTO_INVOICE_OFF(account, previousOverdueState, clearState, context); } catch (final OverdueApiException e) { throw new OverdueException(e); } final OverdueChangeInternalEvent event; try { event = createOverdueEvent(account, previousOverdueState.getName(), clearState.getName(), isBlockBillingTransition(previousOverdueState, clearState), isUnblockBillingTransition(previousOverdueState, clearState), context); } catch (final BlockingApiException e) { log.warn("Failed to create OverdueChangeInternalEvent for accountId='{}'", account.getId(), e); return; } try { bus.post(event); } catch (final Exception e) { log.warn("Failed to post event {}", event, e); } }
bus.post(event); } catch (final Exception e) { log.warn("Failed to post event {}", event, e);
@Override public void create(final AccountModelDao account, final InternalCallContext context) throws AccountApiException { super.create(account, context); try { final Long accountRecordId = getRecordId(account.getId(), context); final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId(); eventBus.post(new DefaultAccountCreationEvent(new DefaultAccountData(account), account.getId(), accountRecordId, tenantRecordId, UUID.randomUUID())); } catch (final EventBusException ex) { Assert.fail(ex.toString()); } }
private void notifyBusOfEffectiveImmediateChange(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) { try { final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId); final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); eventBus.post(busEvent); } catch (final EventBusException e) { log.warn("Failed to post effective event for subscription " + subscription.getId(), e); } }
context.getAccountRecordId(), context.getTenantRecordId()); eventBus.post(busEvent);
@Override public void update(final AccountModelDao account, final boolean treatNullValueAsReset, final InternalCallContext context) { super.update(account, context); final AccountModelDao currentAccount = getById(account.getId(), context); final Long accountRecordId = getRecordId(account.getId(), context); final long tenantRecordId = context == null ? InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID : context.getTenantRecordId(); final AccountChangeInternalEvent changeEvent = new DefaultAccountChangeEvent(account.getId(), currentAccount, account, accountRecordId, tenantRecordId, UUID.randomUUID(), clock.getUTCNow()); if (changeEvent.hasChanges()) { try { eventBus.post(changeEvent); } catch (final EventBusException ex) { Assert.fail(ex.toString()); } } }
parent.getEventBus().post(event); } catch (final EventBusException e) { logger.warn("Failed to post event {}", event, e);
private void postEvent(final BusInternalEvent event) { try { eventBus.post(event); } catch (final EventBusException e) { log.warn("Failed to post event {}", event, e); } }
private void notifyBusOfInvoiceAdjustment(final UUID invoiceId, final UUID accountId, final InternalCallContext context) { final DefaultInvoiceAdjustmentEvent event = new DefaultInvoiceAdjustmentEvent(invoiceId, accountId, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()); try { eventBus.post(event); } catch (final EventBusException e) { log.warn("Failed to post event {}", event, e); } }
@Test(groups = "fast") public void testInvalidInternalEvent() throws Exception { BusInternalEvent event = mock(BusInternalEvent.class); when(event.getBusEventType()).thenReturn(BusInternalEventType.BUNDLE_REPAIR); beatrixListener.handleAllInternalKillbillEvents(event); verify(externalBus, never()).post(any(BusEvent.class)); }
@Test(groups = "fast", expectedExceptions = RuntimeException.class) public void testEventBusException() throws Exception { AccountCreationInternalEvent event = mock(AccountCreationInternalEvent.class); provideCommonBusEventInfo(event); when(event.getBusEventType()).thenReturn(BusInternalEventType.ACCOUNT_CREATE); when(event.getId()).thenReturn(ACCOUNT_ID); doThrow(EventBusException.class).when(externalBus).post(any(BusEvent.class)); beatrixListener.handleAllInternalKillbillEvents(event); }
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 (final Exception e) { Assert.fail("", e); } } }
public void processSubscriptionForInvoiceNotification(final UUID subscriptionId, final LocalDate targetDate, final InternalCallContext context) throws InvoiceApiException { final Invoice dryRunInvoice = processSubscriptionInternal(subscriptionId, targetDate, true, false, context); if (dryRunInvoice != null && dryRunInvoice.getBalance().compareTo(BigDecimal.ZERO) > 0) { final InvoiceNotificationInternalEvent event = new DefaultInvoiceNotificationInternalEvent(dryRunInvoice.getAccountId(), dryRunInvoice.getBalance(), dryRunInvoice.getCurrency(), context.toUTCDateTime(targetDate), context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()); try { eventBus.post(event); } catch (EventBusException e) { log.warn("Failed to post event {}", event, e); } } }
@Test(groups = "fast") public void testAccountCreate() throws Exception { AccountCreationInternalEvent event = mock(AccountCreationInternalEvent.class); provideCommonBusEventInfo(event); when(event.getBusEventType()).thenReturn(BusInternalEventType.ACCOUNT_CREATE); when(event.getId()).thenReturn(ACCOUNT_ID); ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class); beatrixListener.handleAllInternalKillbillEvents(event); verify(externalBus, times(1)).post(eventCaptor.capture()); DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent)eventCaptor.getValue(); assertEquals(postedEvent.getObjectId(), ACCOUNT_ID); assertEquals(postedEvent.getObjectType(), ObjectType.ACCOUNT); assertEquals(postedEvent.getEventType(), ExtBusEventType.ACCOUNT_CREATION); assertNull(postedEvent.getMetaData()); assertCommonFieldsWithAccountId(postedEvent); }
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 (final Exception e) { Assert.fail("", e); } }
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 (final Exception ignored) { } }
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 (final Exception ignored) { } }
private void notifyBusOfEffectiveImmediateChange(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) { try { final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId); final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId()); eventBus.post(busEvent); } catch (final EventBusException e) { log.warn("Failed to post effective event for subscription " + subscription.getId(), e); } }