Skip to main content

More on configuring components in HK2

Posted by kohsuke on July 20, 2007 at 1:52 PM PDT

I've been spending significant part of my time this week on HK2. After some initial work on configuring components inside HK2 and talking to Kedar who knows the current GF configuration mechanism inside out, I decided to make some serious changes to the way HK2 works internally.

In the initial work, I used to load configuration directly into components. While this was faster, it prevents us from deferring the instantiation of components — for example, in Glassfish, you don't want to load ORB related code until someone actually uses it, yet the configuration of ORB is in the same configuration file with everything else.

So the new code instead loads XML into "mini DOM" first. This process is driven by the metadata from the components, so we know what attributes and elements to expect, thus we can report some errors upfront. This metadata is generated from annotations during the development time by the HK2 Maven plugin (using annotations directly would require loading classes, which robs the whole point.)

The intermediate data structure is then registered into the component registry/index, so that these values can be readily injected into other components in the HK2 world. When the component instance is actually requested, the component gets created, receives all the values from mini DOM (which is done by the "injector" code which is generated from the HK2 Maven plugin.)

Another benefit of the mini DOM is that I can do variable expansions like Ant transparently. Since variable definitions can show up after variable uses (think of Maven POM variable substitutions), this requires something like mini DOM.

Now, I'm thinking about whether to go ahead and start integrating this to GFv3 now, or since this being Friday, whether I should spend time on other TODOs that are piling up...

Related Topics >>