Application architecture¶
When you create an application using the Netdef framework your application consists of:
- Exactly one engine.
- At least one rule.
- At least one source.
- At least one controller.
- At least one expression.
Glossary
- engine
The
engine
is an instance ofnetdef.Engines.ThreadedEngine
.- rule
A
rule
is an instance derived fromnetdef.Rules.BaseRule
.- source
A
source
is an instance derived fromnetdef.Sources.BaseSource
.- controller
A
controller
is an instance derived fromnetdef.Controllers.BaseController
.- expression
A python callable that is executed by
engine
when a associated source changes its value. The associated sources are arguments to the callable. Seenetdef.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/andADD_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.