use of com.datastax.driver.core.policies.ReconnectionPolicy.ReconnectionSchedule in project presto by prestodb.
the class NativeCassandraSession method executeWithSession.
@Override
public <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);
}
}
}
}
}
Aggregations