|  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | import com.dy.common.util.ConfigProperties; | 
 |  |  | import com.dy.common.util.IPUtils; | 
 |  |  | import com.dy.rtuMw.server.*; | 
 |  |  | import com.dy.rtuMw.server.mqtt.MqttUnit; | 
 |  |  | import com.dy.rtuMw.server.mqtt.MqttUnitConfigVo; | 
 |  |  | import com.dy.rtuMw.server.msCenter.MsCenterConfigVo; | 
 |  |  | import com.dy.rtuMw.server.msCenter.MsCenterUnit; | 
 |  |  | import com.dy.rtuMw.server.rtuData.RtuDataUnit; | 
 |  |  | import com.dy.rtuMw.server.rtuData.RtuDataUnitConfigVo; | 
 |  |  | import com.dy.rtuMw.server.tasks.FromRtuComResultConstantTask; | 
 |  |  | import com.dy.rtuMw.server.tasks.FromRtuDataConstantTask; | 
 |  |  | import com.dy.rtuMw.server.tasks.*; | 
 |  |  | import com.dy.common.mw.UnitInterface; | 
 |  |  | import com.dy.common.mw.channel.rmi.RmiConfigVo; | 
 |  |  | import com.dy.common.mw.channel.rmi.RmiUnit; | 
 |  |  | import com.dy.common.mw.channel.tcp.TcpConfigVo; | 
 |  |  | import com.dy.common.mw.channel.tcp.TcpUnit; | 
 |  |  | import com.dy.common.mw.core.CoreUnit; | 
 |  |  | 
 |  |  | import com.dy.common.mw.protocol.ProtocolUnit; | 
 |  |  | import com.dy.common.mw.support.SupportUnit; | 
 |  |  | import com.dy.common.mw.support.SupportUnitConfigVo; | 
 |  |  | import com.dy.rtuMw.server.tasks.ToRtuConstantTask; | 
 |  |  | import com.dy.rtuMw.resource.ResourceUnit; | 
 |  |  | import com.dy.rtuMw.resource.ResourceUnitConfigVo; | 
 |  |  | import com.dy.common.springUtil.SpringContextUtil; | 
 |  |  | import com.dy.common.util.ConfigXml; | 
 |  |  | import com.dy.common.util.ConfigXml4Springboot; | 
 |  |  | import com.dy.common.util.IDLongGenerator; | 
 |  |  |  | 
 |  |  | import com.dy.rtuMw.server.upgrade.UpgradeUnit; | 
 |  |  | import com.dy.rtuMw.server.upgrade.UpgradeUnitConfigVo; | 
 |  |  | import org.jdom2.Document; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.core.io.ResourceLoader; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  |  | 
 |  |  | @Component | 
 |  |  | public class Server { | 
 |  |  |  | 
 |  |  |    private ConfigXml conf = null ; | 
 |  |  |    private ConfigXml4Springboot conf = null ; | 
 |  |  |    private Document doc = null ; | 
 |  |  |    private boolean showStartInfo = false ; | 
 |  |  |     | 
 |  |  |    private String orgTag ; | 
 |  |  |    private String RmiSvUrl ; | 
 |  |  |    private String TcpSvUrl ; | 
 |  |  |    @Value("${server.port}") | 
 |  |  |    private String HttpSvPort ; | 
 |  |  |    @Value("${server.servlet.context-path}") | 
 |  |  |    private String HttpSvPath ; | 
 |  |  |  | 
 |  |  |    @Autowired | 
 |  |  |    protected ResourceLoader resourceLoader ; | 
 |  |  |  | 
 |  |  |    private List<UnitInterface> units = new ArrayList<UnitInterface>() ; | 
 |  |  |  | 
 |  |  | 
 |  |  |       new Server().startServer(); | 
 |  |  |    } | 
 |  |  |    */ | 
 |  |  |  | 
 |  |  |    public void  startServer(){ | 
 |  |  |       /** | 
 |  |  |       try { | 
 |  |  |          URL url = Server.class.getResource("/config/this.licence"); | 
 |  |  |          if(!new Lnp(null).parese(url.getPath())){ | 
 |  |  |             System.out.println("licence error!") ; | 
 |  |  |             return ; | 
 |  |  |          } | 
 |  |  |       } catch (Exception e) { | 
 |  |  |          System.out.println("licence error!") ; | 
 |  |  |          return ; | 
 |  |  |       } | 
 |  |  |       */ | 
 |  |  |       if(this.doStartServer()){ | 
 |  |  |          ServerShutDownHook.OnShutDown(); | 
 |  |  |       } | 
 |  |  |    } | 
 |  |  |    /** | 
 |  |  |     * 启动服务 | 
 |  |  |      */ | 
 |  |  |    public void startServer(){ | 
 |  |  | //      try { | 
 |  |  | //         URL url = Server.class.getResource("/config/this.licence"); | 
 |  |  | //         if(!new Lnp(null).parese(url.getPath())){ | 
 |  |  | //            System.out.println("zhzc licence error!") ;    | 
 |  |  | //            return ; | 
 |  |  | //         } | 
 |  |  | //      } catch (Exception e) { | 
 |  |  | //         System.out.println("zhzc licence error!") ;  | 
 |  |  | //         return ; | 
 |  |  | //      } | 
 |  |  |       //Server sv = new Server(); | 
 |  |  |    private boolean doStartServer(){ | 
 |  |  |       boolean running = false ; | 
 |  |  |       long start = System.currentTimeMillis() ; | 
 |  |  |       try { | 
 |  |  |          //ConfigProperties.init(this.getClass().getResourceAsStream("/config/config.properties"), false); | 
 |  |  |          ConfigProperties.init(this.getClass().getResourceAsStream("/config.properties"), false); | 
 |  |  |           | 
 |  |  |          this.conf = new ConfigXml() ; | 
 |  |  |          this.doc = this.conf.createDom(this.getClass(), "config.xml") ; | 
 |  |  |          this.conf = new ConfigXml4Springboot() ; | 
 |  |  |          this.doc = this.conf.createDom(this.resourceLoader, "config.xml") ; | 
 |  |  |          //////////////// | 
 |  |  |          //服务 配置 | 
 |  |  |          this.showStartInfo = this.conf.getSetAttrBoolean(this.doc, "config.server", "showStartInfo", null, null) ; | 
 |  |  | 
 |  |  |             }catch(Exception e){ | 
 |  |  |                company = "" ; | 
 |  |  |             } | 
 |  |  |             System.out.println("OOOOOOOOOO           OOOOOOOO       OOOOOOOO") ; | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@#O    $@@@@@@@@&    @@@@@@@@#") ;        | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@#    @@@@@@@@# $@@@@@@@@&") ;         | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@@@#   #@@@@@@@@@@@@@@@@O") ;     | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@@@@@   &@@@@@@@@@@@@@@") ;            | 
 |  |  |             System.out.println("@@@@@@$      $@@@@@@@@@&   O@@@@@@@@@@@#") ;         | 
 |  |  |             System.out.println("@@@@@@$        @@@@@@@@@     @@@@@@@@@&      " + svName + "RtuMw 1.0.00" ) ;              | 
 |  |  |             System.out.println("$$$$$$$$$$$$         $$$$$$$$       $$$$$$$$") ; | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@#$    $@@@@@@@@&    @@@@@@@@#") ; | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@#    @@@@@@@@# $@@@@@@@@&") ; | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@@@#   #@@@@@@@@@@@@@@@@$") ; | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@@@@@   &@@@@@@@@@@@@@@") ; | 
 |  |  |             System.out.println("@@@@@@$      $@@@@@@@@@&   $@@@@@@@@@@@#") ; | 
 |  |  |             System.out.println("@@@@@@$        @@@@@@@@@     @@@@@@@@@&      " + this.orgTag + svName + "RtuMw 1.0.00" ) ; | 
 |  |  |          if(this.HttpSvPath != null && this.HttpSvPort != null){ | 
 |  |  |             System.out.println("@@@@@@$       O@@@@@@@@@     &@@@@@@@@       HttpSv [ip]:" + this.HttpSvPort + this.HttpSvPath) ; | 
 |  |  |          }else{ | 
 |  |  | 
 |  |  |             }else{ | 
 |  |  |                 System.out.println("@@@@@@$      #@@@@@@@@@$     &@@@@@@@@" ) ;         | 
 |  |  |             } | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@@@@#      &@@@@@@@@       Runing in standalone mode" ) ;     | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@@@@#      &@@@@@@@@       Running in standalone mode" ) ; | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@@@&       &@@@@@@@@       Startup in " + (System.currentTimeMillis() - start) + " MS" ) ;               | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@@@@#         &@@@@@@@@       " + company) ;             | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@#O           &@@@@@@@@") ;               | 
 |  |  |  | 
 |  |  |             System.out.println("@@@@@@@@@@@@@@@@#O           &@@@@@@@@") ; | 
 |  |  |          running = true ; | 
 |  |  |       }catch(Exception e){ | 
 |  |  |          e.printStackTrace(); | 
 |  |  |          running = false ; | 
 |  |  |       } | 
 |  |  |       return running ; | 
 |  |  |    } | 
 |  |  |     | 
 |  |  |    private void startUnits(){ | 
 |  |  | 
 |  |  |          /////////////// | 
 |  |  |          //基本配置 | 
 |  |  |          ServerProperties.orgTag = this.conf.getSetAttrTxt(this.doc, "config.base", "orgTag", null, false, null) ; | 
 |  |  |          if(ServerProperties.orgTag==null || ServerProperties.orgTag.trim().equals("")){ | 
 |  |  |          if(ServerProperties.orgTag == null || ServerProperties.orgTag.trim().equals("")){ | 
 |  |  |             throw new Exception("机构tag不能为空") ; | 
 |  |  |          } | 
 |  |  |          this.orgTag = ServerProperties.orgTag ; | 
 |  |  |          ServerProperties.isLowPower = conf.getSetAttrBoolean(doc, "config.base", "isLowPower", null, null) ;  | 
 |  |  |          if(ServerProperties.isLowPower == null){ | 
 |  |  |             ServerProperties.isLowPower = false ; | 
 |  |  | 
 |  |  |          ServerProperties.downComandMaxResendTimes = conf.getSetAttrPlusInt(doc, "config.base", "downComandMaxResendTimes", null, 1, 5, null).byteValue() ; | 
 |  |  |          //针对一个RTU,下发命令的时间间隔 | 
 |  |  |          ServerProperties.commandSendInterval = conf.getSetAttrPlusInt(doc, "config.base", "commandSendInterval", null, 1, 40, null) * 1000L ; | 
 |  |  |          //针对一个RTU,下发快速命令的时间间隔 | 
 |  |  |          ServerProperties.fastCommandSendInterval = conf.getSetAttrPlusInt(doc, "config.base", "fastCommandSendInterval", null, 1, 40000, null) * 1L ; | 
 |  |  |          //命令已经发送达最大次数,仍未收到命令结果,需要在缓存继续等待,其等待最大时长 | 
 |  |  |          ServerProperties.cachWaitResultTimeout = conf.getSetAttrPlusInt(doc, "config.base", "cachWaitResultTimeout", null, 10, 360, null) * 1000L ; | 
 |  |  |          ServerProperties.cacheWaitResultTimeout = conf.getSetAttrPlusInt(doc, "config.base", "cacheWaitResultTimeout", null, 10, 360, null) * 1000L ; | 
 |  |  |          //不在线缓存的命令最大缓存时长 | 
 |  |  |          ServerProperties.offLineCachTimeout = conf.getSetAttrPlusInt(doc, "config.base", "offLineCachTimeout", null, 15, 172800, null) * 1000L ; | 
 |  |  |          ServerProperties.offLineCacheTimeout = conf.getSetAttrPlusInt(doc, "config.base", "offLineCacheTimeout", null, 15, 172800, null) * 1000L ; | 
 |  |  |          //TCP上行数据时刻缓存时长,当达到时长时,TCP上行数据时刻被清空,采用TCP上行数据时刻目的是,阻止上数据同时下发数据,因为RTU处理不过来 | 
 |  |  |          ServerProperties.lastUpDataTimeLive = conf.getSetAttrPlusInt(doc, "config.base", "lastUpDataTimeLive", null, 0, 5000, null) * 1L ; | 
 |  |  |          //数据库数据id生成器的id后缀,0是默认的后缀,一般web系统应用,数据中间件id后缀大于等于1 | 
 |  |  | 
 |  |  |          if(ServerProperties.cacheUpDownDataMaxCount <= ServerProperties.cacheUpDownDataWarnCount){ | 
 |  |  |             throw new Exception("cacheUpDownDataMaxCount必须大于cacheUpDownDataWarnCount") ; | 
 |  |  |          } | 
 |  |  |          //没有上行数据的分钟数,达到这个分钟数,认为RTU断网了,取值范围是2_100 | 
 |  |  |          //没有上行数据的分钟数,达到这个分钟数,认为RTU断网了,取值范围是2-100 | 
 |  |  |          ServerProperties.disconnectedByNoUpDataMinutes =  0L + conf.getSetAttrPlusInt(doc, "config.base", "disconnectedByNoUpDataMinutes", null, 1, 100, null) ; | 
 |  |  |          if(ServerProperties.disconnectedByNoUpDataMinutes < 1 || ServerProperties.disconnectedByNoUpDataMinutes > 100){ | 
 |  |  |             throw new Exception("disconnectedByNoUpDataMinutes取值必须是1~100") ; | 
 |  |  |          } | 
 |  |  |          ServerProperties.disconnectedByNoUpDataMinutes = ServerProperties.disconnectedByNoUpDataMinutes * 60 * 1000 ; | 
 |  |  |  | 
 |  |  |          //工作报太频繁,N次上报处理1次,取值范围是1-100 | 
 |  |  |          ServerProperties.workReportDealOneByTimes =  conf.getSetAttrPlusInt(doc, "config.base", "workReportDealOneByTimes", null, 1, 100, null) ; | 
 |  |  |  | 
 |  |  |          //触发发送钉钉报警消息的取水口日漏损量的最小值(包括但除0.0外) | 
 |  |  |          ServerProperties.intakeAlarmLossMinValue =  conf.getSetAttrPlusDouble(doc, "config.base", "intakeAlarmLossMinValue", null, 0.0, 1000000.0, null) ; | 
 |  |  |  | 
 |  |  |          //有报警发生时,向钉钉发送消息的间隔时长(分钟) | 
 |  |  |          ServerProperties.sendDingDingAlarmMsInterval =  conf.getSetAttrPlusInt(doc, "config.base", "sendDingDingAlarmMsInterval", null, 1, 600, null) ; | 
 |  |  |  | 
 |  |  |          //设置ID生成器的后缀 | 
 |  |  |          IDLongGenerator.setSuffix(ServerProperties.dbDataIdSuffix.intValue()); | 
 |  |  | 
 |  |  |          //RTU日志文件存储目录(相对目录) | 
 |  |  |          resVo.rtuLogDir = conf.getSetAttrTxt(doc, "config.resource", "rtuLogDir", null, false, null) ; | 
 |  |  |          //RTU日志文件最大字节数(KB) | 
 |  |  |          resVo.rtuLogFileMaxSize = conf.getSetAttrPlusInt(doc, "config.resource", "rtuLogFileMaxSize", null, 100000, 2000000, null) ; | 
 |  |  |          resVo.rtuLogFileMaxSize = conf.getSetAttrPlusInt(doc, "config.resource", "rtuLogFileMaxSize", null, 10, 2000000, null) ; | 
 |  |  |          //RTU日志文件最大文件数 | 
 |  |  |          resVo.rtuLogFileMaxCount = conf.getSetAttrPlusInt(doc, "config.resource", "rtuLogFileMaxCount", null, 1, 10, null) ;  | 
 |  |  |           | 
 |  |  | 
 |  |  |  | 
 |  |  |           | 
 |  |  |          ///////////////// | 
 |  |  |          //RMI模块 | 
 |  |  |          //RMI模块 暂时不应用 | 
 |  |  |          /* | 
 |  |  |          RmiConfigVo rmiVo = new RmiConfigVo(); | 
 |  |  |          rmiVo.enable = conf.getSetAttrBoolean(doc, "config.rmi", "enable", null, null) ; | 
 |  |  |          if(rmiVo.enable){ | 
 |  |  | 
 |  |  |             RmiSvUrl = "[ip]:" + rmiVo.port + "/" + rmiVo.context ; | 
 |  |  |             units.add(rmiUnit) ; | 
 |  |  |          } | 
 |  |  |          */ | 
 |  |  |  | 
 |  |  |  | 
 |  |  |          ///////////////// | 
 |  |  |          //RTU上行数据处理模块 | 
 |  |  |          //消息中心模块 | 
 |  |  |          MsCenterConfigVo mscVo = new MsCenterConfigVo(); | 
 |  |  |          mscVo.enable = conf.getSetAttrBoolean(doc, "config.msCenter", "enable", null, null) ; | 
 |  |  |          mscVo.notifyMsInterval = conf.getSetAttrPlusInt(doc, "config.msCenter", "notifyInterval", null, 1, 600, null) * 1000L ; | 
 |  |  |          mscVo.showStartInfo = showStartInfo ; | 
 |  |  |          AdapterImp_MsCenterUnit mscAdapt = new AdapterImp_MsCenterUnit(); | 
 |  |  |          mscAdapt.setConfig(mscVo); | 
 |  |  |          MsCenterUnit mscUnit = MsCenterUnit.getInstance(); | 
 |  |  |          mscUnit.setAdapter(mscAdapt); | 
 |  |  |          mscUnit.start(obj -> { | 
 |  |  |          }); | 
 |  |  |          units.add(mscUnit) ; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |          ///////////////// | 
 |  |  |          //RTU远程升级模块 | 
 |  |  |          UpgradeUnitConfigVo ugVo = new UpgradeUnitConfigVo(); | 
 |  |  |          ugVo.enable = conf.getSetAttrBoolean(doc, "config.upgrade", "enable", null, null) ; | 
 |  |  |          if(ugVo.enable){ | 
 |  |  |             ugVo.openNoUpgrade = conf.getSetAttrBoolean(doc, "config.upgrade", "openNoUpgrade", null, null) ; | 
 |  |  |             ugVo.lastOpenMaxGoOn = conf.getSetAttrPlusInt(doc, "config.upgrade", "lastOpenMaxGoOn", null, 5, 360000, null); | 
 |  |  |             ugVo.lastOpenMaxGoOn = ugVo.lastOpenMaxGoOn * 1000 ;//变成毫秒 | 
 |  |  |             ugVo.noOneRtuUpgradeMaxDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "noOneRtuUpgradeMaxDuration", null, 5, 360000, null); | 
 |  |  |             ugVo.noOneRtuUpgradeMaxDuration = ugVo.noOneRtuUpgradeMaxDuration * 1000 ;//变成毫秒 | 
 |  |  |             ugVo.runningAndIdleDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "runningAndIdleDuration", null, 5, 360000, null); | 
 |  |  |             ugVo.runningAndIdleDuration = ugVo.runningAndIdleDuration * 1000 ;//变成毫秒 | 
 |  |  |             ugVo.failTryTimes = conf.getSetAttrPlusInt(doc, "config.upgrade", "failTryTimes", null, 0, 100, null); | 
 |  |  |             ugVo.ugMaxRtuAtOnce = conf.getSetAttrPlusInt(doc, "config.upgrade", "ugMaxRtuAtOnce", null, 0, 1000000, null); | 
 |  |  |             ugVo.rtuOffLineWaitDuration = conf.getSetAttrPlusInt(doc, "config.upgrade", "rtuOffLineWaitDuration", null, 1, 3600000, null); | 
 |  |  |             ugVo.rtuOffLineWaitDuration = ugVo.rtuOffLineWaitDuration * 1000;//变成毫秒 | 
 |  |  |             ugVo.notifyStateInterval = conf.getSetAttrPlusInt(doc, "config.upgrade", "notifyStateInterval", null, 1, 300, null); | 
 |  |  |             ugVo.notifyStateInterval = ugVo.notifyStateInterval * 1000;//变成毫秒 | 
 |  |  |             ugVo.notifyTimesAfterOver = conf.getSetAttrPlusInt(doc, "config.upgrade", "notifyTimesAfterOver", null, 0, null, null); | 
 |  |  |             ugVo.showStartInfo = showStartInfo ; | 
 |  |  |             AdapterImp_UpgradeUnit ugAdap = new AdapterImp_UpgradeUnit(); | 
 |  |  |             ugAdap.setConfig(ugVo); | 
 |  |  |             UpgradeUnit ugUnit = UpgradeUnit.getInstance(); | 
 |  |  |             ugUnit.setAdapter(ugAdap); | 
 |  |  |             ugUnit.start(obj -> { | 
 |  |  |             }); | 
 |  |  |             units.add(ugUnit) ; | 
 |  |  |          } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |          ///////////////// | 
 |  |  |          //RTU上行数据处理模块(任务树) | 
 |  |  |          RtuDataUnitConfigVo rducVo = new RtuDataUnitConfigVo(); | 
 |  |  |          rducVo.resourceLoader = this.resourceLoader ; | 
 |  |  |          AdapterImp_RtuDataUnit rducAdap = new AdapterImp_RtuDataUnit(); | 
 |  |  |          rducAdap.setConfig(rducVo); | 
 |  |  |          RtuDataUnit rducUnit = RtuDataUnit.getInstance(); | 
 |  |  | 
 |  |  |          // /////////////// | 
 |  |  |          // 核心 | 
 |  |  |          CoreUnitConfigVo coreConfVo = new CoreUnitConfigVo(); | 
 |  |  |          coreConfVo.sleepBigBusy = conf.getSetAttrPlusInt(doc, "config.core", "sleepBigBusy", null, 1, 200, null).longValue() ; | 
 |  |  |          coreConfVo.sleepSmallBusy = conf.getSetAttrPlusInt(doc, "config.core", "sleepSmallBusy", null, 2, 1000, null).longValue(); | 
 |  |  |          coreConfVo.coreInterval = conf.getSetAttrPlusInt(doc, "config.core", "coreInterval", null, 1, 200, null).longValue() ; | 
 |  |  |          coreConfVo.queueWarnSize = ServerProperties.cacheUpDownDataWarnCount ; | 
 |  |  |          coreConfVo.queueMaxSize = ServerProperties.cacheUpDownDataMaxCount ; | 
 |  |  |          coreConfVo.showStartInfo = showStartInfo ; | 
 |  |  | 
 |  |  |          coreAdap.setConfig(coreConfVo); | 
 |  |  |          CoreUnit coreUnit = CoreUnit.getInstance(); | 
 |  |  |          coreUnit.setAdapter(coreAdap); | 
 |  |  |          CoreUnit.addConstantTask(new ToRtuConstantTask()); | 
 |  |  |          CoreUnit.addConstantTask(new RtuDownConstantTask()); | 
 |  |  |          CoreUnit.addConstantTask(new FromRtuDataConstantTask()); | 
 |  |  |          CoreUnit.addConstantTask(new FromRtuComResultConstantTask()); | 
 |  |  |          Boolean enableMq = conf.getSetAttrBoolean(doc, "config.mqtt", "enable", null, null) ; | 
 |  |  |          if(enableMq != null && enableMq.booleanValue()){ | 
 |  |  |             CoreUnit.addConstantTask(new MqttSubMessageConstantTask()); | 
 |  |  |             CoreUnit.addConstantTask(new MqttPubMessageConstantTask()); | 
 |  |  |             CoreUnit.addConstantTask(new MqttComResultConstantTask()); | 
 |  |  |          } | 
 |  |  |          CoreUnit.addConstantTask(new SendMsConstantTask()); | 
 |  |  |          coreUnit.start(obj -> { | 
 |  |  |          }); | 
 |  |  |          units.add(coreUnit) ; | 
 |  |  | 
 |  |  |             }); | 
 |  |  |             TcpSvUrl = "[ip]:" + tcpVo.port ; | 
 |  |  |             units.add(tcpUnit) ; | 
 |  |  |          }	 | 
 |  |  |          } | 
 |  |  |  | 
 |  |  |          ///////////////// | 
 |  |  |          //MQTT模块 | 
 |  |  |          MqttUnitConfigVo mqVo = new MqttUnitConfigVo(); | 
 |  |  |          mqVo.enable = conf.getSetAttrBoolean(doc, "config.mqtt", "enable", null, null) ; | 
 |  |  |          ServerProperties.mqttUnitEnable = mqVo.enable ; | 
 |  |  |          if(mqVo.enable){ | 
 |  |  |             mqVo.svIp = conf.getSetAttrTxt(doc, "config.mqtt", "svIp", null, false, null) ; | 
 |  |  |             if(!IPUtils.ipValid(mqVo.svIp)){ | 
 |  |  |                throw new Exception("config.mqtt.svIp配置的IP不合法") ; | 
 |  |  |             } | 
 |  |  |             mqVo.svPort = conf.getSetAttrPlusInt(doc, "config.mqtt", "svPort", null, 5, 360000, null); | 
 |  |  |             if(mqVo.svPort < 0 || mqVo.svPort > 65535){ | 
 |  |  |                throw new Exception("config.mqtt.svPort配置的端口不合法") ; | 
 |  |  |             } | 
 |  |  |             mqVo.svUserName = conf.getSetAttrTxt(doc, "config.mqtt", "svUserName", null, false, null) ; | 
 |  |  |             if(mqVo.svUserName == null || mqVo.svUserName.trim().equals("")){ | 
 |  |  |                throw new Exception("config.mqtt.svUserName配置的用户名不合法") ; | 
 |  |  |             }else{ | 
 |  |  |                mqVo.svUserName = mqVo.svUserName.trim() ; | 
 |  |  |             } | 
 |  |  |             mqVo.svUserPassword = conf.getSetAttrTxt(doc, "config.mqtt", "svUserPassword", null, false, null) ; | 
 |  |  |             if(mqVo.svUserPassword == null || mqVo.svUserPassword.trim().equals("")){ | 
 |  |  |                throw new Exception("config.mqtt.svUserName配置的用户密码不合法") ; | 
 |  |  |             }else{ | 
 |  |  |                mqVo.svUserPassword = mqVo.svUserPassword.trim() ; | 
 |  |  |             } | 
 |  |  |             mqVo.poolMaxSize = conf.getSetAttrPlusInt(doc, "config.mqtt", "poolMaxSize", null, 1, 1000, null); | 
 |  |  |  | 
 |  |  |             mqVo.sendInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "sendInterval", null, 1, 3600, null) * 1000L ; | 
 |  |  |  | 
 |  |  |             mqVo.reSendTimesByNoResult = conf.getSetAttrPlusInt(doc, "config.mqtt", "reSendTimesByNoResult", null, 0, 100, null); | 
 |  |  |  | 
 |  |  |             mqVo.comCacheTimeout = conf.getSetAttrPlusInt(doc, "config.mqtt", "comCacheTimeout", null, 1, 3600, null) * 1000L ; | 
 |  |  |  | 
 |  |  |             ServerProperties.acceptManureDataMinInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "acceptManureDataMinInterval", null, 1, 720, null) * 60 * 1000L ; | 
 |  |  |             ServerProperties.acceptSoilDataMinInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "acceptSoilDataMinInterval", null, 1, 720, null) * 60 * 1000L ; | 
 |  |  |             ServerProperties.acceptWeatherDataMinInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "acceptWeatherDataMinInterval", null, 1, 720, null) * 60 * 1000L ; | 
 |  |  |  | 
 |  |  |             mqVo.useMemoryPersistence = conf.getSetAttrBoolean(doc, "config.mqtt", "useMemoryPersistence", null, null) ; | 
 |  |  |             String proAndDevIds = conf.getSetAttrTxt(doc, "config.mqtt", "protocolAndDeviceIds", null, true, null) ; | 
 |  |  |             if(proAndDevIds != null && !proAndDevIds.trim().equals("")){ | 
 |  |  |                proAndDevIds = proAndDevIds.trim() ; | 
 |  |  |                proAndDevIds = proAndDevIds.replaceAll(",", ","); | 
 |  |  |                proAndDevIds = proAndDevIds.replaceAll(";", ";"); | 
 |  |  |                proAndDevIds = proAndDevIds.replaceAll("\\\\", "/"); | 
 |  |  |                mqVo.protocolAndDeviceIds = proAndDevIds.split(",") ; | 
 |  |  |                mqVo.deviceIds = new String[mqVo.protocolAndDeviceIds.length] ; | 
 |  |  |                int index = 0 ; | 
 |  |  |                for(String topicAndQosStr : mqVo.protocolAndDeviceIds){ | 
 |  |  |                   String[] pd = topicAndQosStr.split("/") ; | 
 |  |  |                   mqVo.deviceIds[index] = pd[1].trim() ; | 
 |  |  |                   index++ ; | 
 |  |  |                } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             String subTopicAndQos = conf.getSetAttrTxt(doc, "config.mqtt", "subTopicAndQos", null, true, null) ; | 
 |  |  |             if(subTopicAndQos != null && !subTopicAndQos.trim().equals("")){ | 
 |  |  |                subTopicAndQos = subTopicAndQos.trim() ; | 
 |  |  |                subTopicAndQos = subTopicAndQos.replaceAll(",", ","); | 
 |  |  |                subTopicAndQos = subTopicAndQos.replaceAll(";", ";"); | 
 |  |  |                String[] topicAndQosArr = subTopicAndQos.split(";") ; | 
 |  |  |                mqVo.subTopics = new String[topicAndQosArr.length] ; | 
 |  |  |                mqVo.subTopicsQos = new int[topicAndQosArr.length] ; | 
 |  |  |                int index = 0 ; | 
 |  |  |                for(String topicAndQosStr : topicAndQosArr){ | 
 |  |  |                   String[] tq = topicAndQosStr.split(",") ; | 
 |  |  |                   mqVo.subTopics[index] = tq[0].trim() ; | 
 |  |  |                   mqVo.subTopicsQos[index] = Integer.parseInt(tq[1].trim()) ; | 
 |  |  |                   index++ ; | 
 |  |  |                } | 
 |  |  |             } | 
 |  |  |             mqVo.pubTopicQos = conf.getSetAttrPlusInt(doc, "config.mqtt", "pubTopicQos", null, 0, 3, null); | 
 |  |  |             if(mqVo.pubTopicQos < 0 || mqVo.pubTopicQos > 3){ | 
 |  |  |                throw new Exception("config.mqtt.pubTopicQos配置不合法") ; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             Integer intNoSubThenOff = conf.getSetAttrPlusInt(doc, "config.mqtt", "noSubThenOff", null, 1, 1440, null); | 
 |  |  |             mqVo.noSubThenOff = intNoSubThenOff * 60 * 1000L ; | 
 |  |  |  | 
 |  |  |             mqVo.showStartInfo = showStartInfo ; | 
 |  |  |             AdapterImp_MqttUnit mqAdapt = new AdapterImp_MqttUnit(); | 
 |  |  |             mqAdapt.setConfig(mqVo); | 
 |  |  |             MqttUnit mqUnit = MqttUnit.getInstance(); | 
 |  |  |             mqUnit.setAdapter(mqAdapt); | 
 |  |  |             mqUnit.start(obj -> { | 
 |  |  |             }); | 
 |  |  |             units.add(mqUnit) ; | 
 |  |  |          } | 
 |  |  |  | 
 |  |  |       } catch (Exception e) { | 
 |  |  |          e.printStackTrace(); | 
 |  |  |       }       |