4. ComponentBuilder
Contents
Last time we saw how an implementation of a server over the notification server framework looks like. We discussed code of events, logics and rules. Something we have not discussed yet is how do we link components to one another. This is something that is resolved via a mechanism called component builder.
The component builder is an interface provided by the notification server framework, where one defines the components of a specific server and defines the links between these components. It consists of a single method:
|
|
The interface IRuntimeContext
is an interface which provides information about our server. It will be discussed in another post. IRuntimeContext
has a property named Components
which is of type IComponentContainer
. IComponentContainer
is, as its name suggests, a container of the server components, and it extends (inherits from) the interface ICollection<IComponent>
. I don’t want to go into details about the interfaces IComponent
and IComponentContainer
, so for now let’s just assume that all components implement the interface IComponent
.
In the method BuildComponents
we are expected to create the components of our server and link them one another. Let us demonstrate using the fractal processing server sample we discussed last time:
|
|
As we can see, we first create an instance of each component of our server, then add all the component instances to the Components
property of the provided IRuntimeContext
. Then we perform the links. We perform the links by calling a method called Subscribe
. Every component which is not a target component (i.e., it allows other components to be linked to it) implements an interface called IPublisher
which contains a method with the following signature:
|
|
Again, I do not wish to discuss the interface IRecipient
right now, but every component which is not a source component (i.e., it allows other components to link to it) implements IRecipient
. The Subscribe
method tells the publisher we are interested in receiving events that pass the given rule. This is always confusing for new developers, as they expect Subscribe
to be a method of the subscriber, but this is the convention, and it is the same in other frameworks, such as Reactive Extensions.
Note that when we subscribe our instances of MandelbrotLogic
and JuliaLogic
to our PixelToComplexConvertLogic
, we provide instances of the rules we implemented last time. For the rest of the components, we provide an instance of ActivateAllRule
, that is an implementation of IRule
that allows every event to pass: it always returns true
from the IsActivated
method.
A few remarks about the IComponentBuilder
interface:
- In the far past, there was no interface, but a class named
ComponentBuilder
with 3 methods for building componentsBuildListeners
,BuildLogics
,BuildDispatchers
, in which one would build components of certain types. There was probably also a method calledLinkComponents
where one would link the server’s components. - In modern versions of the notification server one does not need to implement the interface
IComponentBuilder
. Instead, the framework’s user defines their components and their links in a visual tool. This definition is saved as a configuration file. Then the built-inIComponentBuilder
implementation reads this file and constructs the components and links them accordingly.
Author זלינגר
LastMod 2020-08-23