5. Fractal processing server example - part 3
Contents
This is not really part 3, but a correction to the design of the fractal processing server sample. Currently, the design we use is the one in the following picture:
I remind you that the component PixelStoreLogic
receives events from the RequestListener
and events from the ColorConvertLogic
. The events from the RequestListener
tell our logic to store the pixels received from the ColorConvertLogic
. Once PixelStoreLogic
receives all colored pixels of the image, it publishes an event containing all these pixels, and also cleans these events from its storage.
The problem with the current design is that since components work in parallel, it might happen that a colored pixel event from ColorConvertLogic
arrives to PixelStoreLogic
before the event’s corresponding request arrives! Therefore the PixelStoreLogic
will receive an event it was not told to store its pixels!
The solution is pretty simple: we make all requests first go through PixelStoreLogic
, and then forward them to the PixelGeneratorLogic
.
In terms of code:
In the component builder we replace this line:
|
|
with this line:
|
|
And in PixelStoreLogic
we change the behavior of what happens when we receive a request event:
|
|
We also need to add now rules between the PixelStoreLogic
and the PixelGeneratorLogic
and the BitmapConvertLogic
, so that they receive only the events of the types they expect to handle. This can be done with a TypeRule
, which filters events according to their type, and will be discussed later.
So we make two more modifications to the component builder code:
|
|
Where before the modifications, we subscribed the components to PixelStoreLogic
using ActivateAllRule
.
That’s it, we fixed our issue with the server’s design! You can find the relevant diff here.
Author זלינגר
LastMod 2020-08-29