The Computation Monitor Project

Reference Manual

The ComputationMonitor class and its subclasses

To create a monitored computation, the client object should create an object of class computation.ComputationMonitor or of a class derived from it. The only constructor of this class is:

public ComputationMonitor(Frame base, CompInterface computation);

The base parameter is an optional reference to the AWT frame that will be the parent of the monitor window. It can be null.

The computation parameter is a reference to an object implementing the computation.CompInterface abstract class, described later.

When a computation monitor has been constructed, its run() method executes the computation.

The ComputationMonitor class has some other public methods, to be used to customize a single computation monitor. They are the following:

To customize the animation icons of the ComputationMonitor, or to standardize on some customizations, it is possible to derive a class form ComputationMonitor, ovverriding some methods, and then to instantiate monitors from this class.

The methods of the ComputationMonitor class that can be overridden are the following:

He, who would like to change the icons of the animation, should follow the following rules:

The Computation class and its subclasses

Every computation monitor needs an object implementing the computation.CompInterface abstract class. In the computation package, there are two classes derived from this class: Computation and RemoteCompProxy. The first is for local computations, the second is for remote computations.

Actually, also the Computation class is abstract, so it must be subclassed by a class implementing its abstract methods.

However, even for remote computations, it is necessary to define a class derived from Computation, that is a concrete computation.

A concrete computation must implement the following methods:

The concrete computation should define the necessary private variable to store the computation state, and the necessary methods to set the parameters for the computation and to retrieve the results afterwords. These methods will not be called during the computation. The methods getProgress and getStatus are called asynchronously by the computation monitor, so they should not change the state of the computation, and should access only volatile variables.

Running a Local Computation

To run a local computation, the client object should do the following operations, in this order:

  1. Create a concrete computation object.
  2. Set the parameters of the concrete computation object.
  3. Create a computation monitor object, passing to the constructor the concrete computation object.
  4. Optionally, customize the computation monitor object.
  5. Run the computation monitor object.
  6. Get the results from the concrete computation object.

Actually, steps 2 and 3 could be swapped.

Running a Remote Computation

A remote computation, of course, is more complicated. In addition to defining a concrete computation class and an optional computation monitor customized class, it is necessary to define an interface derived from RemoteCompInterface, that is an RMI interface, and a class implementing this interface and derived from the RemoteComputation class, that is an RMI server.

The RMI interface should define the same public methods already defined by the concrete computation class, with the only difference that their declaration should add the clause throws RemoteException.

The RMI server should implement the methods declared by the RMI interface, and should add a private instance variable and a public constructor. Naming AComputation the concrete computation class, and ARemoteComputation the RMI server, the variable and the constructor should be defined by the following code:

private AComputation localComp = new AComputation();
public ARemoteComputation() throws RemoteException {
  setComputation(localComp);
}

The implementation of the RMI methods should simply call the corresponding methods of the private instance variable.

Of course, the RMI server should be bound to an RMI name at the startup of the server, using the Naming class and the rmiregistry process.

To run a remote computation, the client object should do the following operations, in this order:

  1. Instantiate a remote computation object, using the lookup method of the Naming class.
  2. Set the parameters of the remote computation object.
  3. Create a new object of class RemoteCompProxy, passing to the constructor the remote computation object.
  4. Create a computation monitor object with the new RemoteCompProxy object.
  5. Optionally, customize the computation monitor object.
  6. Run the computation monitor object.
  7. Get the results from the remote computation object.

Design Schema The Computation Monitor Project
© Carlo Milanesi - 28 September 2002