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.DemuxingProtocolDecoder.doDecode(Demu
xingProtocolDecoder.java:138)
at
org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(Cumulative
ProtocolDecoder.java:173)
at
org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(Protoco
lCodecFilter.java:170)
... 15 more
[EMAIL PROTECTED]: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-protocolcodecfilter-for-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