Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Revolutionary RMI: Dynamic class loading and behavior objects

Find out how RMI can help you define extensible, distributed object-oriented frameworks

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Welcome to Enterprise Java, a new column dedicated to the Java Enterprise APIs: RMI, Java IDL, JDBC, Servlets, and EJB. I originally intended to call this column "Java Enterprise Jumpgate," in reference to the jumpgate technology in the hit TV series Babylon 5. (A jumpgate allows you to move between known points in the universe for trade, exploration, and laying waste -- which is similar to the purpose of the Internet.) I feel the analogy to distributed programming fits: the goal of this column is to demonstrate the capabilities, strengths, and weaknesses of each distributed programming API, helping you jump to new programming destinations. But you know editors, they just won't let you have any fun at their magazine's expense!

A word to the wise: distributed programming is inherently more difficult than standalone programming. However, the Java Enterprise APIs give Java programmers tools to ease the burden of producing robust, efficient applications. This column will help you get production-level, industrial-strength applications out the door, on time and on target.

When it comes to distributed computing, no area is getting more interest today from programmers than the Remote Method Invocation (RMI) API. Programmers love it, Microsoft hates it, and vendors want to make money off of it. EJB, Jini, and JavaSpaces all have their roots in RMI. So what better subject to kick off this column.

Getting excited about RMI

As an instructor, no Java Enterprise API is more rewarding to teach than RMI. It always works the same way:

  • Introduction
  • RMI hello world
  • Callbacks
  • Object serialization and RMI


The student reactions follow the modules:

  • Come on, caffeine, work!
  • Not "hello world" again...
  • Finally, something I can use
  • Wow, cool! Can we do that again?


Object serialization and RMI puts a smile on programmers' faces because they witness the subtle strength of RMI: the ability to transport true objects between processes.

What excites students is an example that demonstrates behavior objects. A behavior object is an instance that implements an interface, where the interface declares a remote method parameter type. For example, consider the following interfaces:

public interface ScribbleShape {
    public void draw(java.awt.Graphics g);
}

import java.rmi.*;
public interface ScribblePad extends Remote {
    public void addShape(ScribbleShape s) throws RemoteException;
}


The ScribblePad.addShape() method parameter represents a behavior object because the parameter instance must support the ScribbleShape interface, the ScribbleShape interface doesn't extend Remote, and the parameter will be passed between processes using serialization. From the ScribblePad implementation's perspective, the addShape() method is invoked by a Java object running in a process across the network and delivers a serialized version of the ScribbleShape instance that existed in the client process. The ScribblePad implementation can store the parameter value in a Vector, invoke methods on the object, serialize it to a file, or pass to yet another RMI object on a different machine.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Download the complete source in zip format; you will need to have JDK 1.1.x and Swing 1.1 Beta 3 release, or the JDK 1.2 Release Candidate 1 (which includes Swing) to run the code http://www.javaworld.com/jw-12-1998/enterprise/jw-12-enterprise.zip
  • Download the Java Swing Toolkit from JavaSoft http://developer.java.sun.com/developer/earlyAccess/jfc/index.html
  • Bryan Morgan's "Java 1.2 extends Java's distributed object capabilities" (JavaWorld, April 1998) provides an excellent step-by-step RMI example http://www.javaworld.com/javaworld/jw-04-1998/jw-04-distributed.html
  • Sun's online RMI tutorial offers an excellent starting point for those needing a little RMI brush up http://java.sun.com/docs/books/tutorial/rmi/index.html
  • Sun's Java security home page, with specifications whitepapers, articles, and more http://java.sun.com/security/index.html
  • Sun's RMI Web page http://www.javasoft.com/products/jdk/rmi/
  • Always go to the specification if you want to know all the details http://java.sun.com/products/jdk/1.2/docs/guide/rmi/spec/rmiTOC.doc.html