Introduction
gradysim.simulator.handler
The Simulator and EventLoop provide the backbone upon which handlers implement functionalities into the simulation. In principle handlers are classes that have access to the event loop of the simulation and to it's nodes.
Handlers are registered during the building of the simulation, they are associated with a label and providers can access them through this label. Protocols can access them indirectly through the providers. Handlers can also have indirect effect on protocols indirectly since they have access to the encapsulated network node.
Every handler implements the IHandler interface.
gradysim.simulator.handler.interface.INodeHandler
Bases: ABC
The common interface every handler should implement.
Source code in gradysim/simulator/handler/interface.py
after_simulation_step(iteration, timestamp)
This callback function is called after every simulation step. Useful if the handler implements some functionality that depends on running code at every step of the simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iteration |
int
|
Number of the iteration currently being ran |
required |
timestamp |
float
|
Current simulation timestamp in seconds |
required |
Source code in gradysim/simulator/handler/interface.py
finalize()
This is called after the simulation is finished. Useful if the handler implements some functionality that depends on running code at the end of the simulation.
get_label()
abstractmethod
staticmethod
Static method returning the unique label of the handler. If two handlers with the same label are registered only the last registered one will be accessible in the simulation.
Returns:
Type | Description |
---|---|
str
|
The unique label of this handler |
Source code in gradysim/simulator/handler/interface.py
initialize()
This is called after the simulation is initialized. Useful if the handler implements some functionality that depends on running code at the beginning of the simulation.
inject(event_loop)
abstractmethod
This function is called when the simulator is instantiated to provide the handler with the simulation's event loop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_loop |
EventLoop
|
The simulation's event loop instance |
required |
Source code in gradysim/simulator/handler/interface.py
register_node(node)
abstractmethod
This is called after a node is added to the simulation's build process. The encapsulated node is passed as an argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node |
Node
|
Encapsulated node instance added to the simulation |
required |