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 <[EMAIL PROTECTED]> 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