public String getLinkName() { return getEndpoint().getName(); } }
public void removeReceiver(Receiver receiver) { sessionSPI.removeProducer(receiver.getName()); receivers.remove(receiver); }
public void removeReceiver(Receiver receiver) { sessionSPI.removeProducer(receiver.getName()); receivers.remove(receiver); }
public String getLinkName() { return getEndpoint().getName(); } }
public void run() { if (!linkClose.isDone()) { Exception operationTimedout = new TimeoutException(String.format(Locale.US, "%s operation on Receive Link(%s) timed out at %s", "Close", CoreMessageReceiver.this.receiveLink.getName(), ZonedDateTime.now())); TRACE_LOGGER.warn(operationTimedout.getMessage()); ExceptionUtil.completeExceptionally(linkClose, operationTimedout, CoreMessageReceiver.this, true); } } }
@Override public void onLinkLocalOpen(Event evt) { Link link = evt.getLink(); if (link instanceof Receiver) { Receiver receiver = (Receiver) link; if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info( String.format("onLinkLocalOpen linkName[%s], localSource[%s]", receiver.getName(), receiver.getSource())); } } }
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); } }
@Override public void onLinkLocalOpen(Event evt) { Link link = evt.getLink(); if (link instanceof Receiver) { Receiver receiver = (Receiver) link; TRACE_LOGGER.debug("onLinkLocalOpen: linkName:{}, localSource:{}", receiver.getName(), receiver.getSource()); } }
public void run() { if (!linkClose.isDone()) { final Receiver link; synchronized (errorConditionLock) { link = MessageReceiver.this.receiveLink; } final Exception operationTimedout = new TimeoutException(String.format(Locale.US, "Close operation on Receive Link(%s) timed out at %s", link.getName(), ZonedDateTime.now())); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info( String.format(Locale.US, "clientId[%s], receiverPath[%s], linkName[%s], Close call timed out", MessageReceiver.this.getClientId(), MessageReceiver.this.receivePath, link.getName()), operationTimedout); } ExceptionUtil.completeExceptionally(linkClose, operationTimedout, MessageReceiver.this); MessageReceiver.this.onError((Exception) null); } } }
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())); } } }
@Override public void onLinkRemoteOpen(Event event) { Link link = event.getLink(); if (link != null && link instanceof Receiver) { Receiver receiver = (Receiver) link; if (link.getRemoteSource() != null) { TRACE_LOGGER.debug("onLinkRemoteOpen: linkName:{}, remoteSource:{}", receiver.getName(), receiver.getRemoteSource()); synchronized (this.firstResponse) { this.isFirstResponse = false; this.amqpReceiver.onOpenComplete(null); } } else { TRACE_LOGGER.debug("onLinkRemoteOpen: linkName:{}, remoteTarget:{}, remoteTarget:{}, action:{}", receiver.getName(), null, null, "waitingForError"); } } }
@Override public void onError(Exception exception) { if(!this.openFuture.isDone()) { this.onOpenComplete(exception); } if(this.getIsClosingOrClosed()) { if(!this.closeFuture.isDone()) { TRACE_LOGGER.error("Closing internal receive link '{}' of requestresponselink to {} failed.", this.receiveLink.getName(), this.parent.linkPath, exception); AsyncUtil.completeFutureExceptionally(this.closeFuture, exception); } } else { TRACE_LOGGER.warn("Internal receive link '{}' of requestresponselink to '{}' encountered error.", this.receiveLink.getName(), this.parent.linkPath, exception); this.parent.underlyingFactory.deregisterForConnectionError(this.receiveLink); this.matchingSendLink.close(); this.parent.underlyingFactory.deregisterForConnectionError(this.matchingSendLink); this.parent.onInnerLinksClosed(this.linkGeneration, exception); } }
@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 void onClose(ErrorCondition condition) { if (condition == null) { this.onError(new ServiceBusException(true, String.format(Locale.US, "Closing the link. LinkName(%s), EntityPath(%s)", this.receiveLink.getName(), this.receivePath))); } else { Exception completionException = ExceptionUtil.toException(condition); this.onError(completionException); } }
@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; }
@Override public void onOpenComplete(Exception completionException) { if(completionException == null) { TRACE_LOGGER.debug("Opened internal receive link of requestresponselink to {}", parent.linkPath); AsyncUtil.completeFuture(this.openFuture, null); // Send unlimited credit this.receiveLink.flow(Integer.MAX_VALUE); } else { TRACE_LOGGER.error("Opening internal receive link '{}' of requestresponselink to {} failed.", this.receiveLink.getName(), this.parent.linkPath, completionException); this.setClosed(); AsyncUtil.completeFuture(this.closeFuture, null); AsyncUtil.completeFutureExceptionally(this.openFuture, completionException); } }
public CompletableFuture<Collection<Message>> peekMessagesAsync(long fromSequenceNumber, int messageCount, String sessionId) { this.throwIfInUnusableState(); return this.createRequestResponseLinkAsync().thenComposeAsync((v) -> { return CommonRequestResponseOperations.peekMessagesAsync(this.requestResponseLink, this.operationTimeout, fromSequenceNumber, messageCount, sessionId, this.receiveLink.getName()); }, MessagingFactory.INTERNAL_THREAD_POOL); } }
@Override public void onEvent() { if (InternalReceiver.this.receiveLink != null && InternalReceiver.this.receiveLink.getLocalState() != EndpointState.CLOSED) { TRACE_LOGGER.debug("Closing internal receive link of requestresponselink to {}", RequestResponseLink.this.linkPath); InternalReceiver.this.receiveLink.close(); InternalReceiver.this.parent.underlyingFactory.deregisterForConnectionError(InternalReceiver.this.receiveLink); if(waitForCloseCompletion) { RequestResponseLink.scheduleLinkCloseTimeout(InternalReceiver.this.closeFuture, InternalReceiver.this.parent.underlyingFactory.getOperationTimeout(), InternalReceiver.this.receiveLink.getName()); } else { AsyncUtil.completeFuture(InternalReceiver.this.closeFuture, null); } } } });
@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); } } }
public void addReceiver(Receiver receiver) throws Exception { try { ProtonServerReceiverContext protonReceiver = new ProtonServerReceiverContext(sessionSPI, connection, this, receiver); protonReceiver.initialise(); receivers.put(receiver, protonReceiver); ServerProducer serverProducer = new ServerProducerImpl(receiver.getName(), "AMQP", receiver.getTarget().getAddress()); sessionSPI.addProducer(serverProducer); receiver.setContext(protonReceiver); connection.runNow(() -> { receiver.open(); connection.flush(); }); } catch (ActiveMQAMQPException e) { receivers.remove(receiver); receiver.setTarget(null); receiver.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); connection.runNow(() -> { receiver.close(); connection.flush(); }); } } }