Skip to main content

Messaging is degenerate RPC

Posted by cajo on June 25, 2006 at 1:28 PM PDT

Allow me to start with a small disclaimer: For those who do not already know; I lead the cajo project, where we promote the idea that the internet can be a collection of World Wide Virtual Machines; where remote objects are used just as local objects.

Yet there is a small, but rather vocal community, who wish to espouse that distributed object RPC is somehow flawed, and that 'messaging' is a superior solution. Being a somewhat more mature developer; I remember old tales from my childhood, where 'modern' twentieth century businessmen were admonished:

"Avoid the telephone; the network is unreliable: the post is superior."

Clearly they were wrong then; yet surprisingly this ideology is again being promulgated as fact.

To be sure, synchronous invocations are odious, and they are difficult to scale. For example; I actually prefer email to the telephone, since I am not required to respond immediately. Email does not disrupt my work, and I can deal with it when I am ready. However, it is easy to forget: sending email is still synchronous RPC! No matter how you slice it: data must be sent from one computer to another; over the network.

A brand new class has just been added to the cajo project; in less than 30 lines of code, it clearly illustrates that 'messaging' can be trivially implemented, including queueing, in a synchronous RPC environment:

public final class Queue implements gnu.cajo.invoke.Invoke {
   private java.util.LinkedList list;
   private final Object object;
   public Queue(Object object) { this.object = object; }
   public synchronized Object invoke(String method, Object args) {
      if (list == null) {
         list = new java.util.LinkedList();
         new Thread(new Runnable() {
            public void run() {
               try {
                  while (list.size() == 0)
                     synchronized(Queue.this) { Queue.this.wait(); }
                  String method = (String)list.removeFirst();
                  Object args = list.removeFirst();
                  gnu.cajo.invoke.Remote.invoke(object, method, args);
               } catch(Exception x) { return(); }
      return Boolean.TRUE;

Here any object reference, either local or remote, can be made remotely invokable, in any JVM. Yet every method invocation on a Queue object is executed asynchronously, on its member object, in a separate thread. If result data is desired, one could simply provide a callback object reference, as one of the method arguments. The boolean true is returned simply to 'guanantee' that the message has been successfully received.

If you want messaging, by all means, go for it! It is a very useful technique. However, it must be seen for what it is; degenerate synchronous RPC: i.e. a tiny subset of the functionality that is possible with distributed objects.

Related Topics >>