com.speckled.specksim
Interface Speck

All Superinterfaces:
Configurable
All Known Implementing Classes:
AbstractSpeck, CollisionSpeck, FloodSpeck, NeighbourlySpeck, VelocitySpeck

public interface Speck
extends Configurable

The interface for a speck. You'll probably want to subclass AbstractSpeck for your implementation, as it takes care of the unique ID stuff, along with methods to get a seeded random number generator and to control logging.

Author:
ryanm

Field Summary
static int ID_BITS
          The number of bits used in the id
static java.lang.String SPECK_LOG_SOURCE
          The source to use for logging speck events
 
Method Summary
 void deInit()
          Called when the speck is removed from the simulator.
 java.lang.String getFlavourName()
          Gets a name for this flavour of Speck
 SpeckState getState()
          Takes a snapshot of the state of this speck.
 int id()
          Gets a unique identifier for this speck
 void initialise(SpeckCapability simulator)
          Called when the speck is added to the simulator, and when the simulator is reset.
 void setID(int ID)
          Sets this speck's ID.
 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 interface com.ryanm.config.Configurable
getConfigurator
 

Field Detail

ID_BITS

static final int ID_BITS
The number of bits used in the id

See Also:
Constant Field Values

SPECK_LOG_SOURCE

static final java.lang.String SPECK_LOG_SOURCE
The source to use for logging speck events

See Also:
Constant Field Values
Method Detail

getFlavourName

java.lang.String getFlavourName()
Gets a name for this flavour of Speck

Returns:
A name for this type of Speck

id

int id()
Gets a unique identifier for this speck

Returns:
an integer identifier

setID

void setID(int ID)
Sets this speck's ID. Great care must be taken to ensure that all speck IDs are unique

Parameters:
ID - The ID to set

initialise

void initialise(SpeckCapability simulator)
Called when the speck is added to the simulator, and when the simulator is reset. Would be a good place to post your events, set up your state etc.

Parameters:
simulator - The simulator that the speck is added to

deInit

void deInit()
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

void shellEncountered(Speck sender,
                      MessageShell shell,
                      Message message)
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

SpeckState getState()
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