try {
sentinelPool = pickupSentinel();
if (sentinelPool != null) {
HostAndPort masterAddress = queryMasterAddress();
if ((internalPool != null) && isAddressChange(masterAddress)) {
logger.info("The internalPool {} had changed, destroy it now.", previousMasterAddress);
destroyInternelPool();
}
if (internalPool == null) {
logger.info("The internalPool {} is not init or the address had changed, init it now.",
masterAddress);
initInternalPool(masterAddress, masterConnectionInfo, masterPoolConfig);
poolInit.countDown();
}
previousMasterAddress = masterAddress;
sentinelJedis = sentinelPool.getResource();
subscriber = new MasterSwitchSubscriber();
sentinelJedis.subscribe(subscriber, "+switch-master", "+redirect-to-master");
} else {
logger.info("All sentinels down, sleep 2 seconds and try to connect again.");
// When the system startup but the sentinels not yet, init a urgly address to prevent null point
// exception. change the logic later.
if (internalPool == null) {
HostAndPort masterAddress = new HostAndPort(NO_ADDRESS_YET, 6379);
initInternalPool(masterAddress, masterConnectionInfo, masterPoolConfig);
previousMasterAddress = masterAddress;
}
sleep(2000);
}