|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.UnitAdapterInterface; | 
|---|
|  |  |  | import com.dy.common.mw.UnitInterface; | 
|---|
|  |  |  | import com.dy.common.mw.UnitStartedCallbackInterface; | 
|---|
|  |  |  | import com.dy.common.mw.UnitCallbackInterface; | 
|---|
|  |  |  | import com.dy.common.mw.channel.rmi.RmiFrameWork; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class RmiClUnit  implements UnitInterface { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void start(UnitStartedCallbackInterface callback) throws Exception { | 
|---|
|  |  |  | public void start(UnitCallbackInterface callback) throws Exception { | 
|---|
|  |  |  | System.out.println("Rmi Client模块成功启动"); | 
|---|
|  |  |  | this.doStart(); | 
|---|
|  |  |  | callback.call(null) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void stop(UnitStartedCallbackInterface callback) throws Exception { | 
|---|
|  |  |  | public void stop(UnitCallbackInterface callback) throws Exception { | 
|---|
|  |  |  | callback.call(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | RmiRequestVo rqVo = new RmiRequestVo() ; | 
|---|
|  |  |  | rqVo.id = id ; | 
|---|
|  |  |  | rqVo.token = token ; | 
|---|
|  |  |  | rqVo.code = Code.cd4 ; | 
|---|
|  |  |  | rqVo.code = Code.cd5; | 
|---|
|  |  |  | rqVo.count = count ; | 
|---|
|  |  |  | String json = rqVo.toJson() ; | 
|---|
|  |  |  | frmWork.syncRequest(json) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | RmiRequestVo rqVo = new RmiRequestVo() ; | 
|---|
|  |  |  | rqVo.id = id ; | 
|---|
|  |  |  | rqVo.token = token ; | 
|---|
|  |  |  | rqVo.code = Code.cd5 ; | 
|---|
|  |  |  | rqVo.code = Code.cd6; | 
|---|
|  |  |  | rqVo.overCount = count ; | 
|---|
|  |  |  | String json = rqVo.toJson() ; | 
|---|
|  |  |  | frmWork.syncRequest(json) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | RmiRequestVo rqVo = new RmiRequestVo() ; | 
|---|
|  |  |  | rqVo.id = id ; | 
|---|
|  |  |  | rqVo.token = token ; | 
|---|
|  |  |  | rqVo.code = Code.cd6 ; | 
|---|
|  |  |  | rqVo.code = Code.cd7; | 
|---|
|  |  |  | rqVo.over = true ; | 
|---|
|  |  |  | rqVo.seconds = seconds ; | 
|---|
|  |  |  | String json = rqVo.toJson() ; | 
|---|
|  |  |  | 
|---|
|  |  |  | ServerProperties.sendInterval = rVo.sendInterval ; | 
|---|
|  |  |  | ServerProperties.heartbeatTimes = rVo.heartbeatTimes ; | 
|---|
|  |  |  | ServerProperties.sendTimes = rVo.sendTimes ; | 
|---|
|  |  |  | ServerProperties.sendOverThenCloseConnect = rVo.sendOverThenCloseConnect ; | 
|---|
|  |  |  | log.info("得到配置成功"); | 
|---|
|  |  |  | log.info("    开始RtuAddr=" + ServerProperties.rtuAddrStart); | 
|---|
|  |  |  | log.info("    截止RtuAddr=" + ServerProperties.rtuAddrEnd); | 
|---|
|  |  |  | 
|---|
|  |  |  | log.info("    发送数据间隔=" + ServerProperties.sendTimes); | 
|---|
|  |  |  | log.info("    每轮次发送心跳次数=" + ServerProperties.heartbeatTimes); | 
|---|
|  |  |  | log.info("    每RTU上报数据轮次=" + ServerProperties.sendTimes); | 
|---|
|  |  |  | log.info("    发送完数据后,是否关闭TCP连接(1是,0否)=" + ServerProperties.sendOverThenCloseConnect); | 
|---|
|  |  |  | break ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi得到配置失败:json转ResConfigVo为null"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!error){ | 
|---|
|  |  |  | getStart(frmWork) ; | 
|---|
|  |  |  | getStartTcpConnect(frmWork) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //从mwTestServer得到开始上报数据的请允许 | 
|---|
|  |  |  | private void getStart(RmiFrameWork frmWork){ | 
|---|
|  |  |  | log.info("等待服务端允许上报数据"); | 
|---|
|  |  |  | //从mwTestServer得到开始TCP连接的请允许 | 
|---|
|  |  |  | private void getStartTcpConnect(RmiFrameWork frmWork){ | 
|---|
|  |  |  | log.info("等待服务端允许网络连接"); | 
|---|
|  |  |  | boolean error = false ; | 
|---|
|  |  |  | while(true){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Thread.sleep(100L); | 
|---|
|  |  |  | 
|---|
|  |  |  | String json = rqVo.toJson() ; | 
|---|
|  |  |  | Object rObj = frmWork.syncRequest(json) ; | 
|---|
|  |  |  | if(rObj != null){ | 
|---|
|  |  |  | RmiResponseVo rspVo = RmiResponseVo.jsonToObject(String.valueOf(rObj), ResStartVo.class) ; | 
|---|
|  |  |  | RmiResponseVo rspVo = RmiResponseVo.jsonToObject(String.valueOf(rObj), ResStartTcpConnectVo.class) ; | 
|---|
|  |  |  | if(rspVo != null){ | 
|---|
|  |  |  | if(rspVo.success){ | 
|---|
|  |  |  | if(rspVo.obj != null && rspVo.obj instanceof ResStartVo){ | 
|---|
|  |  |  | ResStartVo rVo = (ResStartVo)rspVo.obj ; | 
|---|
|  |  |  | if(rspVo.obj != null && rspVo.obj instanceof ResStartTcpConnectVo){ | 
|---|
|  |  |  | ResStartTcpConnectVo rVo = (ResStartTcpConnectVo)rspVo.obj ; | 
|---|
|  |  |  | if(rVo != null){ | 
|---|
|  |  |  | if(rVo.start){ | 
|---|
|  |  |  | ServerProperties.startWork = true ; | 
|---|
|  |  |  | log.info("允许上报数据工作了( ^_^ )"); | 
|---|
|  |  |  | ServerProperties.startTcpConnectWork = true ; | 
|---|
|  |  |  | log.info("允许TCP网络连接了( ^_^ )"); | 
|---|
|  |  |  | error = false ; | 
|---|
|  |  |  | break ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求启动失败:json转ResStartVo为null"); | 
|---|
|  |  |  | error = true ; | 
|---|
|  |  |  | log.error("rmi请求TCP网络连接失败:json转ResStartTcpConnectVo为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求启动失败:服务端返回ResStartVo为null"); | 
|---|
|  |  |  | error = true ; | 
|---|
|  |  |  | log.error("rmi请求TCP网络连接失败:服务端返回ResStartTcpConnectVo为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求启动失败:服务端返回错误:" + rspVo.errorInfo); | 
|---|
|  |  |  | error = true ; | 
|---|
|  |  |  | log.error("rmi请求TCP网络连接失败:服务端返回错误:" + rspVo.errorInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求启动失败:服务端返回的RmiResponseVo为null"); | 
|---|
|  |  |  | error = true ; | 
|---|
|  |  |  | log.error("rmi请求TCP网络连接失败:服务端返回的RmiResponseVo为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求启动失败:服务端返回json为null"); | 
|---|
|  |  |  | error = true ; | 
|---|
|  |  |  | log.error("rmi请求TCP网络连接失败:服务端返回json为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("rmi请求启动失败" + e.getMessage()); | 
|---|
|  |  |  | error = true ; | 
|---|
|  |  |  | log.error("rmi请求TCP网络连接失败" + e.getMessage()); | 
|---|
|  |  |  | continue ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!error){ | 
|---|
|  |  |  | getStartRtuReport(frmWork) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //从mwTestServer得到开始RTU上报数据的请允许 | 
|---|
|  |  |  | private void getStartRtuReport(RmiFrameWork frmWork){ | 
|---|
|  |  |  | log.info("等待服务端允许上报数据"); | 
|---|
|  |  |  | while(true){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Thread.sleep(100L); | 
|---|
|  |  |  | RmiRequestVo rqVo = new RmiRequestVo() ; | 
|---|
|  |  |  | rqVo.id = id ; | 
|---|
|  |  |  | rqVo.token = token ; | 
|---|
|  |  |  | rqVo.code = Code.cd4 ; | 
|---|
|  |  |  | String json = rqVo.toJson() ; | 
|---|
|  |  |  | Object rObj = frmWork.syncRequest(json) ; | 
|---|
|  |  |  | if(rObj != null){ | 
|---|
|  |  |  | RmiResponseVo rspVo = RmiResponseVo.jsonToObject(String.valueOf(rObj), ResStartRtuReportVo.class) ; | 
|---|
|  |  |  | if(rspVo != null){ | 
|---|
|  |  |  | if(rspVo.success){ | 
|---|
|  |  |  | if(rspVo.obj != null && rspVo.obj instanceof ResStartRtuReportVo){ | 
|---|
|  |  |  | ResStartRtuReportVo rVo = (ResStartRtuReportVo)rspVo.obj ; | 
|---|
|  |  |  | if(rVo != null){ | 
|---|
|  |  |  | if(rVo.report){ | 
|---|
|  |  |  | ServerProperties.startRtuReportWork = true ; | 
|---|
|  |  |  | log.info("允许RTU上报数据工作了( ^_^ )"); | 
|---|
|  |  |  | break ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求Rtu上报数据失败:json转ResStartRtuReportVo为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求Rtu上报数据失败:服务端返回ResStartRtuReportVo为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求Rtu上报数据失败:服务端返回错误:" + rspVo.errorInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求Rtu上报数据失败:服务端返回的RmiResponseVo为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | log.error("rmi请求Rtu上报数据失败:服务端返回json为null"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("rmi请求Rtu上报数据失败" + e.getMessage()); | 
|---|
|  |  |  | continue ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|