I’m writing some kind of registry mechanism to get some data from a set of extandable backends (currently some configuration information).
Now I have a problem – some of these backends might need configuration information in order to fetch the information they were requested. As I want to reuse the same mechanism for all requests, I want the extension to call back into the registry to get more configuration data from that – but from another backend. But as the caller has no control over which backends exist and are available (and I have no intention of breaking the abstraction and supplying that information), I need some way to prevent a dead-lock or infinite loop – when the backend goes back to registry and asks it for data and the registry calls back into the backend to ask it for the data.
My immediate naive solution was to allow a “busy” flag – when the registry loads a backend to ask for data, it first asks the backend if its “busy”, and if so skips it. When a registry backend (extension) is called then it sets the busy flag (maybe only if it plans to reenter the registry) and so gets skipped if it recurses.
There are several problems with that approach that I can come up with off the top of my head:
- It forces me to synchronize entry into the registry to prevent concurrent threads from locking backends from other threads. This of course hurts performance.
- It makes the extension writer responsible to the behavior of the registry itself much more then I want, and an uncareful code could more easily break the system for everyone.
- The interface is extended with another call, which currently makes it 50% larger ( 🙂 ) and it feels more cludgy.
I’m looking for a simpler method for preventing recursing queries from going back to the same backend that originated the recursion, w/o preventing other queries from completing normally either due to lock-out or synchronization.
Any suggestions ?