Richard S. Hall wrote:
For me, #3 seems like the way to go, but I am not sure how easily this
can be achieved. My thought was to create a static implementation of
the URL Handler service with which each framework instance would
register upon creation.
When asked for a handler, I imagine that the URL Handlers service
would always return a handler proxy (except for built-in handlers),
even if no handlers existed, in which case the proxy would just throw
some reasonable exception when it was invoked. The reason to always
return a proxy is somewhat complicated, but is related to the fact
that the JVM libraries cache the answer in some cases and also because
some framework instances may have handlers registered and other may
not, thus the distinction between having and not having a handler is a
little murky.
When a handler proxy is invoked it could use
SecurityManager.getClassContext() to get the call stack of classes and
walk up the call stack to get the first class that is loaded from a
bundle class loader. From the bundle class loader it could then find
out to which framework instance the bundle belonged and use this
information to find out if the framework instance has a registered
handler service that matches the request. If not, it would throw an
appropriate exception, if so the call would be delegated to the
handler service.
Of course, there are probably a lot of little details I have not
thought about, but this is a general outline of how I am thinking of
approaching the problem. Also, I am figuring that we can optimize the
single framework instance case so that it doesn't have to do a lot of
extra work if only one framework instance exists.
Comments are welcome.
-> richard
Now I will admit that I am not too familiar with the OSGi spec - I just
now downloaded it and glanced at it, and I have not looked at the
current code, so what I am suggesting might not make any sense. It
seems to me that option 3 is what you should strive for but it seems the
problem is simply in the implementation. If my quick glance is correct
then:
1. Every bundle should have its own URL handlers.
2. I would assume that if there are multiple instances of the framework
that bundle instances within each framework are separate from the same
bundles within other framework instances.
So why not just maintain the list of stream handlers and content for the
bundle in the Bundle implementation object? Then your proxy could just
look at that to determine if the protocol is supported.
Ralph