10.  Agent-Agent Communication in Ajanta



Two Ajanta agents, on two different or same agent servers, can communicate with each other through RMI proxies that they create at their respective agent servers.

To demonstrate Agent-to-Agent communication in Ajanta, we have created the RMICalculator demo.
Code Directory: $AJANTA_HOME/demo/RMICalculator

This demo starts two generic agent-servers, helloserver1 and helloserver2, and sends two clients to them each, CalculatorAgent and TestAgent respectively. The CalculatorAgent is launched by the CalculatorClient and the TestAgent is launched by the TestAgentClient.

After successful migration to the destination server (helloserver1), the CalculatorAgent will create a Proxy for the RMI calculator resource. Then, the TestAgent, on successfull migration to its destination server
(helloserver2), will query the name registry for the calculator proxy setup by the CalculatorAgent and then request a service from that Proxy. (Do some additions, multiplications, subtractions and/or divisions)

Please follow the following steps to run this demo.
It is assumed that you have run the "userSetup" script to setup the configuration files needed by this demo. If you have not, please run the following script:
%> perl {$AJANTA_HOME}/setup/userSetup
 

Step 1: ------------- Start Rmi Registry ---------------------------

To start agent-servers,the user needs to run a RMI Registry on a user-defined port. We provided the script "startRmi" for this. For example, if you decided to run agent-servers on machine "Machine1", "Machine2", "Machine3" and "Machine4", you need to run the script "startRmi" on all these machines as shown below:

    Machine1>perl {$AJANTA_HOME}/setup/startRmi
    Machine2>perl {$AJANTA_HOME}/setup/startRmi
    Machine3>perl {$AJANTA_HOME}/setup/startRmi
    Machine4>perl {$AJANTA_HOME}/setup/startRmi

The script will start a RMI Registry on the current machine. It will also keep the port information in the configaration file "$HOME/.ajanta/servers/serverConfig". Any consequent run of the script will kill the previous RMI Registry and run a new one.
 

Step 2a: ---------- Run helloserver1 and helloserver2 ------------------

Login to two windows (these windows could be on the same or different machines) and run the agent-servers, helloserver1 and helloserver2. For example,

    Machine1>java ajanta.server.AgentServer helloserver1
    Machine2>java ajanta.server.AgentServer helloserver2

This agent-servers will print their URNs on the screen. The URN will look like:
"urn:ans:"NameRegistry's_DNS_Name"/"UserID"/helloserver1"
"urn:ans:"NameRegistry's_DNS_Name"/"UserID"/helloserver2"

Step 2b: ----------- Run RMICalculator ------------------------------

RMICalculator is the name of the client agent-server that launches the CalculatorAgent and is the first argument for CalculatorClient. We need to provide the destination agent-server as second argument.

NOTE: Before launching the agent, the Launch program will ask you to enter the name of the proxy that it should look up after installing its own proxy.
For this Agent, enter the following string: <your URN>/RMITest/RMITestAgent

Machine3>java ajanta.demo.RMICalculator.CalculatorClient RMICalculator "urn:ans:"NameRegistry's_DNS_Name"/"UserID"/helloserver1

The CalculatorClient will send a CalculatorAgent to the destination agent-server (helloserver1). Upon arriving, the agent will create a Proxy for the class "ajanta.demo.RMICalculator.Calculator" and register it withthe agent-server's RMI registry. Then the agent will wait in a loop and print "CalculatorAgent in loop".

Step 2c: ------------------ Run RMITest ---------------------------

RMITest is the name of the client agent-server that launches the TestAgent and is the first argument for TestAgentClient. We need to provide the destination agent-server as the second argument.

NOTE: Before launching the agent, the Launch program will ask you to enter the name of the proxy that it should look up after installing its own proxy.
For this Agent, enter the following string: <your URN>/RMICalculator/RMICalculatorAgent

Machine4> java ajanta.demo.RMICalculator.TestAgentClient RMITest
urn:ans:"NameRegistry's_DNS_name"/"UserID"/helloserver2

The TestAgentClient will send a TestAgent to the destination agent-server (helloserver2). Upon arriving, this agent will query the name registry to get a proxy for the RMICalculator resource installed by the
CalculatorAgent at helloserver1. Upon recieving the proxy, it will invoke some methods on the interface. The interface is a simple calculator with 4 methods: add, subtract, multiply and divide.
 


 GO  TO- Top of this page    Previous Chapter    Table of Contents of this Guide