I have some rules that are invoked by status updates from a binding. I would like to process the status updates in the order they are received. I see the openhab rule engine schedule my rules in the order the status updates were received. However, my rules do not get run in the same order. All of my rules are using the same concurrency lock for the external device. Log commands within the concurrency lock show that the rules are executing in a different order than the status updates that triggered them. I’m trying to write stateless MVC type code where the device takes care of the M (Model) part and openhab the V (view) and C (control) part. In order to do this, the order of status updates needs to be preserved. Is there any way to force rules to execute in the order scheduled?
I do not think the Event bus has a way to enforce order of processing. It handles each event in a separate thread (based on my observations, I’ve not actually reviewed the code) so for events that occur really close together there is no guarantee of order.
This would take some experimentation to know if it will work but you might be able to write some rules to cache up the updates for a hundred msec or so, use the timestamp from persistence to determine the actual order they were sent and then process them in order.
Rich, I used a timer in the rules to delay their execution. I only needed to guarantee that one rule ran before all the others and this did the trick. I don’t feel great about the solution (I would much prefer some synchronization primitives to guarantee execution order), but it is working.
This is really a problem with the device (Onkyo receiver). If it supported MVC properly, it wouldn’t matter what order status updates were processed in. If fact it looks like they have addresses this on newer models where the complete menu list is sent in one status update. It probably makes sense to fix this deficiency in the binding. I’m not a Java guy, but I can program, so I might give it a shot. I have already made some minor changes to the binding. What’s the best way to get these back into the master branch?