LIME

Using Lime with Your Favorite Mobile Agent System

Lime is designed in a way that should enable interoperability with virtually any Java-based mobile agent system. This goal is achieved through an adaptation layer, that nevertheless requires a little bit of programming in order to integrate a mobile agent system.

The current distribution of Lime provides a built-in adapter towards the µCode system, contained in the package lime.mobileagent.mucode. This page uses the code of this adapter to illustrate how a new adapter towards a different agent platform can be built.

The following steps are necessary in order to create a class representing a Lime-aware mobile agent:

  1. create a new subclass of the mobile agent class provided by your favorite system; this new class must implement the interface lime.ILimeAgent;
  2. in such class, define a new private field containing an object of type lime.LimeAgentMgr, and provide proper initialization;
  3. implement the getMgr() method defined in ILimeAgent, which just returns the LimeAgentMgr object created at the previous step;
  4. redefine the migration primitive so that the disengage() method is called on the LimeAgentMgr object right before migration;
  5. redefine the code that starts up the agent so that the engage() method is called on the LimeAgentMgr object right before the agent starts executing.

Additional modifications depending on idiosyncrasies of the the target mobile agent system may be required.
In most cases, describing the above should actually be more complicated than doing it. As an example, here is the implementation of lime.mobileagent.mucode.MobileAgent, a "Lime-aware" mobile agent based on µCode. Pay attention to the inlined comments in the source code. 

package lime.mobileagent.mucode;
import lime.*;
import mucode.*;
import mucode.abstractions.*;
import java.util.*;
import java.io.*;

// MuAgent is the base class for mobile agents in mucode. 
public abstract class MobileAgent extends MuAgent implements ILimeAgent {   
  public MobileAgent() { super(); }

  // mucode-specific initialization, needed to avoid sending around system classes upon migration.    
  public MobileAgent(MuServer s) {           
    super(s);            		          	
    s.addUbiquitousPackage("lime", true);     
    s.addUbiquitousPackage("lights", true);
    s.addUbiquitousPackage("gp", true);
  }

  // The LimeAgentMgr field, and the corresponding accessor required by ILimeAgent.
  private LimeAgentMgr mgr = new LimeAgentMgr(); 
  public LimeAgentMgr getMgr() { return mgr; }
  
  // mucode defines a go() method for migration. 
  // Here, such method is wrapped in another that first calls disengage() and then triggers the actual migration. 
  public final void migrate(String destination) throws IOException, ClassNotFoundException {
    mgr.disengage();
    super.go(destination);
  }

  // Same as before, since mucode.MobileAgent has two different migration methods. 
  public final void migrate(String destination, String[] classes, 
                            String dynLink, boolean synch) throws IOException, ClassNotFoundException {
    mgr.disengage();
    super.go(destination, classes, dynLink, synch);
  }

  // Similarly to migration, the run() method is wrapped in another method that first calls engage(). 
  public final void run() { 
    mgr.engage();
    doRun(); 
  }

  /** Must be redefined by the programmer with the behavior of the agent. */
  public abstract void doRun();
}
As you may have guessed, the key part is the LimeAgentMgr, which contains all Lime needs to properly manage the agent (e.g., a concept of identifier) and gives to the agent all it needs to interact with Lime (essentially the engage() and disengage() methods). The code modifications are required just to allow your agent to contain a LimeAgentMgr object, and to invoke the methods of this object at the appropriate times.

This technique worked well for µCode, but we did not try it out with other mobile agent systems, and at the moment this is not a priority on our research agenda. If you tried to integrate your favorite mobile agent system with Lime, we would be interested to know whether and how your efforts led to success or failure. If you were successful, you may also want to consider submitting your adapter code as a contribution (that will be properly acknowledged) to the Lime community.

LIME: Linda in a Mobile Environment