Documenting the GlassFish v3 Schema

Once work had started on GlassFish v3 the decision was made to drop schema validation for the domain.xml configuration file.  In previous versions, you could be assured that your xml was valid because we shipped a DTD to enforce that.  In v3, however, that is no longer the case.  The decision was made because v3 is very different in some fundamental ways.  In v3, you can add an arbitrary container to GlassFish and configure it via domain.xml.  This dynamic nature of the document structure makes validation difficult at best so the decision was made to drop validation altogether.  However, the problem still remains of how to determine what the document should look like. First things first, you should avoid editing that xml file by hand.  You should be able to do everything you need via either the admin GUI console or the asadmin CLI tool.  That said, that still doesn't necessarily help you know what values can go where.  The question has come up dozens of times even among the development team.  Various teams have updated and migrated their respective sections of the document leaving some confusion about the new schema.  (My own work on the grizzly-config updates is probably the biggest offender here).  There are, to my knowledge, two different attempts to fix this.

Tim Quinn developed the first publicly available tool.  You can find that here.  I had my own going on locally as well.  I borrowed some ideas from Tim's approach and came up with this.  My version differs from Tim's in that it runs in container as an asadmin command.  This has a few advantages but most importantly is that I think it's easier to use.  The output I generate is also a bit more accessible than Tim's but then Tim's was really a rough first cut.  I'm not sure he's done much with it since.  I, on the other hand, still get questions about the grizzly-config schema changes so this is near and dear to my heart.

At the moment, it only generates a javadoc-like HTML output.  I plan on adding a DTD and XSD option but there are some disconnects between the internal Java API used to configure GlassFish and what a user sees in domain.xml that make this not so trivial.  You can find those details here.  The HTML generated reflects the currently valid structure of the document and not the content.  This structure changes as you add/remove modules such as JRuby support and the like.  The files are generated in the config directory (<glassfish>/domains/domain1/index.html for most people).

The color scheme is a work in progress.  The main blue is a bit jarring, I think, but I just haven't had much time to play with such things lately.  You can find sample output here.  In the detail frame you'll see that some elements have properties defined.  This lists all the documented properties on that attribute.  In a perfect world, that list would be exhaustive but that's not always possible.  e.g., Some configuration elements such as JDBC connection pools configure third party libraries and capturing all possible properties there is impossible.  Nevertheless, for all internal GlassFish items this list should give you much of what you need.  If you find a missing property, don't hesitate to file an issue with the GlassFish tracker and we'll try to update our documentation.

If you find an issue with the doc tool itself, please file an issue and I'll do my best to correct it.  This is an unofficial contribution to GlassFish, though, so bugging the GlassFish lists isn't likely to help much.  I hope this tool helps you as you evaluate v3.  We really are very excited about this one.

Re: Deprecation in the JDK

Everyone hates the deprecation policies of the JDK team but it's certainly an understandable policy.  Millions and millions of lines of code exist out in the wild and there's no telling what calamity would befall us if methods were actually removed the JRE libs.  On the other hand, people still use those deprecated methods despite their failings and the presence of better options.  I was reading Joseph Darcy's blog entry on this policy and ran across an interesting comment. The idea is pretty simple:  make compiling fail against the deprecated methods without actually removing them from code.  This preserves binary compatibility while preventing any new code from compiling against these methods.  This would actually include new releases of applications written before the method was deprecated as these new versions would no longer compile while the previous releases would still run.

This seems to be the best of both worlds.  Building on the idea from comment, I'd offer this enhancement:  Introduce an @Obsolete annotation.  This would supplant the @Deprecated annotation on these methods.  Any usage of a method or class (or field?) with this annotation would return an error at compile time.  Reflective access to these items would also be disallowed just to drive the point home.  Of course, the annotations would need to include facilities to describe the alternatives to use for these old methods to provide the same functionality as the javadoc comment.  Given this simple addition, I think we'd finally start to make some progress on modernizing our code.

Your project needs someone like me

I have a mild compulsion to clean up code.  When i see mixed indentation (usually tabs vs spaces), I start getting twitchy.  When I see star imports, places where old loops can be replace with the "new" foreach loops (thereby reducing line noise in many cases), or any of a number of different "improvements" to the code I start itching to start cleaning up.  But there's (at least) one problem:  not everyone wants their code cleaned up. For many, such janitorial efforts hide any actual functionality changes and they would prefer such changes be made in a separate commit/task.  While there's some merit to that complaint, it's also often true that time for mere janitorial work will rarely/never get allocated.  So without taking advantage of opportunities, it will never get done.  Unless you work on a project that values such changes, these changes will either be made alongside functional fixes or not at all.

To resolve this tension, there are things both camps can do.  If your project is open source, you could implement something like The Linux Kernel Janitor Project.  This project is used as one possible entry point for beginners to begin to learn the system and make some changes without necessarily having to know enough to effect major changes.  This kind of project can work in a corporate setting as well, though most companies would prefer to get some "value" from their employees as quickly as possible.

If a janitorial project is not an option, then try to grant some leeway for intermittent clean up.  If code isn't maintained, it can become so crufty over time that making actual bug fixes or functional enhancements can be difficult.  On the flip side, those like me that like to get code into shape need to show some restraint and courtesy.

Sometimes its just pride that rebels against having someone else muck with "my" code that leads people to object to such changes.  But in many cases, drastic and pervasive reformats or "tweaks" to code can lead to impossible to decipher merge conflicts for people doing significant changes in those files.  It can be tempting (and gratifying) to do a deep clean on a file or whole sets of files but you have to consider the impact of those changes.  You might have to settle for one or two things to clean up this time and catch the rest later.  At the end of the day, it's about making a working product and if your cleanups cause delays for others as they sort out what exactly you did, then you're not exactly helping out.

Of course, prevention is the best medicine so each project should choose a set of standards and conventions.  These could include a set of libraries that everyone agrees to use.  This can lead to a set of standard/best practices in the project rather than everyone choosing their own favorite XML libary for their subsystem, e.g.  It should certainly include code style conventions.  For me, I choose the Sun conventions. There's nothing magical about them.  I like them and encourage their use.  But whatever works for your team, just pick something and stick to it.  This will help reduce the need in the future for large scale janitorial work.

The criteria for what is the "right" way to do things can change over time.  e.g., the foreach loop is newer than most java code, I'd wager.  On older code you're still likely to see many while loops or old style for loops that could be migrated to the new style.  Your team's style/practice guidelines should be periodically reviewed and update to account for the change landscape in both language features and third party libraries.  Once any changes are agreed upon, you need to prepare yourself for those changes to start trickling in.  These can be done in an organized sweep and clean up of the code or piecemeal by individuals as they find them.

Either way, you're going to want people like me in there to help.