Class NGNetwork.CnxHandler

    • Field Detail

      • sid

        private short sid
        Destination server id
      • name

        private String name
        The handler's name.
      • local

        private boolean local
        True if a "local" connection is in progress, a local connection is initiated from this server to the remote one (defined by the server descriptor. This attribute is used to synchronize local and remote attempts to make connections.
      • server

        private ServerDesc server
        The description of the remote server handled by this network session
      • lasttry

        long lasttry
        Date of last connection attempt
      • nbwrite

        int nbwrite
        Informations for output
    • Method Detail

      • getName

        public final String getName()
        Returns this session's name.
        Returns:
        this session's name.
      • localStart

        boolean localStart()
        Its method is called by start in order to initiate a connection from the local server. The corresponding code on remote server is the method remoteStart. Its method creates the socket, initiates the network connection, and negociates with remote server.
        Its method can be overidden in order to change the connection protocol (introduces authentification by example, or uses SSL), but must respect somes conditions:
        • send a Boot object after the initialization of object streams (it is waiting by the wakeOnConnection thread),
        • wait for an acknowledge,
        • set the sock, ois and oos attributes at the end if the connection is correct.

        In order to overide the protocol, we have to implements its method, with the remoteStart and the transmit methods.

        Returns:
        true if the connection is established, false otherwise.
      • remoteStart

        boolean remoteStart​(SocketChannel channel,
                            int boot)
        Its method is called by start method in order to reply to a connection request from a remote server. The corresponding code on remote server is in the method localStart().
        Parameters:
        channel - The SocketChannel to use.
        boot - The boot stamp.
        Returns:
        true if the connection is established, false otherwise.
      • startEnd

        private void startEnd()
                       throws IOException
        The session is well initialized, we can start the server thread that "listen" the connected socket. If the maximum number of connections is reached, one connection from the pool is closed.
        Throws:
        IOException - an error occurs.
      • write

        private void write()
                    throws IOException
        Method called each time the channel is Writable
        Throws:
        IOException - an error occurs.
      • read

        private void read()
                   throws Exception
        Method called each time the channel is Readable
        Throws:
        Exception - an error occurs.
      • doAck

        private final void doAck​(int ack)
                          throws IOException
        Removes all messages in sendList previous to the ack'ed one. Be careful, messages in sendList are not always in stamp order. Its method should not be synchronized, it scans the list from begin to end, and it removes always the first element. Other methods using sendList just adds element at the end.
        Parameters:
        ack - the message to ack.
        Throws:
        IOException - an error occurs.