mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rob Butler <crodste...@yahoo.com>
Subject Keeping state across encode/decode.
Date Sat, 17 Jun 2006 02:51:43 GMT
Hello all,

First off Mina looks pretty awesome.  I've got a
pretty basic protocol encoder/decoder up and going in
just a few hours.  Nice!

I've got several questions about Mina and I hope you
can help.

1) Does mina already handle incomplete messages behind
the scenes or do I need to do something special?  FYI
- I'm extending ProtocolDecoderAdapter.  So, lets say
I'm expecting 10,000 bytes to complete a message, but
so far only 5,000 have been sent by the client.  If I
write:

public void decode(IoSession ioSession, ByteBuffer in,
ProtocolDecoderOutput out) throws Exception
   byte[] x = new byte[10000];
   in.get(x);
   out.write(x);
}

Will I only get the 5,000 bytes or will Mina behind
the scenes feed the next 5,000 bytes when they arrive
so I don't have to be concerned with it?

2) Obviously if I am blocked waiting for 5,000 more
bytes from the client this thread can't do much more. 
This is where the leader/follower thread pool comes
into play correct?  Some background on this would be
really helpful.

3) I have a need to maintain some state gathered
during the decoding process to use during the encoding
process.  At first I thought to place this into the
IoSession as an attribute, but I don't think this will
work.  I think an IoSession basically maps to a client
connection, and in this case I am using TCP.

Each incoming message will have at least one outgoing
response.  But my client CAN send multiple incoming
messages before I've had a chance to send a response
yet.  Since the IoSession is for an entire connection
a second message could have arrived and changed the
state information in the IoSession before I've
completed my first response message.  So using
IoSession attributes is out.

I supposed I could implement a command pattern in my
ProtocolHandler to keep my incoming message and all of
it's state until I generate a response.  Any
suggestions on other ways to do this?

Thanks
Rob

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Mime
View raw message