Re: [mucode-users] mobile agent thread
Brought to you by:
gpietro
|
From: Gian P. P. <pi...@el...> - 2000-10-11 21:50:12
|
Dear Lukito,
> public class Bouncer extends MuAgent {
> String host;
> public Bouncer(String host1, MuServer aServer) {
> super(aServer);
> host = host1;
> }
> public Bouncer() { super(); }
> public void run() {
> try {
> go(host);
> } catch (ClassNotFoundException e) { e.printStackTrace(); }
> catch (IOException e) { e.printStackTrace(); }
> perform(host);
> }
> public void perform(String h) {
> System.out.println("Bouncer: at " + h);
> }
> }
> I issued 'java mucode.util.Launcher -port 4444' on another terminal,
> and run the program with 'java BounceLauncher localhost:4444'.
> I expected Bouncer to migrate to the MuServer at localhost:4444,
> but this did not happen. The program stops after MuServers have
> been activated at port 1968 (default) and 4444.
> What is going wrong here ?
the problem lies in the way you modified the mobile agent, and in the fact
that mucode supports only "weak" mobility, i.e., when the agent's thread is
resumed after migration, execution starts from the beginning of the run()
method and not right after the go() (in other words, the program counter is
not saved as part of the agent's state).
This said, by putting the go instruction as the first one of the run method,
as soon as the mobile agent is woken up at the target site, execution of the
run() method is started from the beginning and so the agent tries to migrate
to the current value of "host". Such value has been set on the source node
to
"localhost:4444" and it has been transmitted as part of state of the agent
along with the agent itself. So, what happens is an infinite loop where the
agent, once reached the server on localhost:4444, keeps migrating on that
host forever.
The problem could have been spotted easily by turning on the debug feature
("-debug on"). That way, you would have seen that the agent was actually
sent, and that plenty of messages were scrolling on the target terminal (due
to continuous migration).
> Also, when I moved the statement 'perform(host)' before the 'go',
> I expected the agent did nothing after migrating to the server
> at 4444. What happened was, after the migration, the thread kept
> executing the 'perform' call at the remote server (like an
> endless loop). Did I miss something ?
Same problem as above. The agent executes the perform() method, and then the
go() method which migrates it on the same host. There, the run() method is
executed from scratch, and so the process goes on forever.
The weak mobility supported by mucode is the standard solution in Java-based
mobile agents. This is a design choice forced by a current limitation of the
JVM, which doesn't provide hooks for implementing strong mobility.
Supporting
strong mobility would entail hacking the JVM or implementing a
preprocessor---alternatives on which nice research outcomes are starting to
appear.
Thanks for your interest in mucode.
Gian Pietro
|