Search in sources :

Example 1 with LifecycleHandlerType

use of org.killbill.billing.platform.api.LifecycleHandlerType 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 LifecycleHandlerType

use of org.killbill.billing.platform.api.LifecycleHandlerType in project killbill by killbill.

the class DefaultBroadcastService method start.

@LifecycleHandlerType(LifecycleHandlerType.LifecycleLevel.START_SERVICE)
public void start() {
    final TimeUnit pendingRateUnit = broadcastConfig.getBroadcastServiceRunningRate().getUnit();
    final long pendingPeriod = broadcastConfig.getBroadcastServiceRunningRate().getPeriod();
    broadcastExecutor.scheduleAtFixedRate(new BroadcastServiceRunnable(this, broadcastDao, eventBus), pendingPeriod, pendingPeriod, pendingRateUnit);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Example 3 with LifecycleHandlerType

use of org.killbill.billing.platform.api.LifecycleHandlerType in project killbill by killbill.

the class DefaultEntitlementService method initialize.

@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
public void initialize() {
    try {
        final NotificationQueueHandler queueHandler = new NotificationQueueHandler() {

            @Override
            public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) {
                final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "EntitlementQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken);
                if (inputKey instanceof EntitlementNotificationKey) {
                    final CallContext callContext = internalCallContextFactory.createCallContext(internalCallContext);
                    processEntitlementNotification((EntitlementNotificationKey) inputKey, internalCallContext, callContext);
                } else if (inputKey instanceof BlockingTransitionNotificationKey) {
                    processBlockingNotification((BlockingTransitionNotificationKey) inputKey, internalCallContext);
                } else if (inputKey != null) {
                    log.error("Entitlement service received an unexpected event className='{}", inputKey.getClass());
                } else {
                    log.error("Entitlement service received an unexpected null event");
                }
            }
        };
        entitlementEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME, NOTIFICATION_QUEUE_NAME, queueHandler);
    } catch (final NotificationQueueAlreadyExists e) {
        throw new RuntimeException(e);
    }
}
Also used : EntitlementNotificationKey(org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey) BlockingTransitionNotificationKey(org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) NotificationQueueAlreadyExists(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) DateTime(org.joda.time.DateTime) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Example 4 with LifecycleHandlerType

use of org.killbill.billing.platform.api.LifecycleHandlerType in project killbill by killbill.

the class DefaultSubscriptionBaseService method initialize.

@LifecycleHandlerType(LifecycleLevel.INIT_SERVICE)
public void initialize() {
    try {
        final NotificationQueueHandler queueHandler = new NotificationQueueHandler() {

            @Override
            public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) {
                if (!(inputKey instanceof SubscriptionNotificationKey)) {
                    log.error("SubscriptionBase service received an unexpected event className='{}'", inputKey.getClass().getName());
                    return;
                }
                final SubscriptionNotificationKey key = (SubscriptionNotificationKey) inputKey;
                final SubscriptionBaseEvent event = dao.getEventById(key.getEventId(), internalCallContextFactory.createInternalTenantContext(tenantRecordId, accountRecordId));
                if (event == null) {
                    // This can be expected if the event is soft deleted (is_active = 0)
                    log.debug("Failed to extract event for notification key {}", inputKey);
                    return;
                }
                final InternalCallContext context = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "SubscriptionEventQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken);
                processEventReady(event, key.getSeqId(), context);
            }
        };
        subscriptionEventQueue = notificationQueueService.createNotificationQueue(SUBSCRIPTION_SERVICE_NAME, NOTIFICATION_QUEUE_NAME, queueHandler);
    } catch (final NotificationQueueAlreadyExists e) {
        throw new RuntimeException(e);
    }
}
Also used : NotificationEvent(org.killbill.notificationq.api.NotificationEvent) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) UUID(java.util.UUID) NotificationQueueAlreadyExists(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists) NotificationQueueHandler(org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) DateTime(org.joda.time.DateTime) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Aggregations

LifecycleHandlerType (org.killbill.billing.platform.api.LifecycleHandlerType)4 UUID (java.util.UUID)2 DateTime (org.joda.time.DateTime)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)2 NotificationQueueAlreadyExists (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists)2 NotificationQueueHandler (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler)2 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BlockingTransitionNotificationKey (org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey)1 EntitlementNotificationKey (org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey)1 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)1 BroadcastModelDao (org.killbill.billing.util.broadcast.dao.BroadcastModelDao)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1