The GLDemo Example System

All elements of GLDemo are in the demo directory. The demo system consists of the Java program GLDemo, provided in source code form. GLDemo is a program that uses several Gublists classes to communicate with another instance of itself (its "counterpart"), in a not particularly realistic way.

When a GLDemo starts, the main thread of the program opens a UDP socket, creates a ByteArrayPipe and a Timeline, and then spawns a separate "listener" thread. The main thread then starts a loop in which it repetitively writes a prompt character to the monitor and reads a message from the keyboard, blocking until a carriage return is entered. If the message is a string of non-zero length (i.e., the user typed something -- anything at all -- before pressing the Return key), then transmission of that message to the GLDemo's counterpart is scheduled in the Timeline; the message's length (in bytes) is used as the number of seconds to wait before sending the message via the UDP socket. But if the message's length is zero, the main thread simply reads and prints the first unread message on the ByteArrayPipe from the listener thread (if any).

The listener thread is simpler than the main thread. It just starts a loop in which it repetitively reads a message from the UDP socket (blocking until one arrives) and writes it on the ByteArrayPipe to the main thread.

Running the demo system

To run GLDemo in a simple configuration, do the following:
  1. Start one instance of GLDemo running on your computer: cd into the demo directory, which contains the GLDemo classes, and enter the following command:
    java -classpath . GLDemo 4001 4002
  2. Start a counterpart instance of GLDemo on the same computer, in another window: cd into the demo directory and enter the following command:
    java -classpath . GLDemo 4002 4001
Now just enter messages at the prompts of both GLDemos and read them as they arrive. To read a message at a GLDemo, you have to press the Return key without entering any message text. Until the message is sent, though, pressing the Return key will do nothing.

You can enter an essentially unlimited number of messages of various lengths at one GLDemo before starting to read any of them at the other GLDemo; the sending GLDemo will never block. Remember, the transmission of each message is delayed by a number of seconds equal to its length in bytes, so a short message entered immediately after a long message will probably arrive before the long one does.

GLDemo should work across a network as well. Just specify the hostname of the counterpart GLDemo as an additional command line parameter when you start each GLDemo, e.g.:

java -classpath . GLDemo 4001 4002 sherlock
java -classpath . GLDemo 4002 4001 mycroft
If you run GLDemo with no command line parameters at all, it will print a usage line explaining what the command line parameters are.