Beep Generator -
Java RMI
In this lab
session you are required to produce a client and a sever program based on the
Java Remote Method Invocation (RMI) mechanism. The server program should
support a sound generation service that can output a given number of system
beeps upon the receipt of requests from a client application. Both the client
and the server should be implemented in Java.
Application Development
For the
development of the above described system follow the below instructions:
- Interface Definition - Define the BeepGenerator
interface in Java, which extends the java.rmi.Remote interface. This
interface must declare the emitBeep method and its parameter, so
that it can be made accessible to remote clients. The parameter should
indicate the number of beeps that are being requested. Note all declared
methods within a Remote interface must be declared to throw the java.rmi.RemoteException
exception.
- Server Implementation – Implement the server object BeepServer
that implements the BeepGenerator interface
and extends the java.rmi.server.UnicastRemoteObject
class. The server object must provide implementation for the emitBeep
method so that it outputs a given number of beeps upon request. You
may wish to use the method java.awt.Toolkit.getDefaultToolkit().beep() to generate the system beep
sounds as well as printing out beep messages for machines with no sound
facilities.
- Servant Implementation - Create a server process (servant) called BeepServant
that will create a new instance of a BeepServer
object and bind it to the local registry using the java.rmi.Naming.rebind method and
the “//localhost/beep” address.
- Stub/Skeleton Generation – First compile all your files using the javac
compiler and then use the Java rmic
compiler tool to generate client stub code and server skeleton code from
your compiled server application BeepServer.
- Security Policy – A security policy file defining the access permissions to
the object should be defined. However, for the purpose of this exercise,
total access to the object is acceptable. You may need to create a file
with the content below (policy.txt):
grant {permission java.security.AllPermission;};
- Client Implementation - Implement the client application BeepClient
that first obtains a reference to the BeepGenerator
server object via the Java RMI Registry java.rmi.Naming.lookup
method and the "rmi://localhost/beep"
parameter. (Note that you can access the object remotely by replacing localhost with the name of the machine on which the
server is started). It should then invoke the emitBeep method
supplying it with a beep frequency parameter.
- RMIRegistry – Start the RMIRegistry by using the
command rmiregistry in the directory
where your files are stored.
- Application Execution – Run the BeepServant
application to initialise and bind an instance of the server object into
the RMI Registry. Finally run the BeepClient
application to verify that it can cause the server to beep a given number
of times.
To launch the BeepServer
application issue the below command:
prompt> java
-Djava.security.policy=policy.txt BeepServer
The client
application (BeepClient) can be launched by
issuing the below command:
prompt> java
-Djava.security.policy=policy.txt BeepClient