Examples
Lime comes with a number of examples that demonstrate some
of its capability. They are found under the directory examples
of the distribution (follow the links to see more information about each example):
- Interactive Agent A simple agent for interacting with a Lime tuple space.
- Interactive Mobile Agent A simple mobile agent that allows interaciton with the tuple space, and migration.
- Interactive
Monitor Agent An InteractiveAgent that monitors the
state of the system configuration using reactions over
the
LimeSystemTupleSpace
. - Simple Lime App A simple Lime application that shows how Lime can be started from within an application.
- Weak Probe LTS Operations An extension of the standard LimeTupleSpace which provides weak read, in, and group operations on the federated tuple space.
- RoamingJigsaw Puzzle. A multiplayer jigsaw puzzle game.
- RedRover. A multiplayer
spatial game where players move in physical space and
their movements are propagated to connected players
through the
LimeTupleSpace
. - Chat: A simple multiuser chat program that uses Lime to share messages among connected participants.
- MobiChat A sophisticated mobile application that enables users to interact by exchanging messages, playing games, and exchanging files.
If you develop a nice application and would like to see it included in the distribution as a Lime demo, contact us! The following is a list of projects maintained separate from the Lime distribution.
- Location Transparent Code Mobility allows one to dynamically link classes with a location transparent scheme. It exploits the Lime tuple space as a code repository.
How to work with the examples:
Makefiles are provided for each of the larger examples, while a single makefile exists that combines the simple examples (InteractiveAgent, InteractiveMobileAgent, InteractiveMonitorAgent, and SimpleLime).
Please see the installation instructions for
how to set your CLASSPATH
.
All the interactive agent examples require launching a Lime server and loading into it the agent that contains the application's logic. Please consult the documentation about using the Launcher.
Interactive Agent
This example
demonstrates the capability of the package lime.util.console
and,
at the same time, provides a useful tool for debugging Lime
applications. The interactive agent simply displays a graphical console which
can be used to perform operations on a Lime tuple space.
How to run the example:
From the directory examples/simpleExamples/bin
, start a Lime
server with an InteractiveAgent
:
java lime.util.Launcher -load InteractiveAgent
Additional InteractiveAgent
s can be loaded into
the same JVM by typing
java lime.util.Launcher -quit -load InteractiveAgent
in a separate window on the same host.
What to expect:
On the shell running the Lime server the following messages will appear:
>java lime.util.Launcher -load InteractiveAgent Lime:Factory set to lights.adapters.builtin.TupleSpaceFactory Lime:Lime server murphy:1973 activated 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 small:
public class InteractiveAgent extends StationaryAgent implements IConsoleProvider { LimeTupleSpace lts = null; LimeConsole c; public InteractiveAgent() throws LimeException { super("InteractiveAgent"); } public void setConsole(LimeConsole c) { this.c = c; } public LimeConsole getConsole() { return c; } public void run() { try { lts = new LimeTupleSpace(); } catch (LimeException le) { le.printStackTrace(); } c = new LimeConsole(getMgr().getID(), lts, this); while(true) { String s = c.performQueuedOp(); } } }
The constructor simply calls the constructor of the standard
StationaryAgent
, naming the thread with a specified string. The
run()
method of the agent takes care of creating a default tuple
space and processing the queue of requested operations maintained by the Lime
console. Remember that the method performQueuedOp
blocks if the
queue is empty, which simplifies the code for the agent.
Please note that the Lime tuple space must be created by the same thread
that performs opertaions on it. In other words, the tuple space cannot be
created from within the InteractiveAgent
constructor. And the
operations to be performed on the tuple space cannot be performed directly by
the LimeConsole
but must be executed by the thread of the
InteractiveAgent
.
Also note that the go
method in the console has no effect on
the InteractiveAgent
.
Interactive Mobile Agent
The primary difference between this agent and the previous
one is the enabling of the go
operation on this agent. To start
this example, you must use the Launcher
associated with µcode
mobile agents, as in:
java lime.mobileagent.mucode.Launcher --mucode --load InteractiveMobileAgent
For details on the mobile agent Launcher
parameters, consult
the documentation.
Note: Due to a known bug in the Sun JDK1.4, this example must be run with JDK1.3.
Interactive Monitor Agent
The
InteractiveMonitorAgent
displays how the
LimeSystemTupleSpace
can be used to track the presence of other
agents, hosts, and tuple spaces. This example installs six separate reactions
on the LimeSystem tuple space, each of which writes a line to the
LimeConsole
when a change occurs in the system
configuration. Launch it as you would a regular InteractiveAgent
:
java lime.util.Launcher -load InteractiveMonitorAgent
Simple Lime
The primary benefit of this
example is to demonstrate how to construct an application that will launch
Lime itself. The source code demonstrates the use of the Launcher
to pass parameters to Lime, and how to load an agent directly into the
LimeServer
. Rather than launching this application directly
using the launcher, use the following:
java SimpleLime msg
or pass Lime any desired Lime parameters as in:
java SimpleLime msg -mcastport 2130
Weak Probe LTS Operations
The WeakProbeLimeTupleSpace
class is unlike the other examples, in that it is not a stand-alone
application which exploits Lime. Instead, it serves as an example of how to
extend the basic LimeTupleSpace with operations that are aggregates of the
basic operations. Specifically, the WeakProbeLimeTupleSpace
provides the operations weakInp
, weakRdp
,
weakIng
, and weakRdg
which probe the federated tuple
space for either a single matching tuple, or all matching tuples.
The execution of these operations is not performed atomically over a
snapshot of the federated tuple space, but is performed individually
and incrementally over the host-level tuple spaces which are present in the
federation when the operation is invoked. For example, if hosts A, B and C
are connected and have agents with transiently shared tuple spaces of the same
name; if an agent on host A issues one of these weak operations, the result
returned will be the cumulative result of probing operation performed first on
A, then on B, then on C. If B or C disconnect before the operation is
complete, it is as if the result of the probe of that host returned
null
. If host D connects during the operation, D is ignored for
this operation.
To use this class, an agent should create an instance of a
WeakProbeLimeTupleSpace
instead of a LimeTupleSpace
.
All normal operations of a LimeTupleSpace
are still available
through a WeakProbeLimeTupleSpace
.
RoamingJigsaw
RoamingJigsaw, is a multi-player jigsaw puzzle assembly game. A group of players cooperate on the solution of the jigsaw puzzle in a disconnected fashion. They construct assemblies independently, share intermediate results, and acquire pieces from each other when connected. Play begins with one player loading the puzzle pieces to a shared tuple space. Any connected player sees the puzzle pieces of the other connected players and can select pieces they wish to work with. When a piece is selected, all connected players observe this as a change in the colored border of the piece, and within the system, the piece itself is moved to be co-located with the selecting player. When a player disconnects, the workspace does not change, but the pieces that have been selected by the departing player can no longer be selected and manipulated. From the perspective of the disconnected player, pieces whose border is tagged with the player's color can be assembled into clusters. Additionally, the player can connect to other players to further redistribute the pieces, and to view the progress made by the other players with respect to any clusters formed since last connected.
This application is based on a pattern of interaction where the shared workspace provides an accurate image of the global state of connected players but only weakly consistent with the global state of the system as a whole. The user workspace contains the last known information about each puzzle piece. It is interesting to observe that the globally set goal of the distributed application, i.e., the solution of the puzzle, is built incrementally through successive updates to the local state, distributed to all other players either immediately if connected or in a ``lazy'' fashion if connectivity is not available at that time.
java lime.util.Launcher -load puzzle.LimePuzzleAgent
More details are available here.
RedRover
RedRover is a spatial game in which individuals equipped with small mobile devices form teams and interact in a physical environment augmented with virtual elements. This forces the participants to rely to a great extent on information provided by the mobile units and not solely on what is visible to the naked eye.
The key component of RedRover is that players share their physical location in space. Each player has a kind of radar image on their screen which is constantly updated with the locations of (connected) players as they move.
java redRover.RedRover rr.blue
More details are available here.
Chat
Chat is a multiuser chat program that allows several users to communicate with each other.
java lime.util.Launcher -load chat.LChat
More details are available here.
MobiChat
This application demonstrates how Lime can be used for communication and entertainment.
How to run the example:
java mobiChat.chatUser.MobiChatApp
More details are available here.