Next: Bibliography
Up: Examples
Previous: Example Configuration File
  Contents
Example Agent
This is the complete code of the example Agent tagents.examples.AgentEx4.
package tagents.examples;
import tagents.agent.*;
import tagents.system.Location;
import tagents.system.Name;
import tagents.system.AgentSystemInfo;
import tagents.sysagent.communication.AgentCommIFace;
import tagents.sysagent.maffinder.MAFFinderIFace;
public class AgentEx4 extends Agent
{
public void initUser()
{
setNextCommand("moveMe");
helper.println("Init called...");
}
public void startUser()
{
try{
Location[] obs = getMAFFinder().lookupAgent(
new Name(helper.getID()),
profile);
helper.println("Registered
with location " + obs[0]);
} catch(Exception e) {helper.print(e);};
helper.println("Start called...");
}
public void moveMe()
{
setNextCommand("showMe");
helper.println("I am in System
" + helper.getAgentSystemName());
try
{
AgentCommIFace commservice =
getCommService("163.117.139.122/test2");
if(commservice != null)
commservice.move(helper.getID(),
new Location("163.117.139.122/test2"));
}
catch(Exception e)
{
helper.print(e);
}
helper.println("End of moveMe
reached.");
}
public void showMe()
{
helper.println("I am now in
" + helper.getAgentSystemName());
helper.println("Sending message
to AgentEx3 where ever it is ...");
try {
Location[] obs = getMAFFinder().lookupAgent(new
Name(),
new AgentProfile(new
Object[]
{"tagents.examples.AgentEx3"}));
if(obs.length > 0)
{
helper.println("AgentEx3
: " + obs[0]);
String ex3system = obs[0].getHost()+"/"+obs[0].getSysName();
String ex3id = obs[0].getAgent();
AgentCommIFace commservice
= getCommService(ex3system);
if(commservice != null)
{
FutureResult fres
= commservice.sendFutureMessage(
helper.getID(),
obs[0],
new
AgentMessage("Hello",
new
Object[]
{helper.getID()}));
helper.println("Waiting
for results");
int time = 0;
while(!fres.isAvailable())
{
try{
Thread.currentThread().sleep(100);
} catch(Exception
e){helper.print(e);};
time += 100;
}
helper.println("Got
result, waited " + time + "ms");
helper.println("Result: "
+ fres.getResults());
}
else
helper.println("No
commservice for Agent " + obs[0]);
}
else
helper.println("No Agent
of type AgentEx3 found !");
} catch(Exception e) { helper.print(e);};
}
public void suspendUser()
{
helper.println("Suspend called...");
}
public void terminateUser()
{
helper.println("terminateUser
called...");
}
}
Next: Bibliography
Up: Examples
Previous: Example Configuration File
  Contents
Thomas Letsch
2001-02-21