Class InstrumentationDecorator<S extends State,E>

java.lang.Object
org.simplesim.model.BasicModelEntity
org.simplesim.model.BasicAgent<S,E>
org.simplesim.model.InstrumentationDecorator<S,E>
All Implemented Interfaces:
Agent, ModelEntity

public final class InstrumentationDecorator<S extends State,E> extends BasicAgent<S,E>
Decorator to add instrumentation functionality to an agent.

The decorator adds listeners to the doEvent method, so that the agent's state can be queried before and after the execution of the agent's strategy. This enables snapshots for data time series and debugging.

The agent's state should considered as read only.

  • Constructor Details

    • InstrumentationDecorator

      public InstrumentationDecorator(BasicAgent<S,E> who)
  • Method Details

    • registerBeforeExecutionListener

      public void registerBeforeExecutionListener(Listener<BasicAgent<?,?>> listener)
    • unregisterBeforeExecutionListener

      public void unregisterBeforeExecutionListener(Listener<BasicAgent<?,?>> listener)
    • registerAfterExecutionListener

      public void registerAfterExecutionListener(Listener<BasicAgent<?,?>> listener)
    • unregisterAfterExecutionListener

      public void unregisterAfterExecutionListener(Listener<BasicAgent<?,?>> listener)
    • addToDomain

      public void addToDomain(BasicDomain domain)
      Description copied from interface: ModelEntity
      Adds this entity to a domain.

      The domain becomes the parent of this entity.

      Note: Connection management has to be done externally by the caller!

      Specified by:
      addToDomain in interface ModelEntity
      Overrides:
      addToDomain in class BasicModelEntity
    • removeFromDomain

      public void removeFromDomain()
      Description copied from interface: ModelEntity
      Removes this entity form its parent domain.

      This method should never be called during a simulation cycle. If the entity could be removed from the domain, the entity's parent is set to null.

      Note: Connection management has to be done externally by the caller.

      Specified by:
      removeFromDomain in interface ModelEntity
      Overrides:
      removeFromDomain in class BasicModelEntity
    • doEvent

      public Time doEvent(Time time)
      Description copied from interface: Agent
      Calculates new outputs from the available inputs and implements the agent's strategy.

      This method is called by the simulator every time this agent is scheduled as an event in the global event queue. Outputs are basically massages that have to be put onto the outport of this agent. It should implement the general strategy of the agent and will acquire the actual simulation time from the simulator.

      This method is supposed to do the following steps:

      • read the messages from the inports
      • modify the agent's state
      • compute output and write messages to other entities to the outports
      • add events to the internal event queue if necessary
      • return the time of the next local event (=next time to call this method)
      If implemented, the agent may also refer read-only to a bulletin board implementation of its parent domain or the root domain for additional external parameters.

      Do not invoke from outside the simulation loop!

      Parameters:
      time - current simulation time
      Returns:
      tone - time of next event
    • getState

      public S getState()
      Description copied from interface: Agent
      Returns the agent's state containing all internal variables
      Specified by:
      getState in interface Agent
      Overrides:
      getState in class BasicAgent<S extends State,E>
      Returns:
      the agent's internal state
    • getTimeOfNextEvent

      public Time getTimeOfNextEvent()
      Description copied from class: BasicAgent
      Returns the time of the next internal event.

      This method is called by the simulator to update the global event queue.

      Specified by:
      getTimeOfNextEvent in interface Agent
      Overrides:
      getTimeOfNextEvent in class BasicAgent<S extends State,E>
      Returns:
      time of the next internal event
    • getName

      public String getName()
      Description copied from interface: ModelEntity
      Returns the name of this model entity

      Returns an empty string as default, may be overridden in derived classes.

      Specified by:
      getName in interface ModelEntity
      Overrides:
      getName in class BasicModelEntity
      Returns:
      the name of this model entity, may be an empty string but not null
    • getFullName

      public String getFullName()
      Description copied from interface: ModelEntity
      Returns the full name of a model, concatenating the names of the parent entities.

      Example: If A and B are parents of this entity and this entity is named C, then the full name is A.B.C

      Specified by:
      getFullName in interface ModelEntity
      Overrides:
      getFullName in class BasicModelEntity
      Returns:
      the full name of this entity
    • getParent

      public Domain getParent()
      Description copied from interface: ModelEntity
      Returns the parent domain of this model entity.
      Specified by:
      getParent in interface ModelEntity
      Overrides:
      getParent in class BasicModelEntity
      Returns:
      the parent of this model
    • getAddress

      public int[] getAddress()
      Description copied from interface: ModelEntity
      Gets the entity address. Can be null.

      Note: The address of the root domain is int[0]. Another dimension is added per model level. The value of each dimension is the index within the corresponding level.

      Specified by:
      getAddress in interface ModelEntity
      Overrides:
      getAddress in class BasicModelEntity
      Returns:
      the address
    • getInport

      public Port getInport()
      Specified by:
      getInport in interface ModelEntity
      Overrides:
      getInport in class BasicModelEntity
    • getOutport

      public Port getOutport()
      Specified by:
      getOutport in interface ModelEntity
      Overrides:
      getOutport in class BasicModelEntity
    • getLevel

      public int getLevel()
      Description copied from interface: ModelEntity
      Returns the level of the entity within the model hierarchy

      Models may be organized in a hierarchy, so that each entity resides in a definite domain level of the model tree. The level information is generated when the getLevel() method is called first. The level of the root node is always 0.

      Specified by:
      getLevel in interface ModelEntity
      Overrides:
      getLevel in class BasicModelEntity
      Returns:
      the level of this entity in the model hierarchy