Extend above facility for shared watchers, one watcher per RS for a given CP, perhaps again keyed on class name.
I like this one. In this case the hooks implemented by the region observer are in a critical path (at least preStoreScannerOpen is), so I do not want to call zk.getData(...) in that hook, and hence the need for a watcher to be asynchronously notified of changes.
Each RegionObserver instance would need to be notified about this, and if I understand the code right there is always exactly one instance per Region for which the observer is loaded. So sharing a single watcher with a listener for each CP would be ideal.
We could bring that back as a map like you suggest but shared across all Observers in a RS, perhaps one map for every class that asks for it
That seems generally useful, and maybe even better suited for the problem mentioned above. A CP would check whether a watcher has been created (an object in that shared map), create one if not, and then add a listener. The watcher would need to support removing listeners.
With that CPs would be able to coordinate among themselves. It's not hard to make a ZK watcher, so the generality of this might be better.
We have found need for this in other projects, but so far have worked around it.
How would that shared be exposed to a RegionObserver? Via the RegionCoprocessorEnvironment, or the CoprocessorContext?