You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Frédéric Brégier <fr...@free.fr> on 2007/11/21 19:23:08 UTC

messageSent on DemuxingIoHandler

Hy all, I am on the way to upgrade to last version of trunk...

I have one question on DemuxingIoHandler in trunk version.
I used DemuxingIoHandler  which enables messageSent function to
be overload ("Invoked when a message written by IoSession.write(Object) is sent out.")

I extend MessageHandler for my own message but now it implies the messageSent function (mandatory) too.
("Invoked when the specific type of message is received from the specified session."
Of course here the manual from API has en error since it is obviously "is sent out" and not "is received")

But why those two functions ? Is one call after the other or just one only (and if so, which one) ?

Continue your great job !
Frederic

Re: messageSent on DemuxingIoHandler

Posted by Frédéric Brégier <fr...@free.fr>.
Hi Trustin,
I am still not sure on the answear. For the moment,
I do like both methods are called when message is
send (both from the specific MessageHandler and from
DemuxingIoHandler).

Frederic
----- Original Message ----- 

Hi Trustin,

Well, I am sometime (always ?) quite long in my email
and obviously not necesseraly more clear than others.. ;-)

The problem I found (is this a problem, I don't know) is :
1) In the past, only DemuxingIoHandler has messageSent() function
    to overload but not mandatory (you can if you want not define
    anything). In my code, I had some codes to do some stuff
    after the message is really sent.
2) Now, in trunk, MessageHandler has a mandatory messageSent()
    function.
    As when you use DemuxingIoHandler, you should use also object
    that extends MessageHandler, I feel like a bit loose.
    
Contrary to what I wrote before, I would not suggest to remove
the messageSent() from DemuxingIoHandler since a message can be
sent, even if no MessageHandler is registered for it.
I try in my code, and I saw "DemuxingIoHandler.messageSent()" called
for such message not registered.

Now the question :
If one messageHandler is registered and such a message is sent, which function will be called ?
DemuxingIoHandler.messageSent() on all messages ? or only on not registered messages ?
MessageHandler.messageSent() on all messages that are registered ? 
Or only one (for registered message) ?
As I need to do some stuff after message is sent, I don't know if I need to
writye the same code (or so) in each messageSent() of MessageHandler.

I hope I am more clear, this time.

And for JMX, I was starting to think about it since I feel like I really should improve
this part in my app. So thank you for this ! I start probably this week some benchmark
(I hope almost all my port to "new" trunk is done). After that, I could spend some useful
time on JMX approach...

Frederic
----- Original Message ----- 
From: "Trustin Lee" 

On Nov 22, 2007 5:40 PM,  fred.bregier wrote:
> I suppose the one from MessageHandler is the one that would be executed, right ?
>
> Since we must defined messageSent function in MessageHandler
> (mandatory), second it is not mandatory to get it in DemuxingIoHandler,
> third as you said only one will be called (the one from
> MessageHandler ?), I would say that probably this function in
> DemuxingIoHandler is no more necessary and probably confusing with the
> one from MessageHandler.
> Except if one can use DemuxingIoHandler with something totally different
> from MessageHandler (?), I would suggest to remove this function (or mark
> it as deprecated and pointing to the one in MessageHandler). WDYT ?

I didn't get the question actually.  Could explain again?

Thanks in advance,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6



Re: messageSent on DemuxingIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
Hi Frédéric,

I am so glad that you like my change.  Let me mark the two methods final then.

Cheers,
Trustin

On Dec 13, 2007 3:37 AM, Frédéric Brégier <fr...@free.fr> wrote:
> Hi Trustin,
> I have made all the changes (about an half hour so quite quickly),
> and it is really perfect and more clear now.
> So I think your original idea from the first mail (splitting MessageHandler by
> adding addSentMessageHandler and addReceivedMessageHandler)
> and the given implementation were the good one (as always) !!!
> I really thank you and it gives me the opportunity to correct the logic
> of my program !
>
> I feel like the idea to make final those functions (messageSent and
> messageReceived) in DemuxingIoHandler should be done in order
> to prevent some users (like me) to override them and so breaking
> the Mina's logic.
>
> Again, a very big thank you !
>
> Frederic
>
>



-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: messageSent on DemuxingIoHandler

Posted by Frédéric Brégier <fr...@free.fr>.
Hi Trustin,
I have made all the changes (about an half hour so quite quickly),
and it is really perfect and more clear now.
So I think your original idea from the first mail (splitting MessageHandler by
adding addSentMessageHandler and addReceivedMessageHandler)
and the given implementation were the good one (as always) !!!
I really thank you and it gives me the opportunity to correct the logic
of my program !

I feel like the idea to make final those functions (messageSent and
messageReceived) in DemuxingIoHandler should be done in order
to prevent some users (like me) to override them and so breaking
the Mina's logic.

Again, a very big thank you !

Frederic


Re: messageSent on DemuxingIoHandler

Posted by Frédéric Brégier <fr...@free.fr>.
Hi Trustin,

>I've made more change to MessageHandler and DemuxingIoHandler to fix
>the API design issue you raised.  Please take a look at the following
>change log.  The code will explain everything:
>
>    http://svn.apache.org/viewvc?view=rev&revision=603158

I understand again more clearly after your words what I should do.
I suppose I was confusing with the "standard way" of IoHandler.
I didn't make the necessary change in my code as I should do.
So I will make the change ASAP, taking the last revision of trunk to test it.
I quickly read your change, and I feel like it could do the trick.
I will come back to you with my final impression.

>You could simply register MessageHandler.NOOP to that type of message,
>no?  If you want to ignore all messageSent events, then you can even
>do the following:
>
>    handler.addSentMessageHandler(MessageHandler.NOOP);
>
>Especially with the change I've just made, I think all the concerns
>you raised have been resolved.  Please let me know if there's any case
>that I missed out.

Let me come back after I made the change.

> > If I am correct, in my case, it is therefore necessary to keep both ways
> > as possible in MINA.
> > Except perhaps I break the logic of Min by doing this ?
>
>The possibility of overriding
>DemuxingIoHandler.messageReceived/messageSent/exceptionCaught/findReceivedMessageHandler/findSentMessageHandler/findExceptionHandler
>means that anyone who extends DemuxingIoHandler can break the existing
>logic of DemuxingIoHandler.  We could make all these methods final and
>provide a kind of hook methods whose access modifier is 'protected'.
>Assuming my recent change has resolved all the issues you raised, we
>could do that.  WDYT?

Yes, I think if one should not overriding such methods, you probably
have to make them final, espcially considering it is quite different than
standard way (standard IoHandler, where you have to override them
in the IoHandler) and so should be point both in documentation API
and with the "final" word.

>> Should I register those written only MessageHandler even if I never received one of them ?
>> Perhaps it is related more to your question on splitting MessageHandler ?
>> I don't like to make the API growing more and more, but you probably know better
>> than me what it is better ot not in this case.
>
>Yes, you have to register MessageHandler.NOOP at least to avoid an
>exception.  I think it's mandatory to prevent any mistake that a user
>might forget to register a required handler.

OK, I will make the change and come back to you.
I suppose it should not take too long... (I hope)

Thank you again for your help !

Frederic 


Re: messageSent on DemuxingIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
Hi Frédéric Brégier,

On Dec 11, 2007 12:09 AM, Frédéric Brégier <fr...@free.fr> wrote:
> Hi Trustin,
> Don't be sorry ! I completely understand the time this mailing
> list takes for you, and I really appreciate all the advices you give !!!
> I hope that you still have some night for you and your family...

Thanks for your understanding.  I really appreciate it.  :)

> Now back on the question :
> I understand better now the way it does with your answear.
> In my case, I probably can continue with only DemuxingIoHandler
> implements the global stuff since it is the same on every message
> (or almost, since I free some data specific to each message).
>
> I am not sure (I'm not such an expert) that splitting MessageHandler
> or making catch-all handler is better than now.
> For now, it was just a matter to know how to do it correctly,
> and your answear is just fine. Perhaps a short note in the API
> would be enough to be clear between those two ways.

I've made more change to MessageHandler and DemuxingIoHandler to fix
the API design issue you raised.  Please take a look at the following
change log.  The code will explain everything:

    http://svn.apache.org/viewvc?view=rev&revision=603158

> Now next question (one answear sometimes brings another question)
> is that are you sure DemuxingIoHandler should throw an exception
> on messageSent when there is no messageHandler for it ?
> I look at the code in MINA, and it seems so.
> In my code, I have one particular message that the server will never
> receive but always anwear (written), so there is no messageHandler for it.
> As I overload the messageSent() function in my deumxingIoHandler,
> it never raised the exception since, if I am understanding clearly,
> mine overloading will never try to find the appropriate messageHandler
> (no call to handler.messageSent()).

You could simply register MessageHandler.NOOP to that type of message,
no?  If you want to ignore all messageSent events, then you can even
do the following:

    handler.addSentMessageHandler(MessageHandler.NOOP);

Especially with the change I've just made, I think all the concerns
you raised have been resolved.  Please let me know if there's any case
that I missed out.

> If I am correct, in my case, it is therefore necessary to keep both ways
> as possible in MINA.
> Except perhaps I break the logic of Min by doing this ?

The possibility of overriding
DemuxingIoHandler.messageReceived/messageSent/exceptionCaught/findReceivedMessageHandler/findSentMessageHandler/findExceptionHandler
means that anyone who extends DemuxingIoHandler can break the existing
logic of DemuxingIoHandler.  We could make all these methods final and
provide a kind of hook methods whose access modifier is 'protected'.
Assuming my recent change has resolved all the issues you raised, we
could do that.  WDYT?

> Should I register those written only MessageHandler even if I never received one of them ?
> Perhaps it is related more to your question on splitting MessageHandler ?
> I don't like to make the API growing more and more, but you probably know better
> than me what it is better ot not in this case.

Yes, you have to register MessageHandler.NOOP at least to avoid an
exception.  I think it's mandatory to prevent any mistake that a user
might forget to register a required handler.

> Perhaps my way (overloading DemuxingIoHandler, just an hypothesis)
> could be related to the other problem of 0 value for messages in statistics ?

No.  It's not related.  Let me respond in the other thread.

Cheers,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: messageSent on DemuxingIoHandler

Posted by Frédéric Brégier <fr...@free.fr>.
Hi Trustin,
Don't be sorry ! I completely understand the time this mailing
list takes for you, and I really appreciate all the advices you give !!!
I hope that you still have some night for you and your family...

Now back on the question :
I understand better now the way it does with your answear.
In my case, I probably can continue with only DemuxingIoHandler
implements the global stuff since it is the same on every message
(or almost, since I free some data specific to each message).

I am not sure (I'm not such an expert) that splitting MessageHandler
or making catch-all handler is better than now.
For now, it was just a matter to know how to do it correctly,
and your answear is just fine. Perhaps a short note in the API
would be enough to be clear between those two ways.

Now next question (one answear sometimes brings another question)
is that are you sure DemuxingIoHandler should throw an exception
on messageSent when there is no messageHandler for it ?
I look at the code in MINA, and it seems so.
In my code, I have one particular message that the server will never
receive but always anwear (written), so there is no messageHandler for it.
As I overload the messageSent() function in my deumxingIoHandler,
it never raised the exception since, if I am understanding clearly,
mine overloading will never try to find the appropriate messageHandler
(no call to handler.messageSent()).
If I am correct, in my case, it is therefore necessary to keep both ways
as possible in MINA.
Except perhaps I break the logic of Min by doing this ?
Should I register those written only MessageHandler even if I never received one of them ?
Perhaps it is related more to your question on splitting MessageHandler ?
I don't like to make the API growing more and more, but you probably know better
than me what it is better ot not in this case.

Perhaps my way (overloading DemuxingIoHandler, just an hypothesis)
could be related to the other problem of 0 value for messages in statistics ?

Frederic
----- Original Message ----- 
From: "Trustin Lee"

Hi Frédéric,

I am sorry for the late answer first of all. :)

On Nov 27, 2007 3:15 AM, Frédéric Brégier  wrote:
> Hi Trustin,
>
> Well, I am sometime (always ?) quite long in my email
> and obviously not necesseraly more clear than others.. ;-)
>
> The problem I found (is this a problem, I don't know) is :
> 1) In the past, only DemuxingIoHandler has messageSent() function
>     to overload but not mandatory (you can if you want not define
>     anything). In my code, I had some codes to do some stuff
>     after the message is really sent.
> 2) Now, in trunk, MessageHandler has a mandatory messageSent()
>     function.
>     As when you use DemuxingIoHandler, you should use also object
>     that extends MessageHandler, I feel like a bit loose.
>
> Contrary to what I wrote before, I would not suggest to remove
> the messageSent() from DemuxingIoHandler since a message can be
> sent, even if no MessageHandler is registered for it.
> I try in my code, and I saw "DemuxingIoHandler.messageSent()" called
> for such message not registered.

You can still do what you want with DemuxingIoHandler by overriding
messageSent():

public class MyDemuxingIoHandler extends DemuxingIoHandler {
    @Override
    public void messageSent(...) {
        if (...) {
            // Implement some common logic
        } else {
            super.messageSent(...);
        }
    }
}

It might be better to 1) split MessageHandler into 2 or 2) add a
catch-all handler (e.g.
DemuxingIoHandler.setCatchAllHandler(MessageHandler)) though.  WDYT?

> Now the question :
> If one messageHandler is registered and such a message is sent, which function will be called ?
> DemuxingIoHandler.messageSent() on all messages ? or only on not registered messages ?
> MessageHandler.messageSent() on all messages that are registered ?
> Or only one (for registered message) ?
> As I need to do some stuff after message is sent, I don't know if I need to
> writye the same code (or so) in each messageSent() of MessageHandler.

DemuxingIoHandler.messageSent() is implemented to look for a proper
MessageHandler and call it.  Therefore,
DemuxingIoHandler.messageSent() is always called.  It will throw an
exception if there's no registered handler for a sent message.  Of
course, you can override this behavior like I suggested above.

Thank you so much for your feed back,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6


Re: messageSent on DemuxingIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
Hi Frédéric,

I am sorry for the late answer first of all. :)

On Nov 27, 2007 3:15 AM, Frédéric Brégier <fr...@free.fr> wrote:
> Hi Trustin,
>
> Well, I am sometime (always ?) quite long in my email
> and obviously not necesseraly more clear than others.. ;-)
>
> The problem I found (is this a problem, I don't know) is :
> 1) In the past, only DemuxingIoHandler has messageSent() function
>     to overload but not mandatory (you can if you want not define
>     anything). In my code, I had some codes to do some stuff
>     after the message is really sent.
> 2) Now, in trunk, MessageHandler has a mandatory messageSent()
>     function.
>     As when you use DemuxingIoHandler, you should use also object
>     that extends MessageHandler, I feel like a bit loose.
>
> Contrary to what I wrote before, I would not suggest to remove
> the messageSent() from DemuxingIoHandler since a message can be
> sent, even if no MessageHandler is registered for it.
> I try in my code, and I saw "DemuxingIoHandler.messageSent()" called
> for such message not registered.

You can still do what you want with DemuxingIoHandler by overriding
messageSent():

public class MyDemuxingIoHandler extends DemuxingIoHandler {
    @Override
    public void messageSent(...) {
        if (...) {
            // Implement some common logic
        } else {
            super.messageSent(...);
        }
    }
}

It might be better to 1) split MessageHandler into 2 or 2) add a
catch-all handler (e.g.
DemuxingIoHandler.setCatchAllHandler(MessageHandler)) though.  WDYT?

> Now the question :
> If one messageHandler is registered and such a message is sent, which function will be called ?
> DemuxingIoHandler.messageSent() on all messages ? or only on not registered messages ?
> MessageHandler.messageSent() on all messages that are registered ?
> Or only one (for registered message) ?
> As I need to do some stuff after message is sent, I don't know if I need to
> writye the same code (or so) in each messageSent() of MessageHandler.

DemuxingIoHandler.messageSent() is implemented to look for a proper
MessageHandler and call it.  Therefore,
DemuxingIoHandler.messageSent() is always called.  It will throw an
exception if there's no registered handler for a sent message.  Of
course, you can override this behavior like I suggested above.

Thank you so much for your feed back,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: messageSent on DemuxingIoHandler

Posted by Frédéric Brégier <fr...@free.fr>.
Hi Trustin,

Well, I am sometime (always ?) quite long in my email
and obviously not necesseraly more clear than others.. ;-)

The problem I found (is this a problem, I don't know) is :
1) In the past, only DemuxingIoHandler has messageSent() function
    to overload but not mandatory (you can if you want not define
    anything). In my code, I had some codes to do some stuff
    after the message is really sent.
2) Now, in trunk, MessageHandler has a mandatory messageSent()
    function.
    As when you use DemuxingIoHandler, you should use also object
    that extends MessageHandler, I feel like a bit loose.
    
Contrary to what I wrote before, I would not suggest to remove
the messageSent() from DemuxingIoHandler since a message can be
sent, even if no MessageHandler is registered for it.
I try in my code, and I saw "DemuxingIoHandler.messageSent()" called
for such message not registered.

Now the question :
If one messageHandler is registered and such a message is sent, which function will be called ?
DemuxingIoHandler.messageSent() on all messages ? or only on not registered messages ?
MessageHandler.messageSent() on all messages that are registered ? 
Or only one (for registered message) ?
As I need to do some stuff after message is sent, I don't know if I need to
writye the same code (or so) in each messageSent() of MessageHandler.

I hope I am more clear, this time.

And for JMX, I was starting to think about it since I feel like I really should improve
this part in my app. So thank you for this ! I start probably this week some benchmark
(I hope almost all my port to "new" trunk is done). After that, I could spend some useful
time on JMX approach...

Frederic
----- Original Message ----- 
From: "Trustin Lee" 

On Nov 22, 2007 5:40 PM,  fred.bregier wrote:
> I suppose the one from MessageHandler is the one that would be executed, right ?
>
> Since we must defined messageSent function in MessageHandler
> (mandatory), second it is not mandatory to get it in DemuxingIoHandler,
> third as you said only one will be called (the one from
> MessageHandler ?), I would say that probably this function in
> DemuxingIoHandler is no more necessary and probably confusing with the
> one from MessageHandler.
> Except if one can use DemuxingIoHandler with something totally different
> from MessageHandler (?), I would suggest to remove this function (or mark
> it as deprecated and pointing to the one in MessageHandler). WDYT ?

I didn't get the question actually.  Could explain again?

Thanks in advance,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6


Re: messageSent on DemuxingIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
On Nov 22, 2007 5:40 PM,  <fr...@free.fr> wrote:
> I suppose the one from MessageHandler is the one that would be executed, right ?
>
> Since we must defined messageSent function in MessageHandler
> (mandatory), second it is not mandatory to get it in DemuxingIoHandler,
> third as you said only one will be called (the one from
> MessageHandler ?), I would say that probably this function in
> DemuxingIoHandler is no more necessary and probably confusing with the
> one from MessageHandler.
> Except if one can use DemuxingIoHandler with something totally different
> from MessageHandler (?), I would suggest to remove this function (or mark
> it as deprecated and pointing to the one in MessageHandler). WDYT ?

I didn't get the question actually.  Could explain again?

Thanks in advance,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: messageSent on DemuxingIoHandler

Posted by fr...@free.fr.
Hi Trustin,
I don't think splitting MessageHandler into the two interfaces makes more sense
since, at least for me, it is simpler to write both sides in one class
as some codes could be duplicated if I split them.
So my question is (I could read the code but I feel like asking could be
faster ;-)

I suppose the one from MessageHandler is the one that would be executed, right ?

Since we must defined messageSent function in MessageHandler
(mandatory), second it is not mandatory to get it in DemuxingIoHandler,
third as you said only one will be called (the one from
MessageHandler ?), I would say that probably this function in
DemuxingIoHandler is no more necessary and probably confusing with the
one from MessageHandler.
Except if one can use DemuxingIoHandler with something totally different
from MessageHandler (?), I would suggest to remove this function (or mark
it as deprecated and pointing to the one in MessageHandler). WDYT ?

Frederic

Selon Trustin Lee <tr...@gmail.com>:

> Hi Frédéric,
>
> On Nov 22, 2007 3:23 AM, Frédéric Brégier <fr...@free.fr> wrote:
> > Hy all, I am on the way to upgrade to last version of trunk...
> >
> > I have one question on DemuxingIoHandler in trunk version.
> > I used DemuxingIoHandler  which enables messageSent function to
> > be overload ("Invoked when a message written by IoSession.write(Object) is
> sent out.")
> >
> > I extend MessageHandler for my own message but now it implies the
> messageSent function (mandatory) too.
> > ("Invoked when the specific type of message is received from the specified
> session."
> > Of course here the manual from API has en error since it is obviously "is
> sent out" and not "is received")
>
> Thanks for pointing out the JavaDoc error.  I've just fixed it.
>
> > But why those two functions ? Is one call after the other or just one only
> (and if so, which one) ?
>
> It depends on situation but only one will be used and the other will
> be left as blank method for most cases.  Thinking of why... well, I
> was somewhat crazy about creating more interfaces (i.e. replacing
> MessageHandler with ReceivedMessageHandler and SentMessageHandler).
> I'm not actually sure if it was a right decision.  Please let me know
> if splitting MessageHandler into the two interfaces makes more sense.
>
> Thanks,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>



Re: messageSent on DemuxingIoHandler

Posted by Trustin Lee <tr...@gmail.com>.
Hi Frédéric,

On Nov 22, 2007 3:23 AM, Frédéric Brégier <fr...@free.fr> wrote:
> Hy all, I am on the way to upgrade to last version of trunk...
>
> I have one question on DemuxingIoHandler in trunk version.
> I used DemuxingIoHandler  which enables messageSent function to
> be overload ("Invoked when a message written by IoSession.write(Object) is sent out.")
>
> I extend MessageHandler for my own message but now it implies the messageSent function (mandatory) too.
> ("Invoked when the specific type of message is received from the specified session."
> Of course here the manual from API has en error since it is obviously "is sent out" and not "is received")

Thanks for pointing out the JavaDoc error.  I've just fixed it.

> But why those two functions ? Is one call after the other or just one only (and if so, which one) ?

It depends on situation but only one will be used and the other will
be left as blank method for most cases.  Thinking of why... well, I
was somewhat crazy about creating more interfaces (i.e. replacing
MessageHandler with ReceivedMessageHandler and SentMessageHandler).
I'm not actually sure if it was a right decision.  Please let me know
if splitting MessageHandler into the two interfaces makes more sense.

Thanks,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6