Hi guys,

I looked at the SelectorListner interface and its implementation.

Here is the hierarchy of classes implementing this interface :

(SelectorListener)
        o
        |
        +-- [NioTcpServer]
        |
        +-- [NioUdpServer]
        |
        +-- [NioTcpSesession]

The interface itself expose one single method :
    void ready(boolean accept, boolean read, ByteBuffer readBuffer,
boolean write);

Considering that the implementers code is like that :

NioTcpServer

    public void ready(final boolean accept, final boolean read, final
ByteBuffer readBuffer, final boolean write) {
        if (accept) {
            createSession(getServerSocketChannel().accept());
        }

        if (read || write) {
            throw new IllegalStateException("should not receive read or
write events");
        }
    }

NioUdpServer

    public void ready(final boolean accept, final boolean read, final
ByteBuffer readBuffer, final boolean write) {
        if (read) {
                readBuffer.clear();

                final SocketAddress source =
datagramChannel.receive(readBuffer);
                readBuffer.flip();

                NioUdpSession session = sessions.get(source);

                if (session == null) {
                    session = new NioUdpSession(this, idleChecker,
address, source);
                }

                session.receivedDatagram(readBuffer);
        }

        if (write) {
            // TODO : flush session
        }
    }

NioTcpSession

    public void ready(final boolean accept, final boolean read, final
ByteBuffer readBuffer, final boolean write) {
        if (read) {
            processRead(readBuffer);
        }

        if (write) {
            processWrite();
        }
        if (accept) {
            throw new IllegalStateException("accept event should never
occur on NioTcpSession");
        }
    }


I'm wondering if it would not be more convenient to have 3 methods
(well, 4 would probably be better) :

    void readyRead(ByteBuffer readBuffer);
    void readyWrite();
    void readyAccept();
    void readyConnect(); // This is for the client

With an intermediate abstract class, we will just have to implement the
method we need in the classes (for instance, the readyConnect() will
only be implemented by the client, not by the server).

wdyt ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to