Hi, the IoBuffer.getHexDump() method does not copy the IoBuffer, and will move the position while dumping the content.
It's clearly not the smartes utility function, as you can imagine...
Anyway, you have to copy the buffer (duplicate() function) you want to
dump before dumping it, to avoid any intercation with the logic of your
application.
Le 22/05/2018 à 03:58, rexxar a écrit :
> Hi,
>
> here is the Implement of encode"
>
> @Override
> public void encode(IoSession session, Object message,
> ProtocolEncoderOutput
> out) throws Exception {
> IoBuffer buf = IoBuffer.allocate(100);
> buf.setAutoExpand(true);
>
> NetMessage msg = (NetMessage) message;
> byte[] bs = msg.toByteArray();
>
> int sourceLen = bs.length;
> boolean needCompress = isNeedCompress(msg, sourceLen);
> if (needCompress) {
> bs = ZlibUtils.compressNormal(bs);
> }
>
> boolean needEncrypt = isNeedEncrypt(msg);
>
> if (needEncrypt) {
> bs = cryptor.encrypt(bs, session);
> }
>
> int len = bs.length; //
> sourceLen = len; //
> if (needCompress) {
> len = len + 4;
> len = len | 0x20000000;
> }
> if (needEncrypt) {
> len = len | 0x10000000;
> }
> buf.clear();
> buf.putInt(len);
> if (needCompress) {
> buf.putInt(sourceLen);
> }
>
> buf.put(bs);
> buf.flip();
> out.write(buf);
>
> /*the "InvalidMarkException" happend When the following log is added
>
> try{
> JLogger.fixInfo(String.format("encodeMsg session
> id[%d], Len[%d],
> Compress[%d], msgId[%d], opcode[%d], buf:%s",
> session.getId(), sourceLen,
> needCompress ? 1 : 0, msg.id,
> msg.opcode,NetMessage.ioBufferToString(buf) ));
> }catch(Exception e){
> JLogger.fixError("print error...",e);
> }*/
>
> }
> "
>
>
> the NetMessage.ioBufferToString fuction is "
>
> public static String ioBufferToString(IoBuffer buffer) {
> StringBuilder sb = new StringBuilder();
> if (buffer.isDirect()) {
> sb.append("DirectBuffer");
> } else {
> sb.append("HeapBuffer");
> }
> sb.append("[pos=");
> sb.append(buffer.position());
> sb.append(" lim=");
> sb.append(buffer.limit());
> sb.append(" cap=");
> sb.append(buffer.capacity());
> sb.append(": ");
> sb.append(buffer.getHexDump());
> sb.append(']');
> return sb.toString();
> }
> "
> here is the log when the problem happend, it seems happend when multithread
> call IoSession.Write()
> <http://apache-mina.10907.n7.nabble.com/file/t2155/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20180522094404.png>
>
>
>
> <http://apache-mina.10907.n7.nabble.com/file/t2155/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_2.png>
>
>
>
> <http://apache-mina.10907.n7.nabble.com/file/t2155/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_3.png>
>
>
>
>
> --
> Sent from:
> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>
--
Emmanuel Lecharny
Symas.com
directory.apache.org
pEpkey.asc
Description: application/pgp-keys
