Hi Johan,

On Tue, May 27, 2008 at 3:47 PM, Johan Haleby <[EMAIL PROTECTED]> wrote:

> Hi,
>
> I'm using Apache Mina to parse continuous XML streams. I.e. a client
> connects to Mina and holds a connection for its entire life-cycle. During
> this time the client may send and receive a lot of (small) XML messages. I
> wonder how I should implement this is in a good way? Right now my protocol
> decoder is a singleton that make use of cached thread pool because each
> client creates a new custom made inputstream implementation that is read in
> a separate thread by XStream. When new data arrives to the decode method it
> just pushes this data to the inputstream. The inputstream itself uses a
> blocking queue, so the read method waits until it has data or that an "end
> of stream marker" has been found, e.g. until </request> has been found.


I presume the read from the InputStream is using threads from this shared
thread pool?  This is a tough problem to deal with when you have some
blocking IO primitives between MINA and your application.

Although not optimal, I would use a decoder per session and start collecting
a request buffer in the MINA session until you detect the completion of a
request.  This way there is minimal processing except for request
termination detection.  Also you don't have to have this thread cache (pool)
to contend with in a singleton.  When you detect the arrival of a complete
request you can trigger XStream deserialization of the buffer to produce the
object and forward the object up to higher layers.

HTH,
Alex

Reply via email to