OSGi Modularity in DaliCMS and GlassFish

If you are following my blog, you probably know that I am recently investigating the modularity of the GlassFish v3 and see how it is using the OSGi technology. The main reason for this is that I see some similarities with DaliCMS, the open source "Web 2.0 ready Content Management" system we developed with LodgON and that runs on top of GlassFish.

With DaliCMS, customers have a very functional Content Management System that also includes some "Web 2.0" features, and that especially allows the quick integration of third party "Web 2.0" stuff.
The total functionality is huge, and although we have some customers that in my opinion really are using almost everything that is possible with DaliCMS, the majority of the customers is only interested in a part of the functionality.
More specifically, customers outside the CMS world often benefit from some Dali components. We currently serve them by either building something small based on the specific components they need, or by installing the full DaliCMS product on top of a full GlassFish v2 stack.

Clearly, this approach has some drawbacks. It is much nicer and more elegant if the project-specific software only contains code that is really used. On the other hand, you don't want to rewrite the specific functionality over and over again.
Some customers just need a tool for managing incoming RSS feeds, or they require only a forum where people can vote for each other, or… .
The same is happening with GlassFish. The GlassFish v2 product really contains a lot of functionality. And there probably are some big projects that use 90% of the code in GlassFish. But many projects only require a webcontainer, and no EJB-container or transaction system. People working on those kinds of projects might opt for other solutions, since "GlassFish is too big".

The OSGi approach provides a possible solution for this. We need a modular system, where inter-module dependencies are solved by meta-information (the manifest file) and by the framework.

A customer project is than created by combining the required modules. The OSGi framework provides more than just a mechanism to combine modules. The separation between interfaces and implementations allows for vendor-interoperability. The lifecycle management allows for dynamic updates of different modules, taking into account the specific requirements on other modules. And there is much more.

We are currently investigating how DaliCMS can be split up into a number of OSGi bundles. These OSGi bundles will have dependencies on some other bundles, some of them might come from GlassFish v3. In the end, we will be able to provide each project with a specific system, based on modules that are used in other projects as well.

DaliCMS is an Open-Source effort, hosted as a GlassFish incubator project. Feel free to join the project, or drop me a note at johan (at) lodgon.com.

GlassFish v3 on OSGi KnopflerFish

GlassFish v3 is really based on OSGi.
Starting the application server via asadmin start-domain launches an OSGi Framework. This is done in the main method of com.sun.enterprise.glassfish.bootstrap.ASMain

By default, GFv3 will use the Apache Felix OSGi platform. However, this can be changed easily at startup, by specifying the GlassFish_Platform parameter in the system environment (e.g. setenv GlassFish_Platform KnopflerFish)

Doing so, the com.sun.enterprise.glassfish.bootstrap.ASMainKnopflerFish class will be used. As far as I know, the svn head version does not contain a (link to a) knopflerfish binary, but KnopflerFish itself is easily downloaded at http://www.knopflerfish.org. GlassFish has to be instructed where it can find KnopflerFish. You have to set the environment variable KNOPFLERFISH_HOME
setenv KNOPFLERFISH_HOME /home/johan/knopflerfish_osgi_2.1.0/knopflerfish.org/osgi

If you startup the application server via
asadmin start-domain --verbose
the framework will be started, but no configuration file will be detected. GF assumes that the xargs file is located in gf.xargs, but I couldn't find this file. You can easily create a gf.xargs file based on Knopflerfish's props.xargs or init.xargs, but this won't start the required bundles. I guess I need to have a look at the Felix configuration in order to determine what bundles have to be installed and or started at startup.

Anyway, the important conclusion for now is that GFv3 is indeed running on top of an OSGi framework, and that it is not to change the OSGi Framework.

Playing with GlassFish v3

Although I did some testing with GlassFishv3TP2 in the past, it is only since yesterday that I am really diving deep into the GlassFish v3 code.

Installing GlassFish v3 TP2 (that is version 3, Technical Preview 2 if I am correct?) is straightforward and easy, except that the graphical installer never quits (on my Fedora system). No worries, the software got installed. I could also easily deploy a war in the Application Server.
Compared with the early days of installing the SunOne Application Server, installation and configuration has become much easier (or I have grown older).

The main reason I want to do some tests with GFv3, however, is to see how exactly OSGi is used internally, and if/how it can be used by applications as well. The best way to find out, is to have a look at the code.
I downloaded the trunk version of GFv3 from the svn repository. The build system for GFv3 is Maven, and I am not very familiar with this tool. It didn't take too long, however, before I could build and run the whole Application Server. Some useful notes about building GFv3 with Maven can be found at http://wiki.glassfish.java.net/Wiki.jsp?page=HowDoesV3BuildWorks and at http://wiki.glassfish.java.net/Wiki.jsp?page=V3DevelopmentInstructions.

Next step: make some changes to the code and run the appserver again. That didn't work with the "mvn gf:run" command for me, unfortunately.
But I noticed that the created jar files were placed in my local maven-repository, so I c ould copy them manually to the GlassFish working directories.

At this moment, the startup process in my local working copy is broken due to

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/enterprise/module/Repository at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:68)

Indeed, ASMain.java uses ASMainFelix.java or ASMainKnopflerFish.java, and these classes extends ASMainOSGi which imports import com.sun.enterprise.module.Repository. And that class isn't in my current source tree. However, building with maven works fine, so I guess maven adds some jars to the classpath that are not in my working directory. I haven't find a way to discover or influence the classpath that is used when compiling, but no worries, we'll solve this. And then we are looking forward to the next problem 😉

development, deployment and GlassFish v3

Tonight, I was experimenting with GlassFish v3. I might add a report with some results later. Today, I ran into a document that contains one of the most important remarks about today's software development.

While deep diving into the GlassFish documentation, I was reading the V3OverviewFunctionalSpec document (someone must have stolen the whitespace), containing some motivations about the rather drastic changes between GlassFish v2 and GlassFish v3.

This document contains some sections that are typical for documents, and that are often only filled in because the process requires so. However, in this case, there is so much value in section 3.1. Problem Area:

The new landscape of server side Java is forcing us in being more open to external technologies than traditional Java EE stack. We have repeatedly heard calls that we needed to offer more choice of technologies as well as provide a slim infrastructure to build a dedicated stack that corresponds to a particular problem area.

We have started seeing a proliferation of scripting solutions coupled with web centric frameworks available on the Java Virtual Machine. However most of these solutions are very developer centric and very little effort has been spent on deployment features. This is a market opportunity for GlassFish to offer these deployment features while respecting the container's original development environment.

 

This is what I am observing as well. Most tools and efforts in software are still focused on the developer. Lots of effort has to be spent on deployment, and the difference between project success and failure is so often dependent on the deployment, rather than on the code.
In a project I am currently working on, focus is completely on deployment. Development will remain important, no doubt about this. But this GF-paper is another signal to me that things are changing… ~