|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Implemented by objects that want to react to an event.
A reaction (as
defined by a Reaction
object) is specified by a template, a
mode, and an object implementing this interface. Reactions are registered
on a tuple space using either the method addStrongReaction
or
addWeakReaction
defined in LimeTupleSpace
.
After each tuple space operation, and before processing another
operation, the Lime runtime support system checks whether there are
reactions that are currently enabled, i.e., whose template matches some
tuple in the tuple space. If such a reaction exists, the
reactsTo
method of the corresponding listener (i.e., of the
object implementing ReactionListener
and originally
associated with the reaction at registration time) is invoked
automatically. After execution of this method, the Lime runtime support
reevaluates the reactions against the new shared tuple space, which can
possibly have been changed by the code in the listener object, to
determine whether there are other reactions enabled. If yes, the
corresponding reactsTo
method is fired. This process
continues until there are no more enabled reactions. At this point, the
normal processing of tuple space operations resumes.
Notably, listeners can contain only operations that are local (i.e., affect at most the host-level tuple space) and are non-blocking (otherwise deadlock could occur immediately). Also, listeners cannot access other Lime tuple space objects even if they are on the same host.
The ReactionEvent
parameter in reactsTo
provides the listener with a copy of the RegisteredReaction
object it is associated to, a copy of the tuple that triggered the
reaction, and a handle to the agent that registered the reaction, such
that the listener can invoke public methods on the agent. However, there
are no limitations about the class of the object that can implement this
interface. In particular, it can be implemented by subclasses of
ILimeAgent
s, that can specify directly the response to the
event, thus leveraging off of unrestricted access to the agent's innards.
As a final remark, particular care should be put in keeping the operations of the listener lightweight. The execution of the listener is performed by the Lime run-time support, not by the agent that registered the reaction. Consequently, if the required computation is heavyweight, the processing of the whole Lime server is slowed down. Also, although blocking tuple space operations are disallowed in Lime, the runtime support does not have any way to prevent other kind of blocking operations that can potentially block the whole Lime server. In particular, AWT/Swing modal dialogboxes, which block the corresponding caller thread, should never be used from within a reaction listener.
LimeTupleSpace
,
Reaction
,
ReactionEvent
,
ILimeAgent
Method Summary | |
void |
reactsTo(ReactionEvent e)
This method is invoked automatically by the system when the corresponding reaction must be fired. |
Method Detail |
public void reactsTo(ReactionEvent e)
e
- the event that triggered the reaction.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |