Skip to content

All aboard the gwitbus!

March 19, 2010

Like many people, I’ve been inspired by, and learnt many things from, Ray Ryan’s talk on GWT Architectural Best Practices from Google I/O 2009. But unlike many people (or, at least, unlike the many people that came up in my Google search) I’ve not been inspired to put together an entire framework that covers all of Ray’s recommendations. I just want to break out one little piece to use, not just in my GWT projects, but in all my Java GUI projects; and that piece is the Event Bus.

I’m fairly sure that I’m not going to do Ray’s talk justice here, so if you want to nip off and watch the video or flick through the slides then please do so. But in a nutshell, two of the things that Ray discusses are; applying the Model-View-Presenter pattern within GWT, and reusing GWT’s built-in EventManager class to provide an event bus that decouples both the GUI from the back-end, and bits of the GUI from each other.

Breaking out the gwitbus

The main reason for pulling the EventManager out of the core GWT library is so that I can use it as the event bus in my non-GWT apps. Because the EventManager and its associated classes are all pure Java, with no dependencies beyond core Java collections, we can just drop them straight into any Java app. Just like I’ve done in the Swing app that I’m working on at the moment.

I could just import the core GWT jar, but that’s over 5MB, which it a bit of an overkill for about seven classes (and I’m not even sure that four of those are required).

At some point in this post, I need to give credit to Matt, who pair-programmed with me on our recent GWT-based task, and is now working with me on our new gwitbus-enabled Swing app. It’ll just get confusing if I try to differentiate between the bits that I’ve done, the bits that he’s done, and the bits that we’ve done together, so I’ll just stick to the first-person-singular for now; but thanks for your help, and if you wanted to take all the credit, you should’ve written your own post and checked it into you own Google code project 😉

How do I use the gwitbus?

I’m planning on putting together a really basic Swing app that demonstrates its usage, but to be honest everything you need to know can be divined either from the code, or from Ray’s slides.

Conceptually, the gwitbus is like any other event bus. It provides an abstract connection between disparate parts of the app; one part can fire events into the gwitbus, and another can listen for those events and react to them. Crucially, the part firing the event has no idea who will be listening, and the part listening has no idea who’s firing the events.

If “the gwitbus is like an other event bus”, then why should I use it?

Well, the most important thing is that you don’t roll your own. Almost everything you can do has already been done better by someone else. If you need an event bus, and your framework comes with an event bus, then feel free to use it. But if you don’t have one already, then why not use one that sits at the core of a proven, Google-backed technology?

Where can I get me a gwitbus?

gwitbus now has its very own project on google code. You can check it out from its subfolder in my subversion repository at, run the ant jar target, and get yourself a gwitbus.jar.

(If you’re browsing through the repository, don’t be fooled by the fact that there doesn’t appear to be any code in there at all; svn:externals pulls in the latest code straight from GWT)

I’ve already got a Hudson job building the latest version every time it’s updated. I hope to have Hudson push the latest release back onto Google Code, but I haven’t yet worked out how to do so without putting my credentials somewhere where they’ll be publicly visible. For now, I’m afraid that you’ll jut have to build it yourself.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: