lime.motes
Class MoteAgent

java.lang.Object
  extended byjava.lang.Thread
      extended bylime.StationaryAgent
          extended bylime.motes.MoteAgent
All Implemented Interfaces:
java.util.EventListener, ILimeAgent, IMoteListener, ReactionListener, java.lang.Runnable, java.io.Serializable

public class MoteAgent
extends StationaryAgent
implements ReactionListener, IMoteListener

This Agent is responsible to establish the bridge between lime and the motes subsystem, it reacts to configuration tuple in the BASENAME-CONFIG tuple space, asks the motes subsystem to read environmental data and out them in the BASENAME tuple space. Please refer to the main documentation for further information on the role of the MoteAccess.

Version:
1.0
Author:
Carlo Curino, Matteo Giani, Marco Giorgetta, Alessandro Giusti
See Also:
StationaryAgent, Location, Reaction, ReactionListener, LimeTupleSpace, IMoteListener, Serialized Form

Nested Class Summary
private  class MoteAgent.MoteStopOperation
          This class is used to react to a tuple that indicates the command to stop a running operation on the motes (typically a reaction).
private  class MoteAgent.ReactionRequestListener
          This class is used to react to tuples in the config tuple space that request for a reaction.
 
Field Summary
private  java.util.HashMap agentsRequests
          This hashmap is used to associate each agent that perform at least a request on the MoteAgent to its requests (so the agent is associated to a vector of requests).
private  java.util.LinkedList dataQueue
          Linked lists used for implementing queues, needed since only the MoteAgent can access the tuple space directly.
private  IMoteLimeTupleDecorator decorator
          Decorator for the MoteLimeTupleDecorator
private static java.lang.String DEFAULT_SPACES_BASE_NAME
          Default name of the tuple space is MOTES.
private  LimeTupleSpace ltc
          LimeTuple space used for configuration.
private  LimeTupleSpace lts
          LimeTupleSpace that contains the data, i.e.
private  IMoteAccess moteaccess
          The IMoteAccess that will be used in accessing the motes network.
private  java.util.LinkedList reactionQueue
           
private  java.lang.String spacesBaseName
          Name of the tuple space, by default set to DEFAULT_SPACES_BASE_NAME.
private  LimeSystemTupleSpace sys
          Used for catching the deregistration of an agent.
private  java.util.HashMap timeouts
          This HashMap is used to associate each tuple that is inserted into the tuplespace to its duration.
private static int TIMER_STEP_SECS
          Establishes the rate at which expired tuples are searched and removed if found.
 
Fields inherited from class lime.StationaryAgent
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MoteAgent()
          Public constructor that calls the StationaryAgent constructor with name "MoteAgent".
 
Method Summary
 void addData(MoteResult mr)
          This is the call back method used by the underlying mote subsystem to return data.
 void addReactionData(MoteResult mr)
          Method implementing the IMoteListener interface; it is called by the moteaccess when reaction data is produced.
private  void buildAndOutAggDataTuples(MoteResult mr)
           
private  void buildAndOutAggReactionTuples(MoteResult mr)
           
private  void buildAndOutDataTuples(MoteResult mr)
          This method accepts as parameter the mote result from a reading of the sensor network and builds a tuple from it, outing the constructed tuple into the tuple space.
private  void buildAndOutReactionTuples(MoteResult mr)
          This method plays the same role as the buildAndOutDataTuples for reaction data.
private  boolean isAggregType(lights.interfaces.ITuple tuple)
          Verifies if the tuple passed as a parameter is an aggregation tuple or not.
private  void logAgentRequest(AgentID aid, RequestID rid)
          This method is used to log the couple RequestID AgentID in order to be able to remove all the operation by a given AgentID.
private  boolean lookForTuples(LimeTuple lt)
          This private method is used to check wether the tuplespace contains at least a tuple that matches the tuple passed as parameter.
 void reactsTo(ReactionEvent e)
          This method implements the ReactionListener ractsTo method, checking the type of the configuration tuple.
private  void removeStuffBy(AgentID aid)
          This method is used to remove all the running operations requested by an agent that is no more present.
 void run()
          The run method instantiates the LimeTupleSpaces, and registers for reactions on needed tuples, like requests for reads or reactions.
 
Methods inherited from class lime.StationaryAgent
getMgr
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SPACES_BASE_NAME

private static final java.lang.String DEFAULT_SPACES_BASE_NAME
Default name of the tuple space is MOTES. This default value is the same in the MotesLimeTupleSpace as well.

See Also:
Constant Field Values

TIMER_STEP_SECS

private static final int TIMER_STEP_SECS
Establishes the rate at which expired tuples are searched and removed if found.

See Also:
Constant Field Values

moteaccess

private IMoteAccess moteaccess
The IMoteAccess that will be used in accessing the motes network.


lts

private LimeTupleSpace lts
LimeTupleSpace that contains the data, i.e. sensor readings and log data.


ltc

private LimeTupleSpace ltc
LimeTuple space used for configuration.


sys

private LimeSystemTupleSpace sys
Used for catching the deregistration of an agent.


spacesBaseName

private java.lang.String spacesBaseName
Name of the tuple space, by default set to DEFAULT_SPACES_BASE_NAME.


timeouts

private java.util.HashMap timeouts
This HashMap is used to associate each tuple that is inserted into the tuplespace to its duration. As a tuple is inserted, it is assigned of duration default of the freshness associated to that sensor. Every TIMER_STEP_SECS its duration is decremented, and as it reaches zero the tuple is removed from the tuple space. This mechanism allows us to keep in the tuple space only fresh data, w.r.t. the default freshness of the ssensor type.


agentsRequests

private java.util.HashMap agentsRequests
This hashmap is used to associate each agent that perform at least a request on the MoteAgent to its requests (so the agent is associated to a vector of requests). This is used when the agent deregisters; all of its still active reqeusts (e.g. a once per tuple reaction) are stopped.


dataQueue

private java.util.LinkedList dataQueue
Linked lists used for implementing queues, needed since only the MoteAgent can access the tuple space directly. They simply decouple the callbacks from the MoteAccess module from the agent.


reactionQueue

private java.util.LinkedList reactionQueue

decorator

private IMoteLimeTupleDecorator decorator
Decorator for the MoteLimeTupleDecorator

Constructor Detail

MoteAgent

public MoteAgent()
Public constructor that calls the StationaryAgent constructor with name "MoteAgent".

Method Detail

run

public void run()
The run method instantiates the LimeTupleSpaces, and registers for reactions on needed tuples, like requests for reads or reactions. Once this setup operations have been done it keeps on checking wether there are old tuples to be purged out of the data tuple space, in order to keep the tuple space "fresh".

Specified by:
run in interface java.lang.Runnable

reactsTo

public void reactsTo(ReactionEvent e)
This method implements the ReactionListener ractsTo method, checking the type of the configuration tuple. That might refer to the deregistration of an agent, or simply the request for a reading. Reactions are handled by another listener, MoteAgent.ReactionRequestListener.

Specified by:
reactsTo in interface ReactionListener
Parameters:
e - the event that triggered the reaction.

isAggregType

private boolean isAggregType(lights.interfaces.ITuple tuple)
Verifies if the tuple passed as a parameter is an aggregation tuple or not.

Parameters:
tuple -
Returns:

lookForTuples

private boolean lookForTuples(LimeTuple lt)
This private method is used to check wether the tuplespace contains at least a tuple that matches the tuple passed as parameter.

Parameters:
lt - the lime tuple which template is searched in the tuplespace.
Returns:
true if there is at least one matching tuple, false otherwise.

removeStuffBy

private void removeStuffBy(AgentID aid)
This method is used to remove all the running operations requested by an agent that is no more present.

Parameters:
aid - the id of the agent that deregistered.

logAgentRequest

private void logAgentRequest(AgentID aid,
                             RequestID rid)
This method is used to log the couple RequestID AgentID in order to be able to remove all the operation by a given AgentID.

Parameters:
aid - the agent id of the agent that performed the request.

addData

public void addData(MoteResult mr)
This is the call back method used by the underlying mote subsystem to return data.

Specified by:
addData in interface IMoteListener
Parameters:
mr -

buildAndOutDataTuples

private void buildAndOutDataTuples(MoteResult mr)
This method accepts as parameter the mote result from a reading of the sensor network and builds a tuple from it, outing the constructed tuple into the tuple space.

Parameters:
mr - The mote result that is produced by the sensor network.

addReactionData

public void addReactionData(MoteResult mr)
Method implementing the IMoteListener interface; it is called by the moteaccess when reaction data is produced.

Specified by:
addReactionData in interface IMoteListener
Parameters:
mr - the MoteResult produced since the reaction fired.

buildAndOutReactionTuples

private void buildAndOutReactionTuples(MoteResult mr)
This method plays the same role as the buildAndOutDataTuples for reaction data.

Parameters:
mr - the MoteResult that carryes the information in response of a request.

buildAndOutAggDataTuples

private void buildAndOutAggDataTuples(MoteResult mr)

buildAndOutAggReactionTuples

private void buildAndOutAggReactionTuples(MoteResult mr)