Project 2 - Simple RPC

Example Java sRPC Binding


The sRPC types are bound to the analogous types in Java:

sRPC typeBound Java type
intint
stringString
array of TVector

Notice that the binding of arrays to Vectors loses information about the element types; within sRPC this information will have to be maintained elsewhere.

The client side has available a class defining the methods available from the sRPC stub providing the service. Each service call is bound to a method of the class; the method signature is

output-parameters call-name(input-parameters)

An input-parameter spec

in type-spec ident

is bound to the formal parameter

bound-type-spec ident

The left-to-right order of the input parameters in the method argument list matches the top-to-bottom order of the in-parameter specs in the service-spec.

The output parameters appear in an instance of a return-value class nested within the client-stub class. An output-parameter spec

out type-spec ident

corresponds to the instance-variable declaration

bound-type-spec ident;

in the return-value class. Instance-variable declarations may be arbitraly ordered within the return-ralue class. Each service call defines an associated return-value class; it is not necessary to optomize the code by combining identical return-value classes (although you may do so if you want).

If a service call doesn't return any values, the associated member function returns void and no associated return-value class need be defined. If a service call only returns one value, the associated method may return the value directory, rather than returning an instance of a return-value class that contains the value.

As an example, the Dictionary service-call spec

call insert
in  string word
out int    inserted
out string emsg

is bound to the method

InsertResults insert(String word);

The return-value class is

class InsertResults {
  int inserted;
  String emsg;
  }

The client-side generic sRPC service calls have the bindings

String startup(String hostname, int port_number);

QueryReply query()

class QueryReply {
  String spec;
  String emsg;
  } 

String shutdown()

Because they return a single value, the startup() and shutdown() methods return a string, rather than an instance of a return-value class containing the string. Because it returns more than one value; the query() method must return an instance of a return-value class.

The server-side file contains the server skeleton. It makes calls to an intance of a class implementing the service calls; the server-side implementor is responsible for implementing the service-calls class.

srpc-gen creates two Java source files from a service-spec file:

Java files generated by srpc-gen

The ServiceClientStub.java file contains the client-stub class definition. Any client-side code wanting to use the service should create an instance of the client-stub class.

The ServiceServerSkeleton.java file contains the server skeleton. The code in the server skeleton makes calls to an instance of the ServiceServiceCalls class, which the server-side implementor has to define.


This page last modified on 29 March 2004.