Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Distribute JavaBean Events Across Java Virtual Machines

The JavaBean event model provides simple messaging, but it works only within a Java virtual machine (JVM). JMS allows you to send messages across a network to other JVMs, but it is quite complex. This article presents a quicker, simpler solution: transparently distributing JavaBean events over JMS.


advertisement
s a Java developer, sooner or later you will build a Java application that needs to communicate with another Java application. You can write Java network I/O code or use the Java Message Service (JMS) API to facilitate this communication. However, I've found both these approaches error prone and time consuming--I often had to rewrite and debug similar I/O or JMS code. So I came up with a better way, one as easy as coding to the JavaBean event model.

This article describes my approach to distributing JavaBean events across Java virtual machines. This approach transparently uses the JMS specification and extends JavaBean events across a LAN—even the Internet—without requiring any JMS-specific code within the event listener or the event source components. Because its main requirement is that both the listeners and sources extend an abstract base class, the approach also is non-intrusive.

For an overview of JMS, along with some sample code, read the sidebar, "The Java Message Service (JMS)."



The Event Distributor
To use JMS, the code you write must be repeated for each JMS application and each publisher, subscriber, producer, and consumer in those applications. To avoid having to copy and paste similar code in multiple places, a good developer would create wrapper code. As a matter of fact, the sample code that comes with Sun Microsystems' JMS API contains a wrapper class for just this reason.

However, being the purist that I am, Sun's wrapper class was not good enough for me. My goal was to create a wrapper class that would make JMS communication as easy as sending and receiving JavaBean events. So I created the Event Distributor, which uses the JMS publish/subscribe paradigm to distribute JavaBean events across Java virtual machines without exposing its details (and repeated code). You can even configure it to use persistent or non-persistent message delivery.

I've included the Event Distributor, along with a demonstration test application, in this article:

  • Click here to download the Event Distributor code along with a readme file on how to build and use it.
  • Click here to download a test application that demonstrates how to use the Event Distributor.

Applications written with the Event Distributor contain typical JavaBean event code. The only addition is an extended base class. You don't need any JMS code or knowledge to make this work.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap