| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| After running my wonderful mina application for 11 hours, I ran into the following problem ------------------ Caused by: org.apache.mina.core.buffer.BufferDataException: dataLength: 1396329569 at com.bluetreewireless.app.server.services.modem.nio .codec.decoder.ATCmdMs gDecoder.decodable(ATCmdMsgDecoder.java:38) at com.bluetreewireless.app.server.services.modem.nio .codec.decoder.Timeout MsgDecoder.decodable(TimeoutMsgDecoder.java:20) at org.apache.mina.filter.codec.demux.DemuxingProtoco lDecoder.doDecode(Demu xingProtocolDecoder.java:138) at org.apache.mina.filter.codec.CumulativeProtocolDec oder.decode(Cumulative ProtocolDecoder.java:173) at org.apache.mina.filter.codec.ProtocolCodecFilter.m essageReceived(Protoco lCodecFilter.java:170) ... 15 more 2008-08-27@03:54:03 ERROR [NioProcessor-2] (ModemIoHandler.java:170) NIO stack exception java.lang.OutOfMemoryError: Java heap space ------------------ My MessageDecoder decodable() method looks like the following: ------------------ public MessageDecoderResult decodable(IoSession session, IoBuffer in) { /* * Return NEED_DATA if buffer doesn't contain the number of bytes * requested by the header. */ if (in.remaining() < 4) { return MessageDecoderResult.NEED_DATA; } int dataLength = in.getInt(in.position()); int maxDataLength = 8192; if (dataLength < 0 || dataLength > maxDataLength) { throw new BufferDataException("dataLength: " + dataLength); } if(in.remaining() >= dataLength) { return MessageDecoderResult.OK; } else { return MessageDecoderResult.NEED_DATA; } } ------------------ So I assume that I must have got BufferDataException all night long since my limit set on the dataLength is set to 8192! From what I got, I can only presume that my IoBuffer kept on growing until it caused the "java.lang.OutOfMemoryError: Java heap space" error My question is, should compact the IoBuffer upon successful decoding of messages? Currently, from all the documentation I have looked at such as (http://mina.apache.org/tutorial-on-p...r-mina-2x.html ) nobody compacts the IoBuffer? What would you recommend? Here's my decode method for reference: ------------------ public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { IntBuffer buffer = in.asIntBuffer(); /* * Get all bytes from packet, starting at the 8th byte, thus skipping * the message header. */ IoBuffer duplicate = in.duplicate(); int bufferLength = in.remaining(); duplicate.position(in.position()+8); String payload = duplicate.getString(charsetDecoder); ATCmdMessage message = getMsgInstance(payload, buffer.get(1)); if(logger.isTraceEnabled()) { SocketAddress remote = session.getRemoteAddress(); IoBuffer bb = in.duplicate(); logger.trace("Receiving from "+remote.toString()+" (" + bb.remaining() + " bytes): "+ bb.getHexDump()); } out.write(message); in.position(in.position()+bufferLength); return MessageDecoderResult.OK; } ------------------ Thanks for your help. Any code sample would be greatly appreciated. By the way, I'm using the latest mina-2.0M3 Simon |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.