use of com.lambdaworks.redis.RedisConnectionException in project x-pipe by ctripcorp.
the class DefaultSentinelCollector method isKeeperOrDead.
@VisibleForTesting
protected boolean isKeeperOrDead(String host, int port) {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Object> role = new AtomicReference<>();
try {
RedisSession redisSession = sessionManager.findOrCreateSession(host, port);
redisSession.role(new RedisSession.RollCallback() {
@Override
public void role(String roleDesc) {
role.set(roleDesc);
latch.countDown();
}
@Override
public void fail(Throwable e) {
logger.error("[isKeeperOrDead][fail]" + host + ":" + port, e);
role.set(e);
latch.countDown();
}
});
} catch (Exception e) {
role.set(e);
logger.error("[isKeeperOrDead]" + host + ":" + port, e);
}
try {
latch.await(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.error("[isKeeperOrDead]latch await error: {}", e);
}
if (role.get() instanceof String && Server.SERVER_ROLE.KEEPER.sameRole((String) role.get())) {
return true;
}
if (role.get() instanceof RedisConnectionException) {
return true;
}
logger.info("[isKeeperOrDead] role: {}", role.get());
return false;
}
Aggregations