3 cool technologies I discovered over summer.

Today I finish up my ‘holidays’ but I did want to write a quick post about the cool stuff I’d been looking at.

Firstly, the LMAX Disruptor pattern. I didn’t think you could fall for a pattern until I came across this. Disruptor is a pattern that lets you run through a queue (well a ring in this case) of requests. Each request has multiple handlers (the small bits of code that do the work). And because each handler is small, you can easily unit test too. The Disruptor facilitates the order in which these handlers execute. Handlers can run ahead and let the slower handlers catch up later. Its certainly worth checking out, it seems that its a style that is newer in Java frameworks, and reminds me of the asynchronous stuff that happens in say Node.js.

The next thing I looked at was Clojure. This language has been around for a while, but I didnt get to appreciate it until someone gave a presentation at a conference in Crete last year. Clojure is like Lisp. Lots of parenthesis, but the beauty is that the code becomes simple to read (once you get used to it). Easier to understand the control flow. A method call would look like this:
(operation argument argument)
A wrapped method call
(operation2 (operation1 arg arg) arg)

The final thing was a bit of fun. Whilst cleaning up a cupboard full of magazine coverdisks, I came across the final issue of CU Amiga magazine. It was quite interesting to see the passion of the Amiga users write in and say sorry to see another bastion fall. Some were realistic about the Amiga’s future, but god love em, some kept hoping things would change and a comeback would take place sometime soon. In a way, the ‘comeback’ has occured (for me at least). No new hardware, but a new operating system, called AROS, based off the old kickstart/workbench of old. The distribution runs in a VM, but can be installed standalone on a PC. There is also discussion on Mac, iOS and Android distros too. If you want to quickly get your Amiga fix on, and reminisce about the old workbench days, then do a search for ‘Icaros’ and download a web capable distro that boots up in seconds. Some of the UI elements are outdated, for example, clicking a window gives it focus, but doesnt bring it to front, but the great thing about Amiga nuts, was/is that there was always a plugin to be installed that gave you the functionality of other OS’. Worth a play if you have some free time and it will leave you wondering what OS X and Windows are doing with all your CPU cycles.

Access restriction: The constructor NotSupposedToUseThisClass() is not accessible due to restriction on required library

So following from my previous post about compiling Java 5 with a Java 6 compiler and the real reason that I am posting today, was to talk about a curly error message I got in Eclipse today.

I had the same Eclipse 3.7 project both on Windows and Mac, but only the Mac version complained with a very unusal message.

sun.misc.Base64 on mac JDK 5

The complaint was against an internal sun.misc.Base64Encoder class which every 2nd Java dev on the internet recommends replacing its internal implementation with an Apache Commons alternative.

Initially I thought it had something to do with the manifest and access restrictions preventing code outside of the jar accessing the internal code – something I recall the JavaPosse talking about from their days of Java Studio. Since it was only isolated to the Mac JDK, perhaps Apple had included these restrictions in the manifest for the classes.jar that these classes were defined.

Turns out it has to do with Eclipse.  I found out that when I add a JRE/JDK in Eclipse, it appears to add Access Rules to a bunch of select classes in the classes jar.  Its a white list.  Anything not there is forbidden.

I don’t know what defines this, and they are ‘non modifiable’ but adding in an access rule at the top leads this to go.

Java Build Path with Access Rules avoided

Looks like this has been tormenting people since Eclipse 3.3

Like rt.jar for like javac

Today I switched an Eclipse project using JDK 6 on OS X to JDK 5.

Even though there are command line tags in javac to produce 1.5 compatible source, the need to use JDK 5 comes into being when implementing interfaces that have grown in the number of methods since Java 5.  A good example is the JDBC classes.  The number of methods in Java 6 versions of the java.sql.Connection interface has grown by at least 6 (look for Since 1.6)

Having the Java 6 rt.jar or classes.jar where that interface resides will expect those new methods to be implemented and lead to a compilation error when you try to build.  On the opposite end, if you blindly start using the latest version of Java, you can easily start using new methods without realising.  Your colleagues will tell you when their 1.5 only environment stops compiling. 🙂

Building Jetty-Ant for Jetty 7

Jetty-ant for Jetty 7 is a hard find.
The documentation is all wrong, but that if you look at the Jetty Developer page they do concede that.
The split between eclipse and codehaus doesnt help either. There are a lot of options to try and search, Maven repo (http://repo1.maven.org/maven2/org/eclipse/jetty/), other bits in svn.codehaus.org (http://svn.codehaus.org/jetty-contrib/sandbox/jetty-ant/), eclipse vs hightide release dirs (http://dist.codehaus.org/jetty/),…. aaarghh!
To make things extra sucky, the SVN URLs in the doc for where you get jetty-ant have moved too.
After a lot of searching it looks like this one is the key
instead of the one the docs refer to (https://svn.codehaus.org/jetty/jetty/branches/jetty-7 ) which 404s.

There are a lot of other resources that are required jetty-integration-project is req’d by the POM.  Its created in the main jetty-7 that I linked above.  Build that first (I only got as far as building the hightide-distribution) but it was enough to download all the required jars to build jetty-ant.  Phew!


in super short

svn co https://svn.codehaus.org/jetty/archived/jetty-7/
cd jetty-7
mvn install

… builds a few different things, ultimately fails

cd jetty-ant
mvn install

… great success (now I just have to try it out – found in jetty-anttargetjetty-ant-7.5.0-SNAPSHOT.jar)

EDIT: When I last checked the documentation on the Eclipse documentation notes, it had thankfully been updated with an updated URL to download the ant target directly (18 Dec)


MacBook Pro vs Soniq TV vs HDMI adaptor

Most things on the Mac are purportedly easy since many of the un-ncessary options are removed.  This is great until you want to non-conform (read, use some hardware that is old, cheap, or just un-ordinary).

Trying to get HDMI with sound working through a Kanex iAdapt v2 mini display port, proved to be tricky due to the lack of options and just some wierdness of HDMI in general.

The other player in this whole mess was my cheopo year old 32″ Soniq QSL 322 LCD TV5.  Its been great so far, I’ve used HDMI connections to a couple of PVR units without problem.

When I plugged everything on the Mac though, even though it automatically recognised the display, the sound would still come through the laptop speakers.  Turns out thats a Sound System Preference Panel option to switch that. (option + F11)

Quick win right? Wrong, still no sound!  Rebooting, changing the order things were switched on.  Turning the volume up on the TV didnt do anything.  Also, while your Mac sound output is HDMI, the volume controls (F11/F12) dont do squat!

Then I tried a different tack.

I rebooted into Bootcamp (win 7 64bit) & the sound was working fine. There was a bit of a hiss in the background, and if no sound for a few seconds, the sound would switch off for a while – no hiss – until I played something again.  There would be a 1/2 sec delay waking up from the silence but otherwise ok for watching movies and music.  I later learnt from Kanex support that this is normal part of HDCP (the handshake that your devices do with each other to make sure they aren’t pirates. aarrrrrrr!)

When I rebooted back into OS X, the sound continued to work fine.

However once I put my computer to sleep and rewoke it, whilst leaving everything plugged in, the sound on the TV stopped working.

I recall reading on the apple support forums that there was some issue to do with HDMI handshaking and turning the devices on and off in a different order would fix the problem. It would appear for me that if the TV is on HDMI input first, then the mac is booted up sound can work.

I thought that was good enough but I found I could do one better and fix the sound whilst the Mac was already on.

I also read about a MIDI control panel that could be used to change how the digital output is sent via HDMI. Eventually I found it in Applications->Utilities-> Audio Midi Setup (not System Preferences).

I found that the HDMI ‘LCD TV’ device was at Format 96000.0 Hz. When I changed this down to 48000.0Hz then I could hear a sound through my TV speakers again. (Another way to get sound working, was press ‘Configure Speakers…’ button on the same screen and do a speaker test which also triggered the TV sound again)

So after changing down to 44100, the sound seems to work consistently on each plugin.  And if I ever do loose the sound again, I can get it back through here without needing to reboot my mac, tv, etc.

[Presentation] Tomorrow’s Tech Today: HTML5

Groovy / Grails ‘personality’  (and I mean that in the most fondest use of the term) Scott Davis presents a great round up of some cool HTML features.

InfoQ: Tomorrow’s Tech Today: HTML5.

He introduces some good tools and utils that help the forward compatible specification be read by HTML4 browsers none the wiser.

Firstly the HTML5 CSS trick to treat all the new HTML5 elements (header, nav, footer, video) to be treated as block elements in all browsers (except IE) and the html5shiv that does the same thing for IE.

Trivia: <input type=”someType”> gets rendered as a textbox if yourbrowser doesnt knowhow to show it.

There are some references to these sites which talk more about HTML

DiveIntoHtml5.org – an upcoming o’reilly book you can read for free here

HTML 5 Rocks

He talks about some stuff I wasnt too aware of such as HTML5 caching support (5mb) and SQL (25mb but no FF or IE, but useful for iPhone and Android browsers)


Modernizr (detect support for HTML5 & CSS3) – see findmebyip.com for an example.

“The goal is to program for HTML 5 and backfill for the rest of the browsers”

A Grails rant.

I agree with most of the points on this blog: Why Grails Sucks Less Than Your Framework.

Except #1. “It works on your current environment.” based on what I’ve been trying to during the last couple of weeks.

Firstly, the point isnt wrong for the conventional cases (which is what Grails is great for looking out for).  I’ve worked with Grails apps in the past that integrate with existing apps. I’ve always been able to deploy them as wars to Glassfish using a shared Jndi datasource. However for integration we have generally kept a thin layer (one or two database tables) kept between each app for them to share data.

This week I’m taking that integration further. I’ve been trying to get an integration happening between Grails and our legacy app which has recently been given some JEE love (session beans for services and JPA annotations over the legacy domain classes, deployed in a Glassfish container).  I want my Grails app to be a consumer of those EJB services, which return these legacy domain classes.

You’d think this would be easy, these problems have been addressed and covered in tutorials, blogs and presentations on the web:

  • Having a container managed datasource with your Grails app having access to that is aok.
  • Having existing hibernate mappings and legacy Java domain objects, also solved.
  • I was also able to talk to local, remote and no-interface session beans deployed in the same Glassfish domain just using the initial context that is supplied by using an empty JndiTemplate and Springs JndiObjectFactoryBean.  Works a charm.

You’d think with all these things I’d be set.  I thought I was too.  But like any app using a new platform/framework, the developers go off and develop and the deployers (or the developers later wearing the deployer hats) have to deal with the implementation issues when it comes to deploy the production release many months later.  Thankfully as I was trying to build a proof of concept I came across these issues early, but I can imagine it would be a hard task for any deployer to try and get this to work.  I suppose thats why many large shops with separate systems teams ask for their Grails apps to be packaged as EARs instead of WARS to avoid any other surprises.  Insurance via forced isolation perhaps.

Whilst I can get the war to generate and deploy successfully, once deployed, I’m still having issues finding the legacy domain classes in the classpath.  One problem is that the domain objects have different versions of the libraries (hibernate, logging, spring etc) that are also used in Grails.  And so you end up with NoSuchMethod or ClassNotFound exceptions.  Jar hell clashes between the large Grails jars library base.  I know that with a bit more time and knowledge I could change our legacy domain class dependencies and our grails libs so that they match and then unit test everything so that it still works, but I just dont have the time.  Whilst this is not a problem with Grails per se, the amount of time spent resolving this erodes the promised productivity gains gotten from using Grails in the first place.

Also to keep things flowing, what I’d really like to do is put the war within an EAR file so that I can access the EJBs in the container and share the same classpath so I can get to all those legacy domain objects and their dependent classes that they require.  Again I run into the above Jar hell.    Additionally getting the web app to work has led to some interesting errors with Spring Web Application Context which look like Jar hell style error messages, but dont appear to have duplicate jars in the CP.

The other issue about trying to deploy a Grails war into an EAR is tooling support.  As an Eclipse shop, the tooling for our EAR with the Glassfish/JWT plugins only supports generating an EAR project that is assembled from other Eclipse projects with JEE facets attached to them.  Of course, the Grails project itself isn’t in the form that a Dynamic Web Facet requires.  To get around this, I built the war using grails war, then extracted the war into a new project called webapp_exploded that I setup as a standard Eclipse Dynamic Web Project, which I can then tell Eclipse to bake into the Ear project.  Its a lot of hoops but gives my the META-INF/applications.xml that I want and appears to have the correct classpaths generated.  (Side note: I think IntelliJ has better support for building such artifacts and it can fire off maven/ant scripts pre-and-post execution in order to get this to work in a nicer fashion but as 2/3 of our dev team prefer Eclipse over Idea, I have to get this working for them).  (And I’m still a Maven n00b).

Once I tried to deploy this though, I got exceptions about the Spring Web App context.  I’m not sure if this is because of my Eclipse hack above or some unfortunate Grails bug because not many people are trying to deploy Grails apps in this way.

I also found that the Grails plugin for Glassfish is old.  It only supported Grail 1.0 initially with embedded GF and shared-war command to reduce the size of wars.  But the grails 1.1 release of the plugin advises in its readme that those features aren’t currently working.  To add insult to injury, WinMerge tells me the glassfish/grails(1.1.2) is exactly the same as the Grails 1.1.2 you’d get from Codehaus.  This defeats the whole purpose of having a plugin in the first place.

That said, I’m still in love with Grails, but think I have to take some smaller bites before I tackle this one again (though just typing out this blog has given me a few more ideas of how to address the problem).  Also to be fair, I haven’t sought help through any of the Grails community lists due to time pressures.

If you are starting from scratch, or even if you have a domain object layer that you can bring in without worrying to much about the dependency tree and you are happy to deploy as a separate war, then of course, Grails is great.  I am sure if I had more time I would get it to work – try maven or IntelliJ to build the WAR – figure out why the Spring container’s ConfigurableWebApplicationContext.setId(String) cant be found when trying to deploy the app.

Rick Wagner’s Blog: How to find which .jar a class is in (easily)

Holy heck, I needed this earlier today

Rick Wagner’s Blog: How to find which .jar a class is in (easily).

Makes mention of JBoss’ tattletale utility.

The comments also mention the Java Class Finder plugin for Eclipse (I used the CTRL+SHIFT+T today personally which did the same job)

There is also LibraryFinder plugin for IntelliJ and classjarsearch command line tool to search a directory of Jars for a class.