Seems you are working on an SMPP decoder using some 3rd party library.

You don't need to copy all the bytes each time. Follow this
1. Check the length from SMPP header
2. Collect the bytes till the length from header is achieved (use
CumulativeProtocolDecoder)
3. Once done, get the byte[] from ByteBuffer (seems you are using MINA 1.1.7)

Would recommend to upgrade to latest MINA version

thanks
ashish

On Mon, May 25, 2009 at 11:35 AM, Arun Soman <[email protected]> wrote:
> Hi
> I am getting the following exceptions
>
> org.apache.mina.filter.codec.ProtocolDecoderException:
> java.lang.OutOfMemoryError: Java heap space (Hexdump: 63 6B 73 64 68 63 6A
> 73 6B 64 63 00 00 00 4F 00 00 00 04 00 00 00 00 00 00 00 AB 43 4D 54 00 01
> 01 33 35 33 38 36 31 32 33 34 35 36 37 38 00 01 01 31 32 33 34 35 36 37 39
> 35 00 00 00 00 00 00 00 00 03 00 15 6A 6D 2C 6E 62 66 64 73 68 6A 63 6B 73
> 64 68 63 6A 73 6B 64 63 00 00 00 4F 00 00 00 04 00 00 00 00 00 00 00 AC 43
> 4D 54 00 01 01 33 35 33 38 36 31 32 33 34 35 36 37 38 00 01 01 31 32 33 34
> 35 36 37 39 35 00 00 00 00 00 00 00 00 03 00 15 6A 6D 2C 6E 62 66 64 73 68
> 6A 63 6B 73 64 68 63 6A 73 6B 64 63 00 00 00 4F 00 00 00 04 00 00 00 00 00
> 00 00 AD 43 4D 54 00 01 01 33 35 33 38 36 31 32 33 34 35 36 37 38 00 01 01
> 31 32 33 34 35 36 37 39 35 00 00 00 00 00 00 00 00 03 00 15 6A 6D 2C 6E 62
> 66 64 73 68 6A 63 6B 73 64 68 63 6A 73 6B 64 63 00 00 00 4F 00 00 00 04 00
> 00 00 00 00 00 00 AE 43 4D 54 00 01 01 33 35 33 38 36 31 32 33 34 35 36 37
> 38 00 01 01 31 32 33 34 35 36 37 39 35 00 00 00 00 00 00 00 00 03 00 15 6A
> 6D 2C 6E 62 66 64 73 68 6A 63 6B 73 64 68 63 6A 73 6B 64 63 00 00 00 4F 00
> 00 00 04 00 00 00 00 00 00 00 AF 43 4D 54 00 01 01 33 35 33 38 36 31 32 33
> 34 35 36 37 38 00 01 01 31 32 33 34 35 36 37 39 35 00 00 00 00 00 00 00 00
> 03 00 15 6A 6D 2C 6E 62 66 64 73 68 6A 63 6B 73 64 68 63 6A 73 6B 64 63 00
> 00 00 4F 00 00 00 04 00 00 00 00 00 00 00 B0 43 4D 54 00 01 01 33 35 33 38
> 36 31 32 33 34 35 36 37 38 00 01 01 31 32 33 34 35 36 37 39 35 00 00 00 00
> 00 00 00 00 03 00 15 6A 6D 2C 6E 62 66 64 73 68 6A 63 6B 73 64 68 63 6A 73
> 6B 64 63)
>    at
> org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:165)
>    at
> org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
>    at
> org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
>    at
> org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
>    at
> org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:220)
>    at
> org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:264)
>    at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>    at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>    at
> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
>    at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.OutOfMemoryError: Java heap space
>    at com.sit.codec.mina.smpp.SmppDecoder.decode(SmppDecoder.java:24)
>    at
> org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:158)
>    ... 9 more
>
>
>
> org.apache.mina.filter.codec.ProtocolDecoderException:
> java.lang.ArrayIndexOutOfBoundsException (Hexdump: 00 00 00 00 00 00 03 00
> 15 6A 6D 2C 6E 62 66 64 73 68 6A 63 6B 73 64 68 63 6A 73 6B 64 63 00 00 00
> 4F 00 00 00 04 00 00 00 00 00 00 01 2F 43 4D 54 00 01 01 33 35 33 38 36 31
> 32 33 34 35 36 37 38 00 01 01 31 32 33 34 35 36 37 39 35 00 00 00 00 00 00
> 00 00 03 00 15 6A 6D 2C 6E 62 66 64 73 68 6A 63 6B 73 64 68 63 6A 73 6B 64
> 63 00 00 00 4F 00 00 00 04 00 00 00 00 00 00 01 30 43 4D 54 00 01 01 33 35
> 33 38 36 31 32 33 34 35 36 37 38 00 01 01 31 32 33 34 35 36 37 39 35 00 00
> 00 00 00 00 00 00 03 00 15 6A 6D 2C 6E 62 66 64 73 68 6A 63 6B 73 64 68 63
> 6A 73 6B 64 63)
>    at
> org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:165)
>    at
> org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
>    at
> org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
>    at
> org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
>    at
> org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:220)
>    at
> org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:264)
>    at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>    at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>    at
> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
>    at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.ArrayIndexOutOfBoundsException
>    at java.lang.System.arraycopy(Native Method)
>    at com.sit.codec.mina.smpp.SmppDecoder.decode(SmppDecoder.java:25)
>    at
> org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:158)
>    ... 9 more
>
>
> my decoder function is given below
>
> public void decode(IoSession ioSession, ByteBuffer byteBuffer,
> ProtocolDecoderOutput output) throws Exception {
>        int packetSize = byteBuffer.getInt();
>        byte[] packet = new
> byte[packetSize];                                              /* line # 24
> */
>        System.arraycopy(Utils.intToByteArray(packetSize), 0, packet, 0, 4);
> /* line # 25 */
>        byteBuffer.get(packet, 4, packetSize-4);
>        byteBuffer.clear();
>        PDU pdu = PDU.createPDU(new org.smpp.util.ByteBuffer(packet));
>        output.write(pdu);
>    }
>
>
> I am passing following arguments to jvm
> -server
> -Xms1024m
> -Xmx1529m
> -Xss128k
> -XX:+UseParallelGC
> -XX:MaxDirectMemorySize=128M
>
> There are no exceptions when i send few messages but whenever i send
> messages in 1000 numbers these are frequent.
>



-- 
thanks
ashish

Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal

Reply via email to