bdelacretaz / OSGi-weaving-hook-examples

Examples of OSGi WeavingHooks - logging method calls etc
8 stars 1 forks source link

Question: Updating the OSGi weaving hook at runtime #1

Open royteeuwen opened 4 years ago

royteeuwen commented 4 years ago

Hey @bdelacretaz ,

I found this repo (even though it is pretty old) and found it interesting. What I would like to try out is to mimick the behaviour of Rookout ( https://www.rookout.com/ ). Rookout allows (read-only) debugging of a production instance by adding a java agent that is able to get object field values at runtime without attaching a real java remote debugging instance.

How I would like to mimick this is by creating an OSGi Weaving Hook, based on your LogMethodCallsHook class, that would allow you to create an OSGi weaving hook at runtime by creating for example an OSGi configuration factory that registers a weaving hook for a class with a method in a specific bundle. Do you see this feasible? Is it possible to register a weaving hook without having to reload the entire bundle again and going through the Activator method again?

Thanks! Roy

bdelacretaz commented 4 years ago

Hi Roy, this is old indeed and it probably represents all the time I spent working with WeavingHookso far, so not much...

As per https://docs.osgi.org/javadoc/r6/core/org/osgi/framework/hooks/weaving/WeavingHook.html weaving hook services are called when a class is being loaded by the framework so you need to do something that causes the desired classes to be reloaded after registering a hook.

My understanding is that you need to reload a bundle for its classes to be reloaded, but maybe there are other tricks.

I'm no OSGi guru though, just a power user maybe...asking on the felix.apache.org dev list might provide better answers as there are a number of OSGi gurus there.