MessageDecoder, IoBuffer resizing

This is a discussion on MessageDecoder, IoBuffer resizing within the Apache forums in Application Servers & Tools category; 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; } ...

Go Back   Application Development Forum > Application Servers & Tools > Apache

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-27-2008, 10:10 AM
Simon Trudeau
Guest
 
Default MessageDecoder, IoBuffer resizing

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


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:42 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.