2. An Example
As an example, we consider the creation of an application with the two classes mentioned in the introduction, App and Aclass. The App class will have a method called doCalculation(...) that invokes an Aclass method addTwo(...). Thus, the App class will be the "client" class and Aclass the "server" class.

The starting point is the construction of a purely local implementation. This implementation can be viewed in Sample1/App.java and Sample1/Aclass.java. The implemenation is as one would expect; App contains the data member A -- an Aclass instance. The doCalculation(...) method merely invokes A.addTwo(...) to obtain the result. The App.main(...) routine tests the construction. The output from the program is

The result of the calculation = 7 (and should = 7)

The next step consists of creating the wrapper classes for Aclass. This is is accomplished by invoking the the cam.codegen.CreateCISI application. The interface to the program has the form

You must type in the name of the package that the class resides in (e.g. if it is in package cam.codegen, then one would type in cam.codegen). In this example, Aclass is in the default package, so one leaves the package field empty. In the Class field one must specify the name of the class. This program creates the wrapper classes, and, by default, internally invokes the Java compiler to compile them. If one doesn't want this program to compile the routines after construction, then clear the Compile After Construction checkbox.

Note that when running the CreateCISI application, the target class must reside in a directory that allows JAVA classes to be loaded; in particular, the concatenation of a directory listed in the CLASSPATH variable and the package name of the target class must yield a directory the target class resides in.

This result of using cam.codegen.CreateCISI is the creation of two classes AclassCI.java and AclassSI.java.

With the wrapper classes constructed and compiled, the next step is to modify the App class to utilize the client implementation class AclassCI. This version is contained in the file Sample2/App.java. The required changes consist of changing the declaration of the variable A from

   Aclass       A; 


   AclassCI     A; 

and changing the constructor from

    A = new Aclass(); 


   A = new AclassCI();
      A.setVerboseFlag(true);// remove to stop messages ..
   }catch(Exception e)

This new code is compiled and then tested by invoking the cam.netapp.ServerManager, and running App.main(...). With the verbose mode on, the output from the program has the form:

NetworkConnection : Setting up Connection
NetworkConnection : Connecting to [] Port : 6789
NetworkConnection : Connected  to [] Start Up Port : 6815
NetworkConnection : Connected  to [] Server   Port : 6816
NetworkConnection : Connected  to [] Server   Port : 6817
NetworkConnection : Connected  to [] Server   Port : 6818
NetworkConnection : Application AclassSI requested
NetworkConnection : Remote Class Found
NetworkConnection : Remote Class Instantiated
NetworkConnection : Streams Connected to Remote Class
NetworkConnection : Connection Complete
NetworkConnection : Starting Remote Application
AclassCI : Connection Complete
The result of the calculation = 7 (and should = 7)

At this point, one can test the program working between two machines. To accomplish this one needs to have App and AclassCI on the client machine and Aclass and AclassSI on the server machine. The server classes Aclass and AclassSI must reside in a directory where they can be loaded by the cam.netapp.ServerManager running on the server machine. Also, the address and port numbers utilized in A.createServerInstance(...); method should be set to the server machine and port where the cam.netapp.ServerManager is running..

Here's a summary of the steps associated with the construction of a distributed application

  1. Develop the client and server class locally. Utilize standard JAVA programming tools and get the application running.

  2. Invoke cam.codegen.CreateCISI and create the client (CI) and server (SI) impementation classes. Compile these classes (if one doesn't select the compile option of the cam.codegen.CreateCISI application).

  3. Modify the client code to utilize the client (CI) implementation of the server class. Test the implementation locally (e.g. run a local cam.netapp.ServerManager and specify the loop back address (usually as the machine location in the createRemoteInstance(...) method ).

  4. Export the server class and its associated server (SI) implementation class to a remote machine. Make sure the classes reside in a location that allows a cam.netapp.ServerManager instance to load. them. One needs to change the address and port number in the createRemoteInstance(...) method called by the client application.

To run the distributed application; start up the cam.netapp.ServerManager on the remote machine, and then start the client application.