Beep Generator Factory – Java RMI

 

In this lab session you are required to produce a beep sound generation service using Java RMI. Client applications must first locate a factory finder object, via the RMI Registry that returns a reference to a factory object. The client application should then instruct the factory object to create and activate an instance of a BeepGenerator server object. The BeepGenerator object should support a sound generation service that can output a given number of beeps upon the receipt of requests from the client application. By relying on factories to create server object instances, we introduce an extra layer of transparency for the creation and location of a server object. All classes should be implemented in Java.

 

You will require the BeepGenerator and BeepGeneratorServer files produced during the previous RMI lab session, available here:

‘/cs/research/sse/home0/rigel/ucaccac/public_html/rmifactory’

 

Application Development

 

For the development of above described system follow the below instructions:

 

  1. Interface Definition – Define the BeepGeneratorFactory, and BeepGeneratorFactoryFinder interfaces. These interfaces must extend the java.rmi.Remote interface.

The BeepGeneratorFactory interface must declare the createBeepServer method, which returns a reference to a newly created instance of a BeepGenerator object.

The BeepGeneratorFactoryFinder interface must declare the findBeepGeneratorFactory (returns a BeepGeneratorFactory object) method that will locate a suitable factory capable of creating BeepGenerator objects.

 

  1. BeepGeneratorFactory Server & servant Implementation – Implement the BeepGeneratorFactoryServer that implements the corresponding interface discussed in section 1. (Extends the java.rmi.server.UnicastRemoteObject class).

The BeepGeneratorFactory’s createBeepServer method should be capable of generating a new   BeepGeneratorServer and returning a reference to it (through the BeepGenerator interface). The Factory’s servant process should register an instance of the Factory with the local registry under the address ‘//localhost/BeepGeneratorFactory’ using the java.rmi.Naming.rebind method.

 

  1. BeepGeneratorFactoryFinder Server and servant implementation – Implement the BeepGeneratorFactoryFinderServer that implements the corresponding interface discussed in section 1.

Upon request an instance of BeepGeneratorFactoryFinderServer will find and return    a reference to a BeepGeneratorFactory object via the Java RMI Registry. Instances of BeepGeneratorFactoryServer create and activate instances of BeepGeneratorServer upon request.

The BeepGeneratorFactoryFinder servant process should register an instance of the factory finder with the local registry under the address ‘‘//localhost/BeepGeneratorFactoryFinder’.

 

  1. Stub/Skeleton Generation – Use the Java rmic compiler tool to generate client stub code and server skeleton code from your compiled server applications BeepGeneratorFactoryFinderServer, BeepGeneratorFactoryServer and BeepGeneratorServer.

 

  1. Security Policy - Java’s security model requires the presence of a security policy file in order to ensure the execution of authorised applications. For this example you may wish to create a policy.txt file with the below content:

 

grant {permission java.security.AllPermission;};

 

Note that this grants total access to the application and should only be used for the purposes of this exercise.

 

  1. Client Implementation – Implement the BeepClient application that first obtains a reference to a BeepGeneratorFactoryFinder object via the RMI Registry. By invoking the findBeepGeneratorFactory method on this reference the application obtains a reference to a BeepGeneratorFactory instance. It can then invoke the createBeepServer method on this reference to cause the creation of a new BeepGenerator instance. Finally the client application can invoke the emitBeep method on the newly created instance, to cause a specified number of beeps to be generated.

 

  1. Application Execution – Run the BeepGeneratorFactoryServer servant application followed by the BeepGeneratorFactoryFinderServer servant application. Once these have registered with the RMI Registry and have been successfully activated, you can launch the BeepClient application. You can now verify the client functionality by generating beep sounds from a newly created BeepGenerator instance.

 

You will be required to launch your applications as follows:

      prompt> java -Djava.security.policy=policy.txt ClassName