private void topup(Receiver link, int window) { int delta = window - link.getCredit(); link.flow(delta); }
private void topup(Receiver link, int window) { int delta = window - link.getCredit(); link.flow(delta); }
private void sendFlow(int credits) { if(!this.isBrowsableSession && credits > 0) { this.receiveLink.flow(credits); TRACE_LOGGER.debug("Sent flow to the service. receiverPath:{}, linkname:{}, updated-link-credit:{}, sentCredits:{}", this.receivePath, this.receiveLink.getName(), this.receiveLink.getCredit(), credits); } }
private void sendFlow(final int credits) { // slow down sending the flow - to make the protocol less-chat'y this.nextCreditToFlow += credits; if (this.shouldSendFlow()) { final int tempFlow = this.nextCreditToFlow; this.receiveLink.flow(tempFlow); this.nextCreditToFlow = 0; if (TRACE_LOGGER.isDebugEnabled()) { TRACE_LOGGER.debug(String.format("clientId[%s], receiverPath[%s], linkName[%s], updated-link-credit[%s], sentCredits[%s], ThreadId[%s]", this.getClientId(), this.receivePath, this.receiveLink.getName(), this.receiveLink.getCredit(), tempFlow, Thread.currentThread().getId())); } } }
/** * This Credit Runnable may be used in Mock tests to simulate the credit semantic here */ public static AtomicRunnable createCreditRunnable(int refill, int threshold, Receiver receiver, AMQPConnectionContext connection) { Runnable creditRunnable = () -> { connection.requireInHandler(); if (receiver.getCredit() <= threshold) { int topUp = refill - receiver.getCredit(); if (topUp > 0) { // System.out.println("Sending " + topUp + " towards client"); receiver.flow(topUp); connection.flush(); } } }; return new AtomicRunnable() { @Override public void atomicRun() { connection.runNow(creditRunnable); } }; }
private void replenishCredit() { if (getEndpoint().getCredit() <= (getConfiguredReceiverCredit() * .2)) { LOG.debug("Sending more credit ({}) to transaction coordinator on session {}", getConfiguredReceiverCredit() - getEndpoint().getCredit(), session.getSessionId()); getEndpoint().flow(getConfiguredReceiverCredit() - getEndpoint().getCredit()); session.pumpProtonToSocket(); } }
private void sendFlowForNoPrefetchListener() { int currentCredit = getEndpoint().getCredit(); if (currentCredit < 1) { int additionalCredit = 1 - currentCredit; LOG.trace("Consumer {} granting additional credit: {}", getConsumerId(), additionalCredit); getEndpoint().flow(additionalCredit); } }
private void sendFlowForNoPrefetchListener() { int currentCredit = getEndpoint().getCredit(); if (currentCredit < 1) { int additionalCredit = 1 - currentCredit; LOG.trace("Consumer {} granting additional credit: {}", getConsumerId(), additionalCredit); getEndpoint().flow(additionalCredit); } }
private void replenishCredit() { if (getEndpoint().getCredit() <= (getConfiguredReceiverCredit() * .2)) { LOG.debug("Sending more credit ({}) to transaction coordinator on session {}", getConfiguredReceiverCredit() - getEndpoint().getCredit(), session.getSessionId()); getEndpoint().flow(getConfiguredReceiverCredit() - getEndpoint().getCredit()); session.pumpProtonToSocket(); } }
@Override public ErrorContext getContext() { final boolean isLinkOpened = this.linkOpen != null && this.linkOpen.getWork().isDone(); final String referenceId = this.receiveLink != null && this.receiveLink.getRemoteProperties() != null && this.receiveLink.getRemoteProperties().containsKey(ClientConstants.TRACKING_ID_PROPERTY) ? this.receiveLink.getRemoteProperties().get(ClientConstants.TRACKING_ID_PROPERTY).toString() : ((this.receiveLink != null) ? this.receiveLink.getName(): null); ReceiverErrorContext errorContext = new ReceiverErrorContext(this.underlyingFactory != null ? this.underlyingFactory.getHostName() : null, this.receivePath, referenceId, isLinkOpened ? this.prefetchCount : null, isLinkOpened && this.receiveLink != null ? this.receiveLink.getCredit(): null, this.currentPrefetechedMessagesCount.get()); return errorContext; }
@Override public ErrorContext getContext() { final Receiver link; synchronized (this.errorConditionLock) { link = this.receiveLink; } final boolean isLinkOpened = this.linkOpen != null && this.linkOpen.getWork().isDone(); final String referenceId = link != null && link.getRemoteProperties() != null && link.getRemoteProperties().containsKey(ClientConstants.TRACKING_ID_PROPERTY) ? link.getRemoteProperties().get(ClientConstants.TRACKING_ID_PROPERTY).toString() : ((link != null) ? link.getName() : null); final ReceiverContext errorContext = new ReceiverContext(this.underlyingFactory != null ? this.underlyingFactory.getHostName() : null, this.receivePath, referenceId, isLinkOpened ? this.prefetchCount : null, isLinkOpened && link != null ? link.getCredit() : null, isLinkOpened && this.prefetchedMessages != null ? this.prefetchedMessages.size() : null); return errorContext; }
int creditToFlowForWorkItem = this.creditNeededtoServePendingReceives.get() - (this.receiveLink.getCredit() + this.currentPrefetechedMessagesCount.get() + this.creditToFlow.get()) + this.prefetchCount; if(creditToFlowForWorkItem > 0)
if (timeoutMills < 0) { if (getEndpoint().getCredit() == 0) { LOG.trace("Receiver {} granting 1 additional credit for pull.", getSubscriptionName()); getEndpoint().flow(1); if (getEndpoint().getCredit() == 0) { LOG.trace("Receiver {} granting 1 additional credit for pull.", getSubscriptionName()); getEndpoint().flow(1); if (getEndpoint().getCredit() == 0) { LOG.trace("Receiver {} granting 1 additional credit for pull.", getSubscriptionName()); getEndpoint().flow(1);
? String.format(Locale.US, "onDelivery linkName[%s], updatedLinkCredit[%s], remoteCredit[%s], " + "remoteCondition[%s], delivery.isSettled[%s]", receiveLink.getName(), receiveLink.getCredit(), receiveLink.getRemoteCredit(), receiveLink.getRemoteCondition(), delivery.isSettled()) : String.format(Locale.US, "delivery.isSettled[%s]", delivery.isSettled())); String.format(Locale.US, "onDelivery linkName[%s], updatedLinkCredit[%s], remoteCredit[%s], " + "remoteCondition[%s], delivery.isPartial[%s]", receiveLink.getName(), receiveLink.getCredit(), receiveLink.getRemoteCredit(), receiveLink.getRemoteCondition(), delivery.isPartial()));
/** * We only send more credits as the credit window dwindles to a certain point and * then we open the window back up to full prefetch size. If this is a pull consumer * or we are stopping then we never send credit here. */ private void sendFlowIfNeeded() { int prefetchSize = getResourceInfo().getPrefetchSize(); if (prefetchSize == 0 || isStopping()) { // TODO: isStopping isn't effective when this method is called following // processing the last of any messages received while stopping, since that // happens just after we stopped. That may be ok in some situations however, and // if will only happen if prefetchSize != 0. return; } int currentCredit = getEndpoint().getCredit(); if (currentCredit <= prefetchSize * 0.5) { int potentialPrefetch = currentCredit + (dispatchedCount - deliveredCount); if (potentialPrefetch <= prefetchSize * 0.7) { int additionalCredit = prefetchSize - potentialPrefetch; LOG.trace("Consumer {} granting additional credit: {}", getConsumerId(), additionalCredit); getEndpoint().flow(additionalCredit); } } }
/** * We only send more credits as the credit window dwindles to a certain point and * then we open the window back up to full prefetch size. If this is a pull consumer * or we are stopping then we never send credit here. */ private void sendFlowIfNeeded() { int prefetchSize = getResourceInfo().getPrefetchSize(); if (prefetchSize == 0 || isStopping()) { // TODO: isStopping isn't effective when this method is called following // processing the last of any messages received while stopping, since that // happens just after we stopped. That may be ok in some situations however, and // if will only happen if prefetchSize != 0. return; } int currentCredit = getEndpoint().getCredit(); if (currentCredit <= prefetchSize * 0.5) { int potentialPrefetch = currentCredit + (dispatchedCount - deliveredCount); if (potentialPrefetch <= prefetchSize * 0.7) { int additionalCredit = prefetchSize - potentialPrefetch; LOG.trace("Consumer {} granting additional credit: {}", getConsumerId(), additionalCredit); getEndpoint().flow(additionalCredit); } } }
@Override public void onDelivery(Event event) { synchronized (this.firstResponse) { if (this.isFirstResponse) { this.isFirstResponse = false; this.amqpReceiver.onOpenComplete(null); } } Delivery delivery = event.getDelivery(); Receiver receiveLink = (Receiver) delivery.getLink(); TRACE_LOGGER.debug("onDelivery: linkName:{}, updatedLinkCredit:{}, remoteCredit:{}, remoteCondition:{}, delivery.isPartial:{}", receiveLink.getName(), receiveLink.getCredit(), receiveLink.getRemoteCredit(), receiveLink.getRemoteCondition(), delivery.isPartial()); //TODO: What happens when a delivery has no message, but only disposition from the remote link? Like when ServiceBus service sends just a disposition to the receiver?" // If a message spans across deliveries (for ex: 200k message will be 4 frames (deliveries) 64k 64k 64k 8k), // all until "last-1" deliveries will be partial // reactor will raise onDelivery event for all of these - we only need the last one if (!delivery.isPartial()) { this.amqpReceiver.onReceiveComplete(delivery); } } }
if (getEndpoint().getCredit() + --sendsInFlight <= (getConfiguredReceiverCredit() * .3)) { LOG.trace("Sending more credit ({}) to producer: {}", getConfiguredReceiverCredit() * .7, getProducerId()); getEndpoint().flow((int) (getConfiguredReceiverCredit() * .7));
if (getEndpoint().getCredit() + --sendsInFlight <= (getConfiguredReceiverCredit() * .3)) { LOG.trace("Sending more credit ({}) to producer: {}", getConfiguredReceiverCredit() * .7, getProducerId()); getEndpoint().flow((int) (getConfiguredReceiverCredit() * .7));