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 <da...@hotmail.com> on 2006/03/14 11:05:11 UTC

how to work with StreamIoHandler

Hello,
I have an application that uses StreamIoHandler.  The processStreamIo method 
starts a new thread to handle the incoming data. This thread does something 
like:

  public void run() {
   try {
    while (true) {
     Message message = null;
     message = Decoder.decode(inputStream);
     System.out.print(message);
    }
   } finally {
    session.close();
   }
  }

The questions is how to break the thread loop when the session is closed. 
The solution should also handle clients that send short messages, so that 
the sessionClosed method is invoked before the thread is started and gets a 
chance to decode the sent message.

Is there a better way within MINA to do that?
Thanks,
Zohar.


Re: how to work with StreamIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
On 3/27/06, Zohar Amir <zo...@gmail.com> wrote:
>
> Hi again,
> While trying to demonstrate the issue I found that the exception _is_
> thrown, but sometimes sessionClosed is invoked before the new thread gets a
> chance to read the available data from the stream.
> I followed the example of the httpserver that is provided with MINA, only
> there is no handling of client socket closure there.
> What is the correct way to tackle this?
> I'm attaching some code that demonstrates the issue - java sources for the
> server and a python script for the client.
>

This issue has been resolved:

* http://svn.apache.org/viewcvs?rev=406508&view=rev
* http://issues.apache.org/jira/browse/DIRMINA-214

Please leave your message to make sure this issue is gone.

Thanks,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: how to work with StreamIoHandler

Posted by Zohar Amir <zo...@gmail.com>.
Hi again,
While trying to demonstrate the issue I found that the exception _is_
thrown, but sometimes sessionClosed is invoked before the new thread gets a
chance to read the available data from the stream.
I followed the example of the httpserver that is provided with MINA, only
there is no handling of client socket closure there.
What is the correct way to tackle this?
I'm attaching some code that demonstrates the issue - java sources for the
server and a python script for the client.

On 3/25/06, Trustin Lee <tr...@gmail.com> wrote:
>
> On 3/15/06, Zohar Amir <da...@hotmail.com> wrote:
> >
> > What do you mean by "read from a closed session"? I read from the
> > InputStream that I get in the processStreamIo method.
> > Second - while reading from the given InputStream and the socket is
> closed
> > (the client closes its end), the sessionClosed method is invoked, but
> the
> > blocked read operation (in a different thread) on the InputStream does
> not
> > throw any exception.
> > Please help.
>
>
> It sounds like a bug.  Could you please post this issue to JIRA?
>
> Thanks,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
>
>

how to post issues to JIRA

Posted by peter royal <pr...@apache.org>.
On Mar 25, 2006, at 3:32 PM, Zohar Amir wrote:
> How do I post issues to JIRA? (told you I'm a newbie... ;))

http://issues.apache.org/jira

you will probably need to create an account, then "Create New Issue",  
and select "Directory MINA" as the project. Fill in all the fields  
and submit!
-pete

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



Re: how to work with StreamIoHandler

Posted by Zohar Amir <zo...@gmail.com>.
How do I post issues to JIRA? (told you I'm a newbie... ;))

On 3/25/06, Trustin Lee <tr...@gmail.com> wrote:
>
> On 3/15/06, Zohar Amir <da...@hotmail.com> wrote:
> >
> > What do you mean by "read from a closed session"? I read from the
> > InputStream that I get in the processStreamIo method.
> > Second - while reading from the given InputStream and the socket is
> closed
> > (the client closes its end), the sessionClosed method is invoked, but
> the
> > blocked read operation (in a different thread) on the InputStream does
> not
> > throw any exception.
> > Please help.
>
>
> It sounds like a bug.  Could you please post this issue to JIRA?
>
> Thanks,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6
>
>

Re: how to work with StreamIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
On 3/15/06, Zohar Amir <da...@hotmail.com> wrote:
>
> What do you mean by "read from a closed session"? I read from the
> InputStream that I get in the processStreamIo method.
> Second - while reading from the given InputStream and the socket is closed
> (the client closes its end), the sessionClosed method is invoked, but the
> blocked read operation (in a different thread) on the InputStream does not
> throw any exception.
> Please help.


It sounds like a bug.  Could you please post this issue to JIRA?

Thanks,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: how to work with StreamIoHandler

Posted by Zohar Amir <da...@hotmail.com>.
What do you mean by "read from a closed session"? I read from the 
InputStream that I get in the processStreamIo method.
Second - while reading from the given InputStream and the socket is closed 
(the client closes its end), the sessionClosed method is invoked, but the 
blocked read operation (in a different thread) on the InputStream does not 
throw any exception.
Please help.


----- Original Message ----- 
From: "Trustin Lee" <tr...@gmail.com>
To: <mi...@directory.apache.org>
Sent: Wednesday, March 15, 2006 5:18 AM
Subject: Re: how to work with StreamIoHandler


Hi Zohar,

On 3/14/06, Zohar Amir <da...@hotmail.com> wrote:
>
> Hello,
> I have an application that uses StreamIoHandler.  The processStreamIo
> method
> starts a new thread to handle the incoming data. This thread does
> something
> like:
>
>   public void run() {
>    try {
>     while (true) {
>      Message message = null;
>      message = Decoder.decode(inputStream);
>      System.out.print(message);
>     }
>    } finally {
>     session.close();
>    }
>   }
>
> The questions is how to break the thread loop when the session is closed.
> The solution should also handle clients that send short messages, so that
> the sessionClosed method is invoked before the thread is started and gets
> a
> chance to decode the sent message.


If you try to read from a closed session, it should throw an IOException.
So you could simply catch an IOException and break the loop.

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: how to work with StreamIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
Hi Zohar,

On 3/14/06, Zohar Amir <da...@hotmail.com> wrote:
>
> Hello,
> I have an application that uses StreamIoHandler.  The processStreamIo
> method
> starts a new thread to handle the incoming data. This thread does
> something
> like:
>
>   public void run() {
>    try {
>     while (true) {
>      Message message = null;
>      message = Decoder.decode(inputStream);
>      System.out.print(message);
>     }
>    } finally {
>     session.close();
>    }
>   }
>
> The questions is how to break the thread loop when the session is closed.
> The solution should also handle clients that send short messages, so that
> the sessionClosed method is invoked before the thread is started and gets
> a
> chance to decode the sent message.


If you try to read from a closed session, it should throw an IOException.
So you could simply catch an IOException and break the loop.

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6