All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class RouterLayer.Router.RouterAction

Abstract.AgentAction
   |
   +----BaseLayer.BAgentAction
           |
           +----KQMLLayer.KQMLAgentAction
                   |
                   +----RouterLayer.Router.RouterAction

public class RouterAction
extends KQMLAgentAction
Router server action class. Router performs to route messages to the receiver agent and keep the messages to the file until the receiver agent request to delete the messages. The Router server will open two ServerSocket, one for accepting the registration and one for accepting the connection from the registered agents. The Router delegate its utilities(ANS,list-users,delete-message) to the RouterRecvThread. The Router does not have centralized MessageBuffer. Each RouterRecvThread has its own MessageBuffer and work invidually. For each router client, one unique RouterRecvThread will be created by accepting the conneciton. If a message is received from the connection the RouterRecvThread will parse the message to find out the receiver. Then, if the receiver is on-line, the message will be stored to the receiver RouterRecvThread's MessageBuffer after adding time stamp. While looping, the RouterRecvThread check its MessageBuffer. If the MessageBuffer is not empty, it will directly send the message through its connection and save it to its incoming file.(Note that by this approach, we can evade critical section when save/retrieve the message from the file).

See Also:
RouterRecvThread

Variable Index

 o _disconnectTable
 o _messageBoxPath
Incoming message file directory path.
 o _offLineCheckPeriod
 o _offLineList
Hashtable which maintains the off-line agent list.
 o _offLineTrialTimes
 o _reserveCheckPeriod
 o _reservedBook
Hashtable which maintains the reserved messages.
 o _reserveTrialTimes
 o _sleepPeriod

Constructor Index

 o RouterAction()
Default constructor.
 o RouterAction(String, String, String, String, String, int, int, int, int, int, int)
Constructor

Method Index

 o Act(Object)
Router does not implement Act(Object) method.
 o createReceiverThread(String, int)
Override AgentAction createRecvThread method Create client receiver thread using name of the agent Override this method if your connection type is different.
 o createServerThread(String, int)
Override AgentAction createServerThread method Create server thread using name of the agent Override this method if your connection type is different.
 o getAddress()
Get Router address
 o getOffLineAgentList()
Get reservation table
 o getReservedBook()
Get reservation table
 o main(String[])
 o processMessage(String, Object)
Override processMessage of AgentAction.
 o resetReservedTime(long, Reservation)
If the attempt to send reserved messages to the receiver, the Router will reset time as one more hour from the original reserved time.
 o run()
check whether there's a reserved messages.
 o sendOffLineAgentMessages()
Send off line agent message if time meets
 o sendReservedMessages()
Send reserved message if time meets
 o setOffLineAgentList(OffLineAgentTable)
Set the Off line agent list
 o setReservedBook(Hashtable)
Set the ReservationTable
 o unregisterAgent(Address)

Variables

 o _messageBoxPath
 protected String _messageBoxPath
Incoming message file directory path. You should specify this data member for the Router to save the incoming messages to the receiver file. The incoming file for each registered agent will be created under the messageBoxPath directory

 o _reservedBook
 protected Hashtable _reservedBook
Hashtable which maintains the reserved messages. The key field is time stamp and the field value is Reservation object.

See Also:
Reservation
 o _offLineList
 protected OffLineAgentTable _offLineList
Hashtable which maintains the off-line agent list. An agent will be added to the off line list, if the receiver thread is time out or the Router can not initiate the connection to the agent. Note that if an agent send disconnect-agent message to the Router, the Router will never initiate the connection. Key is time and the field is a reservation object.

 o _offLineTrialTimes
 protected int _offLineTrialTimes
 o _offLineCheckPeriod
 protected int _offLineCheckPeriod
 o _reserveTrialTimes
 protected int _reserveTrialTimes
 o _reserveCheckPeriod
 protected int _reserveCheckPeriod
 o _sleepPeriod
 protected int _sleepPeriod
 o _disconnectTable
 protected Vector _disconnectTable

Constructors

 o RouterAction
 public RouterAction()
Default constructor. You should use setAddressFilePath, setMessageBoxPath, setPasswordFilePath methods afterwards.

 o RouterAction
 public RouterAction(String id,
                     String addressFilePath,
                     String messageBoxPath,
                     String passwordFilePath,
                     String registryFilePath,
                     int durationTime,
                     int offLineTrialTimes,
                     int offLineCheckPeriod,
                     int reserveTrialTimes,
                     int reserveCheckPeriod,
                     int sleepPeriod)
Constructor

Parameters:
id - Router name
addressFilePath - Address file path. Address file contains the addresses of Router and RouterRegistrar at the minimum. Add on those, you can specify the addresses of other agents where the Router want to initiate the conneciton
messageBoxPath - Message incoming file directory path
passwordFilePath - Password file path
registryFilePath - Registry file path
duration - Maximum idle time
offLineTrialTimes - Maximum trial times to voluntarily reconnect to stand alone agent
offLineCheckPeriod - Off line agent time check period in minutes
reserveTrialTimes - Maximum trial times to send reserved message
reserveCheckPeriod - Reseved message sending time check period in minutes
sleepPeriod - Sleep period in minutes

Methods

 o setReservedBook
 public void setReservedBook(Hashtable reservedBook)
Set the ReservationTable

Parameters:
reservedBook - ReservationTable from the RouterAction
 o getReservedBook
 public Hashtable getReservedBook()
Get reservation table

Returns:
Reserved message table
 o setOffLineAgentList
 public void setOffLineAgentList(OffLineAgentTable offlinelist)
Set the Off line agent list

Parameters:
offlinelist - Off line agent table from the RouterAction
 o getOffLineAgentList
 public OffLineAgentTable getOffLineAgentList()
Get reservation table

Returns:
Reserved message table
 o createServerThread
 public ServerThread createServerThread(String id,
                                        int priority)
Override AgentAction createServerThread method Create server thread using name of the agent Override this method if your connection type is different.

Parameters:
id - ServerThread name
priority - Server thread priority
Returns:
ServerThread, generated. Null if fails
Overrides:
createServerThread in class KQMLAgentAction
 o createReceiverThread
 public ReceiverThread createReceiverThread(String serverid,
                                            int priority)
Override AgentAction createRecvThread method Create client receiver thread using name of the agent Override this method if your connection type is different. Before you invoke this method, the Router name(the same as RouterAction thread name) should be specified.

Parameters:
serverid - Server agent name. This name is not my name. The name of the other agent you want to connect
priority - Receiver thread priority
Returns:
ReceoverThread, generated
Overrides:
createReceiverThread in class KQMLAgentAction
 o getAddress
 public Address getAddress()
Get Router address

Returns:
The Router address
 o processMessage
 public void processMessage(String command,
                            Object obj)
Override processMessage of AgentAction.

Parameters:
command - Command to be executed
obj - String array arguments
Overrides:
processMessage in class BAgentAction
 o Act
 public boolean Act(Object o)
Router does not implement Act(Object) method. A lot of Router action is delegated to the RouterRecvThread

Parameters:
o - Object to be instantiated and performed
Overrides:
Act in class BAgentAction
 o run
 public void run()
check whether there's a reserved messages. If it's time to send try to open connection and sent it to the receiver

Overrides:
run in class BAgentAction
 o sendReservedMessages
 protected void sendReservedMessages()
Send reserved message if time meets

 o resetReservedTime
 protected void resetReservedTime(long time,
                                  Reservation res)
If the attempt to send reserved messages to the receiver, the Router will reset time as one more hour from the original reserved time. This process will be performed five times. If the receiver is still unreachable after five attempt, the reserved messages will be canceled to be sent.

Parameters:
time - Current setting time
res - Reservation object to be delayed
 o sendOffLineAgentMessages
 protected void sendOffLineAgentMessages()
Send off line agent message if time meets

 o unregisterAgent
 protected void unregisterAgent(Address addr)
 o main
 public static void main(String args[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index