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):
LimeSystemTupleSpace
. LimeTupleSpace
. We plan to add fancier examples as Lime gets used for teaching and research purposes. If you develop a nice application and would like to see it included in the distribution as a Lime demo, contact us!
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.
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.
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.
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: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
.
The code for InteractiveAgent
is really small:
public class InteractiveAgent extends StationaryAgent { LimeTupleSpace lts = null; LimeConsole c; public InteractiveAgent() throws LimeException { super("InteractiveAgent"); } public void run() { try { lts = new LimeTupleSpace(); } catch (LimeException le) { le.printStackTrace(); } c = new LimeConsole(getMgr().getID(), lts); 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
.
Please also note that the go
method in the console will have
no effect on the InteractiveAgent
.
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 -debug off --load InteractiveMobileAgent
For details on the mobile agent Launcher
parameters, consult
the documentation.
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
The primary benefit to 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 in 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 -mcast off
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 which 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 hosts-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 available through a
WeakProbeLimeTupleSpace
.
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 LimePuzzleAgent
More details are available here.
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 Game rr.blue
More details are available here.
Chat is a multiuser chat program that allows several users to communicate with each other.
java lime.util.Launcher -load LChat
More details are available here.