Search in sources :

Example 1 with BlockingTransitionNotificationKey

use of org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey in project killbill by killbill.

the class DefaultBlockingStateDao method recordBusOrFutureNotificationFromTransaction.

private void recordBusOrFutureNotificationFromTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final UUID blockingStateId, final DateTime effectiveDate, final UUID blockableId, final BlockingStateType type, final String stateName, final String serviceName, final boolean blockingStateInserted, final BlockingAggregator previousState, final BlockingAggregator currentState, final InternalCallContext context) {
    final boolean isTransitionToBlockedBilling = !previousState.isBlockBilling() && currentState.isBlockBilling();
    final boolean isTransitionToUnblockedBilling = previousState.isBlockBilling() && !currentState.isBlockBilling();
    final boolean isTransitionToBlockedEntitlement = !previousState.isBlockEntitlement() && currentState.isBlockEntitlement();
    final boolean isTransitionToUnblockedEntitlement = previousState.isBlockEntitlement() && !currentState.isBlockEntitlement();
    if (effectiveDate.compareTo(clock.getUTCNow()) > 0) {
        // Add notification entry to send the bus event at the effective date
        final NotificationEvent notificationEvent = new BlockingTransitionNotificationKey(blockingStateId, blockableId, stateName, serviceName, effectiveDate, type, isTransitionToBlockedBilling, isTransitionToUnblockedBilling, isTransitionToBlockedEntitlement, isTransitionToUnblockedEntitlement);
        recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory, effectiveDate, notificationEvent, context);
    } else {
        if (blockingStateInserted) {
            final BusEvent event = new DefaultBlockingTransitionInternalEvent(blockableId, stateName, serviceName, effectiveDate, type, isTransitionToBlockedBilling, isTransitionToUnblockedBilling, isTransitionToBlockedEntitlement, isTransitionToUnblockedEntitlement, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken());
            notifyBusFromTransaction(entitySqlDaoWrapperFactory, event);
        } else {
            log.debug("Skipping event for service {} and blockableId {} (previousState={}, currentState={})", serviceName, blockableId, previousState, currentState);
        }
    }
}
Also used : BlockingTransitionNotificationKey(org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey) DefaultBlockingTransitionInternalEvent(org.killbill.billing.entitlement.api.DefaultBlockingTransitionInternalEvent) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) BusEvent(org.killbill.bus.api.BusEvent)

Example 2 with BlockingTransitionNotificationKey

use of org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey 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)

Aggregations

BlockingTransitionNotificationKey (org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey)2 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)2 UUID (java.util.UUID)1 DateTime (org.joda.time.DateTime)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 DefaultBlockingTransitionInternalEvent (org.killbill.billing.entitlement.api.DefaultBlockingTransitionInternalEvent)1 EntitlementNotificationKey (org.killbill.billing.entitlement.engine.core.EntitlementNotificationKey)1 LifecycleHandlerType (org.killbill.billing.platform.api.LifecycleHandlerType)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1 BusEvent (org.killbill.bus.api.BusEvent)1 NotificationQueueAlreadyExists (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueAlreadyExists)1 NotificationQueueHandler (org.killbill.notificationq.api.NotificationQueueService.NotificationQueueHandler)1