| | |
| | | public class DataCodecFactory implements ProtocolCodecFactory { |
| | | |
| | | private TcpUnitAdapter adapter ; |
| | | private boolean stop = false ;//为true时,停止TCP服务,并把已经TCP连接断连接 |
| | | |
| | | public DataCodecFactory(TcpUnitAdapter adapter) { |
| | | this.adapter = adapter ; |
| | | } |
| | | |
| | | public void stop(){ |
| | | stop = true ; |
| | | } |
| | | |
| | | public void recover(){ |
| | | this.stop = false ; |
| | | } |
| | | |
| | | |
| | | public ProtocolEncoder getEncoder(IoSession ioSession) { |
| | | if(stop){ |
| | | ioSession.closeNow() ; |
| | | } |
| | | return new DataEncoder(); |
| | | } |
| | | |
| | | public ProtocolDecoder getDecoder(IoSession ioSession) { |
| | | if(stop){ |
| | | ioSession.closeNow() ; |
| | | } |
| | | return new DataDecoder(adapter.newPrefixedDataAvailableHandle()); |
| | | } |
| | | } |