-
Notifications
You must be signed in to change notification settings - Fork 4
Agents
Leon Rosenberg edited this page Mar 18, 2024
·
1 revision
Agents are mobile programs which can move between different JVMs via DistributeMe mechanisms and are executed in the target JVM.
Agents can do things, standard programs can't.
- Get access to methods of services or other components that are not exposed via DistributeMe over net.
- Execute massive calculations locally (if you need to make 1000 requests its much faster to execute them locally and move the results, as to execute them over network).
- Load new code which didn't exist at the compile/start time of the service.
- Inspect the JVM.
- Act.
TBD.
This is a HelloWorld Agent which simply travels to the target JVM and prints out a "HelloWorld" message there. Note, that the agent code can be written after the service is deployed: https://github.com/anotheria/distributeme/blob/master/distributeme-agents/src/main/java/org/distributeme/agents/operatives/HelloWorldAgent.java
public class HelloWorldAgent implements Agent{
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void prepareForTransport() {
System.out.println("Going to move now!");
}
@Override
public void awake() {
System.out.println("Hello World");
}
public static void main(String[] args) throws Exception{
System.out.println("Creating agent");
String target = "rmi://org_distributeme_test_echo_EchoService.lfxyotkpcy@192.168.200.101:9250@20110817012752";
if (args.length==1){
target = args[0];
}
System.out.println("Trying to send agent to "+target);
HelloWorldAgent agent = new HelloWorldAgent();
AgencyImpl.INSTANCE.sendAgent(agent, ServiceDescriptor.fromSystemWideUniqueId(target));
System.out.println("done");
}
}