Tuesday, 20 May 2008

Axis2 and OSGi

Thanks to Davanum for the heads up about the OSGi bundle hidden away in side the Axis2 trunk. I intend to try and run it, but having just had a look at the code it seems a little incomplete in the Activator of the bundle at least:

Activator.java :
- If the services it depends on are not available (HttpService, LogService) then it continues to activate, when really it should throw an exception, or even better use a ServiceTracker to dynamically track the services.

- What if there's more than one HttpService?

- It requests a LogService then uses System.out

- It registers itself as a bundle listener before creating an instance of the ServiceRegistry. In the unlikely event that a bundle state changes while this bundle is activating you could get a NullPointerException in the bundleChanged when trying to called the methods on the registry instance.

- Note the big block of code already commented out... that would stop any services which are already registered from being exposed as web services. Remember that OSGi is a very dynamic environment things can come and go as well as already be there when your bundles start.

- While not strictly required (I believe), during the stop() method it is good practice to call ungetService on any services references that have been acquired.

As for the rest of the code, I'm not qualified to comment as I don't know the inner workings of Axis2, so I'm just going to give it a try and see what happens. Watch this space.

Tuesday, 13 May 2008

flex regular expressions

I really like how you can inline regular expressions in Flex. For instance:

var split:Array = someString.split(/\./);

which will of course split "someString" using "." as a delimeter. Of course, all that's really happening is that the regular expression is being converted to an object by the compiler, so the following is the same:

var regexp:RegExp = /\./;
var split:Array = someString.split(regexp);

This is superiour to Java's approach which allows you to specify a regular expression as a String when calling split, the problem being that the above regexp would look like this:

String regExp = "/\\./";

Note how I have to escape the escape character!

Of course, Java has a whole package for regular expression handling, but they all suffer the same problem of having to encode the regular expression in a string and thus having to escape the escape characters... which makes long regular expressions very complicated and as a result I suspect a lot of Java developers simply avoid using regular expressions for that reason. In my view inlining regular expressions is definately a candidate for being added to the core Java language.

Thursday, 1 May 2008

SpringSource Application Platform

Yesterday SpringSource announced the release of their application platform:
a completely module-based Java application server that is based on the new SpringSource Dynamic Module Kernel™ (dm-Kernel). The dm-Kernel harnesses the power of Spring, Apache Tomcat and OSGi-based technologies to give the platform incredible flexibility and resilience for both development and production.
Effectively an OSGi container with some Spring stuff thrown in and another step in the right direction away from the J2EE world.

Referred to as S2AP, the SpringSource Application Platform announcement generated a fair amount of interest and discussion so I decided to cut to the chase and ask Rob Harrop of SpringSource to clarify a few issues.

Firstly, not being a lawyer or Open Source license expert I was a little confused about the implication of using GPL as the Open Source license for the server. Rob managed to clarify this succinctly:

If you are running applications on the S2AP, then there are no requirements placed on you. If you distribute an application including S2AP or GPL components thereof, then you would either need to license your application under GPL or purchase a commercial license from us.

A useful summary of what using GPL means. Next up, I was interested in what S2AP brings to the table if, like me, you're not a user of Spring and currently have no plans to be.

S2AP contains a lot of additional benefits on top of plain OSGi. For starters, OSGi aside, its just a good, solid server platform. We have extensive serviceability features including active deadlock monitoring, detailed trace and first failure data capture. We have provisioning support that makes it easier to handle the installation of hundreds of bundles into your runtime environment. The pre-embedded Tomcat is plus point - that was a lot of work.

There a lot of under the hood tweaks, including resource loading support that works in standard libraries such as Jasper (JSP), load-time weaving support and advanced refresh that handles more module dependencies than those currently handled by the OSGi spec.

My interest is definately peaked now, so I think I will be checking it out in my next development lul or as a distraction from development grind. However, I had one outstanding question regarding a specific piece of functionality that I have been hoping someone would save me the bother of having to implement. It occurs to me that it would be very helpful if I can register a service with the OSGi context and some other bundle automatically makes that service available as a web service. Spring has some functionality enabled rapid development of WebServices, so I asked Rob if this is something that S2AP can help me out with.
Publishing OSGi services as WebServices is on our roadmap, but it won't be available for 1.0 final.
Fair enough. As it happens there is already a Knoplerfish bundle that can do this, but its implementation is not compatible with newer SOAP clients.

So in conclusion, it looks as though S2AP is worth keeping an eye on for the future of OSGi containers. If it lives up to its instant hype and the features described by Rob it is will be a robust platform for purist OSGi developers like myself, as well appealling to those already in the Spring camp.

For more information on S2AP, you can check out Rob's blog entry: Introducing the SpringSource Application Platform