SmartConnector Forum
Schneider Electric support forum about SmartConnector applications for integration of other building management systems (BMS) into EcoStruxure Building Operation.
Link copied. Please paste this link to share this article on your social media post.
What is the best way to share data between processors?
Link copied. Please paste this link to share this article on your social media post.
The SmartConnector framework provides two ways for running Processors to exchange data. Using one over the other is really a matter of preference based on need.
Both Processor subclasses and Native EWS Server Processor subclasses have access to both of these methods via the base Processor class. There are also some extension methods available to you to make getting data in and out of them in type safe manner.
Link copied. Please paste this link to share this article on your social media post.
You mean threads?
I usually have a central class I pass around as reference
Link copied. Please paste this link to share this article on your social media post.
The SmartConnector framework provides two ways for running Processors to exchange data. Using one over the other is really a matter of preference based on need.
Both Processor subclasses and Native EWS Server Processor subclasses have access to both of these methods via the base Processor class. There are also some extension methods available to you to make getting data in and out of them in type safe manner.
Link copied. Please paste this link to share this article on your social media post.
This approach could work as well, but you would need to safeguard against cross thread access to object reference since each Processor is executing in its own thread.
Link copied. Please paste this link to share this article on your social media post.
Yup. Race conditions is a bummer. Till now I only worked with single threads, but being forced to explore mutex 🙂
Link copied. Please paste this link to share this article on your social media post.
Hi Mark,
Yes that's exactly the approach we have been using (mostly just the ProcessorValue store until the recent addition of InMemoryCache), and most recently we used a mixture of the two. Thats's where we wanted to share data across multiple processors and needed this to persist beyond a single run of the SmartConnector service. We stored serialised JSON content to the ProcessorValue store and referenced a flag whilst reading or writing InMemoryCache to block and avoid cross thread issues.
Is there a particular pattern or design which would work better in this case?
Link copied. Please paste this link to share this article on your social media post.
I don’t think there really is a right or wrong answer for this. It all comes down what your needs are. The database store was implemented if you needed non-volatile storage while implicitly allowing for concurrent reads. The down side of course is the “last in wins” write approach used by default. If you needed to ensure only one thing can write (nd not allow a new simultaneous write to overwrite newer content), you would need to implement a semaphore like you did with the InMemoryCache. I suppose someone could easily write some extension methods that do this as well.
InMemoryCache is faster of course, but has the downside of being volatile and (until 2.2 at least with expiring content support) requires manual cleanup else it would become a memory “leak” of sorts.
I’d be interested in hearing what others think in this regard.
P.S.
In 2.2 I used the InMemoryCache quite extensively in the implementation of the “REST for SBO”. This is what was the impetus for expiring content (and silos) in the IMC - to not cause memory "leaks".
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.