lime
Class Reactor

java.lang.Object
  extended bylime.Reactor
All Implemented Interfaces:
java.io.Serializable

class Reactor
extends java.lang.Object
implements java.io.Serializable


Field Summary
private  RegisteredReaction currentRR
          A pointer to the current registered reaction within the linked list.
private  RegisteredReaction firstRR
          A pointer to the first registered reaction within the linked list.
private  RegisteredReaction lastRR
          A pointer to the last registered reaction within the linked list.
private  java.util.Vector matchingTuples
          Holds tuples coming from the main TS that are a match for a new oncepertuple reaction.
private  java.util.Vector newTuples
          Holds the tuples that have been dropped by a write performed within a reaction.
private  java.util.Vector reactions
          Holds the RegisteredReactions for "efficient" access for finding a reaction in the list
(package private)  boolean running
          Keeps track of whether a reactive program is running.
(package private)  java.lang.String tsname
          The tuple space's name
(package private)  lights.interfaces.ITupleSpace tupleSpace
          The tuple space.
private  java.util.Vector workingTuples
          Holds tuples that are being passed to the reactor upon triggering its computation, i.e., tuples from a write or from engagement.
 
Constructor Summary
(package private) Reactor(lights.interfaces.ITupleSpace tupleSpace, java.lang.String tsname)
          The constructor for a Reactor.
 
Method Summary
(package private)  lights.interfaces.ITuple createDeepCopy(lights.interfaces.ITuple t)
          Returns a copy of the tuple by serializing and then deserializing the tuple object.
(package private) static lights.interfaces.ITuple deserialize(byte[] serForm)
          Returns a copy of the tuple by deserializing the byte array passed as a parameter.
(package private)  lights.interfaces.ITuple doRead(lights.interfaces.ITuple t)
           
(package private)  lights.interfaces.ITuple[] doReadg(lights.interfaces.ITuple t)
           
(package private)  lights.interfaces.ITuple doTake(lights.interfaces.ITuple t)
           
(package private)  lights.interfaces.ITuple[] doTakeg(lights.interfaces.ITuple t)
           
(package private)  void doWrite(lights.interfaces.ITuple[] t)
          Places the tuples into the newTuples vector.
private  lights.interfaces.ITuple[] findAllMatches(java.util.Vector tuples, lights.interfaces.ITuple template)
          Return all matches, or an array of length zero if no match is found.
private  lights.interfaces.ITuple findMatch(java.util.Vector tuples, lights.interfaces.ITuple template)
           
(package private)  RegisteredReaction[] getAgentReactions(AgentID a)
          Return the reactions belonging to the specified agent.
(package private)  RegisteredReaction[] getAllReactions()
          Returns all of the reactions that are registered on this tuple space.
(package private)  byte[] getSerializedForm(lights.interfaces.ITuple t)
          Returns the byte array containing the serialized form of the tuple.
(package private)  RegisteredReaction[] installReactions(Reaction[] r, java.lang.String name, AgentID a, long seqNum)
           
(package private)  RegisteredReaction[] installRegisteredReactions(RegisteredReaction[] r)
          Reinstalls a reaction.
(package private)  boolean isRegistered(RegisteredReaction r)
          Returns true if the RegisteredReaction is registered within this Reactor.
(package private)  boolean isRunning()
          Returns whether a reactive program is running.
(package private)  void printAllReactions()
           
(package private)  void putReactions(RegisteredReaction[] r)
          Used when reactions must be merged in the reactor and no reactive program must be run.
private  void react(lights.interfaces.ITuple t, RegisteredReaction r)
           
private  void reactOnce(lights.interfaces.ITuple t, RegisteredReaction r)
          Fires the reaction using the specified tuple.
private  boolean reactOnce(java.util.Vector tuples, lights.interfaces.ITuple t, RegisteredReaction r)
          Tries to react once on those tuples in the multiset that match the tuple.
private  boolean reactSelectively(java.util.Vector tuples, lights.interfaces.ITuple t, RegisteredReaction r)
          Tries to react once-per-tuple on those tuples in the multiset that match the tuple.
private  void removeMatch(java.util.Vector tuples, lights.interfaces.ITuple[] t)
           
(package private)  boolean removeReactions(RegisteredReaction[] r)
          removes an array of reactions from the list of registered reactions processed during runReactiveProgram.
(package private)  void runReactiveProgram(lights.interfaces.ITuple[] wt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tupleSpace

lights.interfaces.ITupleSpace tupleSpace
The tuple space.


tsname

java.lang.String tsname
The tuple space's name


running

boolean running
Keeps track of whether a reactive program is running.


firstRR

private RegisteredReaction firstRR
A pointer to the first registered reaction within the linked list. (Used in managing the linked list of registered reactions).


lastRR

private RegisteredReaction lastRR
A pointer to the last registered reaction within the linked list. (Used in managing the linked list of registered reactions).


currentRR

private RegisteredReaction currentRR
A pointer to the current registered reaction within the linked list. (Used in managing the linked list of registered reactions).


reactions

private java.util.Vector reactions
Holds the RegisteredReactions for "efficient" access for finding a reaction in the list


workingTuples

private transient java.util.Vector workingTuples
Holds tuples that are being passed to the reactor upon triggering its computation, i.e., tuples from a write or from engagement.


matchingTuples

private transient java.util.Vector matchingTuples
Holds tuples coming from the main TS that are a match for a new oncepertuple reaction.


newTuples

private transient java.util.Vector newTuples
Holds the tuples that have been dropped by a write performed within a reaction.

Constructor Detail

Reactor

Reactor(lights.interfaces.ITupleSpace tupleSpace,
        java.lang.String tsname)
The constructor for a Reactor. It is associated with e LTSMgr.

Parameters:
tupleSpace - The tuple space
tsname - The name of the tuple space
Method Detail

installReactions

RegisteredReaction[] installReactions(Reaction[] r,
                                      java.lang.String name,
                                      AgentID a,
                                      long seqNum)

installRegisteredReactions

RegisteredReaction[] installRegisteredReactions(RegisteredReaction[] r)
Reinstalls a reaction.


getAgentReactions

RegisteredReaction[] getAgentReactions(AgentID a)
Return the reactions belonging to the specified agent. These reactions are removed from this reactor.


getAllReactions

RegisteredReaction[] getAllReactions()
Returns all of the reactions that are registered on this tuple space.


putReactions

void putReactions(RegisteredReaction[] r)
Used when reactions must be merged in the reactor and no reactive program must be run.


removeReactions

boolean removeReactions(RegisteredReaction[] r)
removes an array of reactions from the list of registered reactions processed during runReactiveProgram. As a side effect, may also update the next pointer of the current execution of the reactive program. If all of the reactions are registered, they are removed. Otherwise no removals are done and false is returned.

Parameters:
r - array of registered reactions to be removed.
Returns:
true if the reactions were removed. false if not all of the reactions were registered

isRegistered

boolean isRegistered(RegisteredReaction r)
Returns true if the RegisteredReaction is registered within this Reactor.


isRunning

boolean isRunning()
Returns whether a reactive program is running.


doWrite

void doWrite(lights.interfaces.ITuple[] t)
Places the tuples into the newTuples vector.


doRead

lights.interfaces.ITuple doRead(lights.interfaces.ITuple t)

doReadg

lights.interfaces.ITuple[] doReadg(lights.interfaces.ITuple t)

removeMatch

private void removeMatch(java.util.Vector tuples,
                         lights.interfaces.ITuple[] t)

doTake

lights.interfaces.ITuple doTake(lights.interfaces.ITuple t)

doTakeg

lights.interfaces.ITuple[] doTakeg(lights.interfaces.ITuple t)

runReactiveProgram

void runReactiveProgram(lights.interfaces.ITuple[] wt)

react

private void react(lights.interfaces.ITuple t,
                   RegisteredReaction r)

reactOnce

private void reactOnce(lights.interfaces.ITuple t,
                       RegisteredReaction r)
Fires the reaction using the specified tuple. Then removes the reaction from this reactor.

Parameters:
t - the tuple that caused the reaction to fire.
r - the reaction that should be fired.

reactOnce

private boolean reactOnce(java.util.Vector tuples,
                          lights.interfaces.ITuple t,
                          RegisteredReaction r)
Tries to react once on those tuples in the multiset that match the tuple. Returns true as soon as a reaction fires.

Parameters:
tuples - The tuples to look through
r - the reaction to fire.
Returns:
true if the reaction was fired once.

reactSelectively

private boolean reactSelectively(java.util.Vector tuples,
                                 lights.interfaces.ITuple t,
                                 RegisteredReaction r)
Tries to react once-per-tuple on those tuples in the multiset that match the tuple. The information on whether the tuple is already reacted to or not is contained in the RegisteredReaction. Returns true if at least a reaction took place.

Parameters:
tuples - the tuples to look through
r - the reaction to fire.

findMatch

private lights.interfaces.ITuple findMatch(java.util.Vector tuples,
                                           lights.interfaces.ITuple template)

findAllMatches

private lights.interfaces.ITuple[] findAllMatches(java.util.Vector tuples,
                                                  lights.interfaces.ITuple template)
Return all matches, or an array of length zero if no match is found.

Parameters:
tuples - the tuples to look through.
template - the template to match against.
Returns:
an array of ITuples located within the tuples vector that match the template.

printAllReactions

void printAllReactions()

createDeepCopy

lights.interfaces.ITuple createDeepCopy(lights.interfaces.ITuple t)
Returns a copy of the tuple by serializing and then deserializing the tuple object.


getSerializedForm

byte[] getSerializedForm(lights.interfaces.ITuple t)
Returns the byte array containing the serialized form of the tuple.


deserialize

static lights.interfaces.ITuple deserialize(byte[] serForm)
Returns a copy of the tuple by deserializing the byte array passed as a parameter.