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

Reply via email to