@Override protected void loop() { if (!this.isCancelled()) { Duration renewInterval = RenewLockLoop.getNextRenewInterval(this.session.getLockedUntilUtc(), this.sessionIdentifier); if (renewInterval != null && !renewInterval.isNegative()) { this.timerFuture = Timer.schedule(() -> { TRACE_LOGGER.debug("Renewing lock on '{}'", this.sessionIdentifier); this.session.renewSessionLockAsync().handleAsync((v, renewLockEx) -> { if (renewLockEx != null) { renewLockEx = ExceptionUtil.extractAsyncCompletionCause(renewLockEx); TRACE_LOGGER.error("Renewing lock on '{}' failed", this.sessionIdentifier, renewLockEx); this.messageAndSessionPump.notifyExceptionToSessionHandler(renewLockEx, ExceptionPhase.RENEWSESSIONLOCK); if (!(renewLockEx instanceof SessionLockLostException || renewLockEx instanceof OperationCancelledException)) { this.loop(); } } else { TRACE_LOGGER.debug("Renewed lock on '{}'", this.sessionIdentifier); this.loop(); } return null; }, MessagingFactory.INTERNAL_THREAD_POOL); }, renewInterval, TimerType.OneTimeRun); } } } }