MessgeRenewLockLoop(IMessageReceiver innerReceiver, MessageAndSessionPump messageAndSessionPump, IMessage message, Instant stopRenewalAt) { super(); this.innerReceiver = innerReceiver; this.messageAndSessionPump = messageAndSessionPump; this.message = message; this.stopRenewalAt = stopRenewalAt; this.messageIdentifier = String.format("message with locktoken : %s, sequence number : %s", this.message.getLockToken(), this.message.getSequenceNumber()); }
this.receiveAndPumpMessage(); } else { TRACE_LOGGER.trace("Message with sequence number '{}' received from entity '{}'.", message.getSequenceNumber(), this.entityPath); renewLockLoop = new MessgeRenewLockLoop(this.innerReceiver, this, message, stopRenewMessageLockAt); renewLockLoop.startLoop(); TRACE_LOGGER.trace("Started loop to renew lock on message with sequence number '{}' until '{}'", message.getSequenceNumber(), stopRenewMessageLockAt); } else { renewLockLoop = null; TRACE_LOGGER.debug("Invoking onMessage with message containing sequence number '{}'", message.getSequenceNumber()); onMessageFuture = COMPLETED_FUTURE.thenComposeAsync((v) -> this.messageHandler.onMessageAsync(message), this.customCodeExecutor); } catch (Exception onMessageSyncEx) { TRACE_LOGGER.error("Invocation of onMessage with message containing sequence number '{}' threw unexpected exception", message.getSequenceNumber(), onMessageSyncEx); onMessageFuture = new CompletableFuture<Void>(); onMessageFuture.completeExceptionally(onMessageSyncEx); if (onMessageEx != null) { onMessageEx = ExceptionUtil.extractAsyncCompletionCause(onMessageEx); TRACE_LOGGER.error("onMessage with message containing sequence number '{}' threw exception", message.getSequenceNumber(), onMessageEx); this.notifyExceptionToMessageHandler(onMessageEx, ExceptionPhase.USERCALLBACK); if (renewLockLoop != null) { renewLockLoop.cancelLoop(); TRACE_LOGGER.trace("Cancelled loop to renew lock on message with sequence number '{}'", message.getSequenceNumber()); TRACE_LOGGER.debug("Completing message with sequence number '{}'", message.getSequenceNumber()); updateDispositionFuture = this.innerReceiver.completeAsync(message.getLockToken()); } else {
TRACE_LOGGER.trace("Message with sequence number '{}' received from session '{}' on entity '{}'.", message.getSequenceNumber(), session.getSessionId(), this.entityPath); sessionTracker.notifyMessageReceived(); this.sessionHandlerOptions.getMaxAutoRenewDuration(), TimerType.OneTimeRun); TRACE_LOGGER.debug("Invoking onMessage with message containing sequence number '{}'", message.getSequenceNumber()); CompletableFuture<Void> onMessageFuture; try { onMessageFuture = COMPLETED_FUTURE.thenComposeAsync((v) -> this.sessionHandler.onMessageAsync(session, message), this.customCodeExecutor); } catch (Exception onMessageSyncEx) { TRACE_LOGGER.error("Invocation of onMessage with message containing sequence number '{}' threw unexpected exception", message.getSequenceNumber(), onMessageSyncEx); onMessageFuture = new CompletableFuture<Void>(); onMessageFuture.completeExceptionally(onMessageSyncEx); if (onMessageEx != null) { onMessageEx = ExceptionUtil.extractAsyncCompletionCause(onMessageEx); TRACE_LOGGER.error("onMessage with message containing sequence number '{}' threw exception", message.getSequenceNumber(), onMessageEx); this.notifyExceptionToSessionHandler(onMessageEx, ExceptionPhase.USERCALLBACK); TRACE_LOGGER.debug("Completing message with sequence number '{}'", message.getSequenceNumber()); updateDispositionFuture = session.completeAsync(message.getLockToken()); } else { TRACE_LOGGER.debug("Abandoning message with sequence number '{}'", message.getSequenceNumber()); updateDispositionFuture = session.abandonAsync(message.getLockToken()); if (updateDispositionEx != null) { updateDispositionEx = ExceptionUtil.extractAsyncCompletionCause(updateDispositionEx); TRACE_LOGGER.error("{} message with sequence number '{}' failed", dispositionPhase == ExceptionPhase.COMPLETE ? "Completing" : "Abandoning", message.getSequenceNumber(), updateDispositionEx);