Authored by jack

增加redis 重连

@@ -39,6 +39,11 @@ public class RedisTask extends Task { @@ -39,6 +39,11 @@ public class RedisTask extends Task {
39 39
40 this.tUrl = tUrl; 40 this.tUrl = tUrl;
41 41
  42 + sureConnect();
  43 + }
  44 +
  45 +
  46 + private void connect() {
42 try { 47 try {
43 client = new Jedis(this.getIp(), this.getPort(), 5 * 1000); 48 client = new Jedis(this.getIp(), this.getPort(), 5 * 1000);
44 49
@@ -50,7 +55,28 @@ public class RedisTask extends Task { @@ -50,7 +55,28 @@ public class RedisTask extends Task {
50 55
51 client = null; 56 client = null;
52 } 57 }
  58 + }
  59 +
  60 + private void sureConnect() {
  61 + DEBUG.info("start to connect to redis {},time {}", super.url, System.currentTimeMillis());
  62 +
  63 + connect();
  64 +
  65 + //等待两秒重连
  66 + try {
  67 +
  68 + Thread.sleep(2 * 1000);
  69 +
  70 + } catch (InterruptedException e) {
  71 +
  72 + DEBUG.error("Failed to wait for reconnect to redis {}", super.url);
  73 + }
  74 +
  75 + if (null == client || !client.isConnected()) {
  76 + connect();
  77 + }
53 78
  79 + DEBUG.info("End to connect to redis {},time {}", super.url, System.currentTimeMillis());
54 } 80 }
55 81
56 82
@@ -24,7 +24,7 @@ public class Task implements Callable { @@ -24,7 +24,7 @@ public class Task implements Callable {
24 public static final Logger DEBUG = LoggerFactory.getLogger(Task.class); 24 public static final Logger DEBUG = LoggerFactory.getLogger(Task.class);
25 25
26 @Getter 26 @Getter
27 - private String url; 27 + protected String url;
28 28
29 @Getter 29 @Getter
30 private String ip; 30 private String ip;
@@ -32,7 +32,6 @@ public class Task implements Callable { @@ -32,7 +32,6 @@ public class Task implements Callable {
32 @Getter 32 @Getter
33 private int port; 33 private int port;
34 34
35 -  
36 @Getter 35 @Getter
37 private AlarmMsgService alarmMsgService; 36 private AlarmMsgService alarmMsgService;
38 37