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 :
- Since stand alone applications is free to create ServerSocket and to connect
any other machine, SMTP/FTP will be performed directly like numerous
SMTP/FTP applications.
- SMTP : To use SMTP, you should specify your agent email address within agent
Address(_myAddress) object in IPRouterClientAction, which is normally passed to
constructor.
Call sendEmailMessage(Address sender,Address receiver,String msg) or
sendEmailMessage(String kqmlstr) for sending KQML message as an email. If your agent
email address is defined in the 'Address sender' parameter and your agent
knows receiver email address which is included in formal parameter receiver 'Address',
you can use the first one. If your agent does not know receiver agent's email address
use the second one. The second method will ask receiver address to router and router
will reply. If the receiver email is known to router, email will be sent to the
receiver but if it is not defined in registry of router, ConnectionException will be
thrown.
- FTP : The simplest way of FTP is using FTPCon object. Define FTPCon object and
pass it to FTP(FTPCon) method. For error conditions, FTPCon(FTPCon) method will
throw ConnectionException.
For applets :
- Since applet has some restrictions for socket connection, you can not directly
connect to SMTP/FTP server if those servers are different from HTTP server where
router is running. For applets, router will be take a role as a proxy for processing
SMTP/FTP but no data will be saved/cached to router side. Router will create a
ConnectorThread for each transaction and the ConnectorThread redirects input/output
from the applet side to SMTP/FTP server side and vice versa.
- SMTP : To use SMTP, you should specify your agent email address within agent
Address(_myAddress) object in IPRouterClientAction, which is normally passed to
constructor.
Call createEmailConnection(String kqmlmsg) or createEmailConnection(KQMLmessage kqml)
for sending KQML message as an email. Router will create a ServerSocket where the
applet will connect to and reply 'port-info' message to the applet. For error
conditions,such receiver email is not specified or SMTP server connection fails,
etc, router will send an error message instead of 'port-info' reply.
The 'port-info' message includes ServerSocket number for the applet to connect.
After the applet connect to the ServerSocket, IPRouterClientAction will automatically
start to transact SMTP(this will be performed by sendEmailToRouter(KQMLmessage)
so that you do not need to call sendEmailToRouter(KQMLmessage) directly.
For error conditions, sendEmailToRouter method
will throw ConnectionException.
- FTP : Note that an applet can not access to local file system where it is running
but it can transfer data to remote file system using FTP function JATLite is providing.
Call createDataTransferConnection(FTPCon con) or
createDataTransferConnection(String conid, String remotePath, String host,
int port, String userName,String password, String localPath, String[] files, int mode). As the same as SMTP,
IPRouterClientAction will request ServerSocket to router and router will reply
a 'port-info' message. Then IPRouterClientAction will start to transfer data after
connect to the ServerSocket. 'port-info' message will be processed automatically by
processRouterMessage(KQMLmessage).
- See Also:
- RouterClientAction, FTPCon
-
_replyNo
- Static numbering for reply message
-
_replyQueue
- Reply queue is a depository to save information for asynchronous internet protocol
transaction.
-
IPRouterClientAction()
- Default constructor
-
IPRouterClientAction(Address, Address, Address, int)
- Router AgentAction constructor with given my address,rotuer address and router registrar
address.
-
IPRouterClientAction(Address, Address, int)
- Constructor.
-
IPRouterClientAction(String, String, int)
- Constructor using Address strings
-
IPRouterClientAction(String, String, String, int)
- Router AgentAction constructor with given my address,rotuer address and router registrar
address.
-
Act(Object)
- Since message format is different(reading tag and time stamp), this
method should be overriden.
-
cacheAddress(KQMLmessage)
- Cache the receiver address from received KQML message.
-
createDataTransferConnection(FTPCon)
- Data transfer using FTP.
-
createDataTransferConnection(String, String, String, int, String, String, String, String[], int)
- Data transfer using FTP.
-
createEmailConnection(KQMLmessage)
- Asynchronous email sending routine.
-
createEmailConnection(String)
- Asynchronous email sending routine.
-
dataTransferToRouter(KQMLmessage)
- Data transfer through router <-> receiver.
-
FTP(FTPCon)
-
Data transfer using FTP.
-
FTP(String, String, String, int, String, String, String, String[], int)
-
Data transfer using FTP.
-
FTPAppend(String, OutputStream)
- Should implement this for applets.
-
FTPRetrieve(String, InputStream)
- Should implement this for applets.
-
FTPStore(String, OutputStream)
- Should implement this for applets.
-
getEmailAddress(Address)
- Get email address from Address object
-
initReplyQueue()
- Initialize reply queue
-
processMessage(String, Object)
- You should implement this method.
-
processRouterMessage(KQMLmessage)
- Default behavior for the messages from router.
-
sendEmailMessage(Address, Address, String)
- Send KQML message through email.
-
sendEmailMessage(String)
- Send KQML message using email protocol.
-
sendEmailToRouter(KQMLmessage)
- Email sending to router -> receiver.
_replyNo
protected int _replyNo
- Static numbering for reply message
_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.
IPRouterClientAction
public IPRouterClientAction()
- Default constructor
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
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
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
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
initReplyQueue
protected void initReplyQueue()
- Initialize reply queue
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
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
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
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
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
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'.
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.
FTP
public void FTP(FTPCon con) throws ConnectionException
- Data transfer using FTP. Only for stand alone application
- Parameters:
- con - FTPCon object
- See Also:
- FTPCon
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
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
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
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
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
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
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
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
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
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