Push node reference
Enable a node to invert the execution path and push data to a parent
Introduction
The goal is to invert the execution path order of two nodes. This allows a child node to push data to a parent node before the parent node OnEvent method is invoked.
Sometimes we want to push data to a shared node for reading by a sibling node. A problem can occur if the read node is not dependent upon the write node. As reader and writer are siblings their order in the execution path is not guaranteed, it is possible for the reader is notified first. This unpredictable behaviour is undesirable and difficult to understand and explain.
One solution is to force the reader to artificially create a dependency upon the writer. We want to move this error prone operation into the framework if possible, as a reader could easily miss this nuanced requirement.
In Fluxtion we use the @PushReference to mark a parent node as an inverted execution dependency. The child OnEvent method will be invoked before the parent OnEvent method.
If the writer specifies the parent node as a push reference then no reader will need to worry about execution order. The push creates an implicit dependency between reader and writer without the reader specifying anything and the processing will behave as expected.
Example
In this example we create a cache as a shared node, with a cache reader and cache writer. The reader and writer are siblings with no explicit dependency. We use the @PushReference
annotation in the writer to mark the cache as a push destination.
the code for the example is located here.
The node classes
SEPConfig builder
Generated SEP
The following SEP is generated by Fluxtion. Note that the event processing OnEvent methods is inverted for cache and cache writer. The reader is notified of a change after the cache update, behaving as expected.
Generated png
The graphical representation of this execution graph as generated by Fluxtion ESC, shows the cache and writer inverted:
Example without @PushReference
As way of illustration we show the generated code and png if the @PushReference
annotation is removed from the CacheWriter.
Generated SEP
We can see the generated SEP implements counter-intuitive but correct behaviour as the reader accesses the cache before the writer has updated it.
Generated png
The image shows the CacheReader
and CacheWriter
are siblings with no explicit priority order. Also note because the Cache has no event handler parent nodes it is not included in any execution paths. Absence from an execution path means the reconcileCache()
method is never called.
Last updated