Sunday, November 23, 2008

Post-MAX

As promised, I've shared (as in share.acrobat.com'ed) the two demos I presented during my MAX talk this past week. They're both basically the same app as far as the end user is concerned, with one version built on BlazeDS and the other on LiveCycle Data Services (LCDS), and they're a sketch or starting-point for building a real-time collaborative app using either of these server libraries we provide. The app provides a simple Contact List with Presence so you can watch as your peers come online, go offline and change their status. It also supports persistent threaded point-to-point chat between Contacts, with an option to view full chat history or just the messages for your current interaction. Again, I want to emphasize that these are demos. They're certainly not production-quality, fully realized apps, and are not officially endorsed or supported by Adobe.



By implementing the same basic app on both BlazeDS and LCDS, they serve as a simple illustration of how the up-front design considerations as well as the actual implementation of a real-time collaborative app will vary depending on which server library you're using. The delta isn't too serious for simple examples, but LCDS makes things much easier, and the pay-off is way above linear as the complexity of your application and its data model grows. Take a careful look through the configuration as well as the client and server source code for both samples to get a better sense for how the channels/endpoints and services you'd use differ, as well as how your application's use of service destinations would differ.

I've zipped up each demo as a fully self-contained, exploded web app that you can deploy to the JEE app server or Servlet container of your choice. If you're running Tomcat with HTTP on port 8400, deploying these should be very simple. You should be able to simply drop them into your /webapps directory and then add Context entries for them.

I hard-coded my channel/endpoint URLs to use localhost:8400 for HTTP in the BlazeDS demo and the LCDS demo uses RTMP on the default port of 1935. If you need to be using different IPs/domain names/ports locally, simply open up the corresponding /WEB-INF/flex/services-config.xml file and adjust the channel/endpoint URL values accordingly.

Both demos include the integrated web tier compiler so you can browse to either /bchat/BlazeSimpleChat.mxml or /chat/LCDSSimpleChat.mxml respectively and compile and run the app without having to set up, build and compile the client swf manually or in FlexBuilder. This also means you can tweak things, and recompile easily, as you play with the apps.

The one thing both demos depend on is a MySQL database. If you don't have MySQL running locally, go grab it and install it. Once installed, you'll need to define a database for each demo.

For the BlazeDS demo, create the database from the MySQL command line with:
CREATE DATABASE bchat_db;

For the LCDS demo, do:
CREATE DATABASE chat_db;

We also need to define the account the demos use to connect to and manage the databases:
GRANT ALL PRIVILEGES ON *.* TO 'javauser'@'localhost'
IDENTIFIED BY 'javapass' WITH GRANT OPTION;

That's wide-open, and if you have additional security considerations, you'd need to take them into account by limiting the grants to just these two test databases. The MySQL docs are an excellent resource if you have any questions about these steps.

The demos both use Hibernate to simplify the management of persistent application data, and the hibernate.cfg.xml files for both apps should be updated to drop, recreate and re-init these databases the first time you start your web app(s). To do this, uncomment the following line in these files (the copies under WEB-INF/classes, not /WEB-INF/src):
<property name="hbm2ddl.auto">create</property>

Note: the import.sql file in the same directory is used to initialize the data in your database when you have this hibernate property uncommented.

So, without any further ado, links to download the demo zips:

BlazeDS Simple Chat Demo

LCDS Simple Chat Demo


And a link to download the PowerPoint slide-deck for my talk (don't overlook the notes on each slide - they provide more info and background beyond the high level points):

Building Real-Time and Collaborative Applications with Flex and BlazeDS

PS: The session itself was recorded, and the video as well as the PowerPoint slide deck should be available soon to MAX attendees via the MAX site. The video should end up publicly available at some point but I don't have a hard date for that.

3 comments:

Simon Shaw said...

Thanks for a great presentation.
I downloaded both apps, created relevant databases using MySQL and removed the comments from hibernate.cfg.xml. When I run the app I see the dropdown combo box with no entries and when I go to the database I see that there are no tables. I have never used hibernate before but it seems strange that the import.sql file only has data (no schema), could this be the problem? (if not how does hibernate build the db structure).

Thanks,
Simon

Seth Hodgson said...

Hi Simon,

The schema is initialized by Hibernate based on your hibernate config and the optional hibernate.hbm2ddl.auto property in your config file.

If you define that and set it to 'create-drop', then startup and run the app, you'll be all set. Un-def it once you're up and running and want to retain data.

You can find some more detail here: http://www.hibernate.org/hib_docs/reference/en/html/configuration-optional.html

Vijay K Ganesan said...

Hi Seth,
Thanks for posting the examples.

Do you know of any commercial-grade IM applications out there using BlazeDS/LCDS?

Thanks
Vijay Ganesan