Using Compile Time Annotations for Modularizing URLStreamHandlerFactory

Jaroslav Tulach jaroslav.tulach at oracle.com
Mon Jun 18 03:43:53 PDT 2012


Dne Pá 15. června 2012 17:17:32, Jesse Glick napsal(a):
> Something to consider - in a big application it is not uncommon to have
> multiple URL handlers implemented in various places. Yet the JRE only lets
> you set a single URLStreamHandlerFactory for the whole JVM. 

What a coincidence! On Friday I gave a talk at GeekOut, Tallinn, Estonia about 
annotation processors and my main example was creation of effective, modular, 
scalable, robust, condense, no-boiler plate and lazy support for registration 
of URLStreamHandlers.

> So for the
> application to be modular, you need to write a proxy factory which accepts
> modular registrations, 

Indeed I had to start with Proxy factory. Then I demonstrated classical 
ServiceLoader approach (which you probably have in mind when thinking about 
modularity & URLStreamHandlers). I continued showing, that it is not scalable. 
To fix that I provided annotation and its processor. Still the code was too 
verbose. I fixed that by allowing direct registration of URLConnection - and 
generating the rest on a fly. At the end I eliminated almost all boiler plate 
code in my final example[1] by generating wrapper URLConnection registration 
by the annotation processor.

Source code: https://github.com/jtulach/Annotations
Presentation: http://wiki.apidesign.org/images/0/08/HackIntoYourCompiler.pdf

I know many of the ideas of using annotations go beyond the scope of Jigsaw 
and you have your own problems, but (as I think this is the way effective 
modularity should be built) I'd like to be able to build this on top of 
Jigsaw. Won't Jigsaw try to prevent us doing this?
-jt

[1] 
https://github.com/jtulach/Annotations/blob/master/UniversalResourceLocator/test/org/netbeans/geekout/demo/impl/Geeks.java

> I also agree with should look re-visit some of these areas for
> opportunities to use services. I'm less sure about dynamic services,
> which I think you might be suggesting too.

PS: I am not sure people really need dynamic services when it comes to 
URLStreamHandlers. I have never seen a use case requiring addition of new 
protocol support dynamically (without enabling new module).





More information about the jigsaw-dev mailing list