| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import com.dy.aceMw.server.*; |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnit; |
| | | import com.dy.aceMw.server.rtuData.RtuDataUnitConfigVo; |
| | | import com.dy.aceMw.server.tasks.FromRtuConstantTask; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.mw.UnitStartedCallbackInterface; |
| | | import com.dy.common.mw.channel.rmi.RmiConfigVo; |
| | |
| | | import com.dy.common.mw.protocol.ProtocolUnit; |
| | | import com.dy.common.mw.support.SupportUnit; |
| | | import com.dy.common.mw.support.SupportUnitConfigVo; |
| | | import com.dy.aceMw.server.AdapterImp_CoreUnit; |
| | | import com.dy.aceMw.server.AdapterImp_ProtocolUnit; |
| | | import com.dy.aceMw.server.AdapterImp_RmiUnit; |
| | | import com.dy.aceMw.server.AdapterImp_TcpUnit; |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | import com.dy.aceMw.server.tasks.ToRtuConstantTask; |
| | | import com.dy.aceMw.server.AdapterImp_SupportUnit; |
| | | import com.dy.aceMw.resource.ResourceUnit; |
| | | import com.dy.aceMw.resource.ResourceUnitConfigVo; |
| | | import com.dy.aceMw.server.AdapterImp_ResourceUnit; |
| | | import com.dy.common.springUtil.SpringContextUtil; |
| | | import com.dy.common.util.ConfigXml; |
| | | import com.dy.common.util.IDLongGenerator; |
| | |
| | | //TCP上行数据时刻缓存时长,当达到时长时,TCP上行数据时刻被清空,采用TCP上行数据时刻目的是,阻止上数据同时下发数据,因为RTU处理不过来 |
| | | ServerProperties.lastUpDataTimeLive = conf.getSetAttrPlusInt(doc, "config.base", "lastUpDataTimeLive", null, 0, 5, null) * 1000L ; |
| | | //数据库数据id生成器的id后缀,0是默认的后缀,一般web系统应用,数据中间件id后缀大于等于1 |
| | | ServerProperties.dbDataIdSuffix = conf.getSetAttrInt(doc, "config.base", "dbDataIdSuffix", null, 1, 9, null); |
| | | |
| | | ServerProperties.dbDataIdSuffix = conf.getSetAttrInt(doc, "config.base", "dbDataIdSuffix", null, 0, 99, null); |
| | | //上下行数据缓存队列中缓存数据个数的报警量,这个与现实项目所接水表数相关 |
| | | ServerProperties.cacheUpDownDataWarnCount = conf.getSetAttrPlusInt(doc, "config.base", "cacheUpDownDataWarnCount", null, 1, null, null) ; |
| | | //上下行数据缓存队列中缓存数据个数的最大值,这个与现实项目所接水表数相关 |
| | | ServerProperties.cacheUpDownDataMaxCount = conf.getSetAttrPlusInt(doc, "config.base", "cacheUpDownDataMaxCount", null, 1, null, null) ; |
| | | if(ServerProperties.cacheUpDownDataMaxCount <= ServerProperties.cacheUpDownDataWarnCount){ |
| | | throw new Exception("cacheUpDownDataMaxCount必须大于cacheUpDownDataWarnCount") ; |
| | | } |
| | | |
| | | //设置ID生成器的后缀 |
| | | IDLongGenerator.setSuffix(ServerProperties.dbDataIdSuffix.intValue()); |
| | | |
| | |
| | | protoAdap.setConfig(protoVo); |
| | | ProtocolUnit protoUnit = ProtocolUnit.getInstance(); |
| | | protoUnit.setAdapter(protoAdap); |
| | | protoUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | protoUnit.start(obj -> { |
| | | }); |
| | | units.add(protoUnit) ; |
| | | |
| | |
| | | //支持模块: springHibernate和 线程池 |
| | | SupportUnitConfigVo supVo = new SupportUnitConfigVo() ; |
| | | //短工作时长线程池,线程负责用时较短的工作任务 |
| | | supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, 1, 1000, null) ;//池中最大线程数为所有CPU核数+1 |
| | | supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, 1, 5, null) ;//池中最小线程数 |
| | | supVo.short_maxThread = conf.getSetAttrPlusInt(doc, "config.support", "short_maxThread", null, -1, 1000, null) ;//池中最大线程数为所有CPU核数+1 |
| | | if(supVo.short_maxThread < 0){ |
| | | supVo.short_maxThread = -1 ; |
| | | } |
| | | supVo.short_minThread = conf.getSetAttrPlusInt(doc, "config.support", "short_minThread", null, -1, 100, null) ;//池中最小线程数 |
| | | if(supVo.short_minThread < 0){ |
| | | supVo.short_minThread = -1 ; |
| | | } |
| | | supVo.short_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_freeTimeout", null, 1, 90, null) * 1000 ;//线程数空闲时长,若池中线程数量大于minThread,且有的线程空闲时长超过freeTimeout,则清除该线程,为了不清除,把minThread与maxThread设置相等 |
| | | supVo.short_busyTimeout = conf.getSetAttrPlusInt(doc, "config.support", "short_busyTimeout", null, 1, 10, null) * 1000 ;//线程不间断工作时长(单位为秒)超时限,认为线程已经了崩溃,将强制清除,短工作时长设置为5秒 |
| | | if(supVo.short_maxThread == 0 || supVo.short_minThread == 0){ |
| | | supVo.enableShortThreadPool = false ; |
| | | }else{ |
| | | supVo.enableShortThreadPool = true ; |
| | | } |
| | | |
| | | //长工作时长线程池,线程负责用时较长的工作任务 |
| | | supVo.long_maxThread = conf.getSetAttrInt(doc, "config.support", "long_maxThread", null, -1, 1000, null) ;//池中最大线程数,若为-1,不受限制 |
| | | if(supVo.long_maxThread < 0){ |
| | | supVo.long_maxThread = -1 ; |
| | | } |
| | | supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, 0, 5, null) ;//池中最小线程数 |
| | | supVo.long_minThread = conf.getSetAttrPlusInt(doc, "config.support", "long_minThread", null, -1, 100, null) ;//池中最小线程数 |
| | | if(supVo.long_minThread < 0){ |
| | | supVo.long_minThread = -1 ; |
| | | } |
| | | supVo.long_freeTimeout = conf.getSetAttrPlusInt(doc, "config.support", "long_freeTimeout", null, 1, 90, null) * 1000 ;//线程数空闲时长,若池中线程数量大于minThread,且有的线程空闲时长超过freeTimeout,则清除该线程 |
| | | supVo.long_busyTimeout = conf.getSetAttrInt(doc, "config.support", "long_busyTimeout", null, -1, 10, null) ;//线程不间断工作时长(单位为秒)超时限,若为-1,不受限制 |
| | | if(supVo.long_busyTimeout < 0){ |
| | | supVo.long_busyTimeout = -1 ; |
| | | } |
| | | |
| | | supVo.enableThreadPool = conf.getSetAttrBoolean(doc, "config.support", "enableThreadPool", null, null) ; |
| | | |
| | | // supVo.enableSpringHibernate = conf.getSetAttrBoolean(doc, "config.support", "enableSpringHibernate", null, null) ; |
| | | // if(supVo.enableSpringHibernate){ |
| | | // supVo.springXmlFile = conf.getSetAttrTxt(doc, "config.support", "springXmlFile", null, false, null) ; |
| | | // } |
| | | |
| | | if(supVo.long_maxThread == 0 || supVo.long_minThread == 0){ |
| | | supVo.enableLongThreadPool = false ; |
| | | }else{ |
| | | supVo.enableLongThreadPool = true ; |
| | | } |
| | | |
| | | supVo.showStartInfo = showStartInfo ; |
| | | |
| | | AdapterImp_SupportUnit supAdap = new AdapterImp_SupportUnit() ; |
| | | supAdap.setConfig(supVo); |
| | | SupportUnit supUnit = SupportUnit.getInstance() ; |
| | | supUnit.setAdapter(supAdap); |
| | | supUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | supUnit.start(obj -> { |
| | | }); |
| | | units.add(supUnit) ; |
| | | |
| | |
| | | //当前支持spring + hibernate |
| | | resUnit.setSpringContext(SpringContextUtil.getApplicationContext()); |
| | | |
| | | resUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | resUnit.start(obj -> { |
| | | }); |
| | | units.add(resUnit) ; |
| | | |
| | |
| | | rmiAdap.setConfig(rmiVo); |
| | | RmiUnit rmiUnit = RmiUnit.getInstance(); |
| | | rmiUnit.setAdapter(rmiAdap); |
| | | rmiUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | rmiUnit.start(obj -> { |
| | | }); |
| | | RmiSvUrl = "[ip]:" + rmiVo.port + "/" + rmiVo.context ; |
| | | units.add(rmiUnit) ; |
| | | } |
| | | |
| | | |
| | | ///////////////// |
| | | //RTU上行数据处理模块 |
| | | RtuDataUnitConfigVo rducVo = new RtuDataUnitConfigVo(); |
| | | AdapterImp_RtuDataUnit rducAdap = new AdapterImp_RtuDataUnit(); |
| | | rducAdap.setConfig(rducVo); |
| | | RtuDataUnit rducUnit = RtuDataUnit.getInstance(); |
| | | rducUnit.setAdapter(rducAdap); |
| | | rducUnit.start(obj -> { |
| | | }); |
| | | units.add(rducUnit) ; |
| | | |
| | | |
| | | |
| | | // /////////////// |
| | | // 核心 |
| | | 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.queueWarnSize = conf.getSetAttrPlusInt(doc, "config.core", "queueWarnSize", null, 500, 1000000, null) ; |
| | | coreConfVo.queueMaxSize = conf.getSetAttrPlusInt(doc, "config.core", "queueMaxSize", null, 5000, 3000000, null) ; |
| | | coreConfVo.queueWarnSize = ServerProperties.cacheUpDownDataWarnCount ; |
| | | coreConfVo.queueMaxSize = ServerProperties.cacheUpDownDataMaxCount ; |
| | | coreConfVo.showStartInfo = showStartInfo ; |
| | | AdapterImp_CoreUnit coreAdap = new AdapterImp_CoreUnit(); |
| | | coreAdap.setConfig(coreConfVo); |
| | | CoreUnit coreUnit = CoreUnit.getInstance(); |
| | | coreUnit.setAdapter(coreAdap); |
| | | CoreUnit.addConstantTask(new ToRtuConstantTask()); |
| | | coreUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | CoreUnit.addConstantTask(new FromRtuConstantTask()); |
| | | coreUnit.start(obj -> { |
| | | }); |
| | | units.add(coreUnit) ; |
| | | |
| | |
| | | tcpAdap.setConfig(tcpVo); |
| | | TcpUnit tcpUnit = TcpUnit.getInstance(); |
| | | tcpUnit.setAdapter(tcpAdap); |
| | | tcpUnit.start(new UnitStartedCallbackInterface(){ |
| | | @Override |
| | | public void call(Object obj) { |
| | | } |
| | | tcpUnit.start(obj -> { |
| | | }); |
| | | TcpSvUrl = "[ip]:" + tcpVo.port ; |
| | | units.add(tcpUnit) ; |