lime.motes
Class MoteLimeTupleSpace

java.lang.Object
  extended bylime.LimeTupleSpace
      extended bylime.motes.MoteLimeTupleSpace
All Implemented Interfaces:
java.util.EventListener, ReactionListener, java.io.Serializable

public class MoteLimeTupleSpace
extends LimeTupleSpace
implements ReactionListener

This class, MotesLimeTupleSpace, extends the LimeTupleSpace class, overriding the conventional operations in order to adapt them to the semantic they have when working with sensor networks.

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

Nested Class Summary
private  class MoteLimeTupleSpace.MotesReactionInterceptor
          This private class is used to convert a tuple that was requested with a reaction from the lime format to the lime.motes format (i.e.
 
Field Summary
private  LimeTupleSpace inLTS
          Variable used to "receive" the tuples from the motes.
private  LimeTupleSpace outLTS
          Variable used to out the config tuples.
private  MoteLimeTuple reactionResult
          This tuple is returned when performing a rdp with the reaction
private  java.util.HashMap reactions_pool
          This is a Vector that stores all the templates we are reacting to.
private  int sensingTimeout
          This value means how long the MoteAccess reads data from the network in a rdg.
private static int SLEEPING_TIME
          This value represent the rate at which
 
Fields inherited from class lime.LimeTupleSpace
DEFAULT, SYSTEM
 
Constructor Summary
MoteLimeTupleSpace(java.lang.String name)
          Constructor that instantiate both the data tuple space and the config tuple space, called name_CONFIG
 
Method Summary
 RegisteredReaction[] addWeakReaction(Reaction[] reactions)
          This method adds an array of weak reactions to the tuple space.
private  MoteRegisteredReaction buildMrrFromRr(RegisteredReaction rr)
          This method builds a MoteRegisteredReaction from a RegisteredReaction that contains the MoteID in the template.
private  RequestID generateRequestID(java.lang.Object o)
          Helper method used to generate a unique request id.
 RegisteredReaction[] getRegisteredReactions()
          This method returns an array of MoteRegisteredReaction that contains all the reactions registered by any user on this MotesLimeTupleSpace.
 int getSensingTimeout()
          Getter for the sensing timeout.
 LimeTuple in(LimeTemplate template)
          As explained and motivated in the documentation, this method always throws a MotesIllegalOperationException when trying to remove sensig data tuples, since we consider not appropriate to remove from the tuple space a tuple that indicates a property of the environment, such as the temperature or the light status.
 LimeTuple[] ing(LimeTemplate template)
          As explained and motivated in the documentation, this method always throws a MotesIllegalOperationException, since we consider not appropriate to remove from the tuple space a tuple that indicates a property of the environment, such as the temperature or the light status.
 LimeTuple inp(LimeTemplate template)
          As explained and motivated in the documentation, this method always throws a MotesIllegalOperationException, since we consider not appropriate to remove from the tuple space a tuple that indicates a property of the environment, such as the temperature or the light status.
 LimeTuple out(lights.interfaces.ITuple tuple)
          The out operation is forbidden, just like the in; see the documentation for more detailed information and motivation.
 LimeTuple rd(LimeTemplate template)
          This method performs the read operation on the sensor network.
 LimeTuple[] rdg(LimeTemplate template)
          This method performs the readg operation on the sensor network.
 LimeTuple rdp(LimeTemplate template)
          This method performs the readp operation on the sensor network.
 void reactsTo(ReactionEvent e)
          This implementation of the reactsTo method is used when we are reacting to tuples requested with the rd method.
 void removeWeakReaction(RegisteredReaction[] reactions)
          The reactions passed as parameters are removed from the sensor network.
 void setBuzzer()
          This method makes the reachable motes buzz.
 void setDutyCycle(int awake_percentage)
          Setter of the Awake fraction
 void setMotesMode(int mode)
          Setter for the Mote automatic mode.
 void setRadioPower(int power)
          Setter of the Power of the radio of the motes, to be used when in manaul mode.
 void setSensingTimeout(int sensingTimeout)
          Setter for the sensing timout represent the maximum time waited for a motes to answer before declering it unreacheable
 boolean setShared(boolean shared)
          Enable or disable transient sharing of this tuple space with tuple spaces having the same name.
 
Methods inherited from class lime.LimeTupleSpace
addStrongReaction, cloneTuple, cloneTuple, getName, isOwner, isRegisteredReaction, isShared, out, outg, print, removeStrongReaction, setShared
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SLEEPING_TIME

private static final int SLEEPING_TIME
This value represent the rate at which

See Also:
Constant Field Values

outLTS

private LimeTupleSpace outLTS
Variable used to out the config tuples.


inLTS

private LimeTupleSpace inLTS
Variable used to "receive" the tuples from the motes.


reactionResult

private MoteLimeTuple reactionResult
This tuple is returned when performing a rdp with the reaction


sensingTimeout

private int sensingTimeout
This value means how long the MoteAccess reads data from the network in a rdg.


reactions_pool

private java.util.HashMap reactions_pool
This is a Vector that stores all the templates we are reacting to.

Constructor Detail

MoteLimeTupleSpace

public MoteLimeTupleSpace(java.lang.String name)
                   throws TupleSpaceEngineException,
                          IllegalTupleSpaceNameException
Constructor that instantiate both the data tuple space and the config tuple space, called name_CONFIG

Throws:
TupleSpaceEngineException
IllegalTupleSpaceNameException
Method Detail

in

public LimeTuple in(LimeTemplate template)
             throws TupleSpaceEngineException
As explained and motivated in the documentation, this method always throws a MotesIllegalOperationException when trying to remove sensig data tuples, since we consider not appropriate to remove from the tuple space a tuple that indicates a property of the environment, such as the temperature or the light status. The operation is allowed only for log data, that have as last actual parameter the string "log_data".

Overrides:
in in class LimeTupleSpace
Parameters:
template - template the returned tuple must be matched against.
Returns:
the historical requested value.
Throws:
MotesIllegalOperationException.
TupleSpaceEngineException - if a problem is encountered in the underlying tuple space engine.

inp

public LimeTuple inp(LimeTemplate template)
              throws TupleSpaceEngineException
As explained and motivated in the documentation, this method always throws a MotesIllegalOperationException, since we consider not appropriate to remove from the tuple space a tuple that indicates a property of the environment, such as the temperature or the light status. The operation is allowed only for log data, that have as last actual parameter the string "log_data".

Overrides:
inp in class LimeTupleSpace
Parameters:
template - template the returned tuple must be matched against
Returns:
the requested log data, or null if it doesn't exist in the tuple space.
Throws:
TupleSpaceEngineException - if a problem is encountered in the underlying tuple space engine.

ing

public LimeTuple[] ing(LimeTemplate template)
As explained and motivated in the documentation, this method always throws a MotesIllegalOperationException, since we consider not appropriate to remove from the tuple space a tuple that indicates a property of the environment, such as the temperature or the light status. The operation is allowed only for log data, that have as last actual parameter the string "log_data".

Overrides:
ing in class LimeTupleSpace
Parameters:
template - template the returned tuple must be matched against.
Returns:
an array of MoteLimeTuple matching the given pattern.

rd

public LimeTuple rd(LimeTemplate template)
             throws TupleSpaceEngineException
This method performs the read operation on the sensor network.

Overrides:
rd in class LimeTupleSpace
Parameters:
template - this template must be an instance of MotesLimeTemplate.
Returns:
LimeTuple a MoteLimeTuple that matches the given template.
Throws:
TupleSpaceEngineException - if the passed template is not a MotesLimeTemplate.

getRegisteredReactions

public RegisteredReaction[] getRegisteredReactions()
This method returns an array of MoteRegisteredReaction that contains all the reactions registered by any user on this MotesLimeTupleSpace.

Overrides:
getRegisteredReactions in class LimeTupleSpace
Returns:
RegisteredReaction[] actually returns an array of MoteRegisteredReaction

buildMrrFromRr

private MoteRegisteredReaction buildMrrFromRr(RegisteredReaction rr)
This method builds a MoteRegisteredReaction from a RegisteredReaction that contains the MoteID in the template.

Parameters:
rr - the lime RegisteredReaction from which we exctract the MoteID.
Returns:
a MoteRegisteredReaction with the same template of the passed RegisteredReaction.

rdp

public LimeTuple rdp(LimeTemplate template)
              throws TupleSpaceEngineException
This method performs the readp operation on the sensor network. The difference from the rd one, is that this method always returns, also null in case there's no possibility to retrieve the requested data from the sensor network.

Overrides:
rdp in class LimeTupleSpace
Parameters:
template - this template must be an instance of MotesLimeTemplate.
Returns:
LimeTuple a MoteLimeTuple that matches the given template.
Throws:
TupleSpaceEngineException - if the passed template is not a MotesLimeTemplate.

rdg

public LimeTuple[] rdg(LimeTemplate template)
                throws TupleSpaceEngineException
This method performs the readg operation on the sensor network.

Overrides:
rdg in class LimeTupleSpace
Parameters:
template - this template must be an instance of MotesLimeTemplate.
Returns:
LimeTuple[] the array of tuples that match the template.
Throws:
TupleSpaceEngineException - if the passed template is not a MotesLimeTemplate.

out

public LimeTuple out(lights.interfaces.ITuple tuple)
              throws TupleSpaceEngineException
The out operation is forbidden, just like the in; see the documentation for more detailed information and motivation.

Overrides:
out in class LimeTupleSpace
Parameters:
tuple - the tuple to be inserted.
Returns:
the tuple inserted with cur, dest, and id set.
Throws:
TupleSpaceEngineException - if a problem is encountered in the underlying tuple space engine.

addWeakReaction

public RegisteredReaction[] addWeakReaction(Reaction[] reactions)
                                     throws TupleSpaceEngineException
This method adds an array of weak reactions to the tuple space. Each reaction is outed as a configuration tuple, as explained in the documentation.

Overrides:
addWeakReaction in class LimeTupleSpace
Parameters:
reactions - the array of reactions that will be registered.
Returns:
returns an array of handles to the registered reactions. These can later be used to uninstall the reactions.
Throws:
TupleSpaceEngineException

generateRequestID

private RequestID generateRequestID(java.lang.Object o)
Helper method used to generate a unique request id.

Returns:
a unique request ID.

removeWeakReaction

public void removeWeakReaction(RegisteredReaction[] reactions)
                        throws TupleSpaceEngineException,
                               NoSuchReactionException
The reactions passed as parameters are removed from the sensor network.

Overrides:
removeWeakReaction in class LimeTupleSpace
Parameters:
reactions - the reactions to be removed.
Throws:
TupleSpaceEngineException
NoSuchReactionException

setShared

public boolean setShared(boolean shared)
Description copied from class: LimeTupleSpace
Enable or disable transient sharing of this tuple space with tuple spaces having the same name. When a tuple space changes its status from private to shared, it is implicitly engaged with the other tuple spaces in the system. When a tuple space changes its status from shared to private, it is disengaged from any other tuple spaces it was engaged with (both local and remote). Setting a tuple space to shared has no effect if the tuple space is already shared, i.e., no engagement protocol is started. Same holds for setting a private tuple space to private, i.e., no disengagement protocol is started.

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.

Overrides:
setShared in class LimeTupleSpace
Parameters:
shared - true to set the tuple spaces to shared, false to set it to private.
Returns:
true if the tuple space is successfully engaged/disengaged.

getSensingTimeout

public int getSensingTimeout()
Getter for the sensing timeout.

Returns:
the int value indicating the current sensing timeout.

setSensingTimeout

public void setSensingTimeout(int sensingTimeout)
Setter for the sensing timout represent the maximum time waited for a motes to answer before declering it unreacheable

Parameters:
sensingTimeout - the new value of the sensing timeout.

setBuzzer

public void setBuzzer()
This method makes the reachable motes buzz.


setMotesMode

public void setMotesMode(int mode)
Setter for the Mote automatic mode.


setRadioPower

public void setRadioPower(int power)
Setter of the Power of the radio of the motes, to be used when in manaul mode.


setDutyCycle

public void setDutyCycle(int awake_percentage)
Setter of the Awake fraction

Parameters:
awake_percentage - represent the qoute of the cycle that the motes stays up.

reactsTo

public void reactsTo(ReactionEvent e)
This implementation of the reactsTo method is used when we are reacting to tuples requested with the rd method.

Specified by:
reactsTo in interface ReactionListener
Parameters:
e - the reaction event containing the tuple which will be extracted of the MoteID and then assigned to the reactionResult variable. Then a notify is performed in order to awake the threads that are waiting for a tuple (typically the rd function call).