core
Class ModuleCommunicationBus

java.lang.Object
  extended by core.ModuleCommunicationBus

public class ModuleCommunicationBus
extends java.lang.Object

Intermodule communication bus. Works as a blackboard where modules can post data, subscribe to data changes and also poll for data values. This is fairly similar to Message class' property interface, but these values are shared for a node instead of message.


Constructor Summary
ModuleCommunicationBus()
          Constructor.
 
Method Summary
 void addProperty(java.lang.String key, java.lang.Object value)
          Adds a new property for this node.
 double getDouble(java.lang.String key, double naValue)
          Returns a double value from the communication bus.
 int getInt(java.lang.String key, int naValue)
          Returns an integer value from the communication bus.
 java.lang.Object getProperty(java.lang.String key)
          Returns an object that was stored using the given key.
 void subscribe(java.lang.String key, ModuleCommunicationListener module)
          Subscribes a module to changes of a certain value.
 java.lang.String toString()
           
 void unsubscribe(java.lang.String key, ModuleCommunicationListener module)
          Removes a notification subscription
 double updateDouble(java.lang.String key, double delta)
          Changes the Double value with given key with the value delta
 void updateProperty(java.lang.String key, java.lang.Object value)
          Updates a value for an existing property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModuleCommunicationBus

public ModuleCommunicationBus()
Constructor.

Method Detail

addProperty

public void addProperty(java.lang.String key,
                        java.lang.Object value)
                 throws SimError
Adds a new property for this node. The key can be any string but it should be such that no other class accidently uses the same value. Note that, unless the value is immutable, it can be changed by any object that can call getProperty(java.lang.String).

Parameters:
key - The key which is used to lookup the value
value - The value to store
Throws:
SimError - if there is already a value for the given key

getProperty

public java.lang.Object getProperty(java.lang.String key)
Returns an object that was stored using the given key. If such object is not found, null is returned.

Parameters:
key - The key used to lookup the object
Returns:
The stored object or null if it isn't found

updateProperty

public void updateProperty(java.lang.String key,
                           java.lang.Object value)
                    throws SimError
Updates a value for an existing property. For storing the value first time, addProperty(String, Object) should be used which checks for name space clashes.

Parameters:
key - The key which is used to lookup the value
value - The new value to store
Throws:
SimError

updateDouble

public double updateDouble(java.lang.String key,
                           double delta)
                    throws SimError
Changes the Double value with given key with the value delta

Parameters:
key - The key of variable to update
delta - Value added to the old value
Returns:
The new value
Throws:
SimError - if the value with the given key was not a Double

getDouble

public double getDouble(java.lang.String key,
                        double naValue)
                 throws SimError
Returns a double value from the communication bus.

Parameters:
key - The key of the variable
naValue - The value to return if there is no value for the key
Returns:
The value of the key, or the naValue if they key was not found
Throws:
SimError - if the value with the given key was not a Double

getInt

public int getInt(java.lang.String key,
                  int naValue)
           throws SimError
Returns an integer value from the communication bus.

Parameters:
key - The key of the variable
naValue - The value to return if there is no value for the key
Returns:
The value of the key, or the naValue if they key was not found
Throws:
SimError - if the value with the given key was not an Integer

subscribe

public void subscribe(java.lang.String key,
                      ModuleCommunicationListener module)
Subscribes a module to changes of a certain value.

Parameters:
key - The key of the value whose changes the module is interested of
module - The module to subscribe.

unsubscribe

public void unsubscribe(java.lang.String key,
                        ModuleCommunicationListener module)
Removes a notification subscription

Parameters:
key - The key for which the subscription should be removed
module - The module to whose subscription is removed

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object