You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Zohar Amir <zo...@gmail.com> on 2006/03/16 22:48:27 UTC

newbie help required

Hello list,

I've posted here a request for help a few days ago but only got 1 reply,
which did not get me very far. I'll try explaining my problem again, in the
hope of getting some more help.

I need to put up a server that handles client requests. Each client connects
via TCP to the server and then they exchange messages. The messages are
built as a PDU wrapping  an XML message.

Looking at the examples I got with MINA, it seems that the best option is
using a StreamIoHandler (decision 1). When doing that I ran into some
problems:

The processStreamIo method starts a new thread to handle the incoming data.
This thread reads the input stream and decodes the incoming messages. The
first problem was stopping this thread when the sessionClosed method is
invoked, because the read methods are blocking. I solved this by closing the
session's InputStream when the sessionClosed method is invoked, thus causing
the reading thread to throw an IOException and then terminating the
readingloop (decision 2). This seemed to work OK, until I had a client
that sent me
a single message and then closed the TCP connection quickly (hit and run).
This caused my former mechanism to close the InputStream before the new
thread had a chance to read the message and decode it.

OK, I hope all this clear.

Can anyone tell me what I did wrong and how I should solve this?

Thanks,

Zohar.

Re: newbie help required

Posted by Zohar Amir <zo...@gmail.com>.
Thanks for the reply.
How long is long? When should I use IoHandler and when StreamIoHandler?
Zohar.

On 3/17/06, Maarten Bosteels <ma...@dns.be> wrote:
>
> Why do you think you need a StreamIoHandler ?
> Are the messages relatively short or rather long ?
> Is there a big lag between receiving the beginning of a message
> and receiving the end of the message ?
>
> I have never tried StreamIoHandler, I guess to get started it's easier
> to just implement a ProtocolDecoder/ProtocolEncoder and let MINA
> handle the threading stuff.
>
> But of course it should be possible to handle your use case with a
> StreamIoHandler.
>
> Maarten
>
> On 3/17/06, cheng wei <we...@gmail.com> wrote:
> > hello Zohar Amir,
> >   (method 1).You have said "The message are built as a PDU wrapping an
> XML
> > message".you may create an simple example to show where the problem will
> > happens,and show its critical part of code here.
> >   (method 2).With the simple example,you can write same test unit and
> log
> > message.They will help you to solve some problems.(if you don't know how
> to
> > write test unit and log message,i have an simple example.If you
> need,send
> > email to me.)
> >
> > 2006/3/17, Zohar Amir <zo...@gmail.com>:
> > >
> > > Hello list,
> > >
> > > I've posted here a request for help a few days ago but only got 1
> reply,
> > > which did not get me very far. I'll try explaining my problem again,
> in
> > > the
> > > hope of getting some more help.
> > >
> > > I need to put up a server that handles client requests. Each client
> > > connects
> > > via TCP to the server and then they exchange messages. The messages
> are
> > > built as a PDU wrapping  an XML message.
> > >
> > > Looking at the examples I got with MINA, it seems that the best option
> is
> > > using a StreamIoHandler (decision 1). When doing that I ran into some
> > > problems:
> > >
> > > The processStreamIo method starts a new thread to handle the incoming
> > > data.
> > > This thread reads the input stream and decodes the incoming messages.
> The
> > > first problem was stopping this thread when the sessionClosed method
> is
> > > invoked, because the read methods are blocking. I solved this by
> closing
> > > the
> > > session's InputStream when the sessionClosed method is invoked, thus
> > > causing
> > > the reading thread to throw an IOException and then terminating the
> > > readingloop (decision 2). This seemed to work OK, until I had a client
> > > that sent me
> > > a single message and then closed the TCP connection quickly (hit and
> run).
> > > This caused my former mechanism to close the InputStream before the
> new
> > > thread had a chance to read the message and decode it.
> > >
> > > OK, I hope all this clear.
> > >
> > > Can anyone tell me what I did wrong and how I should solve this?
> > >
> > > Thanks,
> > >
> > > Zohar.
> > >
> > >
> >
> >
>

Re: newbie help required

Posted by Maarten Bosteels <ma...@dns.be>.
Why do you think you need a StreamIoHandler ?
Are the messages relatively short or rather long ?
Is there a big lag between receiving the beginning of a message
and receiving the end of the message ?

I have never tried StreamIoHandler, I guess to get started it's easier
to just implement a ProtocolDecoder/ProtocolEncoder and let MINA
handle the threading stuff.

But of course it should be possible to handle your use case with a
StreamIoHandler.

Maarten

On 3/17/06, cheng wei <we...@gmail.com> wrote:
> hello Zohar Amir,
>   (method 1).You have said "The message are built as a PDU wrapping an XML
> message".you may create an simple example to show where the problem will
> happens,and show its critical part of code here.
>   (method 2).With the simple example,you can write same test unit and log
> message.They will help you to solve some problems.(if you don't know how to
> write test unit and log message,i have an simple example.If you need,send
> email to me.)
>
> 2006/3/17, Zohar Amir <zo...@gmail.com>:
> >
> > Hello list,
> >
> > I've posted here a request for help a few days ago but only got 1 reply,
> > which did not get me very far. I'll try explaining my problem again, in
> > the
> > hope of getting some more help.
> >
> > I need to put up a server that handles client requests. Each client
> > connects
> > via TCP to the server and then they exchange messages. The messages are
> > built as a PDU wrapping  an XML message.
> >
> > Looking at the examples I got with MINA, it seems that the best option is
> > using a StreamIoHandler (decision 1). When doing that I ran into some
> > problems:
> >
> > The processStreamIo method starts a new thread to handle the incoming
> > data.
> > This thread reads the input stream and decodes the incoming messages. The
> > first problem was stopping this thread when the sessionClosed method is
> > invoked, because the read methods are blocking. I solved this by closing
> > the
> > session's InputStream when the sessionClosed method is invoked, thus
> > causing
> > the reading thread to throw an IOException and then terminating the
> > readingloop (decision 2). This seemed to work OK, until I had a client
> > that sent me
> > a single message and then closed the TCP connection quickly (hit and run).
> > This caused my former mechanism to close the InputStream before the new
> > thread had a chance to read the message and decode it.
> >
> > OK, I hope all this clear.
> >
> > Can anyone tell me what I did wrong and how I should solve this?
> >
> > Thanks,
> >
> > Zohar.
> >
> >
>
>

Re: newbie help required

Posted by cheng wei <we...@gmail.com>.
hello Zohar Amir,
  (method 1).You have said "The message are built as a PDU wrapping an XML
message".you may create an simple example to show where the problem will
happens,and show its critical part of code here.
  (method 2).With the simple example,you can write same test unit and log
message.They will help you to solve some problems.(if you don't know how to
write test unit and log message,i have an simple example.If you need,send
email to me.)

2006/3/17, Zohar Amir <zo...@gmail.com>:
>
> Hello list,
>
> I've posted here a request for help a few days ago but only got 1 reply,
> which did not get me very far. I'll try explaining my problem again, in
> the
> hope of getting some more help.
>
> I need to put up a server that handles client requests. Each client
> connects
> via TCP to the server and then they exchange messages. The messages are
> built as a PDU wrapping  an XML message.
>
> Looking at the examples I got with MINA, it seems that the best option is
> using a StreamIoHandler (decision 1). When doing that I ran into some
> problems:
>
> The processStreamIo method starts a new thread to handle the incoming
> data.
> This thread reads the input stream and decodes the incoming messages. The
> first problem was stopping this thread when the sessionClosed method is
> invoked, because the read methods are blocking. I solved this by closing
> the
> session's InputStream when the sessionClosed method is invoked, thus
> causing
> the reading thread to throw an IOException and then terminating the
> readingloop (decision 2). This seemed to work OK, until I had a client
> that sent me
> a single message and then closed the TCP connection quickly (hit and run).
> This caused my former mechanism to close the InputStream before the new
> thread had a chance to read the message and decode it.
>
> OK, I hope all this clear.
>
> Can anyone tell me what I did wrong and how I should solve this?
>
> Thanks,
>
> Zohar.
>
>

Re: newbie help required

Posted by Zohar Amir <zo...@gmail.com>.
I looked at the examples, but I just missed the part where the messages can
be constructed by custom codecs. I thought (wrongly) that only Java
Serializable Objects may be sent...
I am still not clear as to when I should use the different approaches, so
I'm not in a position to document this... ;)
Can anyone of the experianced people here write a short "cookbook" about
this in the wiki?
Thanks.

On 3/18/06, peter royal <pr...@apache.org> wrote:
>
> On Mar 17, 2006, at 7:11 PM, Zohar Amir wrote:
> > Is all this documented somewhere?
>
> not fully.. there is javadocs and examples, i really recommend
> looking at the examples in the source, they should help you a lot.
>
> writing up documentation is also a great way to get involved in the
> project! :)
> -pete
>
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
>
>

Re: newbie help required

Posted by Mo <ma...@mo.virtual-bunker.de>.
right zohar, just take one of the basic examples and change it into 
something comparably basic. at least that was the way i started with 
MINA a few weeks ago.

peter royal wrote:

> On Mar 17, 2006, at 7:11 PM, Zohar Amir wrote:
>
>> Is all this documented somewhere?
>
>
> not fully.. there is javadocs and examples, i really recommend  
> looking at the examples in the source, they should help you a lot.
>
> writing up documentation is also a great way to get involved in the  
> project! :)
> -pete
>
>


Re: newbie help required

Posted by peter royal <pr...@apache.org>.
On Mar 17, 2006, at 7:11 PM, Zohar Amir wrote:
> Is all this documented somewhere?

not fully.. there is javadocs and examples, i really recommend  
looking at the examples in the source, they should help you a lot.

writing up documentation is also a great way to get involved in the  
project! :)
-pete


-- 
proyal@apache.org - http://fotap.org/~osi



Re: newbie help required

Posted by Zohar Amir <zo...@gmail.com>.
Is all this documented somewhere?

On 3/18/06, Greg Duffy <gd...@gmail.com> wrote:
>
> StreamIoHandler is mostly for adapting existing stream based IO logic.
> It still internally uses the same things every other IoHandler uses
> (MINA-provided ByteBuffers).
>
> So, if you are doing something new, you might as well write a regular
> IoHandler. Your clients do not need to be written in Java, MINA
> creates the ByteBuffer from the data coming in from the network and
> passes it to you.
>
> -Greg
>
> On 3/17/06, Zohar Amir <zo...@gmail.com> wrote:
> > What are the considerations for using IoHandler vs. StreamIoHandler?
> > As for using a ByteBuffer for the XML - if only my clients were Java...
> ;)
> > Thanks,
> > Zohar.
> >
> > On 3/18/06, peter royal <pr...@apache.org> wrote:
> > >
> > > On Mar 16, 2006, at 4:48 PM, Zohar Amir wrote:
> > > > I need to put up a server that handles client requests. Each client
> > > > connects
> > > > via TCP to the server and then they exchange messages. The messages
> > > > are
> > > > built as a PDU wrapping  an XML message.
> > >
> > > I'd use the protocol encoder/decoder.. If its just an XML message,
> > > you can just put the XML as a string into a ByteBuffer..
> > > -pete
> > >
> > > --
> > > proyal@apache.org - http://fotap.org/~osi
> > >
> > >
> > >
> > >
> > >
> >
> >
>

Re: newbie help required

Posted by Greg Duffy <gd...@gmail.com>.
StreamIoHandler is mostly for adapting existing stream based IO logic.
It still internally uses the same things every other IoHandler uses
(MINA-provided ByteBuffers).

So, if you are doing something new, you might as well write a regular
IoHandler. Your clients do not need to be written in Java, MINA
creates the ByteBuffer from the data coming in from the network and
passes it to you.

-Greg

On 3/17/06, Zohar Amir <zo...@gmail.com> wrote:
> What are the considerations for using IoHandler vs. StreamIoHandler?
> As for using a ByteBuffer for the XML - if only my clients were Java... ;)
> Thanks,
> Zohar.
>
> On 3/18/06, peter royal <pr...@apache.org> wrote:
> >
> > On Mar 16, 2006, at 4:48 PM, Zohar Amir wrote:
> > > I need to put up a server that handles client requests. Each client
> > > connects
> > > via TCP to the server and then they exchange messages. The messages
> > > are
> > > built as a PDU wrapping  an XML message.
> >
> > I'd use the protocol encoder/decoder.. If its just an XML message,
> > you can just put the XML as a string into a ByteBuffer..
> > -pete
> >
> > --
> > proyal@apache.org - http://fotap.org/~osi
> >
> >
> >
> >
> >
>
>

Re: newbie help required

Posted by Zohar Amir <zo...@gmail.com>.
What are the considerations for using IoHandler vs. StreamIoHandler?
As for using a ByteBuffer for the XML - if only my clients were Java... ;)
Thanks,
Zohar.

On 3/18/06, peter royal <pr...@apache.org> wrote:
>
> On Mar 16, 2006, at 4:48 PM, Zohar Amir wrote:
> > I need to put up a server that handles client requests. Each client
> > connects
> > via TCP to the server and then they exchange messages. The messages
> > are
> > built as a PDU wrapping  an XML message.
>
> I'd use the protocol encoder/decoder.. If its just an XML message,
> you can just put the XML as a string into a ByteBuffer..
> -pete
>
> --
> proyal@apache.org - http://fotap.org/~osi
>
>
>
>
>

Re: newbie help required

Posted by peter royal <pr...@apache.org>.
On Mar 16, 2006, at 4:48 PM, Zohar Amir wrote:
> I need to put up a server that handles client requests. Each client  
> connects
> via TCP to the server and then they exchange messages. The messages  
> are
> built as a PDU wrapping  an XML message.

I'd use the protocol encoder/decoder.. If its just an XML message,  
you can just put the XML as a string into a ByteBuffer..
-pete

-- 
proyal@apache.org - http://fotap.org/~osi