Examples


LighTS comes with a minimal number of examples that are meant to test the correct functionality of the tuple space and the adapters. They are found under the directory examples of the distribution (follow the links to see the source files):

We plan to add fancier examples as LighTS gets used for teaching and research purposes and, hopefully, as the base of users grows. 

How to run the examples:

All the examples require starting a Lime server and loading into it an agent that contains the application's logic. Please consult the documentation about using the Lime server.


BasicTest

This example demonstrates the base capability of the package lime.util and, at the same time, provides for a useful tool for debugging Lime applications. The interactive agent just displays a graphical console that can be used to perform operations on a Lime tuple space.

How to run the example:

Start a Lime server with an InteractiveAgent:
java lime.LimeServer -tspaces -load InteractiveAgent

What to expect:

On the shell running the Lime server the following messages will appear:

>java lime.LimeServer -tspaces -load InteractiveAgent
Lime: TSServer activated.
Lime: Lime server activated on port 1968
Lime: Listening for agents
Lime: Agent InteractiveAgent loaded and started.
After a short delay, the window with the console will appear. For details about how to use the console see this description. For details about how to use the Lime console from within your agents, please consult the API documentation of lime.util.LimeConsole.

Worth Noting:

The code for InteractiveAgent is really small:

public class InteractiveAgent extends Agent {
  protected LimeTupleSpace lts = null;
  protected LimeConsole c;
  
  public InteractiveAgent() {
    try { 
      lts = new LimeTupleSpace(this); 
    } catch (LimeException le) { le.printStackTrace(); }
    c = new LimeConsole(lts);
  }
  
  public void run() { while(true) c.performQueuedOp(); }
}
The constructor takes care of creating a Lime tuple space with the default name, and creating a Lime console that allows interaction with it. These two objects are stored in two protected fields, such that they can be accessed by subclasses of InteractiveAgent. The run() method of the agent is trivial, in that it continuously picks the next operation in the queue maintained by the Lime console, and requests its execution. Remember that the method performQueuedOp blocks if the queue is empty, which simplifies the code for the agent.