fr.dyade.aaa.agent
Class NGNetwork.CnxHandler

java.lang.Object
  extended by fr.dyade.aaa.agent.NGNetwork.CnxHandler
Enclosing class:
NGNetwork

 class NGNetwork.CnxHandler
extends java.lang.Object


Nested Class Summary
(package private)  class NGNetwork.CnxHandler.MessageInputStream
          Class used to read messages through a stream.
(package private)  class NGNetwork.CnxHandler.MessageOutputStream
          Class used to send messages through a stream.
 
Field Summary
(package private)  java.nio.ByteBuffer bufin
          Informations for input
(package private)  java.nio.ByteBuffer bufout
           
(package private)  java.nio.channels.SocketChannel channel
          The communication socket channel
(package private)  long lasttry
          Date of last connection attempt
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.
(package private)  NGNetwork.CnxHandler.MessageInputStream mis
           
(package private)  NGNetwork.CnxHandler.MessageOutputStream mos
           
private  java.lang.String name
          The handler's name.
(package private)  int nbwrite
          Informations for output
(package private)  NGNetwork.MessageVector sendlist
          FIFO list of all messages to be sent
private  ServerDesc server
          The description of the remote server handled by this network session
private  short sid
          Destination server id
 
Constructor Summary
NGNetwork.CnxHandler(java.lang.String name, short sid)
           
 
Method Summary
private  void ack(int stamp)
           
(package private)  void close()
           
private  void doAck(int ack)
          Removes all messages in sendList previous to the ack'ed one.
 java.lang.String getName()
          Returns this session's name.
(package private)  void init()
           
(package private)  boolean localStart()
          Its method is called by start in order to initiate a connection from the local server.
private  void read()
          Method called each time the channel is Readable
(package private)  boolean remoteStart(java.nio.channels.SocketChannel channel, int boot)
          Its method is called by start in order to reply to a connection request from a remote server.
(package private)  void send(Message msg)
           
(package private)  void start()
           
private  void startEnd()
          The session is well initialized, we can start the server thread that "listen" the connected socket.
 java.lang.String toString()
           
private  void write()
          Method called each time the channel is Writable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sid

private short sid
Destination server id


name

private java.lang.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


channel

java.nio.channels.SocketChannel channel
The communication socket channel


lasttry

long lasttry
Date of last connection attempt


nbwrite

int nbwrite
Informations for output


mos

NGNetwork.CnxHandler.MessageOutputStream mos

bufout

java.nio.ByteBuffer bufout

sendlist

NGNetwork.MessageVector sendlist
FIFO list of all messages to be sent


bufin

java.nio.ByteBuffer bufin
Informations for input


mis

NGNetwork.CnxHandler.MessageInputStream mis
Constructor Detail

NGNetwork.CnxHandler

NGNetwork.CnxHandler(java.lang.String name,
                     short sid)
               throws java.io.IOException
Throws:
java.io.IOException
Method Detail

init

void init()
    throws java.io.IOException,
           UnknownServerException
Throws:
java.io.IOException
UnknownServerException

getName

public final java.lang.String getName()
Returns this session's name.

Returns:
this session's name.

start

void start()
     throws java.io.IOException
Throws:
java.io.IOException

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:

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(java.nio.channels.SocketChannel channel,
                    int boot)
Its method is called by start in order to reply to a connection request from a remote server. The corresponding code on remote server is the method localStart.

Parameters:
sock - the connected socket
ois - the input stream
oos - the output stream
Returns:
true if the connection is established, false otherwise.

startEnd

private void startEnd()
               throws java.io.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:
java.io.IOException

send

void send(Message msg)
    throws java.io.IOException
Throws:
java.io.IOException

write

private void write()
            throws java.io.IOException
Method called each time the channel is Writable

Throws:
java.io.IOException

read

private void read()
           throws java.lang.Exception
Method called each time the channel is Readable

Throws:
java.lang.Exception

doAck

private final void doAck(int ack)
                  throws java.io.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.

Throws:
java.io.IOException

ack

private final void ack(int stamp)
                throws java.lang.Exception
Throws:
java.lang.Exception

close

void close()
     throws java.io.IOException
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010 ScalAgent D.T.. All Rights Reserved.