All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class ProtocolLayer.IPRouterClientAction

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

public abstract class IPRouterClientAction
extends RouterClientAction
Template to support protocol layer RouterClientAction.
As the same as RouterClientAction, you need to implement Act(Object) method. IPRouterClientAction implements processMessage(String,Object) for managing SMTP/FTP. Therefore, if you want to extend the method, you should call processMessage(String,Object) of IPRouterClientAction like :

public void processMessage(String cmd,Object obj) {
super.processMessage(cmd,obj);
///// Add your implementation here
.....
}

Furthermore, you need to implement three FTP related callback functions :

FTPStore(String finename,OutputStream), FTPAppend(String filename,OutputStream), FTPRetrieve(String filename,InputStream), where filename is the file name you have specified when you call createDataTransferConnection(FTPCon ftp) method and InputStream/OutputStream is iostream from socket. Those three functions are callback functions - it will be invoked by processMessage(String,Object) method from received 'port-info' message, replied from router.

For implementation of FTPXXX callbacks, just assume that you are given file name and iostream. Do whatever you want to the iostream - serialize objects, write informations, retrieve information,etc. You need to wrap the InputStream/OutputStream with appropriate java IO objects such as PrintWriter, DataInputStream,etc.

For stand-alone application :

For applets :

See Also:
RouterClientAction, FTPCon

Variable Index

 o _replyNo
Static numbering for reply message
 o _replyQueue
Reply queue is a depository to save information for asynchronous internet protocol transaction.

Constructor Index

 o IPRouterClientAction()
Default constructor
 o IPRouterClientAction(Address, Address, Address, int)
Router AgentAction constructor with given my address,rotuer address and router registrar address.
 o IPRouterClientAction(Address, Address, int)
Constructor.
 o IPRouterClientAction(String, String, int)
Constructor using Address strings
 o IPRouterClientAction(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 cacheAddress(KQMLmessage)
Cache the receiver address from received KQML message.
 o createDataTransferConnection(FTPCon)
Data transfer using FTP.
 o createDataTransferConnection(String, String, String, int, String, String, String, String[], int)
Data transfer using FTP.
 o createEmailConnection(KQMLmessage)
Asynchronous email sending routine.
 o createEmailConnection(String)
Asynchronous email sending routine.
 o dataTransferToRouter(KQMLmessage)
Data transfer through router <-> receiver.
 o FTP(FTPCon)
Data transfer using FTP.
 o FTP(String, String, String, int, String, String, String, String[], int)
Data transfer using FTP.
 o FTPAppend(String, OutputStream)
Should implement this for applets.
 o FTPRetrieve(String, InputStream)
Should implement this for applets.
 o FTPStore(String, OutputStream)
Should implement this for applets.
 o getEmailAddress(Address)
Get email address from Address object
 o initReplyQueue()
Initialize reply queue
 o processMessage(String, Object)
You should implement this method.
 o processRouterMessage(KQMLmessage)
Default behavior for the messages from router.
 o sendEmailMessage(Address, Address, String)
Send KQML message through email.
 o sendEmailMessage(String)
Send KQML message using email protocol.
 o sendEmailToRouter(KQMLmessage)
Email sending to router -> receiver.

Variables

 o _replyNo
 protected int _replyNo
Static numbering for reply message

 o _replyQueue
 protected Hashtable _replyQueue
Reply queue is a depository to save information for asynchronous internet protocol transaction. When an applet agent want to use router as a proxy, the agent will send appropriate message to the router with reply-with slot and save data to the hashtable. Therefore, the key field is string like 'smtp0' or 'ftp3' and the value field can be anything.

Constructors

 o IPRouterClientAction
 public IPRouterClientAction()
Default constructor

 o IPRouterClientAction
 public IPRouterClientAction(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 IPRouterClientAction
 public IPRouterClientAction(Address myAddress,
                             Address routerAddress,
                             Address registrarAddress,
                             int durationTime)
Router AgentAction constructor with given my address,rotuer address and router registrar address. You can use this constructor if your agent is already registered to the Router

Parameters:
myAddress - My address
routerAddress - The Router address
routerAddress - The Router address
durationTime - Maximum idle time
 o IPRouterClientAction
 public IPRouterClientAction(String routeraddressstr,
                             String registraraddressstr,
                             int durationTime)
Constructor using Address strings

Parameters:
routeraddressstr - The Router address string to connect
registraraddressstr - The Router registrar address string
durationTime - Maximum idle time for the connection
 o IPRouterClientAction
 public IPRouterClientAction(String myAddressstr,
                             String routerAddressstr,
                             String registrarAddressstr,
                             int durationTime)
Router AgentAction constructor with given my address,rotuer address and router registrar address. You can use this constructor if your agent is already registered to the Router

Parameters:
myAddressstr - My address string
routerAddressstr - The Router address string
durationTime - Maximum idle time

Methods

 o initReplyQueue
 protected void initReplyQueue()
Initialize reply queue

 o sendEmailMessage
 public void sendEmailMessage(Address sender,
                              Address receiver,
                              String msg) throws ConnectionException
Send KQML message through email. Address sender and receiver should contains email address within its description field. For example, sender address may be :
AgentName,cdr.stanford.edu,2345,"MessageRouter","(agent-info :password xxx :email jhc@cdr.stanford.edu)"

Parameters:
sender - Sender(usually agent itself) address.
receiver - Receiver address.
msg - KQML message to be sent
Throws: ConnectionException
Note that KQML parse exception will not be thrown
 o sendEmailMessage
 public void sendEmailMessage(String kqmlstr) throws ConnectionException
Send KQML message using email protocol. The receiver address should be cached. My address and receiver address should contain email address in description field

Parameters:
kqmlstr - KQML message to be sent.
Throws: ConnectionException
Note that KQML parse exception will not be thrown
 o createEmailConnection
 public void createEmailConnection(String kqmlmsg) throws ConnectionException
Asynchronous email sending routine. Send email server information to router. The router will provide a connector socket number.

Parameters:
replyWith - Reply-with slot of KQML message. After creating a connector, router will reply connector socket number with in-reply-to.
Throws: ConnectionException
Note that KQML parse exception will not be thrown
 o createEmailConnection
 public void createEmailConnection(KQMLmessage kqml) throws ConnectionException
Asynchronous email sending routine. Send email server information to router. The router will provide a connector socket number.

Parameters:
replyWith - Reply-with slot of KQML message. After creating a connector, router will reply connector socket number with in-reply-to.
Throws: ConnectionException
Note that KQML parse exception will not be thrown
 o sendEmailToRouter
 protected void sendEmailToRouter(KQMLmessage kqml) throws ConnectionException
Email sending to router -> receiver. If an agent want to send a KQML message through email, the applet will create email connection using createEmailConnection method. Router will create a email port and will reply a message with the email port. The applet will connect to the port and start to send the KQML message to router and router will deliver the email to the receiver. This method is for actual data transfer(sending KQML message throuth email) after receiving the port information from router.

Parameters:
kqml - KQML message received from router which contains a proxy socket number
 o cacheAddress
 public Address cacheAddress(KQMLmessage addressKQML)
Cache the receiver address from received KQML message. The message will be sent from router and its performative is 'agent-address'. The address will be added to _addressTable.

Parameters:
addressKQML - KQML message, whose performative is 'agent-address'.
 o getEmailAddress
 public String getEmailAddress(Address addr)
Get email address from Address object

Parameters:
addr - Address
Returns:
null if no email is specified. Email address(e.g. jhc@cdr.stanford.edu) if addr contains email address information.
 o FTP
 public void FTP(FTPCon con) throws ConnectionException
Data transfer using FTP. Only for stand alone application

Parameters:
con - FTPCon object
See Also:
FTPCon
 o FTP
 public void FTP(String conid,
                 String remotePath,
                 String host,
                 int port,
                 String userName,
                 String password,
                 String localPath,
                 String files[],
                 int mode) throws ConnectionException
Data transfer using FTP. Only for stand alone application

Parameters:
conid - FTP connection name
remotePath - FTP site initial directory
host - FTP server host name
port - 21. Otherwiser, you need to set
userName - FTP server login user name
password - FTP server login password
localPath - Local machine initial directory
files - Files to put or get
mode - Mode definition
See Also:
FTPCon
 o createDataTransferConnection
 public void createDataTransferConnection(FTPCon con) throws ConnectionException
Data transfer using FTP. Only for applet agents. Similar to SMTP, an applet will invoke this method first to transfer data using FTP. This method will send a KQML message like :

(data-transfer
:sender me
:receiver Router
:reply-with ftp32
:protocol ftp
:content (get :server FTPserverInternetAddress :port 21))

to router. Router will create a connector between the applet and FTP server and reply a message which contains a proxy socket number. The applet will connect to the proxy socket and start to data transfer.

Parameters:
con - FTPCon object
 o createDataTransferConnection
 public void createDataTransferConnection(String conid,
                                          String remotePath,
                                          String host,
                                          int port,
                                          String userName,
                                          String password,
                                          String localPath,
                                          String files[],
                                          int mode) throws ConnectionException
Data transfer using FTP. Only for applet agents. Similar to SMTP, an applet will invoke this method first to transfer data using FTP. This method will send a KQML message like :

(data-transfer
:sender me
:receiver Router
:reply-with ftp32
:protocol ftp
:content (get :server FTPserverInternetAddress :port 21))

to router. Router will create a connector between the applet and FTP server and reply a message which contains a proxy socket number. The applet will connect to the proxy socket and start to data transfer.

Parameters:
conid - FTP connection name
remotePath - FTP site initial directory
host - FTP server host name
port - 21. Otherwiser, you need to set
userName - FTP server login user name
password - FTP server login password
localPath - Local machine initial directory
files - Files to put or get
mode - Mode definition
See Also:
FTPCon
 o dataTransferToRouter
 protected void dataTransferToRouter(KQMLmessage kqml) throws ConnectionException
Data transfer through router <-> receiver. If an agent want to trasfer data through router, the applet will create data transfer connection using createDataTransferConnection method. Router will create a proxy port and will reply a message with the port. The applet will connect to the port and start to transfer data to router and router will deliver/retrieve data and transfer to the applet. This method is for actual data transfer after receiving the port information from router.

Parameters:
kqml - KQML message received from router which contains a proxy socket number
 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. IPRouterClientAction should perform 'processRouterMessage method first.

Parameters:
o - KQMLmail object.
Overrides:
Act in class RouterClientAction
 o processRouterMessage
 public void processRouterMessage(KQMLmessage kqml) throws ConnectionException
Default behavior for the messages from router. React only the sender is router

Parameters:
kqml - KMQLmessage, received
 o processMessage
 public void processMessage(String command,
                            Object obj)
You should implement this method. By default, messages from SMTPThread and FTPThread will be managed here but you can extends whatever you want. Refer to IPRCActionExample.

Parameters:
command - Command to be executed
obj - Reference object depends on command
Overrides:
processMessage in class RouterClientAction
 o FTPStore
 public abstract void FTPStore(String fileName,
                               OutputStream out) throws ConnectionException
Should implement this for applets. Callback from the FTPThread Assume that the OutputStream will be given and wrap it with appropriate IO streams such as PrintWriter or DataInputStream, etc.

Parameters:
fileName - File name you specified in FTPCon(passed as a formal parameter in createDataTransferConnection).
out - OutputStream derived from a proxy socket
 o FTPAppend
 public abstract void FTPAppend(String fileName,
                                OutputStream out) throws ConnectionException
Should implement this for applets. Callback from the FTPThread Assume that the OutputStream will be given and wrap it with appropriate IO streams such as PrintWriter or DataInputStream, etc.

Parameters:
fileName - File name you specified in FTPCon(passed as a formal parameter in createDataTransferConnection).
out - OutputStream derived from a proxy socket
 o FTPRetrieve
 public abstract void FTPRetrieve(String fileName,
                                  InputStream in) throws ConnectionException
Should implement this for applets. Callback from the FTPThread Assume that the InputStream will be given and wrap it with appropriate IO streams such as PrintWriter or DataInputStream, etc.

Parameters:
fileName - File name you specified in FTPCon(passed as a formal parameter in createDataTransferConnection).
in - InputStream derived from a proxy socket

All Packages  Class Hierarchy  This Package  Previous  Next  Index