Remote method invocation

 

Introduction

We are going to work with the "PatternRMI" package, which will allow us to create a server and customer application that will communicate through "RMI".

 

The package includes:

·         a "Server" class containing the server's "main" method

·         a "Client" class containing the client's "main" method

·         a "TableEntry" class representing an information atom

·         a "Table" class containing access methods to the information

 

The "TableEntry" class represents the capital-country pair.  The "Table" class offers two services, the first providing the capital of a given country, the second giving the country of a given capital.

 

We are going to apply the pattern to the "Table" class in order to provide remote access to its services.

 

Note:      If you are using the JDK 1.2 or more recent, you may have to copy the .java.policy file from the $OBJING_PATH/mdaplugs/JavaDeveloper/4.0.0/FirstSteps into your home directory.  Alternatively, you may have to concatenate its contents with your .java.policy file, if it already exists.

 

 

Model before transformation

 

Figure 33. Initial model

 

 

Running the RMI pattern

After having selected the "Table" class in the explorer, activate the pattern (Figure 34).

 

Figure 34. Running the pattern

 

Steps:

1.      In the explorer, right-click on the "Table" class to open the associated context menu.

2.      Run the "Java Developer/RMI" command.

 

 

A dialog box opens, proposing default names for the class and interface that will be deduced from the "Table" class.  These names can be modified.

 

Figure 35. Entering class and interface names

 

Confirm by clicking on OK.

 

 

Model after transformation

 

Figure 36. Transformed model

 

 

Summary of the transformations

The following modifications were made to the concrete class:

·         the "Table" class was renamed "TableImpl"

·         a "TableImpl" generalization towards "UnicastRemoteObject" was added

·         an import towards "java.rmi.* " on "TableImpl" was added

·         the {JavaThrownException}  tagged value was added to each method, to indicate that it may run the "RemoteException" exception

·         an implementation link towards the "Table" interface was added

 

 

A "Table" interface was also created with:

·         all the "TableImpl" public methods

·         a generalization towards "Remote"

·         an import towards "java.rmi*"

 

 

Generating code

It is now necessary to generate.  Follow the steps below:

1.      Generate code for the package's classes.

 

For further information on these operations, please see chapter 3 of this user guide.

 

Note:      If the "Automatically generate" parameter is active, it is not necessary to carry out these steps.  For further information on this parameter, please refer to "Objecteering Java Developer parameters".

 

 

Execution

On the server machine:

·         add your file compilation directory to your CLASSPATH variable

·         launch the rmiregistry executable if it has not already been launched

·         launch the PatternRMI.Server server application

 

 

On the client machine:

·         launch the PatternRMI.Client application with the server machine name as the parameter

 

 

The following result is displayed in the client console:

 

The capital of China is Beijing.

The country whose capital is Rome is Italy.