mark
This commit is contained in:
parent
3b1c667915
commit
e373cd8e01
@ -283,41 +283,41 @@ public enum S7Client {
|
||||
}
|
||||
|
||||
private void check_ping(){
|
||||
while (true){
|
||||
try {
|
||||
ScheduledFuture<?> schedule = ping_fail_check.schedule(new Runnable() {
|
||||
ping_fail_check.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (connections.size() != coreSize) {
|
||||
int c = coreSize - connections.size();
|
||||
for (int z = 0; z < c; z++) {
|
||||
while (true){
|
||||
try {
|
||||
if(connections.size()!=coreSize){
|
||||
int c = coreSize-connections.size();
|
||||
for(int z=0;z<c;z++){
|
||||
S7Connector connect = connect(host, rack, slot);
|
||||
if (connect != null) {
|
||||
logger.info("host:" + host + " ;;(check_ping()) 检测到有断线 ==》 现在断线恢复成功");
|
||||
if(connect!=null){
|
||||
logger.info("host:"+host +" ;;(check_ping()) 检测到有断线 ==》 现在断线恢复成功");
|
||||
connections.add(connect);
|
||||
} else {
|
||||
logger.info("host:" + host + " ;;(check_ping()) 检测到有断线 ==》 现在断线恢复失败");
|
||||
}else {
|
||||
logger.info("host:"+host +" ;;(check_ping()) 检测到有断线 ==》 现在断线恢复失败");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 10000, TimeUnit.SECONDS);
|
||||
Object o = schedule.get();
|
||||
Thread.sleep(10000);
|
||||
}catch (Exception e){
|
||||
logger.info("( out catched ) host:"+host +" ;;(check_ping) "+"check connect.size 出现异常,errMessage is : "+e.getMessage()+"现在进入下一次轮询");
|
||||
logger.info(" ( outside check_ping catched ) host:"+host +" ;;(check_ping()) Thread.sleep 异常,异常原因:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//todo 当网络断开之后,下面这个ping() 循环不生效。。 可能是read = connector.read( 出来是null,但还是继续通过了,也可能是 ,,当连接全部断开后 getConnector(); 应该是取不到数据的。。也就会报null。这个明天再看看
|
||||
private void ping(){
|
||||
while (true){
|
||||
try {
|
||||
ScheduledFuture<?> schedule = executor.schedule(new Runnable() {
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < coreSize; i++) {
|
||||
while (true){
|
||||
try {
|
||||
for(int i=0;i<coreSize;i++){
|
||||
S7Connector connector = getConnector();
|
||||
try {
|
||||
//只要没有报异常 都是通讯正常的。
|
||||
@ -328,41 +328,43 @@ public enum S7Client {
|
||||
heartBeat.getByteOffset(),
|
||||
heartBeat.getBitOffset(),
|
||||
heartBeat.getType().getTransportSize());
|
||||
System.out.println("host:" + host + " ;; " + connector.hashCode() + " : ping");
|
||||
|
||||
System.out.println("host:"+host +" ;; "+connector.hashCode()+" : ping");
|
||||
Thread.sleep(100);
|
||||
} catch (Exception e) {
|
||||
logger.info("host:" + host + " ;;(ping) " + connector.hashCode() + " : connection error" + "errMessage is : " + e.getMessage());
|
||||
}catch (Exception e){
|
||||
logger.info("host:"+host +" ;;(ping) "+connector.hashCode()+" : connection error"+"errMessage is : "+e.getMessage());
|
||||
//先把 socket close掉
|
||||
try {
|
||||
connector.close();
|
||||
connections.remove(connector);
|
||||
//如果是网络波动照成的socket断开。 等个1S 再重连试试
|
||||
Thread.sleep(100);
|
||||
} catch (Exception ee) {
|
||||
logger.info("host:" + host + " ;;(ping) " + "connector.close() 出现异常,errMessage is : " + ee.getMessage());
|
||||
}catch (Exception ee){
|
||||
logger.info("host:"+host +" ;;(ping) "+"connector.close() 出现异常,errMessage is : "+ee.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//todo 把之前的连接close 掉,然后新增一个连接到connections
|
||||
if (connections.size() != coreSize) {
|
||||
int c = coreSize - connections.size();
|
||||
for (int z = 0; z < c; z++) {
|
||||
if(connections.size()!=coreSize){
|
||||
int c = coreSize-connections.size();
|
||||
for(int z=0;z<c;z++){
|
||||
S7Connector connect = connect(host, rack, slot);
|
||||
if (connect != null) {
|
||||
logger.info("host:" + host + " ;;(ping) " + "ping时候出现异常,尝试重连, 重连成功!!");
|
||||
if(connect!=null){
|
||||
logger.info("host:"+host +" ;;(ping) "+"ping时候出现异常,尝试重连, 重连成功!!");
|
||||
connections.add(connect);
|
||||
} else {
|
||||
logger.info("host:" + host + " ;;(ping) " + "ping时候出现异常,尝试重连, 重连时候还是 出现异常。。");
|
||||
}else {
|
||||
logger.info("host:"+host +" ;;(ping) "+"ping时候出现异常,尝试重连, 重连时候还是 出现异常。。");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 30000, TimeUnit.SECONDS);
|
||||
Object o = schedule.get();
|
||||
Thread.sleep(30000);
|
||||
}catch (Exception e){
|
||||
logger.info("( out catched ) host:"+host +" ;;(ping) "+"ping的时候 整体 出现异常,errMessage is : "+e.getMessage()+"现在进入下一次轮询");
|
||||
e.printStackTrace();
|
||||
logger.info(" ( outside ping catched ) host:"+host +" ;;(ping) "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user