|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlime.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 | |
(package private) static int |
CUR_TAG
|
static java.lang.String |
DEFAULT
The default name for tuple spaces. |
private static int |
defaultID
|
(package private) static int |
DEST_TAG
|
(package private) static int |
ID_TAG
|
(package private) LimeTSMgr |
mgr
|
private java.lang.String |
name
|
(package private) AgentID |
owner
|
(package private) Reactor |
reactor
|
(package private) boolean |
shared
|
static java.lang.String |
SYSTEM
The name of the Lime system tuple space. |
(package private) static int |
TAG_NUMBER
The number of system fields. |
(package private) lights.interfaces.ITupleSpace |
ts
|
(package private) UponMgr |
upons
|
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. |
protected static lights.interfaces.ITuple |
cloneTuple(lights.interfaces.ITuple t)
Copies a tuple. |
protected static lights.interfaces.ITuple |
cloneTuple(lights.interfaces.ITuple t,
int start,
int end)
Copies a subset of the fields of a tuple in a new tuple. |
private LimeTuple |
doBlocking(LimeTemplate template,
short type)
|
private LimeTuple[] |
doOut(AgentLocation destination,
lights.interfaces.ITuple[] tuples,
short op)
|
private LimeTuple[] |
doProbe(LimeTemplate template,
short type)
|
private RegisteredReaction[] |
filterReactions(RegisteredReaction[] reactions)
|
private LimeTuple[] |
getArray(lights.interfaces.ITuple t)
|
private LimeTuple[] |
getArray(lights.interfaces.ITuple[] t)
|
java.lang.String |
getName()
Get the name of the Lime tuple space as given by the user. |
(package private) static java.lang.String |
getPublicName(java.lang.String n)
|
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. |
(package private) java.lang.String |
getUniqueName()
Get the name of the Lime tuple space after going through contortions to make the name unique. |
LimeTuple |
in(LimeTemplate template)
Retrieves a tuple that matches a given template, and removes it from the tuple space. |
LimeTuple[] |
ing(LimeTemplate template)
Retrieve all tuples that match a pattern. |
LimeTuple |
inp(LimeTemplate template)
Retrieves a tuple that matches a given template, and removes it from the tuple space, or returns null if no matching tuple
exists. |
private boolean |
isInReaction()
|
boolean |
isOwner()
Return true if the thread calling this method is the
ILimeAgentAgent object that owns this Lime tuple space
object, false otherwise. |
private static boolean |
isOwner(LimeTupleSpace lts)
|
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. |
(package private) static boolean |
isUnspecified(Location l)
|
LimeTuple |
out(AgentLocation destination,
lights.interfaces.ITuple tuple)
Inserts a tuple in the shared tuple space. |
LimeTuple |
out(lights.interfaces.ITuple tuple)
Inserts a tuple in the shared tuple space. |
LimeTuple[] |
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. |
LimeTuple |
rd(LimeTemplate template)
Retrieves a copy of a tuple that matches a given template. |
LimeTuple[] |
rdg(LimeTemplate template)
Copy all tuples that match a pattern. |
LimeTuple |
rdp(LimeTemplate 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
static final int ID_TAG
static final int CUR_TAG
static final int DEST_TAG
static final int TAG_NUMBER
AgentID owner
private java.lang.String name
transient LimeTSMgr mgr
lights.interfaces.ITupleSpace ts
Reactor reactor
UponMgr upons
boolean shared
private static final int defaultID
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.
IllegalTupleSpaceNameException
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()
java.lang.String getUniqueName()
static java.lang.String getPublicName(java.lang.String n)
public LimeTuple 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 LimeTuple 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 LimeTuple[] 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 inserted
TupleSpaceEngineException
- if a problem is encountered in the
underling tuple space engineprivate LimeTuple[] doOut(AgentLocation destination, lights.interfaces.ITuple[] tuples, short op) throws TupleSpaceEngineException
TupleSpaceEngineException
public LimeTuple inp(LimeTemplate 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.
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. If they are,
an exception is thrown.
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 LimeTuple[] ing(LimeTemplate template) throws TupleSpaceEngineException
AgentLocation.UNSPECIFIED
is NOT a valid
value for current.
template
- the template the return tuples must be matched against.
null
if no
matching tuple can be found
TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public LimeTuple in(LimeTemplate 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 LimeTuple rdp(LimeTemplate 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.
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. If they are,
an exception is thrown.
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 LimeTuple[] rdg(LimeTemplate template) throws TupleSpaceEngineException
AgentLocation.UNSPECIFIED
is NOT a valid
value for current.
template
- the template the return tuples must be matched against.
null
if no
matching tuple can be found
TupleSpaceEngineException
- if a problem is encountered in the
underlying tuple space engine.public LimeTuple rd(LimeTemplate 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 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()
private RegisteredReaction[] filterReactions(RegisteredReaction[] reactions)
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()
protected static lights.interfaces.ITuple cloneTuple(lights.interfaces.ITuple t)
t
- the tuple to be copied.
protected static lights.interfaces.ITuple cloneTuple(lights.interfaces.ITuple t, int start, int end)
t
- the tuple to be copied.start
- the first field to be copied (inclusive)end
- the last field to be copied (exclusive)
private static boolean isOwner(LimeTupleSpace lts)
private boolean isInReaction()
static boolean isUnspecified(Location l)
private LimeTuple doBlocking(LimeTemplate template, short type) throws TupleSpaceEngineException
TupleSpaceEngineException
private LimeTuple[] doProbe(LimeTemplate template, short type) throws TupleSpaceEngineException
TupleSpaceEngineException
private LimeTuple[] getArray(lights.interfaces.ITuple[] t)
private LimeTuple[] getArray(lights.interfaces.ITuple t)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |