The Source for Java Technology Collaboration
User: Password:



John Catherino's Blog

John Catherino John has been deeply fascinated by science and technology since watching the Apollo launches as a young child, from his back yard. Years later he found his perfect outlet for his passion in Java, where he has been steadily working on the coordination of distributed computing systems.



Messaging vs. RPC? Let's fuse 'em.

Posted by cajo on June 19, 2008 at 06:58 PM | Permalink | Comments (9)

What is the fundamental premise of messaging, and how is it different from RPC?

Essentially, messaging focuses on the concept of loosely coupled, event/information delivery; between one or more producers, and one or more consumers. RPC focuses on the concept of tightly coupled synchronous functional invocation; between a client and a server. What would happen if we applied cajo technology to coalesce these two concepts?

This is precisely what the newly updated cajo Queue class does. Queue instances are initially constructed by providing a topic object. This object is a mutually agreed upon class, between producers and consumers, which provides the context for why the community is using this particular Queue instance. For example: the topic object could be something as simple as a string – "Wine Enthusiasts" or as elaborate as a HashMap of subtopics and values.

Consumer objects can be either local or remote to the JVM in which the Queue object is operating, and register using its enqueue method. Producer objects can also be either local or remote, and create events by invoking arbitrary methods on a Queue object reference. These invocations return immediately for producers; and are asynchronously invoked on all registered consumers. The invocation's successful return to the producer, guarantees that the event has been accepted. As the object's name implies; producer invocations are queued, as necessary.

For example:
// Producer actions:

queue.ping(); // invokes the method ping() on all consumers
queue.position("37.391008, -122.082073"); // new location
queue.fill(x, y, width, height, Color.red); // mask area

// note: queue does not implement any of these methods itself
// they are invoked on the consumers, only if they support them
The real gist of fusion takes place in the concept of method invocation on the Queue object. A producer may invoke a method taking no arguments; this is traditional notification messaging. A producer could invoke a method taking a single argument; this is traditional data messaging. Finally, a producer could invoke methods taking multiple arguments; this is traditional RPC, but loosely coupled, i.e. functional messaging -- exhibiting three key features:
* The function signatures are independent of any class or interface definition
* The potential one-to-many relationship, between the producer and its consumers
* The consumer is not required to implement the functions being invoked by the producer
The Queue class performs the consumer invocations asynchronously from the producer's; it discards any direct return values, and exceptions from the consumers. Therefore, if the producer wanted feedback from consumers, it could provide a callback reference as an argument, for example.

If there is only one producer, and one consumer, this is what is commonly referred to as point-to-point messaging. When there is one or more producers, and more than one consumer; this is what is commonly referred to as publish/subscribe messaging. With the Queue class approach, these are just variations in how the object is used.

Lastly, just for fun, the Queue class is serialisable, meaning Queue objects can be passed between JVMs at runtime, (i.e. cloned) whilst retaining all producer and consumer links. The possibilities created by this, are nothing short of mind-boggling. ;-)

Best of all, Queue is implemented in a single class, consisting of less than 100 lines of code. I recommend giving it a try; it is extremely simple to use, highly intuitive, and very powerful. It is a handy new tool, to add to your kit.

Enjoy,

John

June 2008
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          


Search this blog:
  

Categories
Community
Community: Java Communications
Community: Java Enterprise
Community: Java Patterns
Community: Java Tools
Community: JavaDesktop
Community: linux.java.net
Deployment
Distributed
J2EE
J2ME
J2SE
Linux
Mobility
Open Source
Patterns
Performance
Tools
Virtual Machine
Archives

June 2008
September 2007
December 2006
June 2006
May 2006
August 2005
August 2004
June 2004
March 2004

Recent Entries

Messaging vs. RPC? Let's fuse 'em.

Simple Inter-JVM communication... The Grail!

Dynamic Client Subtyping



Powered by
Movable Type 3.01D


 Feed java.net RSS Feeds