Browse user interfaces for Jini services

Build a JFC-based application for browsing and launching Jini services

1 2 3 Page 3
Page 3 of 3

Lookup initialization

The final method called by the constructor is initialize_Lookup(). That method performs a number of steps that allow the application to find Jini services on the network. That process is similar to the registration process we implemented for TimeServiceImpl.

   protected void initialize_Lookup(){
      try{
         jini_Lookup_Discovery = new LookupDiscoveryManager(null,
                                                 new LookupLocator[0],
                                                 null);
         jini_Lease_Manager = new LeaseRenewalManager();
         jini_Service_Discovery = new ServiceDiscoveryManager(jini_Lookup_Discovery,
                                                 jini_Lease_Manager);
         
         jini_ServiceUI_Filter=new ServiceUIFilter();
         jini_Lookup_Cache = jini_Service_Discovery.createLookupCache(null, null, hybrid_Service_Menu);
            
      }catch(Exception e){
         e.printStackTrace();
      }
   }

The first two classes used, LookupDiscoveryManager and LeaseRenewalManager, are common to both service registration and lookup. The next class, ServiceDiscoveryManager, is also part of the Jini 1.1 utility suite, and provides a simplified mechanism for discovering services. As part of that mechanism, you can create a LookupCache object, which maintains a local list of services available. The createLookupCache() method takes three arguments:

  1. ServiceTemplate: This parameter lets you specify a matching pattern for services based on ServiceID, entries, or the interfaces implemented.
  2. ServiceItemFilter: This parameter lets you specify an object that will be responsible for filtering results from the lookup after retrieving them from the lookup services.
  3. ServiceDiscoveryListener: This parameter provides a means for specifying a callback object to be notified when the set of items in the cache has been changed.

At this point, we will not restrict the set of services in the lookup cache, but instead we will use the ServiceUIFilter when retrieving items from the cache (as you saw in ServiceMenu above). That design decision allows us to, in the future, work with services that may not have an associated ServiceUI, without needing to create another LookupCache.

Another subtlety to note is that in the ServiceMenu method reload(), we reference jini_Lookup_Cache and jini_ServiceUI_Filter, although when we create the ServiceMenu, neither of the objects exist. We are safe, however, from throwing NullPointerExceptions because reload() is only called by the ServiceDiscoveryListener methods. Since we are not registering our ServiceMenu with the lookup cache until now, the fields should never be null when reload() is called.

Conclusion

In this article you've learned how to create a simple ServiceUI-based Jini service and how to use services with such ServiceUI-based GUIs from a Swing-based application. We've encountered and examined some of the intricacies of mixing Jini services and Swing applications, and made design decisions based upon them.

The ServiceUI 1.0 specification defines the de facto standard for attaching user interfaces to Jini applications. It is a simple yet powerful framework for developing user-oriented distributed services and applications and, when combined with the Jini service metaphor, it has the potential to change how we view application development in a networked world.

Jeffrey Peden is currently a Java software engineer at Virtual Ink. Prior to Virtual Ink, he performed research in the area of distributed systems engineering and network collaboration technologies at the University of Massachusetts, Amherst. Peden holds a B.S. in computer systems engineering from that university.

Learn more about this topic

1 2 3 Page 3
Page 3 of 3