previous chapter table of contents next chapter

Matching Services

As mentioned previously, a client attempts to find one or more services that satisfy its requirements by creating a ServiceTemplate object and using this in a registrar's lookup() call. A ServiceTemplate object has three fields:

 ServiceID         serviceID; java.lang.Class[] serviceTypes; Entry[]           attributeSetTemplates; 

If the client is repeating a request, then it may have recorded the serviceID from an earlier request. The serviceID is a globally unique identifier, so it can be used to identify a service unambiguously. This serviceID can be used by the service locator as a filter to quickly discard other services.

Alternatively, a client may want to find a service satisfying several interface requirements at once. For example, a client may look for a service that implements both Toaster and FireAlarm (so that it can properly handle burnt toast ). The client will fill the serviceTypes array with all of the interface classes that the service has to implement.

And finally, the client will specify a set of attributes in the attrSetTemplates field that must be satisfied by each service. Each attribute required by the client is taken in turn and matched against the set offered by the service. For example, in addition to requesting a Toaster with a FireAlarm, a client entry may specify a location in GP South Building. This will be tried against all the variations of location offered by the service. A single match is good enough. An additional client requirement of, say, manufacturer would also have to be matched by the service.

The more formal description that follows comes from the ServiceTemplate API documentation:

  1. A service item (item) matches a service template (tmpl) if: item.serviceID equals tmpl.serviceID (or if tmpl.serviceID is null ); and item.service is an instance of every type in tmpl.serviceTypes ; and item.attributeSets contains at least one matching entry for each entry template in tmpl.attributeSetTemplates
  2. An entry matches an entry template if the class of the template is the same as, or a superclass of, the class of the entry, and every non- null field in the template equals the corresponding field of the entry. Every entry can be used to match more than one template. Note that in a service template, for serviceTypes and attributeSetTemplates , a null field is equivalent to an empty array; both represent a wildcard.

A Programmer[ap]s Guide to Jini Technology
A Programmer[ap]s Guide to Jini Technology
ISBN: 1893115801
Year: 2000
Pages: 189

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net