use of org.killbill.commons.locker.GlobalLock in project killbill by killbill.
the class CompletionTaskBase method tryToDoJanitorOperationWithAccountLock.
protected <T> T 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 by killbill.
the class InvoiceApiHelper method dispatchToInvoicePluginsAndInsertItems.
public List<InvoiceItem> dispatchToInvoicePluginsAndInsertItems(final UUID accountId, final boolean isDryRun, final WithAccountLock withAccountLock, final CallContext context) throws InvoiceApiException {
GlobalLock lock = null;
try {
lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), accountId.toString(), invoiceConfig.getMaxGlobalLockRetries());
final Iterable<Invoice> invoicesForPlugins = withAccountLock.prepareInvoices();
final List<InvoiceModelDao> invoiceModelDaos = new LinkedList<InvoiceModelDao>();
for (final Invoice invoiceForPlugin : invoicesForPlugins) {
// Call plugin
final List<InvoiceItem> additionalInvoiceItems = invoicePluginDispatcher.getAdditionalInvoiceItems(invoiceForPlugin, isDryRun, context);
invoiceForPlugin.addInvoiceItems(additionalInvoiceItems);
// Transformation to InvoiceModelDao
final InvoiceModelDao invoiceModelDao = new InvoiceModelDao(invoiceForPlugin);
final List<InvoiceItem> invoiceItems = invoiceForPlugin.getInvoiceItems();
final List<InvoiceItemModelDao> invoiceItemModelDaos = toInvoiceItemModelDao(invoiceItems);
invoiceModelDao.addInvoiceItems(invoiceItemModelDaos);
// Keep track of modified invoices
invoiceModelDaos.add(invoiceModelDao);
}
final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(accountId, context);
final List<InvoiceItemModelDao> createdInvoiceItems = dao.createInvoices(invoiceModelDaos, internalCallContext);
return fromInvoiceItemModelDao(createdInvoiceItems);
} catch (final LockFailedException e) {
log.warn("Failed to process invoice items for accountId='{}'", accountId.toString(), e);
return ImmutableList.<InvoiceItem>of();
} finally {
if (lock != null) {
lock.release();
}
}
}
use of org.killbill.commons.locker.GlobalLock in project killbill by killbill.
the class InvoiceDispatcher method processParentInvoiceForInvoiceGeneration.
public void processParentInvoiceForInvoiceGeneration(final Account childAccount, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException {
GlobalLock lock = null;
try {
lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), childAccount.getParentAccountId().toString(), invoiceConfig.getMaxGlobalLockRetries());
processParentInvoiceForInvoiceGenerationWithLock(childAccount, childInvoiceId, context);
} catch (final LockFailedException e) {
log.warn("Failed to process parent invoice for parentAccountId='{}'", childAccount.getParentAccountId().toString(), e);
} finally {
if (lock != null) {
lock.release();
}
}
}
use of org.killbill.commons.locker.GlobalLock in project killbill by killbill.
the class InvoiceDispatcher method processParentInvoiceForAdjustments.
public void processParentInvoiceForAdjustments(final Account childAccount, final UUID childInvoiceId, final InternalCallContext context) throws InvoiceApiException {
GlobalLock lock = null;
try {
lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), childAccount.getParentAccountId().toString(), invoiceConfig.getMaxGlobalLockRetries());
processParentInvoiceForAdjustmentsWithLock(childAccount, childInvoiceId, context);
} catch (final LockFailedException e) {
log.warn("Failed to process parent invoice for parentAccountId='{}'", childAccount.getParentAccountId().toString(), e);
} finally {
if (lock != null) {
lock.release();
}
}
}
Aggregations