Class Network
- java.lang.Object
-
- fr.dyade.aaa.agent.Network
-
- All Implemented Interfaces:
MessageComparator,MessageConsumer,NetworkMBean
- Direct Known Subclasses:
StreamNetwork,UDPNetwork
public abstract class Network extends Object implements MessageConsumer, NetworkMBean
TheNetworkabstract class provides ..
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classNetwork.NetworkAverageLoadTask
-
Field Summary
Fields Modifier and Type Field Description protected static intALREADY_DELIVEREDThe message has already been delivered.(package private) Network.NetworkAverageLoadTaskaverageLoadTaskprivate int[]bootTSprotected StringbootTSFNFilename for boot time stamp storage.protected static booleanDEBUGprotected static intDELIVERThe message can be delivered.protected StringdomainThe domain name.protected intidxLSIndex of local server in status and matrix arrays.protected Loggerloggerprotected StringnameThe component's name as it appears in logging.protected intnbMessageInprotected intnbMessageOutprotected intportThe communication port.protected MessageVectorqoutTheMessageVectorassociated with this network component.protected short[]serversList of id. for all servers in the domain, this list is sorted and is used as index for internal tables.protected StringserversFNFilename for servers storage.protected shortsidId. of local server.private int[]stampLogical timestamp information for messages in domain, stamp[idxLS)] for messages sent, and stamp[index(id] for messages received.private byte[]stampbufBuffer used to optimize transactions.(package private) longWDActivationPeriodPeriod of time in ms between two activations of watch-dog thread, default value is 1000L (1 second).(package private) intWDNbRetryLevel1Number of try at stage 1, default value is 5.(package private) intWDNbRetryLevel2Number of try at stage 2, default value is 30.(package private) longWDRetryPeriod1Period of time in ms between two connection try at stage 1, default value is WDActivationPeriod.(package private) longWDRetryPeriod2Period of time in ms between two connection try at stage 2, default value is 10000L (10 seconds).(package private) longWDRetryPeriod3Period of time in ms between two connection try at stage 3, default value is 60000L (1 minute).
-
Constructor Summary
Constructors Constructor Description Network()Creates a new network component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddServer(short id)Adds the server sid in the network configuration.protected voidchannelPostAndValidate(Message msg)protected voidcheckActive(ServerDesc desc)voiddelete()Deletes the component, removes all persistent data.protected voiddeleteMessage(Message msg)protected voiddeliver(Message msg)Try to deliver the received message to the right consumer.voiddelServer(short id)Removes the server sid in the network configuration.floatgetAverageLoad1()Returns the load averages for the last minute.floatgetAverageLoad15()Returns the load averages for the past 15 minutes.floatgetAverageLoad5()Returns the load averages for the past 5 minutes.(package private) intgetBootTS()StringgetDomainName()Returns the corresponding domain's name.protected shortgetMessageDest(Message msg)protected shortgetMessageSource(Message msg)StringgetName()Returns this session's name.intgetNbMessageReceived()Returns the number of messages received since last reboot.intgetNbMessageSent()Returns the number of messages sent since last reboot.intgetNbWaitingMessages()Gets the number of waiting messages in this engine.intgetPort()MessageQueuegetQueue()Get this consumer'sMessageQueue.private intgetSendUpdate(short to)Computes the matrix clock of a send message.protected byte[]getStamp()longgetWDActivationPeriod()Gets the WDActivationPeriod value.intgetWDNbRetryLevel1()Gets the WDNbRetryLevel1 value.intgetWDNbRetryLevel2()Gets the WDNbRetryLevel2 value.longgetWDRetryPeriod1()Gets the WDRetryPeriod1 value.longgetWDRetryPeriod2()Gets the WDRetryPeriod2 value.longgetWDRetryPeriod3()Gets the WDRetryPeriod3 value.protected intindex(short id)Returns the index in internal table of the specified server.voidinit(String name, int port, short[] servers)Initializes a new network component.voidinsert(Message msg)Insert a message in theMessageQueue.booleanisPrior(Message m1, Message m2)Compares the 2 messages for time ordering.voidpost(Message msg)Adds a message in "ready to deliver" list.voidpostAndValidate(Message msg)Posts and validates a message.protected voidpostMessage(Message msg)protected voidprepareMessage(Message msg)protected voidprepareMessageWithoutStamp(Message msg)(package private) voidresetServer(short id, int boot)Reset all information related to server sid in the network configuration.voidrestore()Restores component's information from persistent storage.voidsave()Saves information to persistent storage.protected voidsaveChannel()protected voidsetMessageSource(Message msg, short source)voidsetPort(int port)Updates the network port.voidsetProperties()Set the properties of the network.protected voidsetStamp(byte[] stampbuf)voidsetWDActivationPeriod(long WDActivationPeriod)Sets the WDActivationPeriod value.voidsetWDNbRetryLevel1(int WDNbRetryLevel1)Sets the WDNbRetryLevel1 value.voidsetWDNbRetryLevel2(int WDNbRetryLevel2)Sets the WDNbRetryLevel2 value.voidsetWDRetryPeriod1(long WDRetryPeriod1)Sets the WDRetryPeriod1 value.voidsetWDRetryPeriod2(long WDRetryPeriod2)Sets the WDRetryPeriod2 value.voidsetWDRetryPeriod3(long WDRetryPeriod3)Sets the WDRetryPeriod3 value.(package private) voidtestBootTS(short source, int boot)protected inttestRecvUpdate(short source, int update)Test if a received message with the specified clock must be delivered.StringtoString()Returns a string representation of this consumer.private voidupdateStamp(int idx, int update)voidvalidate()Validates all messages pushed in queue during transaction session.protected voidvalidateChannel()-
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
-
DEBUG
protected static final boolean DEBUG
-
logger
protected Logger logger
-
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 settingWDActivationPeriodglobal property or for a particular network by setting<DomainName>.WDActivationPeriodspecific property.Theses properties can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration file.
-
WDNbRetryLevel1
int WDNbRetryLevel1
Number of try at stage 1, default value is 5. This value can be adjusted for all network components by settingWDNbRetryLevel1global property or for a particular network by setting<DomainName>.WDNbRetryLevel1specific property.Theses properties can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration 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 settingWDRetryPeriod1global property or for a particular network by setting<DomainName>.WDRetryPeriod1specific property.Theses properties can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration 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 settingWDNbRetryLevel2global property or for a particular network by setting<DomainName>.WDNbRetryLevel2specific property.Theses properties can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration 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 settingWDRetryPeriod2global property or for a particular network by setting<DomainName>.WDRetryPeriod2specific property.Theses properties can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration 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 settingWDRetryPeriod3global property or for a particular network by setting<DomainName>.WDRetryPeriod3specific property.Theses properties can be fixed either from
javalaunching command, or ina3servers.xmlconfiguration 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
-
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 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 String bootTSFN
Filename for boot time stamp storage.
-
name
protected String name
The component's name as it appears in logging.
-
domain
protected String domain
The domain name.
-
port
protected int port
The communication port.
-
qout
protected MessageVector qout
TheMessageVectorassociated with this network component.
-
DELIVER
protected static final int DELIVER
The message can be delivered.- See Also:
- Constant Field Values
-
ALREADY_DELIVERED
protected static final int ALREADY_DELIVERED
The message has already been delivered.- See Also:
- Constant Field Values
-
averageLoadTask
Network.NetworkAverageLoadTask averageLoadTask
-
-
Method Detail
-
getWDActivationPeriod
public long getWDActivationPeriod()
Gets the WDActivationPeriod value.- Specified by:
getWDActivationPeriodin interfaceNetworkMBean- Returns:
- the WDActivationPeriod value
-
setWDActivationPeriod
public void setWDActivationPeriod(long WDActivationPeriod)
Sets the WDActivationPeriod value.- Specified by:
setWDActivationPeriodin interfaceNetworkMBean- Parameters:
WDActivationPeriod- the WDActivationPeriod value
-
getWDNbRetryLevel1
public int getWDNbRetryLevel1()
Gets the WDNbRetryLevel1 value.- Specified by:
getWDNbRetryLevel1in interfaceNetworkMBean- Returns:
- the WDNbRetryLevel1 value
-
setWDNbRetryLevel1
public void setWDNbRetryLevel1(int WDNbRetryLevel1)
Sets the WDNbRetryLevel1 value.- Specified by:
setWDNbRetryLevel1in interfaceNetworkMBean- Parameters:
WDNbRetryLevel1- the WDNbRetryLevel1 value
-
getWDRetryPeriod1
public long getWDRetryPeriod1()
Gets the WDRetryPeriod1 value.- Specified by:
getWDRetryPeriod1in interfaceNetworkMBean- Returns:
- the WDRetryPeriod1 value
-
setWDRetryPeriod1
public void setWDRetryPeriod1(long WDRetryPeriod1)
Sets the WDRetryPeriod1 value.- Specified by:
setWDRetryPeriod1in interfaceNetworkMBean- Parameters:
WDRetryPeriod1- the WDRetryPeriod1 value
-
getWDNbRetryLevel2
public int getWDNbRetryLevel2()
Gets the WDNbRetryLevel2 value.- Specified by:
getWDNbRetryLevel2in interfaceNetworkMBean- Returns:
- the WDNbRetryLevel2 value
-
setWDNbRetryLevel2
public void setWDNbRetryLevel2(int WDNbRetryLevel2)
Sets the WDNbRetryLevel2 value.- Specified by:
setWDNbRetryLevel2in interfaceNetworkMBean- Parameters:
WDNbRetryLevel2- the WDNbRetryLevel2 value
-
getWDRetryPeriod2
public long getWDRetryPeriod2()
Gets the WDRetryPeriod2 value.- Specified by:
getWDRetryPeriod2in interfaceNetworkMBean- Returns:
- the WDRetryPeriod2 value
-
setWDRetryPeriod2
public void setWDRetryPeriod2(long WDRetryPeriod2)
Sets the WDRetryPeriod2 value.- Specified by:
setWDRetryPeriod2in interfaceNetworkMBean- Parameters:
WDRetryPeriod2- the WDRetryPeriod2 value
-
getWDRetryPeriod3
public long getWDRetryPeriod3()
Gets the WDRetryPeriod3 value.- Specified by:
getWDRetryPeriod3in interfaceNetworkMBean- Returns:
- the WDRetryPeriod3 value
-
setWDRetryPeriod3
public void setWDRetryPeriod3(long WDRetryPeriod3)
Sets the WDRetryPeriod3 value.- Specified by:
setWDRetryPeriod3in interfaceNetworkMBean- Parameters:
WDRetryPeriod3- the WDRetryPeriod3 value
-
getNbWaitingMessages
public int getNbWaitingMessages()
Gets the number of waiting messages in this engine.- Specified by:
getNbWaitingMessagesin interfaceNetworkMBean- Returns:
- the number of waiting messages.
-
getNbMessageSent
public int getNbMessageSent()
Returns the number of messages sent since last reboot.- Specified by:
getNbMessageSentin interfaceNetworkMBean- Returns:
- the number of messages sent since last reboot.
-
getNbMessageReceived
public int getNbMessageReceived()
Returns the number of messages received since last reboot.- Specified by:
getNbMessageReceivedin interfaceNetworkMBean- Returns:
- the number of messages received since last reboot.
-
getName
public final String getName()
Returns this session's name.- Specified by:
getNamein interfaceMessageConsumer- Specified by:
getNamein interfaceNetworkMBean- Returns:
- this session's name.
-
getDomainName
public final String getDomainName()
Returns the corresponding domain's name.- Specified by:
getDomainNamein interfaceMessageConsumer- Returns:
- this domain's name.
-
toString
public String toString()
Returns a string representation of this consumer.- Specified by:
toStringin interfaceNetworkMBean- Overrides:
toStringin classObject- Returns:
- A string representation of this consumer.
-
insert
public void insert(Message msg)
Insert a message in theMessageQueue. This method is used during initialization to restore the component state from persistent storage.- Specified by:
insertin interfaceMessageConsumer- Parameters:
msg- the message
-
save
public void save() throws IOExceptionSaves information to persistent storage.- Specified by:
savein interfaceMessageConsumer- Throws:
IOException- an error occurs.
-
restore
public void restore() throws ExceptionRestores component's information from persistent storage. If it is the first load, initializes it.- Specified by:
restorein interfaceMessageConsumer- Throws:
Exception- an error occurs.
-
init
public void init(String name, int port, short[] servers) throws 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 theClass.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:
Exception- an error occurs.
-
setProperties
public void setProperties() throws ExceptionSet the properties of the network. Can be extended by subclasses.- Throws:
Exception- an error occurs.
-
addServer
public void addServer(short id) throws ExceptionAdds the server sid in the network configuration.- Parameters:
id- the unique server id.- Throws:
Exception- an error occurs.
-
delServer
public void delServer(short id) throws ExceptionRemoves the server sid in the network configuration.- Parameters:
id- the unique server id.- Throws:
Exception- an error occurs.
-
resetServer
void resetServer(short id, int boot) throws IOExceptionReset all information related to server sid in the network configuration.- Parameters:
id- the unique server id.boot- ?- Throws:
IOException- an error occurs.
-
post
public void post(Message msg) throws 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:
postin interfaceMessageConsumer- Parameters:
msg- the message to transmit.- Throws:
Exception- an error occurs.
-
postAndValidate
public void postAndValidate(Message msg) throws Exception
Posts and validates a message.- Specified by:
postAndValidatein interfaceMessageConsumer- Parameters:
msg- the message to transmit.- Throws:
Exception- an error occurs.
-
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.- Returns:
- the index of server.
-
getStamp
protected final byte[] getStamp()
-
setStamp
protected final void setStamp(byte[] stampbuf)
-
updateStamp
private void updateStamp(int idx, int update) throws IOException- Throws:
IOException
-
testRecvUpdate
protected int testRecvUpdate(short source, int update) throws IOExceptionTest if a received message with the specified clock must be delivered. If the message is ready to be delivered, the method returnsDELIVERand the matrix clock is updated. If the message has already been delivered, the method returnsALREADY_DELIVERED, and if other messages are waited before this message the method returnsWAIT_TO_DELIVER. In the last two case the matrix clock remains unchanged.- Parameters:
source- The identifier of source server.update- The message matrix clock (list of update).- Returns:
DELIVER,ALREADY_DELIVERED, orWAIT_TO_DELIVERcode.- Throws:
IOException- an error occurs.
-
getSendUpdate
private int getSendUpdate(short to) throws IOExceptionComputes 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:
IOException- an error occurs.
-
isPrior
public boolean isPrior(Message m1, Message m2)
Description copied from interface:MessageComparatorCompares the 2 messages for time ordering. Returns true if the first message is earlier than the second, false otherwise.- Specified by:
isPriorin interfaceMessageComparator- Parameters:
m1- The first message.m2- The second message.- Returns:
- true if the first message is earlier than the second, false otherwise.
-
getBootTS
final int getBootTS()
-
testBootTS
final void testBootTS(short source, int boot) throws IOException- Throws:
IOException
-
deliver
protected void deliver(Message msg) throws Exception
Try to deliver the received message to the right consumer.- Parameters:
msg- the message.- Throws:
Exception- an error occurs.
-
delete
public void delete() throws IllegalStateExceptionDeletes 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:
deletein interfaceMessageConsumer- Throws:
IllegalStateException- the server is running.- See Also:
Transaction
-
validate
public void validate()
Validates all messages pushed in queue during transaction session.- Specified by:
validatein interfaceMessageConsumer
-
getQueue
public MessageQueue getQueue()
Description copied from interface:MessageConsumerGet this consumer'sMessageQueue. Use in administration and debug tasks, should be replaced by a common attribute.- Specified by:
getQueuein interfaceMessageConsumer- Returns:
- this
MessageConsumer's queue.
-
setPort
public void setPort(int port)
Updates the network port.- Parameters:
port- the listening port.
-
getPort
public final int getPort()
-
getAverageLoad1
public float getAverageLoad1()
Returns the load averages for the last minute.- Specified by:
getAverageLoad1in interfaceMessageConsumer- Specified by:
getAverageLoad1in interfaceNetworkMBean- Returns:
- the load averages for the last minute.
-
getAverageLoad5
public float getAverageLoad5()
Returns the load averages for the past 5 minutes.- Specified by:
getAverageLoad5in interfaceMessageConsumer- Specified by:
getAverageLoad5in interfaceNetworkMBean- Returns:
- the load averages for the past 5 minutes.
-
getAverageLoad15
public float getAverageLoad15()
Returns the load averages for the past 15 minutes.- Specified by:
getAverageLoad15in interfaceMessageConsumer- Specified by:
getAverageLoad15in interfaceNetworkMBean- Returns:
- the load averages for the past 15 minutes.
-
deleteMessage
protected void deleteMessage(Message msg)
-
getMessageSource
protected short getMessageSource(Message msg)
-
setMessageSource
protected void setMessageSource(Message msg, short source)
-
getMessageDest
protected short getMessageDest(Message msg)
-
checkActive
protected void checkActive(ServerDesc desc)
-
channelPostAndValidate
protected void channelPostAndValidate(Message msg) throws Exception
- Throws:
Exception
-
validateChannel
protected void validateChannel()
-
-