@Override public void flow(final int credits) throws IllegalStateException { receiver.flow(credits); }
@Override public void replenish(final int downstreamCredit) { int remainingCredit = link.getCredit(); if (downstreamCredit > 0 && remainingCredit <= MIN_LINK_CREDIT) { int credit = Math.min(MAX_LINK_CREDIT, downstreamCredit); LOG.debug("replenishing client [{}] with {} credits", id, credit); link.flow(credit); } else { // link has remaining credit, no need to replenish yet } }
private void flowCreditToRequestor(final String replyTo) { final ProtonReceiver receiver = replyToReceiverMap.get(replyTo); if (receiver == null) { logger.warn("No receiver found for reply-to address [{}]", replyTo); return; } // flow one credit back to the receiver receiver.flow(1); if (logger.isTraceEnabled()) { logger.trace("Flowing credit back to sender - replyTo: [{}], currentCredits: {}", replyTo, receiver.getCredit()); } }
private void flowCreditToRequestor(final String replyTo) { final ProtonReceiver receiver = replyToReceiverMap.get(replyTo); if (receiver == null) { logger.warn("No receiver found for reply-to address [{}]", replyTo); return; } // flow one credit back to the receiver receiver.flow(1); if (logger.isTraceEnabled()) { logger.trace("Flowing credit back to sender - replyTo: [{}], currentCredits: {}", replyTo, receiver.getCredit()); } }
/** * Issues credits to the peer that the command has been received from. * * @param credits The number of credits. * @throws IllegalArgumentException if credits is < 1 */ private void flow(final int credits) { if (credits < 1) { throw new IllegalArgumentException("credits must be positve"); } currentSpan.log(String.format("flowing %d credits to sender", credits)); receiver.flow(credits); } }
private void flowCreditIfNeeded(long n) { int currentCredit = receiver.getCredit(); if(currentCredit < maxOutstandingCredit) { int limit = maxOutstandingCredit - currentCredit; int addedCredit = (int) Math.min(n, limit); if(addedCredit > 0) { if(!completed.get()) { LOG.trace("Flowing additional credits : {0}", addedCredit); receiver.flow(addedCredit); } else { LOG.trace("Skipping flowing additional credits as already completed: {0}", addedCredit); } } } }
private void forwardMessage(ProtonSender protonSender, ProtonReceiver protonReceiver, ProtonDelivery sourceDelivery, Message message) { MessageAnnotations annotations = message.getMessageAnnotations(); if (annotations == null) { annotations = new MessageAnnotations(Collections.singletonMap(replicated, true)); } else { annotations.getValue().put(replicated, true); } message.setMessageAnnotations(annotations); protonSender.send(message, protonDelivery -> { sourceDelivery.disposition(protonDelivery.getRemoteState(), protonDelivery.remotelySettled()); protonReceiver.flow(protonSender.getCredit() - protonReceiver.getCredit()); }); }
private void messageHandler(ProtonReceiver receiver, ProtonDelivery delivery, Message message) { try { AmqpWillMessage amqpWillMessage = AmqpWillMessage.from(message); LOG.info("Received will on topic [{}] by client [{}]", amqpWillMessage.topic(), receiver.getName()); // TODO : having a callback to check if handling went well and send right disposition ? this.willHandler.handle(new WillData(receiver.getName(), amqpWillMessage)); delivery.disposition(Accepted.getInstance(), true); // NOTE : after receiving the AMQP_WILL, a new credit is issued because // with AMQP we want to change the "will" message during the client life receiver.flow(AMQP_WILL_CREDITS); } catch (IllegalArgumentException ex) { LOG.error("Error decoding will message", ex); ErrorCondition errorCondition = new ErrorCondition(AmqpError.DECODE_ERROR, "Received message is not a will message"); receiver.setCondition(errorCondition) .close(); } }
LOG.debug("successfully created command consumer [{}]", address); receiverRef.set(receiver); receiver.flow(1); // allow sender to send one command final CommandConsumer consumer = new CommandConsumer(context, props, receiver, tracer); consumer.setLocalCloseHandler(sourceAddress -> {
receiver.flow(sender.getCredit()); receiver.setSource(source); receiver.handler(((delivery, message) -> handleMessage(sender, receiver, delivery, message)));
private void receiverHandler(ProtonReceiver receiver) { LOG.info("Attaching link request"); // the LWT service supports only the control address if (!receiver.getRemoteTarget().getAddress().equals(LWT_SERVICE_ENDPOINT)) { ErrorCondition errorCondition = new ErrorCondition(AmqpError.NOT_FOUND, "The provided address isn't supported"); receiver.setCondition(errorCondition) .close(); } else { receiver.setTarget(receiver.getRemoteTarget()) .setQoS(ProtonQoS.AT_LEAST_ONCE) .handler((delivery, message) -> { this.messageHandler(receiver, delivery, message); }) .closeHandler(ar -> { this.closeHandler(receiver, ar); }) .detachHandler(ar -> { this.closeHandler(receiver, ar); }) .setPrefetch(0) .open(); receiver.flow(AMQP_WILL_CREDITS); } }
receiver.flow(config.getReceiverLinkCredit());
receiver.flow(config.getReceiverLinkCredit());
.flow(amqpConfigProperties.getFlowCredit());