private boolean isRODBIAllowed() { return getCurrentState() == RO_ALLOWED; }
public static Object withRODBIAllowed(final boolean allowRODBI, final WithProfilingCallback<Object, Throwable> callback) throws Throwable { final THREAD_STATE currentState = getCurrentState(); CURRENT_THREAD_STATE.set(allowRODBI ? RO_ALLOWED : RW_ONLY); try { return callback.execute(); } finally { CURRENT_THREAD_STATE.set(currentState); } }
boolean shouldUseRODBI(final boolean requestedRO) { if (requestedRO) { if (isRODBIAllowed()) { logger.debug("Using RO DBI"); return true; } else { // Redirect to the rw instance, to work-around any replication delay logger.debug("RO DBI requested, but thread state is {}, using RW DBI", getCurrentState()); return false; } } else { // Disable RO DBI for future calls in this thread disallowRODBI(); logger.debug("Using RW DBI"); return false; } }
private boolean isRODBIAllowed() { return getCurrentState() == RO_ALLOWED; }
public static Object withRODBIAllowed(final boolean allowRODBI, final WithProfilingCallback<Object, Throwable> callback) throws Throwable { final THREAD_STATE currentState = getCurrentState(); CURRENT_THREAD_STATE.set(allowRODBI ? RO_ALLOWED : RW_ONLY); try { return callback.execute(); } finally { CURRENT_THREAD_STATE.set(currentState); } }
private void updateLastThreadState() { lastThreadState = DBRouterUntyped.getCurrentState(); } }
boolean shouldUseRODBI(final boolean requestedRO) { if (requestedRO) { if (isRODBIAllowed()) { logger.debug("Using RO DBI"); return true; } else { // Redirect to the rw instance, to work-around any replication delay logger.debug("RO DBI requested, but thread state is {}, using RW DBI", getCurrentState()); return false; } } else { // Disable RO DBI for future calls in this thread disallowRODBI(); logger.debug("Using RW DBI"); return false; } }
@Override public Object execute() throws Throwable { assertEquals(DBRouterUntyped.getCurrentState(), THREAD_STATE.RO_ALLOWED); final Payment retrievedPayment2 = paymentApi.getPayment(payment.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(retrievedPayment2.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); // No thread switch, RO as well assertEquals(mockPaymentProviderPlugin.getLastThreadState(), THREAD_STATE.RO_ALLOWED); assertEquals(DBRouterUntyped.getCurrentState(), THREAD_STATE.RO_ALLOWED); return null; } });
@Override public Payment execute() throws Throwable { // Shouldn't happen in practice, but it's just to verify the behavior assertEquals(DBRouterUntyped.getCurrentState(), THREAD_STATE.RO_ALLOWED); final BigDecimal requestedAmount = BigDecimal.TEN; testListener.pushExpectedEvent(NextEvent.PAYMENT); final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); testListener.assertListenerStatus(); // Thread switch, RW by default assertEquals(mockPaymentProviderPlugin.getLastThreadState(), THREAD_STATE.RW_ONLY); // Switched to RW, because of RW DAO call assertEquals(DBRouterUntyped.getCurrentState(), THREAD_STATE.RW_ONLY); return payment; } });