February 25, 2021
Hot Topics:

A first look at Jini lookup and discovery protocols

  • By Benoît Marchal
  • Send Email »
  • More Articles »


The discovery protocol is implemented in the Jini class LookupDiscovery. In practice, LookupDiscovery uses both multicast requests and multicast announcements. At startup, LookupDiscovery actively seeks lookup services using multicast requests. When it has found all the lookup services on the network, it switches to passively listening for multicast announcements.

Jini is a toolbox to build distributed applications
with each

LookupDiscovery sends discovered and discarded events to the application when it finds or loses track of a lookup service. The DoLookupDiscovery application in Listing 1 demonstrates how to use it. It registers as a listener for the discovered events and prints all the lookup services available on the network.

keeps the application running forever.

Listing 1. DoLookupDiscovery.java

import java.rmi.*;
import net.jini.discovery.*;
import net.jini.core.lookup.*;

public class DoLookupDiscovery
   public static void main(String[] args)
      throws Exception
      System.setSecurityManager(new RMISecurityManager());
      LookupDiscovery ld =
         new LookupDiscovery(LookupDiscovery.NO_GROUPS);
      ld.addDiscoveryListener(new DiscoveryListener()
         public void discovered(DiscoveryEvent de)
               // Invoke getRegistrar() on the
               // LookupLocator to perform unicast
               // discovery of the lookup service.
               ServiceRegistrar[] registrars =
               for(int i = 0;
                   i < registrars.length;
            catch (Exception e)
         public void discarded(DiscoveryEvent de)

Running the application

The Jini Starter Kit from Sun ships with a default lookup service called reggie. To test this application, you will need to run one or more copies of reggie. DoLookupDiscovery will print the list of available reggie. To compile and run the DoLookupDiscovery, follow these steps:

  • Download and install the Jini Starter Kit from www.sun.com/jini (look under Community Resources).
  • Compile the application:

  •    javac -classpath jini-ext.jar;jini-core.jar DoLookupDiscovery.java

  • Create the policy.all file with the following content:
    grant {
        permission java.security.AllPermission "", "";
  • Start the RMI activation daemon in its own console:

    Warning! This creates a log directory that you must manually delete between calls to rmid.

  • Start one or more instances of reggie. You should start reggie and wait until the prompt reappears to continue. You may have to adapt paths to your system:
       java -jar c:\jini1_0\lib\reggie.jar file:///c:\jini1_0\reggie-dl.jar 
    policy.all c:\reggie_public public

    To invoke a second copy of reggie, you must change the last two parameters, for example:

    java -jar c:\jini1_0\lib\reggie.jar file:///c:\jini1_0\lib\reggie-dl.jar 
    policy.all c:\reggie_second second
  • Warning! Again the fifth parameter is a log directory that you must manually delete between calls to reggie.

  • Finally, start DoLookupDiscovery:
         java -classpath c:\jini1_0\lib\jini-ext.jar;. 
    -Djava.security.policy=policy.all DoLookupDiscovery

    (Editor's note: Some lines of code above have been broken for display purposes.)

    It will search for lookup services and print them.

    To effectively test DoMulticast, you should start several copies of reggie, the lookup service. It is more interesting if you start some instances of reggie before running DoLookupDiscovery and others while DoLookupDiscovery is running. See DoLookupDiscovery dynamically discover new lookup services.


    Jini is a toolbox to build distributed applications that dynamically communicate with each other. The discovery protocol allows servers to explore their environment at runtime.

    Future articles in Gamelan will show you how to write your own Jini services.

    About the author

    Benoît Marchal is a software engineer and consultant based in Namur, Belgium. He has been working extensively on Java and XML. He also likes teaching and writing. Ben runs his own consulting company, Pineapplesoft, and can be reached at bmarchal@pineapplesoft.com. His first book, XML by Example will be published by Que at the end of the year.

    Page 2 of 2

    This article was originally published on November 4, 1999

  • Enterprise Development Update

    Don't miss an article. Subscribe to our newsletter below.

    Thanks for your registration, follow us on our social networks to keep up-to-date