Is that the best way to know when TransactionManagers and DataSources
come
and go too? Or is there a more specific concept for listening to an "OSGi
service"?
At least for TransactionManagers, yes, the BundleListener is probably the best approach.
I'm not aware of a more specific way beyond that, but I'm not 100%. Honestly not
sure about the DataSource -- can't remember if most containers automatically expose
that or not.
Also, do the containers generally handle "in-flight" requests in
regards to TransactionManagers
and DataSources on activated/deactivated? I guess this is more a
curiosity, since I do not see what we could do if the container does not
manage it.
Really good question, but not sure. The hope is that a truly OSGi-friendly bundle is
"dynamic" enough to gracefully terminate in-progress actions if deactivated.
They're given that opportunity through BundleActivator#stop. Of course, that's
entirely up to the specific impl. I would expect Karaf container-provided defaults
(Geronimo JTA, etc.) to handle that reasonably well for basic cases, but not sure about
the real-world edge cases...
Note that I always hoped to make Hibernate fit that bill, but we're *far* from it.
Deactivation would, in all likelihood, be catastrophic. And no idea about re-activation.