@Override public void acquireCredits(final int credits) throws ActiveMQException { checkCredits(credits); actualAcquire(credits); afterAcquired(credits); }
@Override public void close() { super.close(); // Closing a producer that is blocking should make it return semaphore.release(Integer.MAX_VALUE / 2); }
protected void checkCredits(final int credits) { int needed = Math.max(credits, windowSize); int toRequest = -1; synchronized (this) { if (getBalance() + arriving < needed) { toRequest = needed - arriving; pendingCredits += toRequest; arriving += toRequest; } } if (toRequest != -1) { requestCredits(toRequest); } }
@Override public void receiveFailCredits(final int credits) { serverRespondedWithFail = true; // receive credits like normal to keep the sender from blocking receiveCredits(credits); }
@Override public synchronized void reset() { // Any pendingCredits credits from before failover won't arrive, so we re-initialise int beforeFailure = pendingCredits; pendingCredits = 0; arriving = 0; // If we are waiting for more credits than what's configured, then we need to use what we tried before // otherwise the client may starve as the credit will never arrive checkCredits(Math.max(windowSize * 2, beforeFailure)); }
@Override public void receiveFailCredits(final int credits) { super.receiveFailCredits(credits); callback.onCreditsFail(this); }
@Override public synchronized void reset() { // Any pendingCredits credits from before failover won't arrive, so we re-initialise semaphore.drainPermits(); super.reset(); }
@Override protected void afterAcquired(int credits) throws ActiveMQAddressFullException { // check to see if the blocking mode is FAIL on the server synchronized (this) { super.afterAcquired(credits); if (serverRespondedWithFail) { serverRespondedWithFail = false; // remove existing credits to force the client to ask the server for more on the next send semaphore.drainPermits(); pendingCredits = 0; arriving = 0; throw ActiveMQClientMessageBundle.BUNDLE.addressIsFull(address.toString(), credits); } } }
@Override public void receiveCredits(final int credits) { synchronized (this) { super.receiveCredits(credits); } semaphore.release(credits); }
@Override public void init(SessionContext sessionContext) { // We initial request twice as many credits as we request in subsequent requests // This allows the producer to keep sending as more arrive, minimising pauses checkCredits(windowSize); this.sessionContext = sessionContext; this.sessionContext.linkFlowControl(address, this); }
@Override public void receiveFailCredits(final int credits) { super.receiveFailCredits(credits); callback.onCreditsFail(this); }
@Override public synchronized void reset() { // Any pendingCredits credits from before failover won't arrive, so we re-initialise semaphore.drainPermits(); super.reset(); }
@Override protected void afterAcquired(int credits) throws ActiveMQAddressFullException { // check to see if the blocking mode is FAIL on the server synchronized (this) { super.afterAcquired(credits); if (serverRespondedWithFail) { serverRespondedWithFail = false; // remove existing credits to force the client to ask the server for more on the next send semaphore.drainPermits(); pendingCredits = 0; arriving = 0; throw ActiveMQClientMessageBundle.BUNDLE.addressIsFull(address.toString(), credits); } } }
@Override public void acquireCredits(final int credits) throws ActiveMQException { checkCredits(credits); actualAcquire(credits); afterAcquired(credits); }
protected void checkCredits(final int credits) { int needed = Math.max(credits, windowSize); int toRequest = -1; synchronized (this) { if (getBalance() + arriving < needed) { toRequest = needed - arriving; pendingCredits += toRequest; arriving += toRequest; } } if (toRequest != -1) { requestCredits(toRequest); } }
@Override public void receiveCredits(int credits) { synchronized (this) { super.receiveCredits(credits); balance += credits; callback.onCreditsFlow(balance <= 0, this); } }
@Override public synchronized void reset() { // Any pendingCredits credits from before failover won't arrive, so we re-initialise int beforeFailure = pendingCredits; pendingCredits = 0; arriving = 0; // If we are waiting for more credits than what's configured, then we need to use what we tried before // otherwise the client may starve as the credit will never arrive checkCredits(Math.max(windowSize * 2, beforeFailure)); }
@Override public void receiveFailCredits(final int credits) { super.receiveFailCredits(credits); callback.onCreditsFail(this); }
@Override public void close() { super.close(); // Closing a producer that is blocking should make it return semaphore.release(Integer.MAX_VALUE / 2); }
@Override public synchronized void reset() { // Any pendingCredits credits from before failover won't arrive, so we re-initialise semaphore.drainPermits(); super.reset(); }