Exercise 4. JINI and the Activation Framework
What this exercise is about
Though not a part of Jini, the RMI activation framework was introduced with Java 2. It is used by the core Jini run-time services such as the lookup service. This framework can be used for new services that need to be activated and deactivated in order to avoid continuously active processes. This exercise will use RMI and remote activation for a "Hello World" service.
What you should learn
Introductions: RMI and the Activation Framework
RMI:
Remote Method Invocation (RMI) is a way for Java applications running on different virtual machines to communicate. It is a lot like Remote Procedure Call. A server exports methods via an interface. A client must know this interface. These interfaces must extend java.rmi.Remote.
Extra code (middleware) running atop the JVM knows how to accept network connections from clients, take data from those connections and turn them into local method invocations. On the client side, the client invoking a method of a remote object actually deals with a local object that understands how to connect to a server, send it the data, accept any results, and hand them to the client. The server side of the middleware is called "skeleton" code, and the client middleware code is called "stub" code.
How it will work
The Server will start and the thread of Exercise 1 that kept the service going will be used to handle the lease management. The new implementation of run()will sleep until it is awaken to renew a lease, then go back to sleep.
The interesting thing about this example is that we need to remember that the discovered()method of the client is in another thread, and that a new lookup service registration may happen at any time. If a new lease is added while the thread is asleep, that lease may be shorter than the next scheduled wakeup. So the registerWithLookup()method is also overridden to call the super method and then wake up the lease management thread.
To avoid typing, ftp the source code for this java program from shop110ab.cse
You can use account guest with password shop110guest
The code is found in /opt/jini/corejini/chapter5/HelloWorldServiceWithLeases.java. We will walk through this code. You may safely jump to step 8 if you want to invest in the details of the service later or get lost in the details of what is going on.
The new Server
_
Compiling and running the new Client
_____ 18. Compile the source code files for the client as before. Work in the files directory and give the command, removing returns, modifying paths and slash directions as required
javac
-classpath c:\jini\jini1_0\lib\jini-core.jar;
c:\jini\jini1_0\lib\jini-ext.jar;
c:\jini\jini1_0\lib\sun-util.jar;
c:\jini\service
-d c:\jini\client
c:\jini\corejini\chapter5\HelloWorldClientWithLeases.java
____ 19. Check your directories and files. Check that the class files have been added to the correct subdirectory of client corresponding to the package.
_____ 20. Start an HTTP server to export the client’s downloadable code
java –jar $JINI_HOME/lib/tools.jar
-dir HOME/client-dl –verbose –port 8080
.
_____ 21. Check for the security policy file. If none, Edit a file named policy and place it in your directory.
grant {
// This one allows everyone everything
permission java.security.AllPermission;
} ;
_____ 22. Run the client (a Windows run…modify for unix…i..e slashes and colons)
java -cp
c:\jini\jini1_0\jini-core.jar;
c:\jini\jini1_0\lib\jini-ext.jar;
c:\jini\jini1_0\sun-util.jar;
c:\jini\client
-Djava.rmi.server.codebase=http://myhost:8080
-Djava.security.policy=c:\jini\policy
corejini.chapter5.HelloWorldClientWithLeases