com.speckled.specksim.imp.specks
Class NeighbourlySpeck

java.lang.Object
  extended by com.speckled.specksim.imp.specks.AbstractSpeck
      extended by com.speckled.specksim.imp.specks.NeighbourlySpeck
All Implemented Interfaces:
Configurable, Speck

@ConfigurableType(value="Neighbourly Speck")
public class NeighbourlySpeck
extends AbstractSpeck

This speck implementation simply broadcasts its id periodically, and keeps a decaying list of all the IDs it has received. Look in the source for voluminous comments demonstrating how to write a Speck implementation.

Author:
ryanm

Field Summary
static float broadcastDelay
          The time delay between broadcasts
static CarrierSenseMac mac
          The mac protocol used to broadcast
static float recordLife
          The time for which a neighbour record exists
static MessageShell shell
          The message shell that we use to send messages
 
Fields inherited from class com.speckled.specksim.imp.specks.AbstractSpeck
name, RNG_OFFSET_CONF_DESC, RNG_OFFSET_CONF_NAME, simulator
 
Fields inherited from interface com.speckled.specksim.Speck
ID_BITS, SPECK_LOG_SOURCE
 
Constructor Summary
NeighbourlySpeck()
          Constructs a new NeighbourlySpeck.
 
Method Summary
 void deInit()
          Called when the speck is removed from the simulator.
 Configurator getConfigurator()
          Gets a Configurator object that describes and can manipulate the variables of this Configurable.
 SpeckState getState()
          Takes a snapshot of the state of this speck.
 void init()
          Called when the speck is added to the simulator, and when the simulator is reset.
 void shellEncountered(Speck sender, MessageShell shell, Message message)
          Called when the simulator determines that this speck lies within the bounds of a transmission.
 
Methods inherited from class com.speckled.specksim.imp.specks.AbstractSpeck
getFlavourName, getRandom, getRandomSeedOffset, id, initialise, isLoggingEnabled, setID, setLoggingEnabled, setRandomSeedOffset, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

shell

@SubConfigurable
@Priority(value=0)
public static MessageShell shell
The message shell that we use to send messages


mac

@SubConfigurable
@Priority(value=1)
public static CarrierSenseMac mac
The mac protocol used to broadcast


broadcastDelay

@ConfigurableVariable(value="Broadcast Delay")
@Description(value="How often each speck will broadcast its ID")
@NumberRange(value={0.0f,10.0f})
@Priority(value=2)
public static float broadcastDelay
The time delay between broadcasts


recordLife

@ConfigurableVariable(value="Record Lifetime")
@Description(value="How long each speck will remember its neighbours")
@NumberRange(value={0.0f,20.0f})
@Priority(value=3)
public static float recordLife
The time for which a neighbour record exists

Constructor Detail

NeighbourlySpeck

public NeighbourlySpeck()
Constructs a new NeighbourlySpeck. Every speck implementation must have a no-argument constructor

Method Detail

init

public void init()
Description copied from class: AbstractSpeck
Called when the speck is added to the simulator, and when the simulator is reset. Would be a good place to reset the speck's fields and post your events.

Specified by:
init in class AbstractSpeck

deInit

public void deInit()
Description copied from interface: Speck
Called when the speck is removed from the simulator. Might be a good place to remove your events or clean up other state. Note that all SimulationEvents that have this speck as a parent will automatically be removed for you.


shellEncountered

public void shellEncountered(Speck sender,
                             MessageShell shell,
                             Message message)
Description copied from interface: Speck
Called when the simulator determines that this speck lies within the bounds of a transmission.

Parameters:
sender - The speck that sent the message
shell - The shell used to send the message
message - The content of the message

getState

public SpeckState getState()
Description copied from interface: Speck
Takes a snapshot of the state of this speck. For performance reasons, it is advisable that each Speck should keep a reference to one SpeckState object, and simply update and return it when this is called

Returns:
A SpeckState object that encapsulates the state of this speck at the current time

getConfigurator

public Configurator getConfigurator()
Description copied from interface: Configurable
Gets a Configurator object that describes and can manipulate the variables of this Configurable. This method must only return null if the Configurable object is Annotated such that an AnnotatedConfigurator can be built from it.

Returns:
A configurator object, or null if annotated