Search in sources :

Example 1 with BroadcastModelDao

use of org.killbill.billing.util.broadcast.dao.BroadcastModelDao in project killbill by killbill.

the class DefaultBroadcastService method initialize.

@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
public void initialize() {
    final BroadcastModelDao entry = broadcastDao.getLatestEntry();
    this.latestRecordIdProcessed = entry != null ? new AtomicLong(entry.getRecordId()) : new AtomicLong(0L);
    this.broadcastExecutor = Executors.newSingleThreadScheduledExecutor("BroadcastExecutor");
    this.isStopped = false;
}
Also used : BroadcastModelDao(org.killbill.billing.util.broadcast.dao.BroadcastModelDao) AtomicLong(java.util.concurrent.atomic.AtomicLong) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Example 2 with BroadcastModelDao

use of org.killbill.billing.util.broadcast.dao.BroadcastModelDao in project killbill by killbill.

the class DefaultBroadcastApi method broadcast.

@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);
    }
}
Also used : BroadcastModelDao(org.killbill.billing.util.broadcast.dao.BroadcastModelDao) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) BroadcastInternalEvent(org.killbill.billing.events.BroadcastInternalEvent)

Example 3 with BroadcastModelDao

use of org.killbill.billing.util.broadcast.dao.BroadcastModelDao in project killbill by killbill.

the class TestBroadcastService method testBasic.

@Test(groups = "slow")
public void testBasic() {
    final String eventJson = "\"{\"pluginName\":\"foo\",\"pluginVersion\":\"1.2.3\",\"properties\":[{\"key\":\"something\",\"value\":\"nothing\"}]}\"";
    eventsListener.pushExpectedEvent(NextEvent.BROADCAST_SERVICE);
    broadcastDao.create(new BroadcastModelDao("svc", "type", eventJson, clock.getUTCNow(), "tester"));
    assertListenerStatus();
}
Also used : BroadcastModelDao(org.killbill.billing.util.broadcast.dao.BroadcastModelDao) Test(org.testng.annotations.Test)

Aggregations

BroadcastModelDao (org.killbill.billing.util.broadcast.dao.BroadcastModelDao)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BroadcastInternalEvent (org.killbill.billing.events.BroadcastInternalEvent)1 LifecycleHandlerType (org.killbill.billing.platform.api.LifecycleHandlerType)1 EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)1 Test (org.testng.annotations.Test)1