|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--lime.LimeTupleSpace
This class, LimeTupleSpace
, provides an implementation for
the Interface Tuple Space (ITS), the most basic component of a Lime-based
application. It is through the ITS that a process interacts with the rest
of the world. In addition to the conventional operations to write a tuple
to the tuple space (out
) and read or withdraw a matching
tuple from the tuple space (rd, in
), Lime provides location
enhanced operations, reactivity, and operations to set a tuple space's
sharing properties (shared or private)
StationaryAgent
,
Location
,
Reaction
,
ReactionListener
, Serialized FormField Summary | |
static java.lang.String |
DEFAULT
The default name for tuple spaces. |
static java.lang.String |
SYSTEM
The name of the Lime system tuple space. |
Constructor Summary | |
LimeTupleSpace()
Create a default Lime tuple space, named DEFAULT. |
|
LimeTupleSpace(java.lang.String name)
Create a named Lime tuple space. |
Method Summary | |
RegisteredReaction[] |
addStrongReaction(LocalizedReaction[] reactions)
Registers a group of reactions with the Lime tuple space. |
RegisteredReaction[] |
addWeakReaction(Reaction[] reactions)
Registers a group of weak reactions with the Lime tuple space. |
java.lang.String |
getName()
Get the name of the Lime tuple space as given by the user. |
RegisteredReaction[] |
getRegisteredReactions()
Return all the reactions registered on this Lime tuple space, i.e., all those registered by the agent owning this Lime tuple space. |
lights.interfaces.ITuple |
in(lights.interfaces.ITuple template)
Retrieves a tuple that matches a given template, and removes it from the tuple space. |
lights.interfaces.ITuple |
in(Location current,
AgentLocation destination,
lights.interfaces.ITuple template)
Retrieves a tuple that matches a given template, and removes it from the tuple space. |
lights.interfaces.ITuple[] |
ing(Location current,
AgentLocation destination,
lights.interfaces.ITuple template)
Retrieve all tuples that match a pattern. |
lights.interfaces.ITuple |
inp(Location current,
AgentLocation destination,
lights.interfaces.ITuple template)
Retrieves a tuple that matches a given template, and removes it from the tuple space, or returns null if no matching tuple
exists. |
boolean |
isOwner()
Return true if the thread calling this method is the
ILimeAgentAgent object that owns this Lime tuple space
object, false otherwise. |
boolean |
isRegisteredReaction(RegisteredReaction reaction)
Checks whether a given reaction is still registered. |
boolean |
isShared()
Returns true if this tuple space is currently shared,
false otherwise. |
void |
out(AgentLocation destination,
lights.interfaces.ITuple tuple)
Inserts a tuple in the shared tuple space. |
void |
out(lights.interfaces.ITuple tuple)
Inserts a tuple in the shared tuple space. |
void |
outg(AgentLocation destination,
lights.interfaces.ITuple[] tuples)
Write a set of tuples to the tuple space. |
void |
print()
Prints the contents of the tuple space. |
lights.interfaces.ITuple |
rd(lights.interfaces.ITuple template)
Retrieves a copy of a tuple that matches a given template. |
lights.interfaces.ITuple |
rd(Location current,
AgentLocation destination,
lights.interfaces.ITuple template)
Retrieves a copy of a tuple that matches a given template. |
lights.interfaces.ITuple[] |
rdg(Location current,
AgentLocation destination,
lights.interfaces.ITuple template)
Copy all tuples that match a pattern. |
lights.interfaces.ITuple |
rdp(Location current,
AgentLocation destination,
lights.interfaces.ITuple template)
Retrieves a copy of a tuple that matches a given template, or returns null if no matching tuple exists. |
void |
removeStrongReaction(RegisteredReaction[] reactions)
Deregisters a group of strong reactions. |
void |
removeWeakReaction(RegisteredReaction[] reactions)
Deregisters a group of weak reactions. |
boolean |
setShared(boolean isShared)
Enable or disable transient sharing of this tuple space with tuple spaces having the same name. |
static boolean |
setShared(LimeTupleSpace[] lts,
boolean isShared)
Enable or disable transient sharing of a set of tuple spaces. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String SYSTEM
public static final java.lang.String DEFAULT
Constructor Detail |
public LimeTupleSpace(java.lang.String name) throws TupleSpaceEngineException, IllegalTupleSpaceNameException
ILimeAgent
, otherwise an exception
is raised. Such thread will be the owner of the Lime tuple space, i.e.,
the only one that can invoke operations on it.name
- the name of the tuple space.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.IllegalTupleSpaceNameException
- if the agent tries to create a
tuple space with the name SYSTEM.public LimeTupleSpace() throws TupleSpaceEngineException, IllegalTupleSpaceNameException
ILimeAgent
, otherwise an exception is raised. Such thread
will be the owner of the Lime tuple space, i.e., the only one that can
invoke operations on it. TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.Method Detail |
public boolean isOwner()
true
if the thread calling this method is the
ILimeAgentAgent
object that owns this Lime tuple space
object, false
otherwise. The owner of the Lime tuple space is
the agent which created it. This agent is the only agent in the system
that is allowed to perform an operation on this Lime tuple space.
This fact has non-trivial consequences, because attention must be put
in ensuring that no other thread is issuing operations on this tuple
space. In particular, this is true for user interfaces, where AWT/Swing
listeners are executed in a thread that is created by the Java
VM. Consequently, GUI listeners can never call directly a method on the
Lime tuple space of an agent, otherwise an
IllegalTupleSpaceAccessException
is raised. Instead, they
must somehow coordinate with the agent they are associated with (typically
by means of an operation queue, as in LimeConsole
), and
have the latter perform the operation. In any case, tuple space operations
in GUI applications may be dangerous. For instance, a rd
perform from an AWT/Swing listener when no matching tuple is available
effectively blocks the AWT/Swing thread, thus for instance preventing a
correct repainting.
public boolean setShared(boolean isShared)
Note: setting a tuple space to shared is different from calling engage on the LimeServer. setShared operates only on the public/private status of a tuple space while engage/disengage operate on the status of the host which is holding the tuple spaces.
isShared
- true
to set the tuple spaces to shared,
false
to set it to private.true
if the tuple space is successfully
engaged/disengaged.public static boolean setShared(LimeTupleSpace[] lts, boolean isShared)
Note: setting a tuple space to shared is different from calling engage on the LimeServer. setShared operates only on the public/private status of a tuple space while engage/disengage operate on the status of the host which is holding the tuple spaces.
lts
- an array of tuple spaces to be set to shared or not shared in
one step.isShared
- true
to set the tuple spaces to shared,
false
to set it to private.true
if engagement/disengagment was successful.public boolean isShared()
true
if this tuple space is currently shared,
false
otherwise.public java.lang.String getName()
public void out(lights.interfaces.ITuple tuple) throws TupleSpaceEngineException
Since no destination location is specified in this method, the tuple is inserted in the ITS of the agent that owns this Lime tuple space object. The reactive program is executed to termination before this operation returns.
tuple
- the tuple to be inserted.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public void out(AgentLocation destination, lights.interfaces.ITuple tuple) throws TupleSpaceEngineException
A destination (agent) location for the tuple must be specified. If the
agent is currently connected, the tuple is delivered to the agent's ITS
before the operation returns. Otherwise, the tuple is inserted in the
ITS of the agent invoking this operation, thus becoming a "misplaced"
tuple. If and when the recipient of the tuple appears in the system,
the misplaced tuple will be delivered to its ITS as a consequence of the
engagement process (note: it is possible for any agent to remove a
misplaced tuple before it reaches its destination). The destination
location can be left unspecified (using
AgentLocation.UNSPECIFIED
), in which case this operation is
equivalent to the one without a location parameter. The reactive
program is executed to termination before this operation returns.
destination
- the agent location specifying the ITS to which the
tuple is destined.tuple
- the tuple to be inserted.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public void outg(AgentLocation destination, lights.interfaces.ITuple[] tuples) throws TupleSpaceEngineException
destination
- the agent location specifying the ITS to which the
tuples are destinedtuples
- the tuples to be insertedTupleSpaceEngineException
- if a problem is encountered in the
underling tuple space enginepublic lights.interfaces.ITuple in(lights.interfaces.ITuple template) throws TupleSpaceEngineException
template
- the template the return tuple must be matched against.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public lights.interfaces.ITuple inp(Location current, AgentLocation destination, lights.interfaces.ITuple template) throws TupleSpaceEngineException
null
if no matching tuple
exists. Only the projection of the transiently shared tuple space
defined by the current and destination locations are searched. If
multiple tuples match the template, one is selected
non-deterministically.current
- the current location of the tuples can never be left
unspecified, i.e., neither the value
HostLocation.UNSPECIFIED
nor
AgentLocation.UNSPECIFIED
are allowed, since probe
operations are not allowed on the federated tuple space.destination
- the destination location of the tuple that can be
searched. The value AgentLocation.UNSPECIFIED
is allowed.template
- the template the return tuple must be matched against.null
if the tuple cannot be found.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public lights.interfaces.ITuple[] ing(Location current, AgentLocation destination, lights.interfaces.ITuple template) throws TupleSpaceEngineException
current
- the currnet location of the tuples that can be searched.
The value AgentLocation.UNSPECIFIED
is NOT allowed.destination
- the destination location of the tuple that can be
searched. The value AgentLocation.UNSPECIFIED
is allowed.template
- the template the return tuples must be matched against.null
if no
matching tuple can be foundTupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public lights.interfaces.ITuple in(Location current, AgentLocation destination, lights.interfaces.ITuple template) throws TupleSpaceEngineException
current
- the current location of the tuples that can be
matched. The value HostLocation.UNSPECIFIED
or
AgentLocation.UNSPECIFIED
are allowed, in which case only
the destination location will matter.destination
- the destination location of the tuple that can be
searched. The value AgentLocation.UNSPECIFIED
is allowed, in
which case only the current location will matter.template
- the template the return tuple must be matched against.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public lights.interfaces.ITuple rd(lights.interfaces.ITuple template) throws TupleSpaceEngineException
template
- the template the return tuple must be matched against.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public lights.interfaces.ITuple rdp(Location current, AgentLocation destination, lights.interfaces.ITuple template) throws TupleSpaceEngineException
null
if no matching tuple exists. Only the projection of
the transiently shared tuple space defined by the current and
destination locations are searched. If multiple tuples match the
template, one is selected non-deterministically.current
- the current location of the tuples can never be left
unspecified, i.e., neither the value
HostLocation.UNSPECIFIED
nor
AgentLocation.UNSPECIFIED
are allowed, since probe
operations are not allowed on the federated tuple space.destination
- the destination location of the tuple that can be
searched. The value AgentLocation.UNSPECIFIED
is allowed.template
- the template the return tuple must be matched against.null
if the tuple cannot be found.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public lights.interfaces.ITuple[] rdg(Location current, AgentLocation destination, lights.interfaces.ITuple template) throws TupleSpaceEngineException
current
- the currnet location of the tuples that can be searched.
The value AgentLocation.UNSPECIFIED
is NOT allowed.destination
- the destination location of the tuple that can be
searched. The value AgentLocation.UNSPECIFIED
is allowed.template
- the template the return tuples must be matched against.null
if no
matching tuple can be foundTupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public lights.interfaces.ITuple rd(Location current, AgentLocation destination, lights.interfaces.ITuple template) throws TupleSpaceEngineException
current
- the current location of the tuples that can be
matched. The value HostLocation.UNSPECIFIED
or
AgentLocation.UNSPECIFIED
are allowed, in which case only
the destination location will matter.destination
- the destination location of the tuple that can be
searched. The value AgentLocation.UNSPECIFIED
is allowed, in
which case only the current location will matter.template
- the template the return tuple must be matched against.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public boolean isRegisteredReaction(RegisteredReaction reaction)
removeReaction
, or
implicitly and automatically if its mode is ONCE
and the
reaction has already fired.reaction
- the RegisteredReaction
whose presence must
be checked.true
if reaction
is still
registered with the tuple space, false
otherwise.public RegisteredReaction[] getRegisteredReactions()
public RegisteredReaction[] addStrongReaction(LocalizedReaction[] reactions) throws TupleSpaceEngineException
reactions
- an array containing the reactions to be registered.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public RegisteredReaction[] addWeakReaction(Reaction[] reactions) throws TupleSpaceEngineException
weakReaction
operation. Thus,
they can have either of the location fields unspecified, or no location
field at all (i.e., UbiquitousReaction
s can be specified as
well.reactions
- an array containing the reactions to be registered.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public void removeStrongReaction(RegisteredReaction[] reactions) throws TupleSpaceEngineException, NoSuchReactionException
NoSuchReactionException
is raised.reactions
- an array containing the reactions to be deregistered.NoSuchReactionException
- if some of the reactions are actually
not registered.IllegalTupleSpaceAccessException
- if an agent other than the
owner is trying to access this tuple space.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.NoSuchReactionException
- if at least one of the reactions
which was being removed does not exist..public void removeWeakReaction(RegisteredReaction[] reactions) throws TupleSpaceEngineException, NoSuchReactionException
reactions
- an array containing the weak reactions to be deregistered.NoSuchReactionException
- if some of the weak reactions are
actually not registered.TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public void print()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |