mina心跳的实现和业务逻辑之间的问题

 @Override
    protected boolean doDecode(IoSession session, IoBuffer buffer,
            ProtocolDecoderOutput out) throws Exception {
        int position = buffer.position();
        //第一次读取数据的时候
        if(session.getAttribute("fileName")==null){
            session.setAttribute("fileName",buffer.getInt());
            session.setAttribute("fileContent", buffer.getInt());
            return false;
        }
        else{
            int fileName = (Integer) session.getAttribute("fileName");
            int fileContent = (Integer) session.getAttribute("fileContent");
            //数据全部传输完,开始解码
            if(buffer.limit()-buffer.position()>=fileContent+fileName){
                byte[] nameByte = new byte[fileName]; 
                byte[] contentByte = new byte[fileContent]; 
                PictureBean picture = new PictureBean();
                int start = buffer.position();
                int limit = buffer.limit();
                buffer.limit(start+fileName);
                buffer.slice().get(nameByte);
                picture.setFileName(nameByte);
                buffer.position(start+fileName);
                buffer.limit(limit);
                buffer.slice().get(contentByte);
                picture.setFileContent(contentByte);
                session.removeAttribute("fileName");
                session.removeAttribute("fileContent");
                out.write(picture);
                return true;
            }
            buffer.position(position);
            return false;
        }
}

刚刚学mina,用mina来传输文件可以了,客户端的encoder和服务端的Decoder是自定义的。
但是在想加入心跳的时候发现,心跳的内容会和业务的内容冲突,就是解码器那里很难把这两个完全分开。没用XMPP协议。想问下怎么不影响业务的情况下实现心跳

心跳包内容是固定的啊。在解码完成后,可以判断出来了。
我记得可以添加心跳类,里面有判断吧。

 KeepAliveMessageFactory heartBeatFactory = new IMKeepAlive();
        // 设置时间
        KeepAliveFilter keepAliveFilter = new KeepAliveFilter(heartBeatFactory,
                IdleStatus.BOTH_IDLE, KeepAliveRequestTimeoutHandler.CLOSE,
                IDLE_TIME, TIME_OUT);

第一句话忽略吧。