mina-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@apache.org>
Subject Re: Filters & POJO Messaging with Large File Transfers / BufferException Issue
Date Fri, 25 Nov 2011 16:32:41 GMT
On 11/25/11 5:17 PM, Cesar Barria wrote:
> Yup... The @Overrides are being called appropriately. I think my problem
> is here... I just don't know how to fix it.
> This returns false which I think just indicates not enough buffer data
> available to decode... So it will call the doDecode method on the
> ObjecSerializationCodec class again instead of moving on to the
> StreamWriterFilter class.

When you are dealing with a file, you must accumulate the incoming data, 
as the file content will be send piece by piece. You have to encapsulate 
your messages by a marker to distinguish between the two cases (file or 
serialied object), otherwise you won't be able to know what kind of data 
you are dealing with.

Bottom line, you have to define the protocol you are using and the 
associated encoder/decoder.

For instance, the messages will look likes :
[flag] [size] [data]

where [flag] can be a byte indicating if it's a file (0) or an object 
(1), followed by the data size and the data itself. Of course, if the 
data is a serialized object, then you will have to serialize it to a 
stream and send it, and on the other end, to deserialize it.

You can copy the ObjectSerializationEn/DeCoder, modify it and use it to 
make it deal with this first byte and the 2 cases. A bit more work, but 
you already have almost all the code written...
>
>
> @Override
> protected boolean doDecode(IoSession session, IoBuffer in,
> ProtocolDecoderOutput out) throws Exception {
>       if (session.getAttribute("state") == SessionState.RECV_FILE ||
> session.getAttribute("state") == SessionState.SEND_FILE)
>           return false;
>       else {
>           return super.doDecode(session, in, out);
>       }
> }
> }
>
> On the encoder everything appears to be working appropriately:
>
>   @Override
>    public void encode(IoSession session, Object message,
> ProtocolEncoderOutput out) throws Exception {
>       if (session.getAttribute("state") == SessionState.RECV_FILE ||
> session.getAttribute("state") == SessionState.SEND_FILE)
>            return;
>        else
>            super.encode(session, message, out);
>        }
> }
>
>
>
>
>
>
> On 11/25/11 9:49 AM, "Emmanuel Lécharny"<elecharny@apache.org>  wrote:
>
>> On 11/25/11 3:41 PM, Cesar Barria wrote:
>>> I was hoping that these three @Overrides would bypass the serialization
>>> codec and allow streamwritefilter to deal with the files
>> It should, but are you sure that they are called everytime a file is
>> sent ? Add some logs in your code to be sure.
>>
>>
>> -- 
>> Regards,
>> Cordialement,
>> Emmanuel Lécharny
>> www.iktek.com
>>
>>
>
>


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com


Mime
View raw message