The Artima Developer Community
Sponsored Link

Time Service

Advertisement

Eran Davidov posted some example code that can help those trying to get started with Jini. (This version works with the latest Jini release, which works with JDK1.2 FCS.) You can download the code from here:

timeservice.zip

Here are Eran's original messages with which he posted this material:

People,

Due to the number of requests, attached is the TimeService example converted to work with the latest Jini release. The alterations were simple package renaming, so all my comments from the original post (below) are still valid.

Included is also Ken Arnold's conv2sh script to make the example work on UNIX.

Remember - I'm not part of the Jini team and this is not official. Hope it helps.

Enjoy

---------------- Original Message ------------------------------------

Folks,

Here's my small contribution to the learning curve. The attached are my first experiments with creating services and and looking them up. Hope this helps someone.

The attached includes an interface named service.TimeServer. It defines three methods: getTime, getHost and getText. There are three different service implementation for it. One of them is a "local" implementation that gets downloaded into the client and runs from inside the client's VM. Kind of a cheat :) The second is a remote implementation. The service runs in the registering VM, passing the remote stub through the lookup service to the client. The third is a proxy. It runs the service in the registering VM, registers it in the RMIREGISTRY, then creates a proxy class and tells it where to find the service when it needs it. When the client downloads the proxy, the proxy will make connection with the RMIREGISTRY and get the stub from there. Kind of a stupid implementation, but I wanted to see it work. I should have just passed the remote object inside the proxy.

The getText method just returns some text. When running the remote and proxy examples, this is the text provided as the first parameter when running the example. With the local service, the first parameter you should pass to it when executing the registerer is a URL. The local service will try to open the URL and return the first line of its content.

There is also a client that looks for lookup services in the net, displays various stuff on registered services within, then looks for TimeServer services registered and uses them.

Instructions: 1. unjar the attached file to an empty directory.

2. edit the env.bat file to reflect your installation. See the comments within.

3. Run the makeall.bat in the directory. This will compile the classes, package up the different JAR files needed by clients, and place them in your web server's path, or other URL you specified.

4. run any / all of the services to make them register: local.bat URL-to-some-file remote.bat "my text message" proxy.bat "my text mesage"

remember - running the "proxy.bat" requires a running RMIREGISTRY.

You will know a service has registered when it prints out its service ID.

5. Run the client.bat, to see how it recognizes the various time services registered and uses them

Notes: 1. I'm not part of the Jini team. There is nothing official about these examples.

2. This is NOT a clean implementation. Not everything is taken care of, spesifically not exception handling and unregistering services. Unregistration is done when the lease from the lookup service runs out. Typically around a minute or two.

3. Running the client in the same directory structure where you compiled the servers is kind of cheating, since you cannot be sure the classes did indeed get downloaded from the URL location. In order to check this, copy the following files to a separate directory and run the client: service\TimeServer.class client\TimeClient.class client.bat policy.all

4. The security file used with these examples is the policy.all file, granting all permission to anyone, any time, any place :) DO NOT rely on it in a production implementation.

5. These services do not take care of preserving their service IDs. I didn't bother with it.

6. Let me know how it works. I've only tried it on my computer.

7. If you have any questions / problems, send them to the list.

8. I know. The TimeServer service is not really something you'd want :)

Eran
-------------------------------------------------
Eran Davidov
JavaSoft Israel


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use