The Artima Developer Community
Sponsored Link

Finding Services with the Jini Lookup Service
The Power and Limitations of the ServiceRegistrar Interface
by Bill Venners
First Published in JavaWorld, February 2000

<<  Page 4 of 13  >>

Advertisement

The browsing methods

In addition to the two lookup() methods, the ServiceRegistrar has three methods called browsing methods that let clients get information about registered service items. These three methods -- getServiceTypes(), getEntryClasses(), and getFieldValues() -- are called "browsing methods" because they enable clients to browse the services and attributes in the lookup service.

The getServiceTypes() method takes a ServiceTemplate (the same ServiceTemplate that is passed to the lookup() methods) and a String prefix. It returns an array of Class instances representing the most specific types (classes or interfaces) of the service objects that match the template. These service objects are neither equal to, nor a superclass of, any of the types specified in the template and have names that start with the specified prefix. The service object or objects for whom Class instances are returned are all instances of all the types (if any) passed in the template, but the Class instances are all more specific than (and are subclasses or subinterfaces of) those types. Each class appears only once in the returned array, and in arbitrary order.

Here's what getServiceTypes() looks like:

public java.lang.Class[] getServiceTypes(ServiceTemplate tmpl,
    java.lang.String prefix) throws java.rmi.RemoteException;

The getEntryTypes() method takes a ServiceTemplate, and returns an array of Class instances that represent the most specific classes of entries for the service items that match the template which either don't match any entry template or are a subclass of one. Each class appears only once in the returned array, and again in arbitrary order.

Here's what getEntryClasses() looks like:

public java.lang.Class[] getEntryClasses(ServiceTemplate tmpl)
    throws java.rmi.RemoteException;
The getFieldValues() method takes a ServiceTemplate, an integer index, and a String field name. It returns an array of Objects for the named field of all instances of the entry that appears in the ServiceTemplate's Entry[] array at any matching service item's passed index. Each object of a particular class and value appears only once in the returned array, and in arbitrary order.

Here's what getFieldValues() looks like:

public java.lang.Object[] getFieldValues(ServiceTemplate tmpl,
    int setIndex, java.lang.String field)
    throws java.lang.NoSuchFieldException, java.rmi.RemoteException;

The behavior and purpose of these browsing methods can be obscure. A good way to think of them is that they enable clients to incrementally narrow queries of the lookup service.

For example, a client, such as a graphical lookup service browser, could first invoke getServiceTypes() with an empty template. The getServiceTemplate() method returns all possible service types registered in the lookup service, which the browser could display. The user could select one or more types, then push the Requery button. The browser would add that type (or types) to the service template, and invoke getServiceTypes() again. A smaller list of types would be returned, and displayed by the browser. The user could select one and press an Entries button. The browser would form a template with the most recently selected service type or types, and invoke getEntryTypes(). The getEntryTypes() method would return an array of entry classes, which the browser could then display. The user could select some entries, and a field of a selected entry, and push a Fields button. The browser would build a template using the currently selected service and entry types, and pass the index of the entry class in which the user selected the field, and the name of the selected field, to getFieldValues(). The browser would display all the values that getFieldValues() returned. The user could use these values to further narrow the search for a service, eventually using a particular service. Thus, these methods help clients, whether or not a human user is involved, to browse the services registered in a lookup service. The arrays returned from the browsing methods can help the client further refine its queries, ultimately resulting in a ServiceTemplate that, when passed to lookup(), returns the most appropriate service object.

<<  Page 4 of 13  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us