fr.dyade.aaa.agent
Class Network

java.lang.Object
  extended by fr.dyade.aaa.agent.Network
All Implemented Interfaces:
MessageConsumer, NetworkMBean
Direct Known Subclasses:
StreamNetwork, UDPNetwork

public abstract class Network
extends java.lang.Object
implements MessageConsumer, NetworkMBean

The Network abstract class provides ..


Nested Class Summary
(package private)  class Network.NetworkAverageLoadTask
           
 
Field Summary
(package private) static int ALREADY_DELIVERED
          The message has already been delivered.
(package private)  Network.NetworkAverageLoadTask averageLoadTask
           
private  int[] bootTS
           
protected  java.lang.String bootTSFN
          Filename for boot time stamp storage.
(package private) static int DELIVER
          The message can be delivered.
protected  java.lang.String domain
          The domain name.
protected  int idxLS
          Index of local server in status and matrix arrays.
protected  org.objectweb.util.monolog.api.Logger logmon
           
protected  java.lang.String name
          The component's name as it appears in logging.
protected  int nbMessageIn
           
protected  int nbMessageOut
           
protected  int port
          The communication port.
protected  MessageVector qout
          The MessageVector associated with this network component.
protected  short[] servers
          List of id. for all servers in the domain, this list is sorted and is used as index for internal tables.
protected  java.lang.String serversFN
          Filename for servers storage.
protected  short sid
          Id. of local server.
private  int[] stamp
          Logical timestamp information for messages in domain, stamp[idxLS)] for messages sent, and stamp[index(id] for messages received.
private  byte[] stampbuf
          Buffer used to optimize transactions.
(package private)  long WDActivationPeriod
          Period of time in ms between two activations of watch-dog thread, default value is 1000L (1 second).
(package private)  int WDNbRetryLevel1
          Number of try at stage 1, default value is 5.
(package private)  int WDNbRetryLevel2
          Number of try at stage 2, default value is 30.
(package private)  long WDRetryPeriod1
          Period of time in ms between two connection try at stage 1, default value is WDActivationPeriod.
(package private)  long WDRetryPeriod2
          Period of time in ms between two connection try at stage 2, default value is 10000L (10 seconds).
(package private)  long WDRetryPeriod3
          Period of time in ms between two connection try at stage 3, default value is 60000L (1 minute).
 
Constructor Summary
Network()
          Creates a new network component.
 
Method Summary
 void addServer(short id)
          Adds the server sid in the network configuration.
 void delete()
          Deletes the component, removes all persistent data.
protected  void deliver(Message msg)
          Try to deliver the received message to the right consumer.
 void delServer(short id)
          Removes the server sid in the network configuration.
 float getAverageLoad1()
          Returns the load averages for the last minute.
 float getAverageLoad15()
          Returns the load averages for the past 15 minutes.
 float getAverageLoad5()
          Returns the load averages for the past 5 minutes.
(package private)  int getBootTS()
           
 java.lang.String getDomainName()
          Returns the corresponding domain's name.
 java.lang.String getName()
          Returns this session's name.
 int getNbMessageReceived()
          Returns the number of messages received since last reboot.
 int getNbMessageSent()
          Returns the number of messages sent since last reboot.
 int getNbWaitingMessages()
          Gets the number of waiting messages in this engine.
 int getPort()
           
 MessageQueue getQueue()
          Get this consumer's MessageQueue.
private  int getSendUpdate(short to)
          Computes the matrix clock of a send message.
protected  byte[] getStamp()
           
 long getWDActivationPeriod()
          Gets the WDActivationPeriod value.
 int getWDNbRetryLevel1()
          Gets the WDNbRetryLevel1 value.
 int getWDNbRetryLevel2()
          Gets the WDNbRetryLevel2 value.
 long getWDRetryPeriod1()
          Gets the WDRetryPeriod1 value.
 long getWDRetryPeriod2()
          Gets the WDRetryPeriod2 value.
 long getWDRetryPeriod3()
          Gets the WDRetryPeriod3 value.
protected  int index(short id)
          Returns the index in internal table of the specified server.
 void init(java.lang.String name, int port, short[] servers)
          Initializes a new network component.
 void insert(Message msg)
          Insert a message in the MessageQueue.
 void post(Message msg)
          Adds a message in "ready to deliver" list.
(package private)  void resetServer(short id, int boot)
          Reset all information related to server sid in the network configuration.
 void restore()
          Restores component's information from persistent storage.
 void save()
          Saves information to persistent storage.
 void setPort(int port)
          Updates the network port.
 void setProperties()
          Set the properties of the network.
protected  void setStamp(byte[] stampbuf)
           
 void setWDActivationPeriod(long WDActivationPeriod)
          Sets the WDActivationPeriod value.
 void setWDNbRetryLevel1(int WDNbRetryLevel1)
          Sets the WDNbRetryLevel1 value.
 void setWDNbRetryLevel2(int WDNbRetryLevel2)
          Sets the WDNbRetryLevel2 value.
 void setWDRetryPeriod1(long WDRetryPeriod1)
          Sets the WDRetryPeriod1 value.
 void setWDRetryPeriod2(long WDRetryPeriod2)
          Sets the WDRetryPeriod2 value.
 void setWDRetryPeriod3(long WDRetryPeriod3)
          Sets the WDRetryPeriod3 value.
(package private)  void testBootTS(short source, int boot)
           
private  int testRecvUpdate(short source, int update)
          Test if a received message with the specified clock must be delivered.
 java.lang.String toString()
          Returns a string representation of this consumer.
private  void updateStamp(int idx, int update)
           
 void validate()
          Validates all messages pushed in queue during transaction session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fr.dyade.aaa.agent.MessageConsumer
isRunning, start, stop
 
Methods inherited from interface fr.dyade.aaa.agent.NetworkMBean
isRunning, start, stop
 

Field Detail

WDActivationPeriod

long WDActivationPeriod
Period of time in ms between two activations of watch-dog thread, default value is 1000L (1 second). This value can be adjusted for all network components by setting WDActivationPeriod global property or for a particular network by setting \.WDActivationPeriod specific property.

Theses properties can be fixed either from java launching command, or in a3servers.xml configuration file.


WDNbRetryLevel1

int WDNbRetryLevel1
Number of try at stage 1, default value is 5. This value can be adjusted for all network components by setting WDNbRetryLevel1 global property or for a particular network by setting \.WDNbRetryLevel1 specific property.

Theses properties can be fixed either from java launching command, or in a3servers.xml configuration file.


WDRetryPeriod1

long WDRetryPeriod1
Period of time in ms between two connection try at stage 1, default value is WDActivationPeriod. This value can be adjusted for all network components by setting WDRetryPeriod1 global property or for a particular network by setting \.WDRetryPeriod1 specific property.

Theses properties can be fixed either from java launching command, or in a3servers.xml configuration file.

Be careful, in most Network components setting this value to a value less than WDActivationPeriod is useless. In the same way, the real try period is depending of the connection timeout.


WDNbRetryLevel2

int WDNbRetryLevel2
Number of try at stage 2, default value is 30. This value can be adjusted for all network components by setting WDNbRetryLevel2 global property or for a particular network by setting \.WDNbRetryLevel2 specific property.

Theses properties can be fixed either from java launching command, or in a3servers.xml configuration file.


WDRetryPeriod2

long WDRetryPeriod2
Period of time in ms between two connection try at stage 2, default value is 10000L (10 seconds). This value can be adjusted for all network components by setting WDRetryPeriod2 global property or for a particular network by setting \.WDRetryPeriod2 specific property.

Theses properties can be fixed either from java launching command, or in a3servers.xml configuration file.

Be careful, in most Network components setting this value to a value less than WDActivationPeriod is useless. In the same way, the real try period is depending of the connection timeout.


WDRetryPeriod3

long WDRetryPeriod3
Period of time in ms between two connection try at stage 3, default value is 60000L (1 minute). This value can be adjusted for all network components by setting WDRetryPeriod3 global property or for a particular network by setting \.WDRetryPeriod3 specific property.

Theses properties can be fixed either from java launching command, or in a3servers.xml configuration file.

Be careful, in most Network components setting this value to a value less than WDActivationPeriod is useless. In the same way, the real try period is depending of the connection timeout.


nbMessageOut

protected int nbMessageOut

nbMessageIn

protected int nbMessageIn

logmon

protected org.objectweb.util.monolog.api.Logger logmon

sid

protected short sid
Id. of local server.


idxLS

protected int idxLS
Index of local server in status and matrix arrays.


servers

protected short[] servers
List of id. for all servers in the domain, this list is sorted and is used as index for internal tables.


serversFN

protected transient java.lang.String serversFN
Filename for servers storage.


stamp

private int[] stamp
Logical timestamp information for messages in domain, stamp[idxLS)] for messages sent, and stamp[index(id] for messages received.


stampbuf

private byte[] stampbuf
Buffer used to optimize transactions.


bootTS

private int[] bootTS

bootTSFN

protected transient java.lang.String bootTSFN
Filename for boot time stamp storage.


name

protected java.lang.String name
The component's name as it appears in logging.


domain

protected java.lang.String domain
The domain name.


port

protected int port
The communication port.


qout

protected MessageVector qout
The MessageVector associated with this network component.


DELIVER

static final int DELIVER
The message can be delivered.

See Also:
Constant Field Values

ALREADY_DELIVERED

static final int ALREADY_DELIVERED
The message has already been delivered.

See Also:
Constant Field Values

averageLoadTask

Network.NetworkAverageLoadTask averageLoadTask
Constructor Detail

Network

public Network()
Creates a new network component. This simple constructor is required in order to use Class.newInstance() method during configuration. The configuration of component is then done by init method.

Method Detail

getWDActivationPeriod

public long getWDActivationPeriod()
Gets the WDActivationPeriod value.

Specified by:
getWDActivationPeriod in interface NetworkMBean
Returns:
the WDActivationPeriod value

setWDActivationPeriod

public void setWDActivationPeriod(long WDActivationPeriod)
Sets the WDActivationPeriod value.

Specified by:
setWDActivationPeriod in interface NetworkMBean
Parameters:
WDActivationPeriod - the WDActivationPeriod value

getWDNbRetryLevel1

public int getWDNbRetryLevel1()
Gets the WDNbRetryLevel1 value.

Specified by:
getWDNbRetryLevel1 in interface NetworkMBean
Returns:
the WDNbRetryLevel1 value

setWDNbRetryLevel1

public void setWDNbRetryLevel1(int WDNbRetryLevel1)
Sets the WDNbRetryLevel1 value.

Specified by:
setWDNbRetryLevel1 in interface NetworkMBean
Parameters:
WDNbRetryLevel1 - the WDNbRetryLevel1 value

getWDRetryPeriod1

public long getWDRetryPeriod1()
Gets the WDRetryPeriod1 value.

Specified by:
getWDRetryPeriod1 in interface NetworkMBean
Returns:
the WDRetryPeriod1 value

setWDRetryPeriod1

public void setWDRetryPeriod1(long WDRetryPeriod1)
Sets the WDRetryPeriod1 value.

Specified by:
setWDRetryPeriod1 in interface NetworkMBean
Parameters:
WDRetryPeriod1 - the WDRetryPeriod1 value

getWDNbRetryLevel2

public int getWDNbRetryLevel2()
Gets the WDNbRetryLevel2 value.

Specified by:
getWDNbRetryLevel2 in interface NetworkMBean
Returns:
the WDNbRetryLevel2 value

setWDNbRetryLevel2

public void setWDNbRetryLevel2(int WDNbRetryLevel2)
Sets the WDNbRetryLevel2 value.

Specified by:
setWDNbRetryLevel2 in interface NetworkMBean
Parameters:
WDNbRetryLevel2 - the WDNbRetryLevel2 value

getWDRetryPeriod2

public long getWDRetryPeriod2()
Gets the WDRetryPeriod2 value.

Specified by:
getWDRetryPeriod2 in interface NetworkMBean
Returns:
the WDRetryPeriod2 value

setWDRetryPeriod2

public void setWDRetryPeriod2(long WDRetryPeriod2)
Sets the WDRetryPeriod2 value.

Specified by:
setWDRetryPeriod2 in interface NetworkMBean
Parameters:
WDRetryPeriod2 - the WDRetryPeriod2 value

getWDRetryPeriod3

public long getWDRetryPeriod3()
Gets the WDRetryPeriod3 value.

Specified by:
getWDRetryPeriod3 in interface NetworkMBean
Returns:
the WDRetryPeriod3 value

setWDRetryPeriod3

public void setWDRetryPeriod3(long WDRetryPeriod3)
Sets the WDRetryPeriod3 value.

Specified by:
setWDRetryPeriod3 in interface NetworkMBean
Parameters:
WDRetryPeriod3 - the WDRetryPeriod3 value

getNbWaitingMessages

public int getNbWaitingMessages()
Gets the number of waiting messages in this engine.

Specified by:
getNbWaitingMessages in interface NetworkMBean
Returns:
the number of waiting messages.

getNbMessageSent

public int getNbMessageSent()
Returns the number of messages sent since last reboot.

Specified by:
getNbMessageSent in interface NetworkMBean
Returns:
the number of messages sent since last reboot.

getNbMessageReceived

public int getNbMessageReceived()
Returns the number of messages received since last reboot.

Specified by:
getNbMessageReceived in interface NetworkMBean
Returns:
the number of messages received since last reboot.

getName

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

Specified by:
getName in interface MessageConsumer
Specified by:
getName in interface NetworkMBean
Returns:
this session's name.

getDomainName

public final java.lang.String getDomainName()
Returns the corresponding domain's name.

Specified by:
getDomainName in interface MessageConsumer
Returns:
this domain's name.

toString

public java.lang.String toString()
Returns a string representation of this consumer.

Specified by:
toString in interface NetworkMBean
Overrides:
toString in class java.lang.Object
Returns:
A string representation of this consumer.

insert

public void insert(Message msg)
Insert a message in the MessageQueue. This method is used during initialization to restore the component state from persistent storage.

Specified by:
insert in interface MessageConsumer
Parameters:
msg - the message

save

public void save()
          throws java.io.IOException
Saves information to persistent storage.

Specified by:
save in interface MessageConsumer
Throws:
java.io.IOException

restore

public void restore()
             throws java.lang.Exception
Restores component's information from persistent storage. If it is the first load, initializes it.

Specified by:
restore in interface MessageConsumer
Throws:
java.lang.Exception

init

public void init(java.lang.String name,
                 int port,
                 short[] servers)
          throws java.lang.Exception
Initializes a new network component. This method is used in order to easily creates and configure a Network component from a class name. So we can use the Class.newInstance() method for create (without any parameter) the component, then we can initialize it with this method.
This method initializes the logical clock for the domain.

Parameters:
name - The domain name.
port - The listen port.
servers - The list of servers directly accessible from this network interface.
Throws:
java.lang.Exception

setProperties

public void setProperties()
                   throws java.lang.Exception
Set the properties of the network. Can be extended by subclasses.

Throws:
java.lang.Exception

addServer

public void addServer(short id)
               throws java.lang.Exception
Adds the server sid in the network configuration.

Parameters:
id - the unique server id.
Throws:
java.lang.Exception

delServer

public void delServer(short id)
               throws java.lang.Exception
Removes the server sid in the network configuration.

Parameters:
id - the unique server id.
Throws:
java.lang.Exception

resetServer

void resetServer(short id,
                 int boot)
           throws java.io.IOException
Reset all information related to server sid in the network configuration.

Parameters:
id - the unique server id.
Throws:
java.io.IOException

post

public void post(Message msg)
          throws java.lang.Exception
Adds a message in "ready to deliver" list. This method allocates a new time stamp to the message ; be Careful, changing the stamp imply the filename change too.

Specified by:
post in interface MessageConsumer
Throws:
java.lang.Exception

index

protected final int index(short id)
Returns the index in internal table of the specified server. The servers array must be ordered.

Parameters:
id - the unique server id.

getStamp

protected final byte[] getStamp()

setStamp

protected final void setStamp(byte[] stampbuf)

updateStamp

private void updateStamp(int idx,
                         int update)
                  throws java.io.IOException
Throws:
java.io.IOException

testRecvUpdate

private int testRecvUpdate(short source,
                           int update)
                    throws java.io.IOException
Test if a received message with the specified clock must be delivered. If the message is ready to be delivered, the method returns DELIVER and the matrix clock is updated. If the message has already been delivered, the method returns ALREADY_DELIVERED, and if other messages are waited before this message the method returns WAIT_TO_DELIVER. In the last two case the matrix clock remains unchanged.

Parameters:
update - The message matrix clock (list of update).
Returns:
DELIVER, ALREADY_DELIVERED, or WAIT_TO_DELIVER code.
Throws:
java.io.IOException

getSendUpdate

private int getSendUpdate(short to)
                   throws java.io.IOException
Computes the matrix clock of a send message. The server's matrix clock is updated.

Parameters:
to - The identification of receiver.
Returns:
The message matrix clock (list of update).
Throws:
java.io.IOException

getBootTS

final int getBootTS()

testBootTS

final void testBootTS(short source,
                      int boot)
               throws java.io.IOException
Throws:
java.io.IOException

deliver

protected void deliver(Message msg)
                throws java.lang.Exception
Try to deliver the received message to the right consumer.

Parameters:
msg - the message.
Throws:
java.lang.Exception

delete

public void delete()
            throws java.lang.IllegalStateException
Deletes the component, removes all persistent data. The component may have been previously stopped, and removed from MessageConsumer list. This operation use Transaction calls, you may use commit to validate it.

Specified by:
delete in interface MessageConsumer
Throws:
java.lang.IllegalStateException
See Also:
Transaction

validate

public void validate()
Validates all messages pushed in queue during transaction session.

Specified by:
validate in interface MessageConsumer

getQueue

public MessageQueue getQueue()
Description copied from interface: MessageConsumer
Get this consumer's MessageQueue. Use in administration and debug tasks, should be replaced by a common attribute.

Specified by:
getQueue in interface MessageConsumer
Returns:
this MessageConsumer's queue.

setPort

public void setPort(int port)
Updates the network port.


getPort

public final int getPort()

getAverageLoad1

public float getAverageLoad1()
Returns the load averages for the last minute.

Specified by:
getAverageLoad1 in interface MessageConsumer
Specified by:
getAverageLoad1 in interface NetworkMBean
Returns:
the load averages for the last minute.

getAverageLoad5

public float getAverageLoad5()
Returns the load averages for the past 5 minutes.

Specified by:
getAverageLoad5 in interface MessageConsumer
Specified by:
getAverageLoad5 in interface NetworkMBean
Returns:
the load averages for the past 5 minutes.

getAverageLoad15

public float getAverageLoad15()
Returns the load averages for the past 15 minutes.

Specified by:
getAverageLoad15 in interface MessageConsumer
Specified by:
getAverageLoad15 in interface NetworkMBean
Returns:
the load averages for the past 15 minutes.


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