Application architecture

When you create an application using the Netdef framework your application consists of:



The engine is an instance of netdef.Engines.ThreadedEngine.


A rule is an instance derived from netdef.Rules.BaseRule.


A source is an instance derived from netdef.Sources.BaseSource.


A controller is an instance derived from netdef.Controllers.BaseController.


A python callable that is executed by engine when a associated source changes its value. The associated sources are arguments to the callable. See netdef.Engines.expression.Expression.

# Example:
def expression(arg1, arg2):
    print("expression was called")
    print("This is a netdef.Engines.expression.Expression.Argument:", arg1)
    print("This is the associated source instance:", arg1.instance)
    print("The name of the associated controller:", arg1.instance.controller)

Shared queues

All instances have their own incoming queue. This queue is available to the other instances in the shared object. See netdef.Shared.SharedQueues.SharedQueues


The instances communicate with each other by registering messages in the recipient’s queue. The example below shows a project with one controller and one rule:


The most important message types in your application are APP_STATE, ADD_SOURCE, ADD_PARSER, WRITE_SOURCE and RUN_EXPRESSION. See netdef.Shared.SharedQueues.MessageType

The message flow will in most cases be as follows:

At application initialization:

  • The engine will send APP_STATE to all active controllers.
  • Every rule will send ÀDD_PARSER or/and ADD_SOURCE to a specific controller depending on what is in the configuration files.
  • The engine will send a new APP_STATE to all active controllers.

Repeats until application is terminated:

  • Every controller will send RUN_EXPRESSION back to a specific rule on data changes.
  • The specific rule will then collect the associated expression to be evaluated depending on given data change and send RUN_EXPRESSION to the engine.
  • If the expression generate a new data change then a WRITE_SOURCE message is sent back directly to controller.
blockdiag ThreadedEngine Rule Controller External Parses / Unpacks external data format and updates value of source [n] Value change in source [n] ThreadedEngine Executes expression [n] in ThreadPoolExecutor Looks up the expression for given source and passes it to ThreadedEngine If expression produces a value change Packs value into external data format APP_STATE, AppStateType.SETUP ADD_PARSER, source class ADD_SOURCE, source 1 ADD_SOURCE, source 2 ADD_SOURCE, source [n] APP_STATE, AppStateType.RUNNING [optional] Setup subscription for source [n] [optional] Polling Data received RUN_EXPRESSION, source [n] RUN_EXPRESSION, expression [n] WRITE_SOURCE, source [n], value, timestamp Data sent Initialization Setup Parsing config files Parsing finished Running Begin loop End Loop