| | |
| | | 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 Integer ugMaxRtuSameTime ;//同时升级RTU最大个数 |
| | | |
| | | private UpgradeTask task ;//升级任务 |
| | | private boolean monitorFirst = true ;//是否是第一次监视 |
| | | |
| | | private UpgradeManager(){} |
| | | private UpgradeManager(){ |
| | | monitorFirst = true ; |
| | | } |
| | | |
| | | public static UpgradeManager getInstance() { |
| | | return UpgradeManager.INSTANCE; |
| | |
| | | /** |
| | | * 设置升级任务 |
| | | * @param vo UpgradeTaskVo 升级任务对象 |
| | | * @throws Exception |
| | | * @throws Exception 异常 |
| | | */ |
| | | public void setUpgradeTask(UpgradeTaskVo vo) throws Exception { |
| | | if(this.task != null && !this.task.taskIsOver){ |
| | |
| | | this.task = null ; |
| | | throw ex ; |
| | | }else{ |
| | | this.start(this); |
| | | this.start(1000L, (long) UpgradeUnit.confVo.notifyStateInterval, this); |
| | | } |
| | | } |
| | | } |
| | |
| | | * 此功能可能不会开放出去, |
| | | * 因为强制结束升级任务,对一个未升级完成的RTU就会卡死, |
| | | * 所以当强制结束升级任务,代码逻辑并没有强制结果RTU升级过程,如果升级过程也强制停止,那么RTU真会卡死 |
| | | * @throws Exception |
| | | */ |
| | | public void forceOverUpgradeTask() throws Exception { |
| | | public void forceOverUpgradeTask() { |
| | | if(this.task != null){ |
| | | this.stop(); |
| | | this.task.forceOver(); |
| | |
| | | |
| | | /** |
| | | * RTU有上行数据了,触发下发升级数据 |
| | | * @param rtuAddr |
| | | * @param code |
| | | * @param protocolName |
| | | * @param protocolVersion |
| | | * @param callbackCom |
| | | * @param rtuAddr 控制器RTU地址 |
| | | * @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){ |
| | |
| | | //////////////////////////////////////////////////// |
| | | /** |
| | | * 当前升级状态 |
| | | * @return |
| | | * @return 当前升级状态 |
| | | */ |
| | | public UpgradeState currentUpgradeState() { |
| | | if(task != null){ |
| | |
| | | |
| | | /** |
| | | * Rtu升级信息 |
| | | * @param rtuAddr |
| | | * @return |
| | | * @param rtuAddr 控制器RTU地址 |
| | | * @return 控制器RTU升级状态 |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public UpgradeRtu upgradeRtuInfo(String rtuAddr){ |
| | | if(task != null){ |
| | | return task.upgradeInfos(rtuAddr) ; |
| | |
| | | |
| | | /** |
| | | * Rtu升级信息 |
| | | * @param rtuAddrList |
| | | * @return |
| | | * @param rtuAddrList 控制器地址列表 |
| | | * @return 指定列表中的控制器RTU升级状态 |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public List<UpgradeRtu> upgradeRtuInfos(List<String> rtuAddrList){ |
| | | if(task != null){ |
| | | return task.upgradeInfos(rtuAddrList) ; |
| | |
| | | |
| | | |
| | | /** |
| | | * Rtu升级信息 |
| | | * @return |
| | | * 所有Rtu升级信息 |
| | | * @return 所有Rtu升级信息 |
| | | */ |
| | | public List<UpgradeRtu> upgradeRtuInfoAll(){ |
| | | if(task != null){ |
| | |
| | | // 统计状态 + 状态通知 |
| | | // |
| | | //////////////////////////////////////////////////// |
| | | @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){ |
| | | } |
| | | }else{ |
| | | try{ |
| | | //停X毫秒 |
| | | Thread.sleep(UpgradeUnit.confVo.notifyStateInterval); |
| | | }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){ |
| | | //任务为空 |
| | | break ; |
| | | this.stop() ; |
| | | }else{ |
| | | if(!this.task.taskIsOver){ |
| | | //升级任务未完成 |
| | |
| | | //} |
| | | } |
| | | //工作5:升级状态通知 |
| | | if(!first){ |
| | | if(!this.monitorFirst){ |
| | | this.notifyUpgradeStatus() ; |
| | | } |
| | | }else{ |
| | |
| | | this.stop(); |
| | | } |
| | | } |
| | | if(first){ |
| | | first = false ; |
| | | } |
| | | if(this.monitorFirst){ |
| | | this.monitorFirst = false ; |
| | | } |
| | | return true ; |
| | | } |
| | |
| | | @Override |
| | | public void call(Object obj) { |
| | | //线程工作执行完了,obj = Boolean(true) |
| | | this.thread = null ;//赋值为null,使线程对象被垃圾回收器回收 |
| | | } |
| | | @Override |
| | | public void call(Object... objs) { |