Tropical Software Observations

A quick note on how to inject Service objects -- or for that matter any object -- via Spring.

Grails has always been able to support the injection of objects via Spring whether using XML or Spring DSL. A good scenario of using Spring DSL is to swap implementations easily.

In our project, Party Time, we use a lot of services. Most of these services implement Java interfaces and may be changed in the future. To be flexible in the changing of these service implementation, we auto-wire the services via Spring DSL.

For example, we have a Service class, LocalCDNService that implements the ICDNProvider interface. We configure the implementation by specifying in grails-app/conf/spring/resources.groovy:

beans = { cdnProvider(LocalCDNService) }

And from then onwards we can refer to the service object within our Grails controllers, taglibs, or services by simply declaring:

class ExampleController { def cdnProvider ... }

Contrast this to the common way of autowiring services by declaring:

class ExampleController { def localCdnService}

If we were to change CDN provider from LocalCDNService to AWSCDNService, we would probably need to change many classes. However if you were to use the Spring DSL way, you just need to change grails-app/conf/spring/resources.groovy:

beans = { cdnProvider(AWSCDNService) }

Hopefully this will shed more light to those new to using Spring within Grails.

Arrived early and saw a huge crowd of people queuing up for registration. The registration process was efficient -- I got my badge, orange goodie bag, and was quickly shown the way to the foyer. I'll be frank, I was expecting a light breakfast. No breakfast, only coffee and tea. Well as long as they serve coffee I am happy.

We were given a small Chinese rattle drum on the way into the hall. It's cool to use those small drums instead of clapping. This drum rattling event was supposed to be in Singapore's Book of Records for largest number of developers drumming away. Well whatever floats their boat.

Next thing I remember is seeing Mr Jeff Jackson taking on the stage to coordinate a few demo sessions. Between the sessions I remember lots of mentions of Glassfish, social networking, Google, YouTube, Ruby, OpenSolaris, etc.

Notable demos in the technology showcase:

Mr Arun Gupta demoing Glassfish Prelude -- nice to see Felix container there. Which reminds me, I need to check with the folks at Qi4J. It's been a while since I've dabbled with OSGi stuff.

jMaki demo -- yawn yawn.

Simon Ritter's Wii controller hack -- very cool stuff. I hope he will put the projects and code that he used for the Wii hack in his blog soon.

Somebody got lucky and went home with a Toshiba laptop. I am still jealous.

Next I went on to the JavaFX: The New Platform for Rich Internet Applications track session. Well I had my doubts about JavaFX before but not after this session. Man I'm going to pull out my favorite book on animation and graphics -- Foundation Actionscript 3.0 Animation:Making Things Move and try some exercises with JavaFX. The Wow factor is definitively there but I'm also wondering aloud if this could be another one of those J2ME feel-good-sessions: you know everyone feels really excited to see the rallying around J2ME in McNealy's days as the next platform to bring computing power to everyone's palm, and people end up jumping in droves to Android and iPhone development. Anyway -- a big applause to the demo, it was smooth and very entertaining. Especially when the sharks swim away!

Peter Karlsson was the speaker and though he had some hiccups with his demo, I really wished he didn't give up. He should've probably stuck his fingers on the console, fixed the problems and continued calmly. But I guess keeping calm is easier said and than done when you are running out of time. I enjoyed it anyway but since I will be attending the 9400 – Exposing the Depths of Java Applications with DTrace I thought I will have my chance to know DTrace better later.

Then we are let out for a 15 minute break. I had another cup of coffee and some cakes. Nice. Next to my lab session on DTrace.

Here is a summary of the LAB-9400: Exposing the Depths of Java Applications with DTrace session:

Peter Karlsson and Joey Shen are conducting this session

Many didn't come with their laptop and I'm not sure what they got out from this since the session is pretty code intensive

Of those with laptops I'm the only one with Mac so the bootable USB of OpenSolaris won't work on me. Oh well at least I have DTrace built in on my Mac OSX 10.5.6. heh

The lab slides are about 200+ pages -- we were told that it would take about 8 hours to cover them all. We have like about 2 hours. :-O

The depth of DTrace is overwhelming -- I barely understand the D language: probe, predicate, and action scripting.

While Peter was talking about the introduction of DTrace, I did a quick search on "Mac OSX dtrace dtracetoolkit", I realize that my mac already have most of the DTraceToolkit available. Try "ls /usr/bin/*.d"

Later I got a good grasp at how DTrace and D language works -- I began to open up the D scripts on my Mac to see the gory details of the scripts.

DTrace is more than a super steroid debugger -- you can turn it into all kinds of monitoring instrumentation. (Need to google for an anti-keylogger D script)

This session is way too short and too brief. If Peter and Joey are reading this, may I suggest to you guys this: pick a topic short enough to fit into 1.5 hours. Stop telling me about all the cool stuff I can do with DTrace. I know that already, or else I wouldn't be sitting there in the first place. Show me how to "X-Ray" my Java apps!

At the end of this session, I am reminded of the saying, "the teacher only shows you the door, you have to go in yourself". Well thanks, I will be writing about D scripts shortly.

Next, maybe I had too much coffee, was palpitating. By now it's already 4.30pm, I had another coffee in this very short break.

I chose the OpenSolaris session because I wanted to see some OpenSolaris 2008.11 in action. Here are my thoughts of that session:

I was late a bit and didn't get the speaker's name. I got the overall impression that he is floating the on clouds with OpenSolaris here.

Way too much time playing with Compiz on the Gnome desktop. C'mon guys, it's Compiz -- lets move on already!

And seriously, somebody should tell the crowd that OpenSolaris is using the Gnome desktop -- we're developers, we will get it even if you need to explain such things as X11, desktop client and Unix stuff like that.

The ZFS part was not impressive. I have seen better webminar videos on this. yawn

The DTrace part was a waste of time. He should've probably skipped it altogether or summed it up in a one paragraph or politely pointed to some online resource.

The speaker fumbled way too often on the command line. Stop using "clear", use "ctrl+l" to clear the screen. (hold on, is OpenSolaris using Bash by default?)

5.45pm, rushed to the Groovy and Grails session track. Boy, I have something serious to say about this.

I was expecting to see some experts sum up to us the latest JRuby progress in this session.

Why the heck is the description of the track about JRuby on Rails yet titled as Groovy and Grails? If I knew it was really on Groovy and Grails I would have skipped it and gone to the Porting Open Source Packages to OpenSolaris session.

Mr Chuk Munn Lee, Sir, I don't think you did your homework on Grails. I sort of tuned out when I heard Mr Chuk said that Grails doesn't support many-to-many relationship. I thought I heard wrong, but he followed by explaining how you need to tweak some mappings to get that feature.

The example on Groovy was too shallow and the Grails part was not good. I think the audience would appreciate what Grails is all about by starting the introduction to domain modeling and GORM instead of starting with "How many of you have programmed taglibs in JSP before?"

On my way out, I handed in my feedback form and was surprised to get a nice flap-over-bag. It's basically a small soft messenger bag. I'm happy to find the latest OpenSolaris 2008.11 inside. See the other goodies I got today below.

This is what I did to start consuming RSS feeds with Groovy within 20 minutes!

1. Download Rome.2. Download Rome Fetcher.3. Download JDOM is you haven't done so.4. Extract rome-x.jar, rom-fetcher-x.jar and jdom.jar to a tmp directory -- I placed them in lib/.5. Start your Groovy console with the classpath set to the jar files, like this: $ groovyConsole -cp lib/rome-1.0RC1.jar:lib/rome-fetcher-0.9.jar:lib/jdom.jar6. Use the code below:

Testing Grails service classes is easy if the service does not call any domain persistence methods. Meaning if your service class does cause some domain object to persist to database, it's going to be painful to try to mock the calls and check the result. And I'm not even sure if it's worth it to try.

The problem is that grails-testing newbies like me will want to try to do unit testing for services. In short, don't do that unless your service classes are simple and easy. (Keep this in mind when you start your project -- you won't see this unless you've experienced the pain before).

The best way that I found so far is to make service tests into integration tests. This mean putting service tests into the "integration" folder under the test directory. For more explanation on the difference between Unit Testing and Integration Testing in Grails, go here.

Testing Service classes is easy once you understand that it is:

it is an integration test -- will talk to the database

it is slow -- probably because of the data connection overhead

will persist data to database -- make sure your test environment database settings don't point to a production database