How to write a client

A Gestalt client is a Java class that extends the gestalt.Client abstract class. Only one argument need be passed to the Client class constructor: the name of the server to connect to. The Client class is a self starting thread that immediately opens a TCP socket to the server, and then calls the only function that must be implemented by classes that extend Client: begin().

In the begin() function should lie the body of the client program. Here the client program should instantiate a series of objects that are sub classes of gestalt.Task, and using the send() method of the gestalt.Connection object that is passed to the begin() method, submit them to the server for computation. The client should then go into a loop, calling the avail() method of the Connection object, and using the Connection object's recv() method to read in objects that the server sends back. These objects will be of at least two types, and I'm reserving the right to increase this number in later releases. Obviously, one of the object types will be your sub class of gestalt.Task, but in addition to that, the server periodically sends gestalt.msg.ServerUpdate objects to each of it's clients, indicating that either the number of local slaves that the server is connected to, or the total number of tasks that are pending computation on the server has changed. Once each of the tasks that you submitted has been returned, your begin() function should return, allowing the gestalt.Client super class to close the connection to the server.

Here is an example client: flop.FlopMetricClient. FlopMetricClient generates a number of Tasks that do a series of floating point operations, and submits them to the server for computation. It then loops, collecting the results as they come in from the server. It breaks out of the loop should the connection to the server close.

A subclass of gestalt.Task is what must be submitted to the server for calculation, so Task should be subclassed one or more times by the author of a client. A task consists of a run() method that will be called by whichever slave the task is assigned to. The task object is sent to the server via object serialization, so any class variables will be sent along with it (when run on the slave, the entire graph of objects available to the task before it is sent to the server will be available).

Here is an example subclass of Task, used by FlopMetricClient: flop.FlopMetricTask. FlopMetricTask performs a number of floating point additions in it's run() method.

Here is an example of how to do a practical parallel calculation using the network: a mandelbrot fractal generator.

mandel.MandelClient breaks a certain resolution of display into several rectangular regions, submits them to the server for calculation, and then loops, waiting for the results to come back.

mandel.MandelTask is the class that performs the divergence calculation over a rectangular area.

mandel.Boundary is a class that describes a two dimensional area enclosed by floating point numbers. This class must implement the java.io.Serializable interface, because it is sent to the server in a MandelTask.

mandel.Complex is a class that represents a complex number, and allows simple arithmetic operations to be performed it. This class must implement the java.io.Serializable interface, because it is sent to the server in a MandelTask.

mandel.MandelFrame is a sub class of java.awt.Frame that plots the divergence of the fractal in a window.


Last Modified: 7/24/97 by jack@cs.hmc.edu