O'Reilly logo

Java Distributed Computing by Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Whiteboard Applet

One of the examples that seems like an obvious candidate for use as an applet is our whiteboard example from Chapter 10. Currently, support for RMI within web browsers is scarce, so let’s concentrate on a message-passing version of the whiteboard, instead of the RMI-based version shown in Example 10.3. The message-passing version is very similar, but is based on the MessageCollaborator and MessageMediator classes from that chapter. This version, which we called the MsgWhiteboardUser, is shown in Example 1.1. Since the differences between this and the RMI-based WhiteboardUser are minor, we won’t go into details about the code here.

Example A-1. Message-Passing Whiteboard
package dcj.examples.Collaborative; import dcj.util.Collaborative.*; import java.awt.event.*; import java.awt.*; import java.util.Hashtable; import java.util.Properties; import java.io.IOException; import java.util.Vector; class Msg { public Object data; public String tag; public Msg(Object o, String t) { data = o; tag = t; } } class CommHelper extends Thread { Collaborator collaborator; static Vector msgs = new Vector(); public CommHelper(Collaborator c) { collaborator = c; } public static void addMsg(Object o, String t) { synchronized (msgs) { msgs.addElement(new Msg(o, t)); } } public void run() { while (true) { try { Msg m = null; synchronized (msgs) { m = (Msg)msgs.elementAt(0); msgs.removeElementAt(0); } collaborator.broadcast(m.tag, m.data); } catch (Exception e) {} } } } public class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required