| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.simRtu.tcpClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.UnitAdapterInterface; | 
|---|
|  |  |  | import com.dy.common.mw.UnitCallbackInterface; | 
|---|
|  |  |  | import com.dy.common.mw.UnitInterface; | 
|---|
|  |  |  | import com.dy.common.util.Callback; | 
|---|
|  |  |  | import com.dy.simRtu.ServerProperties; | 
|---|
|  |  |  | import com.dy.simRtu.tcpClient.upData.UpData; | 
|---|
|  |  |  | import com.dy.simRtu.tcpClient.upData.UpHeartBeat; | 
|---|
|  |  |  | import org.apache.logging.log4j.LogManager; | 
|---|
|  |  |  | import org.apache.logging.log4j.Logger; | 
|---|
|  |  |  | import org.apache.mina.core.session.IoSession; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class TcpClUnit implements UnitInterface { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static TcpClUnit instance = new TcpClUnit() ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static TcpClUnitAdapter adapter ; | 
|---|
|  |  |  | public static TcpClUnitConfigVo confVo ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static Worker worker ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private TcpClUnit(){} ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static TcpClUnit getInstance(){ | 
|---|
|  |  |  | return instance ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void setAdapter(UnitAdapterInterface adapter) throws Exception { | 
|---|
|  |  |  | if(adapter == null){ | 
|---|
|  |  |  | throw new Exception("Tcp Client模块适配器对象不能为空!") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TcpClUnit.adapter = (TcpClUnitAdapter)adapter ; | 
|---|
|  |  |  | TcpClUnit.confVo = TcpClUnit.adapter.getConfig() ; | 
|---|
|  |  |  | if(TcpClUnit.confVo == null){ | 
|---|
|  |  |  | throw new Exception("Tcp Client模块配置对象不能为空!") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | TcpClUnit.worker = Worker.getInstance(TcpClUnit.confVo) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void start(UnitCallbackInterface callback) throws Exception { | 
|---|
|  |  |  | System.out.println("Tcp Client模块成功启动"); | 
|---|
|  |  |  | TcpClUnit.worker.doStart(); | 
|---|
|  |  |  | callback.call(null) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void stop(UnitCallbackInterface callback) throws Exception { | 
|---|
|  |  |  | callback.call(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|