use of org.killbill.commons.locker.GlobalLock in project killbill by killbill.
the class InvoiceDispatcher method processSubscriptionStartRequestedDate.
public void processSubscriptionStartRequestedDate(final RequestedSubscriptionInternalEvent transition, final InternalCallContext context) {
final long dryRunNotificationTime = invoiceConfig.getDryRunNotificationSchedule(context).getMillis();
final boolean isInvoiceNotificationEnabled = dryRunNotificationTime > 0;
if (!isInvoiceNotificationEnabled) {
return;
}
final UUID accountId;
try {
accountId = subscriptionApi.getAccountIdFromSubscriptionId(transition.getSubscriptionId(), context);
} catch (final SubscriptionBaseApiException e) {
log.warn("Failed handling SubscriptionBase change.", new InvoiceApiException(ErrorCode.INVOICE_NO_ACCOUNT_ID_FOR_SUBSCRIPTION_ID, transition.getSubscriptionId().toString()));
return;
}
GlobalLock lock = null;
try {
lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), accountId.toString(), invoiceConfig.getMaxGlobalLockRetries());
processSubscriptionStartRequestedDateWithLock(accountId, transition, context);
} catch (final LockFailedException e) {
log.warn("Failed to process RequestedSubscriptionInternalEvent for accountId='{}'", accountId.toString(), e);
} finally {
if (lock != null) {
lock.release();
}
}
}
use of org.killbill.commons.locker.GlobalLock in project killbill by killbill.
the class IncompletePaymentTransactionTask method tryToDoJanitorOperationWithAccountLock.
private TransactionStatus tryToDoJanitorOperationWithAccountLock(final JanitorIterationCallback callback, final InternalTenantContext internalTenantContext) throws LockFailedException {
GlobalLock lock = null;
try {
final ImmutableAccountData account = accountInternalApi.getImmutableAccountDataByRecordId(internalTenantContext.getAccountRecordId(), internalTenantContext);
lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), account.getId().toString(), paymentConfig.getMaxGlobalLockRetries());
return callback.doIteration();
} catch (final AccountApiException e) {
log.warn("Error retrieving accountRecordId='{}'", internalTenantContext.getAccountRecordId(), e);
} finally {
if (lock != null) {
lock.release();
}
}
return null;
}
use of org.killbill.commons.locker.GlobalLock in project killbill-analytics-plugin by killbill.
the class AnalyticsListener method handleAnalyticsJob.
private void handleAnalyticsJob(final AnalyticsJob job) throws AnalyticsRefreshException {
final AnalyticsConfiguration analyticsConfiguration = analyticsConfigurationHandler.getConfigurable(job.getTenantId());
if (!locker.isFree(ANALYTICS_REFRESH_LOCK_NAME, job.getAccountId().toString())) {
final Integer delaySec = analyticsConfiguration.rescheduleIntervalOnLockSeconds;
if (delaySec > 0) {
final DateTime nextRescheduleDt = clock.getUTCNow().plusSeconds(delaySec);
if (scheduleAnalyticsJob(job, analyticsConfiguration)) {
logger.info("Lock is busy for account {}, rescheduling job at time {}", job.getAccountId(), nextRescheduleDt);
return;
}
}
}
GlobalLock lock = null;
try {
lock = locker.lockWithNumberOfTries(ANALYTICS_REFRESH_LOCK_NAME, job.getAccountId().toString(), analyticsConfiguration.lockAttemptRetries);
handleAnalyticsJobWithLock(job);
} catch (final LockFailedException e) {
throw new RuntimeException(e);
} finally {
if (lock != null) {
lock.release();
}
}
}
Aggregations