All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class RouterLayer.AgentClient.RouterClientAction

Abstract.AgentAction
   |
   +----BaseLayer.BAgentAction
           |
           +----KQMLLayer.KQMLAgentAction
                   |
                   +----RouterLayer.AgentClient.RouterClientAction

public abstract class RouterClientAction
extends KQMLAgentAction
Template to support RouterClientAction. You should fill in processAction and Act method. The RouterClient is a KQML agent which just follow the RouterSecurity protocol for connection. However 'sendMessage' is different - the messages will be sent to the Router whoever the receiver is. And the Router will deliver the message to the actual receiver. To maintain the Router more efficiently, it would be better to send the delete-message message frequently.(It is just like the same as using e-mail. If your mail box has a lot of mails, the mail server's process speed will be very slow).

See Also:
RCActionExample

Variable Index

 o _deleteFPT
Delete message number array for buffering the delete messages
 o _deleteFPTSize
Current buffered delete message size
 o _mailQueue
Message repository
 o _maxDeleteSize
Deleted message numbers will be piled up to the maximum size.
 o _messageNumber
number of messages you have received from the Router
 o _myAddress
My address
 o _registrarName
The registrar name
 o _routerName
The Router name

Constructor Index

 o RouterClientAction()
Default constructor.
 o RouterClientAction(Address, Address, Address, int)
Router AgentAction constructor with given my address,rotuer address and router registrar address.
 o RouterClientAction(Address, Address, Address, int, ThreadGroup)
Router AgentAction constructor with given my address,rotuer address ,router registrar address ,maximum idle time, and thread group.
 o RouterClientAction(Address, Address, int)
Constructor.
 o RouterClientAction(String, String, int)
Constructor using Address strings.
 o RouterClientAction(String, String, String, int)
Router AgentAction constructor with given my address,rotuer address and router registrar address.

Method Index

 o Act(Object)
Since message format is different(reading tag and time stamp), this method should be overriden.
 o addToDeleteBuffer(int)
If a message is performed, you should request to delete the message for the Router to maintain the incoming files.
 o addToDeleteBuffer(int[])
Passing integer array which contains the message number to be deleted.
 o connect()
Connect to the Router, using current agent name
 o connect(Address)
Connect to the Router.
 o connect(String)
Connect to the Router, using the agent name
 o ConvertStringToAddress(String)
Parse KQML address string and convert to Address object.
 o disconnect()
Disconnect from the Router.
 o endAction()
Override endAction() to send buffered delete-messages
 o getMailQueue()
Get mail queue
 o getMaxDeleteSize()
Get maximum delete buffer size.
 o getMyAddress()
Get my address
 o getRouterName()
Get the Router name
 o initDataMembers()
Initialize all data members
 o listUsers()
Router utility to request list the current registered agent to the Router
Message format:
(list-agent :sender xx :receiver Router)
Returned message format from the Router
(registered-agent :sender Router :receiver xx :content (aaa bbb ccc))
 o processMessage(String, Object)
You should implement this method.
 o register()
Router utility to register.
 o register(Address, Address)
Router utility to register.
 o requestAddress(String)
Router utility for agent name service.
 o requestAddress(String, String)
Router utility for agent name service.
 o reserveMessage(long, int[], Address)
Make message reservation content from given time,message number array and reserved address and send 'reserve-message' message to the Router
 o reserveMessage(long, String, Address)
Send 'reserve-message' message to the Router The reserve-message will follow the message format:
(reserve-message :sender xx :receiver Router :content (1 3 5 7) :time 888837363524 :address (receive-address :name xx :host cdr.stanford.edu :port 4352 :message-method MessageRouter :description (agent-info :password zzz)))
The 'receive-address' name slot represent that the intended receiver may be different from the 'sender'.
 o sendDeleteMessage()
Update the message number when the deleted message number is upto _maxDeleteSize.
 o sendKQMLMessage(String)
Send message to the router.
 o sendMessage(KQMLmessage)
Send KQMLmessage.
 o sendMessage(String)
Send message to the router
 o sendMessage(String, String)
 o setMyAddress(Address)
Set my address
 o setMyAddress(String)
Set my address using address string
 o setRegistrarAddress(Address)
Set router registrar address
 o setRegistrarAddress(String)
Set router registrar address using address string
 o setRouterAddress(Address)
Set router address
 o setRouterAddress(String)
Set router address using address string
 o unregister()
Router utility to unregister
 o unregister(Address)
Router utility to unregister

Variables

 o _routerName
 protected String _routerName
The Router name

 o _registrarName
 protected String _registrarName
The registrar name

 o _myAddress
 protected Address _myAddress
My address

 o _messageNumber
 protected int _messageNumber
number of messages you have received from the Router

 o _deleteFPT
 protected int _deleteFPT[]
Delete message number array for buffering the delete messages

 o _deleteFPTSize
 protected int _deleteFPTSize
Current buffered delete message size

 o _mailQueue
 protected Vector _mailQueue
Message repository

 o _maxDeleteSize
 protected int _maxDeleteSize
Deleted message numbers will be piled up to the maximum size. For more delete, actual delete operation will be happen on the Router and AgentClient also should update the message number Default is 1.

Constructors

 o RouterClientAction
 public RouterClientAction()
Default constructor. All data members will be initialized except addresses for me, route and registrar. If you use this constructor, you shoud use setMyAddress(Address),setRouterAddress(Address) and setRegistrarAddress(Address) to initialize essential addresses.

 o RouterClientAction
 public RouterClientAction(Address routeraddress,
                           Address registraraddress,
                           int durationTime)
Constructor. Note that your address is not specified yet. You should use setMyAddress() method before invoke connect() method.

Parameters:
routeraddress - The Router address to connect
router - registrar address
durationTime - Maximum idle time for the connection
 o RouterClientAction
 public RouterClientAction(Address myAddress,
                           Address routerAddress,
                           Address registrarAddress,
                           int durationTime)
Router AgentAction constructor with given my address,rotuer address and router registrar address.

Parameters:
myAddress - My address
routerAddress - The Router address
registrarAddress - The Registrar address
durationTime - Maximum idle time
 o RouterClientAction
 public RouterClientAction(String routeraddressstr,
                           String registraraddressstr,
                           int durationTime)
Constructor using Address strings. Addresses string is basically a line of string :
The address string should have the format :
(agent-address :name [agent-name] :host [host-inetaddress] :port [port no]
:password [password] :KQML-extensions [kqml extensions] :email [email address]
:description [agent description])
KQML-extensions, email and description is optional.
Example
(agent-address :name agentA :host java.stanford.edu :port 1234 :password xxxxxxxx
:KQML-extensions http://java.stanford.edu/newprotocol :email jhc@cdr.stanford.edu
:description (Network service))

Parameters:
routeraddressstr - The Router address string to connect
registraraddressstr - The Router registrar address string
durationTime - Maximum idle time for the connection
 o RouterClientAction
 public RouterClientAction(String myAddressstr,
                           String routerAddressstr,
                           String registrarAddressstr,
                           int durationTime)
Router AgentAction constructor with given my address,rotuer address and router registrar address. The address string should have the format :
(agent-address :name [agent-name] :host [host-inetaddress] :port [port no]
:password [password] :KQML-extensions [kqml extensions] :email [email address]
:description [agent description])
KQML-extensions, email and description is optional.
Example
(agent-address :name agentA :host java.stanford.edu :port 1234 :password xxxxxxxx
:KQML-extensions http://java.stanford.edu/newprotocol :email jhc@cdr.stanford.edu
:description (Network service))

Parameters:
myAddressstr - My address string
routerAddressstr - The Router address string
durationTime - Maximum idle time
 o RouterClientAction
 public RouterClientAction(Address myAddress,
                           Address routerAddress,
                           Address registrarAddress,
                           int durationTime,
                           ThreadGroup t)
Router AgentAction constructor with given my address,rotuer address ,router registrar address ,maximum idle time, and thread group.

Parameters:
myAddress - My address
routerAddress - The Router address
routerAddress - The Router address
durationTime - Maximum idle time
t - Thread group

Methods

 o initDataMembers
 protected void initDataMembers()
Initialize all data members

 o setMyAddress
 public void setMyAddress(Address address)
Set my address

Parameters:
address - My address to be set
 o setRouterAddress
 public void setRouterAddress(Address addr)
Set router address

Parameters:
addr - The Router address
 o setRegistrarAddress
 public void setRegistrarAddress(Address addr)
Set router registrar address

Parameters:
addr - The rotuer registrar address
 o setMyAddress
 public void setMyAddress(String addressstr)
Set my address using address string

Parameters:
addressstr - My address string to be set
 o setRouterAddress
 public void setRouterAddress(String addrstr)
Set router address using address string

Parameters:
addr - The Router address
 o setRegistrarAddress
 public void setRegistrarAddress(String addrstr)
Set router registrar address using address string

Parameters:
addr - The rotuer registrar address
 o getMyAddress
 public Address getMyAddress()
Get my address

Returns:
My address
 o connect
 public synchronized void connect(Address addr) throws ConnectionException
Connect to the Router. Addrss should be passed. If the connection is already exist, it first disconnect the connection and try to reconnect.

Parameters:
addr - My address to be sent to the Router
Throws: ConnectionException
for any error occurs during processing connect. If addr is null, it will also throws ConnectionException
 o connect
 public synchronized void connect(String id) throws ConnectionException
Connect to the Router, using the agent name

Parameters:
id - My name
 o connect
 public synchronized void connect() throws ConnectionException
Connect to the Router, using current agent name

 o disconnect
 public void disconnect()
Disconnect from the Router.

 o register
 public synchronized void register(Address registrar,
                                   Address myaddress) throws ConnectionException
Router utility to register. Declared to be as a critical section, to finish registration before connect.

Parameters:
registrar - The Router Registrar address
myaddress - My address to be registered
Throws: ConnectionException
for any error occurs during processing this service
 o register
 public synchronized void register() throws ConnectionException
Router utility to register. Declared to be as a critical section, to finish registration before connect. Before you invoke this method, my address and the registrar address should be set(either by constructor or setRegistrarAddress, setMyAddress methods.

Throws: ConnectionException
for any error occurs during processing this service
 o unregister
 public synchronized void unregister(Address myaddress) throws ConnectionException
Router utility to unregister

Parameters:
myaddress - My address to be unregistered
Throws: ConnectionException
for any error during processing this service
 o unregister
 public synchronized void unregister() throws ConnectionException
Router utility to unregister

Throws: ConnectionException
for any error during processing this service
 o requestAddress
 public void requestAddress(String name) throws ConnectionException
Router utility for agent name service. Request the other agent address by passing its name.
Message format:
(request-address :sender xx :receiver Router :content Xname)
Returned message format from the Router:
(address :sender Router :receiver xx :name Xname :host cdr.stanford.edu :port 1234 :message-method MessageRouter :description (agent-info :service sort-service))

Parameters:
name - Agent name you want to get the address information
Throws: ConnectionException
for any error during the processing this service
 o requestAddress
 public void requestAddress(String name,
                            String replyWith) throws ConnectionException
Router utility for agent name service. Request the other agent address by passing its name.
Message format:
(request-address :sender xx :receiver Router :content Xname)
Returned message format from the Router:
(address :sender Router :receiver xx :name Xname :host cdr.stanford.edu :port 1234 :message-method MessageRouter :description (agent-info :service sort-service))

Parameters:
name - Agent name you want to get the address information
Throws: ConnectionException
for any error during the processing this service
 o listUsers
 public void listUsers() throws ConnectionException
Router utility to request list the current registered agent to the Router
Message format:
(list-agent :sender xx :receiver Router)
Returned message format from the Router
(registered-agent :sender Router :receiver xx :content (aaa bbb ccc))

Throws: ConnectionException
for any error during processing the message
 o reserveMessage
 public void reserveMessage(long time,
                            String mailNoList,
                            Address address) throws ConnectionException
Send 'reserve-message' message to the Router The reserve-message will follow the message format:
(reserve-message :sender xx :receiver Router :content (1 3 5 7) :time 888837363524 :address (receive-address :name xx :host cdr.stanford.edu :port 4352 :message-method MessageRouter :description (agent-info :password zzz)))
The 'receive-address' name slot represent that the intended receiver may be different from the 'sender'. You can reserve message for other agent.
The 'address' slot is optional.

Parameters:
time - Time stamp
mailNoList - list of message numbers
address - Intended receiving address. Null if the receiving location is not different
Throws: ConnectionException
if the given information is incomplete
 o reserveMessage
 public void reserveMessage(long time,
                            int a[],
                            Address address) throws ConnectionException
Make message reservation content from given time,message number array and reserved address and send 'reserve-message' message to the Router

Parameters:
time - Time stamp
a[] - Reserved message numbers
address - Reserved location if different from the current address
 o sendMessage
 public void sendMessage(String receiver,
                         String msg) throws ConnectionException
Parameters:
receiver - Whoever the receiver is, the message will be sent to the Router
msg - Message to be sent
Overrides:
sendMessage in class BAgentAction
 o sendMessage
 public void sendMessage(String msg) throws ConnectionException, ParseException
Send message to the router

Parameters:
msg - Message to be sent to the Router
 o sendMessage
 public void sendMessage(KQMLmessage kqml) throws ConnectionException
Send KQMLmessage.

Parameters:
kqml - KQMLmessage object
Overrides:
sendMessage in class KQMLAgentAction
 o sendKQMLMessage
 public void sendKQMLMessage(String msg) throws ConnectionException, ParseException
Send message to the router. Message will be parsed and checked before sent to router. If KQML parse error occurs, ParseException will be thrown. This method is safer than sendMessage(String msg).

Parameters:
msg - Message to be sent to the Router
Throws: ConnectionExcaption,
KQMLLayer.ParseException.
 o getRouterName
 public String getRouterName()
Get the Router name

Returns:
Router name the agent is registered to and communicate witl
 o getMailQueue
 public Vector getMailQueue()
Get mail queue

Returns:
Mail queue
 o getMaxDeleteSize
 public int getMaxDeleteSize()
Get maximum delete buffer size.

Returns:
Maximum delete buffer size
 o processMessage
 public abstract void processMessage(String command,
                                     Object obj)
You should implement this method.

Parameters:
command - Command to be executed
obj - Reference object
Overrides:
processMessage in class BAgentAction
 o Act
 public boolean Act(Object o)
Since message format is different(reading tag and time stamp), this method should be overriden. At least, you need to add the received KQMLmail to the _mailQueue.

Parameters:
o - KQMLmail object.
Overrides:
Act in class BAgentAction
 o addToDeleteBuffer
 public void addToDeleteBuffer(int mailno)
If a message is performed, you should request to delete the message for the Router to maintain the incoming files. Since Router will update the deleteMessage when the number of deletedMessage Size is _maxDeleteSize, the message number after delete _maxDeleteSize messages will be updated

Parameters:
mailno - Message number to be deleted
 o sendDeleteMessage
 public void sendDeleteMessage()
Update the message number when the deleted message number is upto _maxDeleteSize.

 o addToDeleteBuffer
 public void addToDeleteBuffer(int a[])
Passing integer array which contains the message number to be deleted. Internally, if the deleted message size is over the _maxDeleteSize, the message numbers will be updated.

Parameters:
a[] - Current message numbers to be deleted
 o endAction
 public void endAction()
Override endAction() to send buffered delete-messages

Overrides:
endAction in class BAgentAction
 o ConvertStringToAddress
 public Address ConvertStringToAddress(String kqmladdr)
Parse KQML address string and convert to Address object. The address string should have the format :
(agent-address :name [agent-name] :host [host-inetaddress] :port [port no]
:password [password] :KQML-extensions [kqml extensions] :email [email address]
:description [agent description])
KQML-extensions, email and description is optional.
Example
(agent-address :name agentA :host java.stanford.edu :port 1234 :password xxxxxxxx
:KQML-extensions http://java.stanford.edu/newprotocol :email jhc@cdr.stanford.edu
:description (Network service))

Parameters:
addrstr - Address string
Returns:
Address object. If wrong format, return null

All Packages  Class Hierarchy  This Package  Previous  Next  Index