The Artima Developer Community
Sponsored Link

Browse User Interfaces for Jini Services
Build a JFC-Based Application for Browsing and Launching Jini Services
by Jeffrey Peden
First Published in JavaWorld, March 2001

<<  Page 6 of 7  >>


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(){
         jini_Lookup_Discovery = new LookupDiscoveryManager(null,
                                                 new LookupLocator[0],
         jini_Lease_Manager = new LeaseRenewalManager();
         jini_Service_Discovery = new ServiceDiscoveryManager(jini_Lookup_Discovery,
         jini_ServiceUI_Filter=new ServiceUIFilter();
         jini_Lookup_Cache = jini_Service_Discovery.createLookupCache(null, null, hybrid_Service_Menu);
      }catch(Exception e){

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.

<<  Page 6 of 7  >>

Sponsored Links

Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use