Now that jigsaw is prohibiting deep reflection on types provided by the 
boot modules we are running into an issue with the ugly things we do [1] 
in order to support multiple factories in Equinox (an OSGi 
implementation).  Each Equinox instance has its own context aware 
ContentHandlerFactory and URLStreamHandlerFactory which serves up handlers 
that are available for the particular instance of Equinox.  In order to do 
this we have to resort to some very ugly reflection.  This allows us to 
gain access to the 'base' factory object set in the VM so that each 
instance of the framework can register itself with the 'base' factory. The 
'base' factory handlers do the complicated work of figuring out which 
factory to call based on the context which is calling the base handler.

We also resort to reflection on framework shutdown in order to flush our 
factories out from the VM so that the base factory is not pinning our 
framework in memory.  I am also aware that the Apache Felix OSGi Framework 
implementation uses similar deep reflection in its implementation.  Are 
there any plans in Java 9 that will make this scenario easier to achieve 
without resorting to the use of deep reflection on the URL types from the 
VM?  If not, are there going to be command line options that will allow us 
to open up deep reflection of specific VM types as a compatibility mode 
until we can get a proper solution?

At a minimum I think we need someway to unset the statically set handlers 
in the VM to avoid pinning our base factories.  I can think of other 
non-reflective ways to gain access to the base handler instance in order 
to register each framework instance with the base handler.  For example, 
the base factory could implement a specific protocol which allows a 
connection to register another framework.

But we are still left with a delima of how to wrap the handlers returned 
by various framework factory instances from the base handlers.  All the 
interesting methods on are protected.  Even 
though the proxy base handler extends it is not 
allowed to call the protected methods on another instance of  We resorted to deep reflection on the class methods to do that.  The class is not an interface so we cannot easily 
create proxy classes using java.lang.reflect.Proxy.



Reply via email to