The Blog

Mar 7, 2009

Flex Camp Miami: Merapi or How to Blow Your Mind with AIR (Andrew Powell)

Andrew Powell delivered his ever-popular presentation on using Merapi to extend AIR applications by adding hooks in to Java, and thus everything the underlying OS has to offer you.

Personally, I have been following the progression of Merapi from back in the Artemis days before AIR was even released. Being a Java programmer at heart and also loving Flex and AIR, the integration between these technologies on the desktop had always seemed like a perfect marriage to me (especially since Swing is such a train wreck). I had signed up for the Merapi alpha ages ago with the intention of hooking in through the Java-Cocoa bridge to capture MIDI events from one of my keyboards and do something (anything?) with them in an AIR app, but had never got around to kicking the tires, so I was really interested in Andy's presentation.

As it turns out, Merapi was made possible through the open-sourcing of the BlazeDS libraries for performing asynchronous messaging and AMF serialization. When a Merapi app is launched, it basically just fires up a listener on a local socket, and launches an AIR app which connects to this socket. Once connectivity is established, AIR and Java can send objects back and forth through the same AMF gateway code that makes BlazeDS and LiveCycle Data Services do their thing - just in a much slimmer environment than you'd get by running either BlazeDS or LCDS locally on the desktop. This is (in two words): pure awesome.

Andy's slide deck was only 10 deep, so we quickly got to the good stuff: hooking AIR apps in to hardware. Andy had brought along a number of toys to demo. First off, we got to see a set of RFID chips and a USB-based reader purchased from phidgets.com. Andy had set up the AIR app to scan the RFIDs via the USB bridge and show if a specific ID key had been found. Since phidgets.com supplies a Java library with their devices, this was a pretty simple setup, but you can imagine how cool it would be to build an AIR app for managing an inventory of products with RFIDs. Andy had three volunteers come up from the audience to scan books and see the tools in action, after which the volunteers (myself included) were allowed to keep the books (sweet!).

Next, we got to see the star of the show, which was a Mindstorms NXT kit hooked up once again through a Java API (I believe the API in question is LeJOS - Andy said he never even touched the APIs that came with the kit). Andy had a simple control panel with forward/backwards and steering controls in AIR, which responded to mouse clicks and pressing of the arrow keys. Hitting the controls resulted in commands going across Merapi to the Java API, and ultimately connecting wirelessly to the Mindstorms robot (in this case a cool little Lego car) via Bluetooth. The entire sum of attendees crowded up to the front to see the robot in action.

During the Q&A, Andy touched on some interesting notes. Firstly, since connectivity between AIR and Java through Merapi is socket-based, you can have an AIR app on one machine remotely control one or more Java apps running on remote machines. Second, message channels can be differentiated by message type, or you can have multiple socket listeners from different apps and establish channel separation that way. The final note I found useful was that there is currently no encryption on the socket channel, but this is planned for a future release.

Hopefully Merapi will get the creative juices flowing for all of you AIR/Java programmers out there. While the library is still in alpha state, it clearly works great, and since it's outside of the realm of Adobe you can use it at your own risk without having to wait for Adobe to incorporate similar capabilities in to AIR.