public void clear(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), overdueable.getId().toString(), MAX_LOCK_RETRIES); clearWithLock(effectiveDate, context); } catch (final LockFailedException e) { log.warn("Failed to clear overdue for accountId='{}'", overdueable.getId(), e); } finally { if (lock != null) { lock.release(); } } }
public OverdueState refresh(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { if (overdueStateSet.size() < 1) { // No configuration available return overdueStateSet.getClearState(); } GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), overdueable.getId().toString(), MAX_LOCK_RETRIES); return refreshWithLock(effectiveDate, context); } catch (final LockFailedException e) { log.warn("Failed to process overdue for accountId='{}'", overdueable.getId(), e); } finally { if (lock != null) { lock.release(); } } return null; }
@Test(groups = "slow") public void testSimpleLocking() throws IOException, LockFailedException { final String lockName = UUID.randomUUID().toString(); final GlobalLock lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 3); dbi.inTransaction(new TransactionCallback<Void>() { @Override public Void inTransaction(final Handle conn, final TransactionStatus status) throws Exception { conn.execute("insert into dummy2 (dummy_id) values ('" + UUID.randomUUID().toString() + "')"); return null; } }); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), false); boolean gotException = false; try { locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 1); } catch (LockFailedException e) { gotException = true; } Assert.assertTrue(gotException); lock.release(); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), true); } }
public Invoice processAccount(final boolean isApiCall, final UUID accountId, @Nullable final LocalDate targetDate, @Nullable final DryRunArguments dryRunArguments, final boolean isRescheduled, final InternalCallContext context) throws InvoiceApiException { boolean parkedAccount = false; try { parkedAccount = parkedAccountsManager.isParked(context); if (parkedAccount && !isApiCall) { log.warn("Ignoring invoice generation process for accountId='{}', targetDate='{}', account is parked", accountId.toString(), targetDate); return null; } } catch (final TagApiException e) { log.warn("Unable to determine parking state for accountId='{}'", accountId); } GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), accountId.toString(), invoiceConfig.getMaxGlobalLockRetries()); return processAccountWithLock(parkedAccount, accountId, targetDate, dryRunArguments, isRescheduled, context); } catch (final LockFailedException e) { log.warn("Failed to process invoice for accountId='{}', targetDate='{}'", accountId.toString(), targetDate, e); } finally { if (lock != null) { lock.release(); } } return null; }
public void clear(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), overdueable.getId().toString(), MAX_LOCK_RETRIES); clearWithLock(effectiveDate, context); } catch (final LockFailedException e) { log.warn("Failed to clear overdue for accountId='{}'", overdueable.getId(), e); } finally { if (lock != null) { lock.release(); } } }
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(); } } }
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(); } } }
public OverdueState refresh(final DateTime effectiveDate, final InternalCallContext context) throws OverdueException, OverdueApiException { if (overdueStateSet.size() < 1) { // No configuration available return overdueStateSet.getClearState(); } GlobalLock lock = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), overdueable.getId().toString(), MAX_LOCK_RETRIES); return refreshWithLock(effectiveDate, context); } catch (final LockFailedException e) { log.warn("Failed to process overdue for accountId='{}'", overdueable.getId(), e); } finally { if (lock != null) { lock.release(); } } return null; }
@Test(groups = "slow") public void testSimpleLocking() throws IOException, LockFailedException { final String lockName = UUID.randomUUID().toString(); final GlobalLock lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 3); dbi.inTransaction(new TransactionCallback<Void>() { @Override public Void inTransaction(final Handle conn, final TransactionStatus status) throws Exception { conn.execute("insert into dummy2 (dummy_id) values ('" + UUID.randomUUID().toString() + "')"); return null; } }); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), false); boolean gotException = false; try { locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), lockName, 1); } catch (LockFailedException e) { gotException = true; } Assert.assertTrue(gotException); lock.release(); Assert.assertEquals(locker.isFree(LockerType.ACCNT_INV_PAY.toString(), lockName), true); } }
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(); } } }
Iterable<DefaultInvoice> invoicesForPlugins = null; try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), accountId.toString(), invoiceConfig.getMaxGlobalLockRetries());
lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), account.getId().toString(), paymentConfig.getMaxGlobalLockRetries());
try { lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), account.getId().toString(), 1);