RedisConnectionException handling during cluster init. #65

pull/110/head
Nikita 10 years ago
parent 8bf61cb665
commit 7855cd9a34

@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
import com.lambdaworks.redis.RedisAsyncConnection; import com.lambdaworks.redis.RedisAsyncConnection;
import com.lambdaworks.redis.RedisClient; import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.RedisConnectionException;
import com.lambdaworks.redis.pubsub.RedisPubSubAdapter; import com.lambdaworks.redis.pubsub.RedisPubSubAdapter;
import com.lambdaworks.redis.pubsub.RedisPubSubConnection; import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
@ -47,15 +48,15 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
public ClusterConnectionManager(ClusterServersConfig cfg, Config config) { public ClusterConnectionManager(ClusterServersConfig cfg, Config config) {
init(config); init(config);
Map<String, ClusterPartition> partitions = new HashMap<String, ClusterPartition>();
for (URI addr : cfg.getNodeAddresses()) { for (URI addr : cfg.getNodeAddresses()) {
RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout()); RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout());
try {
RedisAsyncConnection<String, String> connection = client.connectAsync(); RedisAsyncConnection<String, String> connection = client.connectAsync();
String nodesValue = connection.clusterNodes().awaitUninterruptibly().getNow(); String nodesValue = connection.clusterNodes().awaitUninterruptibly().getNow();
System.out.println(nodesValue);
List<ClusterNodeInfo> nodes = parse(nodesValue); List<ClusterNodeInfo> nodes = parse(nodesValue);
Map<String, ClusterPartition> partitions = new HashMap<String, ClusterPartition>();
for (ClusterNodeInfo clusterNodeInfo : nodes) { for (ClusterNodeInfo clusterNodeInfo : nodes) {
String id = clusterNodeInfo.getNodeId(); String id = clusterNodeInfo.getNodeId();
if (clusterNodeInfo.getFlags().contains(Flag.SLAVE)) { if (clusterNodeInfo.getFlags().contains(Flag.SLAVE)) {
@ -95,9 +96,13 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
SingleEntry entry = new SingleEntry(codec, group, c); SingleEntry entry = new SingleEntry(codec, group, c);
entries.put(partition.getEndSlot(), entry); entries.put(partition.getEndSlot(), entry);
} }
break;
} catch (RedisConnectionException e) {
log.warn(e.getMessage(), e);
} finally {
client.shutdown(); client.shutdown();
break; }
} }
this.config = create(cfg); this.config = create(cfg);

Loading…
Cancel
Save