com.speckled.specksim
Class SpeckSim

java.lang.Object
  extended by com.speckled.specksim.SpeckSim
All Implemented Interfaces:
Configurable, SpeckCapability, StateSource

public class SpeckSim
extends java.lang.Object
implements Configurable, SpeckCapability, StateSource

The main class of the simulator.

Author:
ryanm

Field Summary
static java.lang.String SIM_SOURCE
          The logging source for logging events in the simulator
 
Method Summary
 void addCommsModelListener(CommunicationModelListener listener)
          Registers a MessageListener's interest.
 void addExecutionListener(ExecutionListener listener)
          Registers an ExecutionListener's interest.
 void addMovementModelListener(MovementModelListener listener)
          Registers a MovementModelListener's interest.
 void addPopulationListener(PopulationListener listener)
          Register's a PopulationListener's interest.
 void addSpeck(Speck speck)
          Adds a speck to the simulator
 void addWallListener(WallListener listener)
          Register an object's interest in changes to the walls
 void advanceToTime(float time)
          Advances the state of the simulation to the specified time
 int countSpecks()
          Gets the number of specks, of all flavours, in the simulator
 int countSpecks(java.lang.String name)
          Gets the number of specks of a given flavour in the simulator
 int findSpeckIndex(Speck speck)
          Finds the index of a given speck in the master list of specks
static SpeckSim getandResetSimulator()
          Gets the SpeckSim instance and resets it.
 CommunicationModel getCommunicationModel()
          Gets the current communications model
 Configurator getConfigurator()
          Gets a Configurator object that describes and can manipulate the variables of this Configurable.
 Environment getEnvironment(java.lang.String name)
          Gets an Environment object from the simulator
 java.lang.String[] getEnvironmentNames()
          Gets an array containing the name sof available Environment objects
 MovementModel getMovementModel()
          Gets the current movement model
static SpeckSim getSimulator()
          Gets the SpeckSim instance
 java.util.Iterator<Speck> getSpecks()
          Gets an iterator over all the specks.
 java.util.Iterator<Speck> getSpecks(java.lang.String name)
          Gets an iterator over all the specks of a given flavour.
 SimulatorState getState()
          Gets a SimulatorState object from the source
 float getTime()
          Gets the current simulation time
 WallManager getWallManager()
          Gets the WallManager.
 void initiateBroadcast(Speck speck, Message m, MessageShell shell, MACProtocol mac)
          Initiates a broadcast
 void initiateBroadcast(Speck speck, MessageProducer mp, MessageShell shell, MACProtocol mac)
          Initiates a broadcast.
 float peekNextEventTime()
          Peeks at the next pending event, and returns its event time
 void postEvent(SimulationEvent se)
          Post an event onto the queue.
 java.lang.String printEventQueue()
          Builds and returns a string representation of the current state of the event queue
 void removeCommsModelListener(CommunicationModelListener listener)
          Registers a MessageListener's boredom.
 void removeEvent(SimulationEvent se)
          Removes an event from the event queue.
 void removeExecutionListener(ExecutionListener listener)
          Registers an ExecutionListener's boredom.
 void removeMovementModelListener(MovementModelListener listener)
          Registers a MovementModelListener's boredom.
 void removeOwnedEvents(Speck owner)
          Remove all events with a particular Speck as an owner
 void removePopulationListener(PopulationListener listener)
          Register's a PopulationListener's boredom.
 void removeSpeck(Speck speck)
          Removes a speck from the simulator
 void removeWallListener(WallListener listener)
          Register an object's disinterest in changes to the walls
 void reset()
          Resets this simulator's state to time 0
 void setCommunicationModel(CommunicationModel model)
          Sets the active CommunicationModel
 void setMovementModel(MovementModel mm)
          Sets the current movement model
 void setNumberOfSpecks(java.lang.String type, int n)
          Sets the number of specks of a given type in the simulation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIM_SOURCE

public static final java.lang.String SIM_SOURCE
The logging source for logging events in the simulator

See Also:
Constant Field Values
Method Detail

getandResetSimulator

public static SpeckSim getandResetSimulator()
Gets the SpeckSim instance and resets it. All extension classes, ( Speck implementations, MovementModels, etc ) should be registered before the first call to this method is made

Returns:
The SpeckSim object

getSimulator

public static SpeckSim getSimulator()
Gets the SpeckSim instance

Returns:
the SpeckSim object

getWallManager

public WallManager getWallManager()
Gets the WallManager.

Returns:
The WallManager

reset

public void reset()
Resets this simulator's state to time 0


getTime

public float getTime()
Description copied from interface: SpeckCapability
Gets the current simulation time

Specified by:
getTime in interface SpeckCapability
Returns:
The number of simulated seconds that have passed.

getState

public SimulatorState getState()
Description copied from interface: StateSource
Gets a SimulatorState object from the source

Specified by:
getState in interface StateSource
Returns:
A SimulatorState object

setMovementModel

public void setMovementModel(MovementModel mm)
Sets the current movement model

Parameters:
mm - The new movement model

getMovementModel

public MovementModel getMovementModel()
Gets the current movement model

Returns:
The current movement model

setCommunicationModel

public void setCommunicationModel(CommunicationModel model)
Sets the active CommunicationModel

Parameters:
model - The new model

getCommunicationModel

public CommunicationModel getCommunicationModel()
Gets the current communications model

Returns:
The current communications model

setNumberOfSpecks

public void setNumberOfSpecks(java.lang.String type,
                              int n)
Sets the number of specks of a given type in the simulation

Parameters:
type - The name of the speck type
n - The desired number of specks

addSpeck

public void addSpeck(Speck speck)
Adds a speck to the simulator

Parameters:
speck - The speck to add

removeSpeck

public void removeSpeck(Speck speck)
Removes a speck from the simulator

Parameters:
speck - The speck to remove

findSpeckIndex

public int findSpeckIndex(Speck speck)
Finds the index of a given speck in the master list of specks

Parameters:
speck - The speck to find
Returns:
the index of the speck in the master list, or -1 if not found

getSpecks

public java.util.Iterator<Speck> getSpecks()
Gets an iterator over all the specks. The iterator should only be used, and indeed, this method called, inside blocks that are synchronised on this SpeckSim object

Returns:
An iterator over all specks

getSpecks

public java.util.Iterator<Speck> getSpecks(java.lang.String name)
Gets an iterator over all the specks of a given flavour. The iterator should only be used, and indeed, this method called, inside blocks that are synchronized on this SpeckSim object

Parameters:
name - The name of the speck flavour
Returns:
An iterator over all specks of a given flavour

countSpecks

public int countSpecks()
Gets the number of specks, of all flavours, in the simulator

Returns:
The number of specks currently in the simulator

countSpecks

public int countSpecks(java.lang.String name)
Gets the number of specks of a given flavour in the simulator

Parameters:
name - The speck flavour name
Returns:
The number of specks of that type

initiateBroadcast

public void initiateBroadcast(Speck speck,
                              Message m,
                              MessageShell shell,
                              MACProtocol mac)
Description copied from interface: SpeckCapability
Initiates a broadcast

Specified by:
initiateBroadcast in interface SpeckCapability
Parameters:
speck - The transmitting speck
m - The message to transmit
shell - The extents of the broadcast
mac - The MAC protocol that controls the broadcast

initiateBroadcast

public void initiateBroadcast(Speck speck,
                              MessageProducer mp,
                              MessageShell shell,
                              MACProtocol mac)
Description copied from interface: SpeckCapability
Initiates a broadcast. Allows construction of the message to be deferred until it is actually going to be transmitted

Specified by:
initiateBroadcast in interface SpeckCapability
Parameters:
speck - The transmitting speck
mp - The provider of the method to transmit.
shell - The extents of the broadcast
mac - The MAC protocol that controls the broadcast

advanceToTime

public void advanceToTime(float time)
Advances the state of the simulation to the specified time

Parameters:
time - The target time that the simulation will be at when the method returns

postEvent

public void postEvent(SimulationEvent se)
Description copied from interface: SpeckCapability
Post an event onto the queue.

Specified by:
postEvent in interface SpeckCapability
Parameters:
se - The event to post.

peekNextEventTime

public float peekNextEventTime()
Peeks at the next pending event, and returns its event time

Returns:
The time at which the next pending event will execute, or -1 if there is no next event

removeEvent

public void removeEvent(SimulationEvent se)
Description copied from interface: SpeckCapability
Removes an event from the event queue.

Specified by:
removeEvent in interface SpeckCapability
Parameters:
se - The event to remove. Must be non-null

removeOwnedEvents

public void removeOwnedEvents(Speck owner)
Description copied from interface: SpeckCapability
Remove all events with a particular Speck as an owner

Specified by:
removeOwnedEvents in interface SpeckCapability
Parameters:
owner - The owner Speck

addMovementModelListener

public void addMovementModelListener(MovementModelListener listener)
Registers a MovementModelListener's interest. The listener will be appraised of changes to the movement model

Parameters:
listener - the listener to add

removeMovementModelListener

public void removeMovementModelListener(MovementModelListener listener)
Registers a MovementModelListener's boredom. The listener could no longer care less what happens.

Parameters:
listener - the listener to remove

addExecutionListener

public void addExecutionListener(ExecutionListener listener)
Registers an ExecutionListener's interest. The listener will be appraised of the execution status of the simulator

Parameters:
listener - the listener to add. Adding the same listener multiple times will have no effect - it will still only be notified once

removeExecutionListener

public void removeExecutionListener(ExecutionListener listener)
Registers an ExecutionListener's boredom. The listener could no longer care less what happens.

Parameters:
listener - the listener to remove

addCommsModelListener

public void addCommsModelListener(CommunicationModelListener listener)
Registers a MessageListener's interest. The listener will be notified whenever a message is sent in the simulator.

Parameters:
listener - The listener to add. Adding the same listener multiple times will have no effect - it will still only be notified once

removeCommsModelListener

public void removeCommsModelListener(CommunicationModelListener listener)
Registers a MessageListener's boredom. The listener could no longer care less what happens.

Parameters:
listener - The listener to remove

addPopulationListener

public void addPopulationListener(PopulationListener listener)
Register's a PopulationListener's interest. The listener will be notified of any changes to the speck population

Parameters:
listener - The listener to add. Adding the same listener multiple times will have no effect - it will still only be notified once

removePopulationListener

public void removePopulationListener(PopulationListener listener)
Register's a PopulationListener's boredom. The listener could no longer care less what happens.

Parameters:
listener - The listener to remove

addWallListener

public void addWallListener(WallListener listener)
Register an object's interest in changes to the walls

Parameters:
listener - the interested object. Adding the same listener multiple times will have no effect - it will still only be notified once

removeWallListener

public void removeWallListener(WallListener listener)
Register an object's disinterest in changes to the walls

Parameters:
listener - the disinterested object

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.

Specified by:
getConfigurator in interface Configurable
Returns:
A configurator object, or null if annotated

printEventQueue

public java.lang.String printEventQueue()
Builds and returns a string representation of the current state of the event queue

Returns:
a string of the event queue

getEnvironmentNames

public java.lang.String[] getEnvironmentNames()
Gets an array containing the name sof available Environment objects

Returns:
The name sof available Environment objects

getEnvironment

public Environment getEnvironment(java.lang.String name)
Description copied from interface: SpeckCapability
Gets an Environment object from the simulator

Specified by:
getEnvironment in interface SpeckCapability
Parameters:
name - The name of the desired Environment object
Returns:
The named Environment object, or null if there is no such object