From fbc250276c78ca2afa45a55e8af8deddd65e4f8a Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期一, 16 十二月 2024 11:23:41 +0800
Subject: [PATCH] 临时任务功能,修改bug
---
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeManager.java | 265 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 177 insertions(+), 88 deletions(-)
diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeManager.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeManager.java
index acfc12e..021c224 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeManager.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeManager.java
@@ -7,30 +7,37 @@
import com.dy.common.springUtil.SpringContextUtil;
import com.dy.common.util.Callback;
import com.dy.common.util.DateTime;
-import com.dy.common.util.ThreadJob;
+import com.dy.common.util.TimerTaskJob;
import com.dy.rtuMw.web.webRequest.WebRequestDeal;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-
import java.util.List;
/**
- * @Author: liurunyu
- * @Date: 2024/11/4 16:03
+ * 鍗囩骇绠$悊绫�
+ * @Author liurunyu
+ * @Date 2024/11/4 16:03
* @Description
*/
-public class UpgradeManager extends ThreadJob implements Callback {
+public class UpgradeManager extends TimerTaskJob implements Callback {
private static final Logger log = LogManager.getLogger(UpgradeManager.class.getName());
private static final UpgradeManager INSTANCE = new UpgradeManager();
+ private Boolean openNoUpgrade ;//闃�寮�锛堟车寮�锛変笉鎵ц鍗囩骇
+ private Integer lastOpenMaxGoOn ;//闃�寮�锛堟车寮�锛夌姸鎬佽缃互鏉ユ寔缁渶闀挎椂闂达紙绉掗挓锛夛紝瓒呰繃杩欎釜鏃堕棿璁や负鐘舵�佹棤鏁堬紙杩欎釜鏃堕暱鍙栧喅浜庡伐浣滄姤闂撮殧锛�
private Integer failTryTimes ;//鍗囩骇澶辫触鍚庯紝閲嶆柊鍋胯瘯鍗囩骇娆℃暟锛�0琛ㄧず涓嶉噸鏂板伩璇曞崌绾�
private Integer ugMaxRtuSameTime ;//鍚屾椂鍗囩骇RTU鏈�澶т釜鏁�
+ private Integer notifyTimesAfterOver; //鍗囩骇缁撴潫鍚庯紝鍐嶅悜web鏈嶅姟绯荤粺閫氱煡鐘舵�佺殑娆℃暟
+ private int nowNotifyTimesAfterOver; //鍗囩骇缁撴潫鍚庯紝鍐嶅悜web鏈嶅姟绯荤粺閫氱煡鐘舵�佺殑娆℃暟
private UpgradeTask task ;//鍗囩骇浠诲姟
+ private boolean monitorFirst ;//鏄惁鏄涓�娆$洃瑙�
- private UpgradeManager(){}
+ private UpgradeManager(){
+ monitorFirst = true ;
+ }
public static UpgradeManager getInstance() {
return UpgradeManager.INSTANCE;
@@ -40,14 +47,17 @@
* 鍒濆鍖栭厤缃俊鎭�
*/
public void initOption(UpgradeUnitConfigVo configVo) {
+ this.openNoUpgrade = configVo.openNoUpgrade;
+ this.lastOpenMaxGoOn = configVo.lastOpenMaxGoOn;
this.failTryTimes = configVo.failTryTimes;
this.ugMaxRtuSameTime = configVo.ugMaxRtuAtOnce;
+ this.notifyTimesAfterOver = configVo.notifyTimesAfterOver;
}
/**
* 璁剧疆鍗囩骇浠诲姟
* @param vo UpgradeTaskVo 鍗囩骇浠诲姟瀵硅薄
- * @throws Exception
+ * @throws Exception 寮傚父
*/
public void setUpgradeTask(UpgradeTaskVo vo) throws Exception {
if(this.task != null && !this.task.taskIsOver){
@@ -59,8 +69,15 @@
this.task.forceOver();
}
this.task = new UpgradeTask();
- this.task.initOption(this.failTryTimes, this.ugMaxRtuSameTime);
+ this.task.initOption(this.openNoUpgrade, this.lastOpenMaxGoOn, this.failTryTimes, this.ugMaxRtuSameTime);
this.task.setTask(vo);
+ this.nowNotifyTimesAfterOver = 0 ;
+ this.monitorFirst = true ;
+ log.info("======================================================") ;
+ log.info("= =") ;
+ log.info("=璁剧疆浜嗗崌绾т换鍔★紝娑夊強RTU" + vo.rtuAddrList.size() + "鍙� =") ;
+ log.info("= =") ;
+ log.info("======================================================") ;
}catch (Exception e){
ex = e ;
}finally {
@@ -68,31 +85,40 @@
this.task = null ;
throw ex ;
}else{
- this.start(this);
+ this.start(1000L, (long) UpgradeUnit.confVo.notifyStateInterval, this);
}
}
}
}
/**
- * 缁撴潫褰撳墠鍗囩骇浠诲姟
- * @throws Exception
+ * 寮哄埗缁撴潫褰撳墠鍗囩骇浠诲姟锛�
+ * 姝ゅ姛鑳藉彲鑳戒笉浼氬紑鏀惧嚭鍘伙紝
+ * 鍥犱负寮哄埗缁撴潫鍗囩骇浠诲姟锛屽涓�涓湭鍗囩骇瀹屾垚鐨凴TU灏变細鍗℃锛�
+ * 鎵�浠ュ綋寮哄埗缁撴潫鍗囩骇浠诲姟锛屼唬鐮侀�昏緫骞舵病鏈夊己鍒剁粨鏋淩TU鍗囩骇杩囩▼锛屽鏋滃崌绾ц繃绋嬩篃寮哄埗鍋滄锛岄偅涔圧TU鐪熶細鍗℃
*/
- public void overUpgradeTask() throws Exception {
+ public String forceOverUpgradeTask() {
if(this.task != null){
- this.stop();
- this.task.forceOver();
+ this.task.countRunningRtuCount();
+ if(this.task.curUgRunningRtuTotal > 0){
+ return "褰撳墠瀛樺湪鍗囩骇涓殑璁惧锛屼笉鑳界粨鏉熷崌绾т换鍔�" ;
+ }else{
+ this.stop();
+ this.task.forceOver();
+ return null ;
+ }
+ }else{
+ return "褰撳墠娌℃湁鍗囩骇浠诲姟" ;
}
- this.task = null ;
}
/**
* RTU鏈変笂琛屾暟鎹簡锛岃Е鍙戜笅鍙戝崌绾ф暟鎹�
- * @param rtuAddr
- * @param code
- * @param protocolName
- * @param protocolVersion
- * @param callbackCom
+ * @param rtuAddr 鎺у埗鍣≧TU鍦板潃
+ * @param code 涓婅鏁版嵁鍔熻兘鐮�
+ * @param protocolName 涓婅鏁版嵁瀵瑰簲鐨勫崗璁悕绉�
+ * @param protocolVersion 涓婅鏁版嵁瀵瑰簲鐨勫崗璁増鏈彿
+ * @param callbackCom 鍥炶皟鍑芥暟锛屽鐞嗕笅琛屽懡浠�
*/
public void trigger(String rtuAddr, String code, String protocolName, Short protocolVersion, Callback callbackCom){
if(task != null && !task.taskIsOver){
@@ -107,7 +133,7 @@
////////////////////////////////////////////////////
/**
* 褰撳墠鍗囩骇鐘舵��
- * @return
+ * @return 褰撳墠鍗囩骇鐘舵��
*/
public UpgradeState currentUpgradeState() {
if(task != null){
@@ -119,9 +145,10 @@
/**
* Rtu鍗囩骇淇℃伅
- * @param rtuAddr
- * @return
+ * @param rtuAddr 鎺у埗鍣≧TU鍦板潃
+ * @return 鎺у埗鍣≧TU鍗囩骇鐘舵��
*/
+ @SuppressWarnings("unused")
public UpgradeRtu upgradeRtuInfo(String rtuAddr){
if(task != null){
return task.upgradeInfos(rtuAddr) ;
@@ -132,9 +159,10 @@
/**
* Rtu鍗囩骇淇℃伅
- * @param rtuAddrList
- * @return
+ * @param rtuAddrList 鎺у埗鍣ㄥ湴鍧�鍒楄〃
+ * @return 鎸囧畾鍒楄〃涓殑鎺у埗鍣≧TU鍗囩骇鐘舵��
*/
+ @SuppressWarnings("unused")
public List<UpgradeRtu> upgradeRtuInfos(List<String> rtuAddrList){
if(task != null){
return task.upgradeInfos(rtuAddrList) ;
@@ -145,8 +173,8 @@
/**
- * Rtu鍗囩骇淇℃伅
- * @return
+ * 鎵�鏈塕tu鍗囩骇淇℃伅
+ * @return 鎵�鏈塕tu鍗囩骇淇℃伅
*/
public List<UpgradeRtu> upgradeRtuInfoAll(){
if(task != null){
@@ -163,73 +191,135 @@
// 缁熻鐘舵�� + 鐘舵�侀�氱煡
//
////////////////////////////////////////////////////
- @Override
- public Object execute() throws Exception {
- boolean first = true ;
- while (true){
- if(this.isStop()){
- break ;
- }
- if(first){
- try{
- //棣栨鍚姩锛屽仠1绉�
- Thread.sleep(1000L);
- }catch (Exception e){
+ public Object execute() {
+ if(this.task == null
+ || this.task.taskVo == null
+ || this.task.taskVo.rtuAddrList == null
+ || this.task.taskVo.rtuAddrList.size() == 0){
+ //浠诲姟涓虹┖
+ this.stop() ;
+ }else{
+ if(!this.task.taskIsOver){
+ if(this.openNoUpgrade != null
+ && this.openNoUpgrade.booleanValue()
+ && this.monitorFirst){
+ //绗竴娆¤繘鍏ワ紝杩涜闃�寮�涓嶅崌绾у鐞�
+ this.task.openNoUpgrade() ;
}
- }else{
- try{
- //鍋淴姣
- Thread.sleep(UpgradeUnit.confVo.notifyStateInterval);
- }catch (Exception e){
- }
- }
- if(this.task == null
- || this.task.taskVo == null
- || this.task.taskVo.rtuAddrList == null
- || this.task.taskVo.rtuAddrList.size() == 0){
- //浠诲姟涓虹┖
- break ;
- }else{
- if(!this.task.taskIsOver){
- //鍗囩骇浠诲姟鏈畬鎴�
- //宸ヤ綔1锛氱粺璁″綋鍓嶆鍦ㄥ崌绾х殑RTU鏁伴噺锛屼负鍙楅檺鍚屾椂鍗囩骇鏁伴噺鍋氬噯澶�
- this.task.statisticsRunningRtuCount() ;
-
- //宸ヤ綔2锛氱粺璁¢渶瑕佸崌绾т絾褰撳墠绂荤嚎RTU鐨勬儏鍐�
- this.task.statisticsOffRtuCountAndSet() ;
-
- //宸ヤ綔3锛氱粺璁℃槸鍚﹀叏閮ㄥ崌绾у畬鎴�
- this.task.taskIsOver = this.task.statisticsIsAllOver() ;
-
- if(this.task.taskIsOver){
- if(!this.task.taskOverType.equals(UpgradeTask.TaskOverType_Force)){
- //浠诲姟涓嶆槸寮哄埗缁撴潫鐨�
- this.task.taskOverType = UpgradeTask.TaskOverType_Natural ;//浠诲姟瀹屾垚鏂瑰紡锛堣嚜鐒讹紝寮哄埗锛�
- this.task.taskOverDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;//浠诲姟瀹屾垚鏃堕棿(yyyy-mm-dd HH:MM:SS)
- }
- //浠诲姟瀹屾垚锛屾墽琛屾渶鍚庝竴娆″崌绾х姸鎬侀�氱煡
- //宸ヤ綔4锛氬崌绾х姸鎬侀�氱煡
- if(!first){
- this.notifyUpgradeStatus() ;
- }
- }else{
- //浠诲姟鏈畬鎴愶紝缁х画鎵ц鍗囩骇鐘舵�侀�氱煡
- //宸ヤ綔4锛� 鍗囩骇鐘舵�侀�氱煡
- if(!first){
- this.notifyUpgradeStatus() ;
- }
- }
- }else{
- //浠诲姟宸茬粡瀹屾垚
+ this.nowNotifyTimesAfterOver = 0 ;
+ //鍗囩骇浠诲姟鏈畬鎴�
+ //宸ヤ綔1锛氬垽鏂槸鍚︽棤浠讳綍涓�涓猂TU杩涜杩囧崌绾э紝骞朵笖杈惧埌鏃堕檺锛屽垯璁や负褰撳墠鍗囩骇浠诲姟瀹屾垚
+ //-1:鏃犱竴RTU鍗囩骇涓旇秴鏃讹紝0锛氭棤RTU鍗囩骇浣嗘湭瓒呮椂绛夊緟锛�1鏈塕TU鍗囩骇姝e父鎵ц
+ //int temp = 1 ;
+ int temp = this.task.countNoOneRtuUpgradeInDuration() ;
+ if(temp == -1){
+ //褰撳墠娌℃湁RTU杩涜杩囧崌绾э紝鑰屼笖瓒呮椂浜嗭紝璁や负浠诲姟宸茬粡瀹屾垚
+ this.task.taskIsOver = true ;
this.stop();
+ log.info("===========================================================") ;
+ log.info("= =") ;
+ log.info("=鏃燫TU鍗囩骇瓒呮椂锛屽洜鏃犱竴鍙癛TU杩涜鍗囩骇锛屽苟涓旂瓑寰呰秴鏃讹紝寮哄埗璁剧疆鍗囩骇瀹屾垚 =") ;
+ log.info("= =") ;
+ log.info("===========================================================") ;
+ }else if(temp == 1){
+ //褰撳墠鏈塕TU杩涜杩囧崌绾�
+ //宸ヤ綔2锛氱粺璁″綋鍓嶆鍦ㄥ崌绾х殑RTU鏁伴噺锛屼负鍚屾椂鍗囩骇鏁伴噺闄愬埗鍋氬噯澶�
+ temp = this.task.countRunningRtuCount() ;
+ if(temp > 0){
+ //璇村墠褰撳墠杩樻湁鍗囩骇涓殑RTU
+ }
+
+ //宸ヤ綔3锛氱粺璁¢渶瑕佸崌绾т絾褰撳墠绂荤嚎RTU鐨勬儏鍐碉紝瓒呰繃鏃堕檺鐨勮缃负鍗囩骇瀹屾垚
+ int tmp = this.task.countOffRtuAndSetIfOver() ;
+ if(tmp >= 1){
+ //瓒呮椂锛屽己鍒惰缃竴浜汻TU鍗囩骇澶辫触骞朵笖鍗囩骇瀹屾垚
+ log.info("======================================================") ;
+ log.info("= =") ;
+ log.info("=鍥犵绾胯秴鏃讹紝寮哄埗璁剧疆" + tmp + "鍙癛TU鍗囩骇澶辫触骞朵笖鍗囩骇瀹屾垚 =") ;
+ log.info("= =") ;
+ log.info("======================================================") ;
+ }else if(tmp == 0){
+ /*
+ log.info("======================================================") ;
+ log.info("= =") ;
+ log.info("=绂荤嚎瓒呮椂锛屼絾鏃犱竴鍙癛TU鍥犵绾胯�岃璁剧疆鎴愬崌绾уけ璐ュ苟涓斿崌绾у畬鎴� =") ;
+ log.info("= =") ;
+ log.info("======================================================") ;
+ */
+ }else{//tmp = -1
+ //鏃犱换鍔¢�昏緫
+ }
+
+ //宸ヤ綔4锛氱粺璁¤繘琛屽崌绾ц繃绋嬭�屽悗鍙堝仠姝㈠崌绾э紝鍙戝憜涓�瀹氭椂闀跨殑璁惧
+ tmp = this.task.countRunningIdleRtuAndSetIfOver() ;
+ if(tmp >= 1){
+ //鍗囩骇鍙戝憜瓒呮椂锛屽己鍒惰缃竴浜汻TU鍗囩骇澶辫触骞朵笖鍗囩骇瀹屾垚
+ log.info("======================================================") ;
+ log.info("= =") ;
+ log.info("=鍥犲崌绾у彂鍛嗚秴鏃讹紝寮哄埗璁剧疆" + tmp + "鍙癛TU鍗囩骇澶辫触骞朵笖鍗囩骇瀹屾垚 =") ;
+ log.info("= =") ;
+ log.info("======================================================") ;
+ }
+
+ //宸ヤ綔5锛氱粺璁℃槸鍚﹀叏閮ㄥ崌绾у畬鎴�
+ this.task.taskIsOver = this.task.countIsAllOver() ;
+ if(this.task.taskIsOver){
+ log.info("==================================================") ;
+ log.info("= =") ;
+ log.info("= 鍗囩骇鍏ㄩ儴缁撴潫锛岃缃崌绾т换鍔″畬鎴愶紝娑夊強RTU" + this.task.taskVo.rtuAddrList.size() + "鍙� =") ;
+ log.info("= =") ;
+ log.info("==================================================") ;
+ }
+ }else if(temp == 0){
+ //褰撳墠娌℃湁涓�涓猂TU杩涜杩囧崌绾э紝涔熸病鏈夎秴鏃讹紝涓嶄綔涓�
}
+ if(this.task.taskIsOver){
+ if(!this.task.taskOverType.equals(UpgradeTask.TaskOverType_Force)){
+ //浠诲姟涓嶆槸寮哄埗缁撴潫鐨�
+ this.task.taskOverType = UpgradeTask.TaskOverType_Natural ;//浠诲姟瀹屾垚鏂瑰紡锛堣嚜鐒讹紝寮哄埗锛�
+ this.task.taskOverDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;//浠诲姟瀹屾垚鏃堕棿(yyyy-mm-dd HH:MM:SS)
+ }
+ //浠诲姟瀹屾垚锛屾墽琛屾渶鍚庝竴娆″崌绾х姸鎬侀�氱煡
+ //宸ヤ綔6锛氬崌绾х姸鎬侀�氱煡
+ //if(!first){
+ // this.notifyUpgradeStatus() ;
+ //}
+ }else{
+ //浠诲姟鏈畬鎴愶紝缁х画鎵ц鍗囩骇鐘舵�侀�氱煡
+ //宸ヤ綔6锛� 鍗囩骇鐘舵�侀�氱煡
+ //if(!first){
+ // this.notifyUpgradeStatus() ;
+ //}
+ }
+ //宸ヤ綔6锛氬崌绾х姸鎬侀�氱煡
+ if(!this.monitorFirst){
+ this.notifyUpgradeStatus() ;
+ }
+ }else{
+ //浠诲姟宸茬粡瀹屾垚
+ //宸ヤ綔6锛氫换鍔$粨鏉熷悗锛屾渶鍚庡彂鍗囩骇鐘舵�侀�氱煡
+ if(this.nowNotifyTimesAfterOver == 0){
+ this.nowNotifyTimesAfterOver++ ;
+ this.notifyUpgradeStatus() ;//蹇呴』閫氱煡涓�娆�
+ }else{
+ //鐒跺悗閲嶅閫氱煡
+ if(this.nowNotifyTimesAfterOver <= this.notifyTimesAfterOver){
+ //淇濊瘉涓婇潰蹇呴』閫氱煡涓�娆★紝閭f澶勪笂闈f涓氨寰楃敤<=
+ this.nowNotifyTimesAfterOver++ ;
+ this.notifyUpgradeStatus() ;
+ }else{
+ this.stop();
+ }
+ }
+
}
- if(first){
- first = false ;
- }
+ }
+ if(this.monitorFirst){
+ this.monitorFirst = false ;
}
return true ;
}
+
/**
* 鍗囩骇鐘舵�侀�氱煡
@@ -254,7 +344,6 @@
@Override
public void call(Object obj) {
//绾跨▼宸ヤ綔鎵ц瀹屼簡锛宱bj = Boolean(true)
- this.thread = null ;//璧嬪�间负null锛屼娇绾跨▼瀵硅薄琚瀮鍦惧洖鏀跺櫒鍥炴敹
}
@Override
public void call(Object... objs) {
--
Gitblit v1.8.0