private <T> T executeWithSession(SessionCallable<T> sessionCallable) { ReconnectionPolicy reconnectionPolicy = cluster.getConfiguration().getPolicies().getReconnectionPolicy(); ReconnectionSchedule schedule = reconnectionPolicy.newSchedule(); long deadline = System.currentTimeMillis() + noHostAvailableRetryTimeout.toMillis(); while (true) { try { return sessionCallable.executeWithSession(session.get()); } catch (NoHostAvailableException e) { long timeLeft = deadline - System.currentTimeMillis(); if (timeLeft <= 0) { throw e; } else { long delay = Math.min(schedule.nextDelayMs(), timeLeft); log.warn(e.getCustomMessage(10, true, true)); log.warn("Reconnecting in %dms", delay); try { Thread.sleep(delay); } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new RuntimeException("interrupted", interrupted); } } } } }
private synchronized void updateReconnectionTime() { long now = System.nanoTime(); if (nextReconnectionTime > now) // Someone else updated the time before us return; if (reconnectionSchedule == null) reconnectionSchedule = reconnectionPolicy.newSchedule(); long nextDelayMs = reconnectionSchedule.nextDelayMs(); Host.statesLogger.debug( "[{}] preventing new connections for the next {} ms", host, nextDelayMs); nextReconnectionTime = now + NANOSECONDS.convert(nextDelayMs, MILLISECONDS); }
public void start() { long firstDelay = (initialDelayMs >= 0) ? initialDelayMs : schedule.nextDelayMs(); logger.debug("First reconnection scheduled in {}ms", firstDelay); try { handlerFuture.nextTry = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); while (true) { ListenableFuture<?> previous = currentAttempt.get(); if (previous != null && !previous.isCancelled()) { logger.debug("Found another already active handler, cancelling"); handlerFuture.cancel(false); break; } if (currentAttempt.compareAndSet(previous, handlerFuture)) { Host.statesLogger.debug("[{}] starting reconnection attempt", name); break; } } ready.countDown(); } catch (RejectedExecutionException e) { // The executor has been shutdown, fair enough, just ignore logger.debug("Aborting reconnection handling since the cluster is shutting down"); } }
assertTrue(schedule.nextDelayMs() == 2000); assertTrue(schedule.nextDelayMs() == 4000); assertTrue(schedule.nextDelayMs() == 8000); assertTrue(schedule.nextDelayMs() == 16000); assertTrue(schedule.nextDelayMs() == 32000); for (int i = 0; i < 64; ++i) schedule.nextDelayMs(); assertTrue(schedule.nextDelayMs() == reconnectionPolicy.getMaxDelayMs());
currentAttempt.compareAndSet(localFuture, null); } catch (ConnectionException e) { long nextDelay = schedule.nextDelayMs(); if (onConnectionException(e, nextDelay)) reschedule(nextDelay); } catch (AuthenticationException e) { logger.error(e.getMessage()); long nextDelay = schedule.nextDelayMs(); if (onAuthenticationException(e, nextDelay)) { reschedule(nextDelay); reschedule(schedule.nextDelayMs()); } catch (UnsupportedProtocolVersionException e) { logger.error(e.getMessage()); long nextDelay = schedule.nextDelayMs(); if (onUnsupportedProtocolVersionException(e, nextDelay)) { reschedule(nextDelay); long nextDelay = schedule.nextDelayMs(); if (onUnknownException(e, nextDelay)) reschedule(nextDelay);
private <T> T executeWithSession(SessionCallable<T> sessionCallable) { ReconnectionPolicy reconnectionPolicy = cluster.getConfiguration().getPolicies().getReconnectionPolicy(); ReconnectionSchedule schedule = reconnectionPolicy.newSchedule(); long deadline = System.currentTimeMillis() + noHostAvailableRetryTimeout.toMillis(); while (true) { try { return sessionCallable.executeWithSession(session.get()); } catch (NoHostAvailableException e) { long timeLeft = deadline - System.currentTimeMillis(); if (timeLeft <= 0) { throw e; } else { long delay = Math.min(schedule.nextDelayMs(), timeLeft); log.warn(e.getCustomMessage(10, true, true)); log.warn("Reconnecting in %dms", delay); try { Thread.sleep(delay); } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new RuntimeException("interrupted", interrupted); } } } } }
assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000);
private <T> T executeWithSession(SessionCallable<T> sessionCallable) { ReconnectionPolicy reconnectionPolicy = cluster.getConfiguration().getPolicies().getReconnectionPolicy(); ReconnectionSchedule schedule = reconnectionPolicy.newSchedule(); long deadline = System.currentTimeMillis() + noHostAvailableRetryTimeout.toMillis(); while (true) { try { return sessionCallable.executeWithSession(session.get()); } catch (NoHostAvailableException e) { long timeLeft = deadline - System.currentTimeMillis(); if (timeLeft <= 0) { throw e; } else { long delay = Math.min(schedule.nextDelayMs(), timeLeft); log.warn(e.getCustomMessage(10, true, true)); log.warn("Reconnecting in %dms", delay); try { Thread.sleep(delay); } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new RuntimeException("interrupted", interrupted); } } } } }
public void start() { long firstDelay = (initialDelayMs >= 0) ? initialDelayMs : schedule.nextDelayMs(); logger.debug("First reconnection scheduled in {}ms", firstDelay); try { handlerFuture.nextTry = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); while (true) { ListenableFuture<?> previous = currentAttempt.get(); if (previous != null && !previous.isCancelled()) { logger.debug("Found another already active handler, cancelling"); handlerFuture.cancel(false); break; } if (currentAttempt.compareAndSet(previous, handlerFuture)) { Host.statesLogger.debug("[{}] starting reconnection attempt", name); break; } } ready.countDown(); } catch (RejectedExecutionException e) { // The executor has been shutdown, fair enough, just ignore logger.debug("Aborting reconnection handling since the cluster is shutting down"); } }
public void start() { long firstDelay = (initialDelayMs >= 0) ? initialDelayMs : schedule.nextDelayMs(); logger.debug("First reconnection scheduled in {}ms", firstDelay); try { handlerFuture.nextTry = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); while (true) { ListenableFuture<?> previous = currentAttempt.get(); if (previous != null && !previous.isCancelled()) { logger.debug("Found another already active handler, cancelling"); handlerFuture.cancel(false); break; } if (currentAttempt.compareAndSet(previous, handlerFuture)) { Host.statesLogger.debug("[{}] starting reconnection attempt", name); break; } } ready.countDown(); } catch (RejectedExecutionException e) { // The executor has been shutdown, fair enough, just ignore logger.debug("Aborting reconnection handling since the cluster is shutting down"); } }
public void start() { long firstDelay = (initialDelayMs >= 0) ? initialDelayMs : schedule.nextDelayMs(); logger.debug("First reconnection scheduled in {}ms", firstDelay); try { handlerFuture.nextTry = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); while (true) { ListenableFuture<?> previous = currentAttempt.get(); if (previous != null && !previous.isCancelled()) { logger.debug("Found another already active handler, cancelling"); handlerFuture.cancel(false); break; } if (currentAttempt.compareAndSet(previous, handlerFuture)) { Host.statesLogger.debug("[{}] starting reconnection attempt", name); break; } } ready.countDown(); } catch (RejectedExecutionException e) { // The executor has been shutdown, fair enough, just ignore logger.debug("Aborting reconnection handling since the cluster is shutting down"); } }
public void start() { long firstDelay = schedule.nextDelayMs(); logger.debug("First reconnection scheduled in {}ms", firstDelay); try { localFuture = executor.schedule(this, firstDelay, TimeUnit.MILLISECONDS); // If there a previous task, cancel it, so only one reconnection handler runs. while (true) { ScheduledFuture<?> previous = currentAttempt.get(); if (currentAttempt.compareAndSet(previous, localFuture)) { if (previous != null) previous.cancel(false); break; } } readyForNext = true; } catch (RejectedExecutionException e) { // The executor has been shutdown, fair enough, just ignore logger.debug("Aborting reconnection handling since the cluster is shutting down"); } }
private synchronized void updateReconnectionTime() { long now = System.nanoTime(); if (nextReconnectionTime > now) // Someone else updated the time before us return; if (reconnectionSchedule == null) reconnectionSchedule = reconnectionPolicy.newSchedule(); long nextDelayMs = reconnectionSchedule.nextDelayMs(); Host.statesLogger.debug("[{}] preventing new connections for the next {} ms", host, nextDelayMs); nextReconnectionTime = now + NANOSECONDS.convert(nextDelayMs, MILLISECONDS); }
private synchronized void updateReconnectionTime() { long now = System.nanoTime(); if (nextReconnectionTime > now) // Someone else updated the time before us return; if (reconnectionSchedule == null) reconnectionSchedule = reconnectionPolicy.newSchedule(); long nextDelayMs = reconnectionSchedule.nextDelayMs(); Host.statesLogger.debug("[{}] preventing new connections for the next {} ms", host, nextDelayMs); nextReconnectionTime = now + NANOSECONDS.convert(nextDelayMs, MILLISECONDS); }
private synchronized void updateReconnectionTime() { long now = System.nanoTime(); if (nextReconnectionTime > now) // Someone else updated the time before us return; if (reconnectionSchedule == null) reconnectionSchedule = reconnectionPolicy.newSchedule(); long nextDelayMs = reconnectionSchedule.nextDelayMs(); Host.statesLogger.debug("[{}] preventing new connections for the next {} ms", host, nextDelayMs); nextReconnectionTime = now + NANOSECONDS.convert(nextDelayMs, MILLISECONDS); }
@Override public long nextDelayMs() { count.incrementAndGet(); return childSchedule.nextDelayMs(); } }
logger.debug("Reconnection successful, cleared the future"); } catch (ConnectionException e) { long nextDelay = schedule.nextDelayMs(); if (onConnectionException(e, nextDelay)) reschedule(nextDelay); else currentAttempt.compareAndSet(handlerFuture, null); } catch (AuthenticationException e) { logger.error(e.getMessage()); long nextDelay = schedule.nextDelayMs(); if (onAuthenticationException(e, nextDelay)) { reschedule(nextDelay); } catch (UnsupportedProtocolVersionException e) { logger.error(e.getMessage()); long nextDelay = schedule.nextDelayMs(); if (onUnsupportedProtocolVersionException(e, nextDelay)) { reschedule(nextDelay); long nextDelay = schedule.nextDelayMs(); if (onClusterNameMismatchException(e, nextDelay)) { reschedule(nextDelay); long nextDelay = schedule.nextDelayMs(); if (onUnknownException(e, nextDelay)) reschedule(nextDelay); else currentAttempt.compareAndSet(handlerFuture, null);
assertTrue(schedule.nextDelayMs() == 2000); assertTrue(schedule.nextDelayMs() == 4000); assertTrue(schedule.nextDelayMs() == 8000); assertTrue(schedule.nextDelayMs() == 16000); assertTrue(schedule.nextDelayMs() == 32000); for (int i = 0; i < 64; ++i) schedule.nextDelayMs(); assertTrue(schedule.nextDelayMs() == reconnectionPolicy.getMaxDelayMs());
assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000); assertTrue(schedule.nextDelayMs() == 10000);
@Override public long nextDelayMs() { count.incrementAndGet(); return childSchedule.nextDelayMs(); } }