AgentSender.java
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.airport.core;
import com.airport.Main;
import org.apache.log4j.Logger;
import com.caac.imf.api.IMFClient;
import redis.clients.jedis.Jedis;
public class AgentSender extends Thread{
private static final Logger logger = Logger.getLogger(AgentSender.class);
public static boolean isrunning;
Jedis jedis = new Jedis("10.50.3.73", 6379);
private IMFClient client;
public AgentSender(IMFClient client){
this.client = client;
}
public void run(){
logger.info(jedis);
try {
if (this.client == null) {
logger.info("IMFClient has been closed");
return;
}
isrunning=true;
if(Main.isSuc){
logger.info("《《《主线程初始化成功。。。。》》》");
if(Main.LOGIN_OK){
logger.info("《《《登录成功开始轮询500mm一次。。。。》》》");
while(true){
String SendMsg = jedis.rpoplpush("task-queue", "tmp-queue"); //取队列消息
//队列消息不为NULL开始发送
if(SendMsg !=null && SendMsg.length() != 0){
String returnMsg = this.client.sendMSG(SendMsg);
logger.debug("<<发送返回的信息:"+returnMsg+">>");
//9是发送成功
if(returnMsg.indexOf("<CODE>9</CODE>")>=0){
try {
jedis.rpop("tmp-queue");
logger.debug("<<移除队列>>");
} catch (Exception e) {
e.printStackTrace();
logger.info(e.getMessage());
logger.info("!!移除队列失败!!");
}
}else{
//如果发送不成功继续发送
try{
jedis.rpoplpush("tmp-queue", "task-queue");
logger.info("!!<<执行未成功发送的消息返回到发送消息队列>>!!");
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
logger.info("!!回写TMP到TASK队列失败!!");
}
}
}
//发送延迟
try {
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
logger.info(e.getMessage());
}
}
}else{
logger.info("---------登陆中");
}
}
}catch (Exception var14) {
var14.printStackTrace();
logger.info(var14.getMessage());
}
isrunning=false;
logger.info("---------线程不在了");
}
}