public boolean hasCredits() { if (!connection.flowControl(onflowControlReady)) { return false; } synchronized (creditsLock) { return credits > 0 && sender.getLocalState() != EndpointState.CLOSED; } }
@Override public boolean isWritable(ReadyListener callback, Object protocolContext) { ProtonServerSenderContext senderContext = (ProtonServerSenderContext) protocolContext; return transportConnection.isWritable(callback) && senderContext.getSender().getLocalState() != EndpointState.CLOSED; }
@Override public void onEvent() { if (!MessageSender.this.getIsClosingOrClosed() && (sendLink == null || sendLink.getLocalState() == EndpointState.CLOSED || sendLink.getRemoteState() == EndpointState.CLOSED)) { recreateSendLink(); } } });
@Override public void onEvent() { if (sendLink != null && sendLink.getLocalState() != EndpointState.CLOSED) { sendLink.close(); } else if (sendLink == null || sendLink.getRemoteState() == EndpointState.CLOSED) { if (closeTimer != null && !closeTimer.isCancelled()) { closeTimer.cancel(false); } linkClose.complete(null); } } });
@Override public boolean isWritable(ReadyListener callback, Object protocolContext) { ProtonServerSenderContext senderContext = (ProtonServerSenderContext) protocolContext; return transportConnection.isWritable(callback) && senderContext.getSender().getLocalState() != EndpointState.CLOSED; }
@Override public void onEvent() { if (!MessageSender.this.getIsClosingOrClosed() && (sendLink.getLocalState() == EndpointState.CLOSED || sendLink.getRemoteState() == EndpointState.CLOSED)) { recreateSendLink(); } } });
@Override public IOObjectState getState() { if (sendLink.getLocalState() == EndpointState.UNINITIALIZED || receiveLink.getLocalState() == EndpointState.UNINITIALIZED || sendLink.getRemoteState() == EndpointState.UNINITIALIZED || receiveLink.getRemoteState() == EndpointState.UNINITIALIZED) return IOObjectState.OPENING; if (sendLink.getRemoteState() == EndpointState.ACTIVE && receiveLink.getRemoteState() == EndpointState.ACTIVE && sendLink.getLocalState() == EndpointState.ACTIVE && receiveLink.getRemoteState() == EndpointState.ACTIVE) return IOObjectState.OPENED; if (sendLink.getRemoteState() == EndpointState.CLOSED && receiveLink.getRemoteState() == EndpointState.CLOSED) return IOObjectState.CLOSED; return IOObjectState.CLOSING; // only left cases are if some are active and some are closed }
@Override public void onEvent() { if (InternalSender.this.sendLink != null && InternalSender.this.sendLink.getLocalState() != EndpointState.CLOSED) { TRACE_LOGGER.debug("Closing internal send link of requestresponselink to {}", RequestResponseLink.this.linkPath); InternalSender.this.sendLink.close(); InternalSender.this.parent.underlyingFactory.deregisterForConnectionError(InternalSender.this.sendLink); if(waitForCloseCompletion) { RequestResponseLink.scheduleLinkCloseTimeout(InternalSender.this.closeFuture, InternalSender.this.parent.underlyingFactory.getOperationTimeout(), InternalSender.this.sendLink.getName()); } else { AsyncUtil.completeFuture(InternalSender.this.closeFuture, null); } } } });
private synchronized CompletableFuture<Void> ensureLinkIsOpen() if (!(this.sendLink.getLocalState() == EndpointState.ACTIVE && this.sendLink.getRemoteState() == EndpointState.ACTIVE))
/** * handle an out going message from ActiveMQ Artemis, send via the Proton Sender */ public int deliverMessage(final MessageReference messageReference, final ServerConsumer consumer) throws Exception { if (closed) { return 0; } try { synchronized (creditsLock) { if (sender.getLocalState() == EndpointState.CLOSED) { return 0; } pending.incrementAndGet(); credits--; } if (messageReference instanceof Runnable && consumer.allowReferenceCallback()) { messageReference.onDelivery(executeDelivery); connection.runNow((Runnable)messageReference); } else { connection.runNow(() -> executeDelivery(messageReference)); } // This is because on AMQP we only send messages based in credits, not bytes return 1; } finally { } }
public CompletableFuture<Message> requestAysnc(Message requestMessage, TransactionContext transaction, Duration timeout) { this.throwIfClosed(null); CompletableFuture<Message> responseFuture = new CompletableFuture<Message>(); RequestResponseWorkItem workItem = new RequestResponseWorkItem(requestMessage, transaction, responseFuture, timeout); String requestId = "request:" + this.requestCounter.incrementAndGet(); requestMessage.setMessageId(requestId); requestMessage.setReplyTo(this.replyTo); this.pendingRequests.put(requestId, workItem); workItem.setTimeoutTask(this.scheduleRequestTimeout(requestId, timeout)); TRACE_LOGGER.debug("Sending request with id:{}", requestId); this.amqpSender.sendRequest(requestId, false); // Check and recreate links if necessary if(!((this.amqpSender.sendLink.getLocalState() == EndpointState.ACTIVE && this.amqpSender.sendLink.getRemoteState() == EndpointState.ACTIVE) && (this.amqpReceiver.receiveLink.getLocalState() == EndpointState.ACTIVE && this.amqpReceiver.receiveLink.getRemoteState() == EndpointState.ACTIVE))) { this.ensureUniqueLinkRecreation(); } return responseFuture; }
if (this.sendLink != null && this.sendLink.getLocalState() != EndpointState.CLOSED)
while(this.sendLink != null && this.sendLink.getLocalState() == EndpointState.ACTIVE && this.sendLink.getRemoteState() == EndpointState.ACTIVE && this.availableCredit.get() > 0)
private void processSendWork() { if (this.sendLink.getLocalState() == EndpointState.CLOSED || this.sendLink.getRemoteState() == EndpointState.CLOSED) { if (!this.getIsClosingOrClosed()) this.recreateSendLink(); while (this.sendLink.getLocalState() == EndpointState.ACTIVE && this.sendLink.getRemoteState() == EndpointState.ACTIVE && this.sendLink.getCredit() > 0) { final WeightedDeliveryTag weightedDelivery;
private void executeDelivery(MessageReference messageReference) { if (sender.getLocalState() == EndpointState.CLOSED) { log.debug("Not delivering message " + messageReference + " as the sender is closed and credits were available, if you see too many of these it means clients are issuing credits and closing the connection with pending credits a lot of times"); return;
if (this.sendLink != null && this.sendLink.getLocalState() != EndpointState.CLOSED)
&& sendLinkCurrent.getLocalState() == EndpointState.ACTIVE && sendLinkCurrent.getRemoteState() == EndpointState.ACTIVE && this.linkCredit > 0)
if (closed || sender.getLocalState() == EndpointState.CLOSED) {