if(len > 0) {
/* loop thru the set of lookups, randomly selecting each lookup */
int rand = (Math.abs(random.nextInt())) % len;
for(int i=0; i<len; i++) {
int max = maxMatches;
ServiceRegistrar proxy = proxys[(i + rand) % len];
try {
/* If a filter is to be applied (filter != null), then
* the value of the maxMatches parameter will not
* suffice when querying the current lookup service.
* This is because although services returned from a
* query of the lookup service will match the template,
* some of those services may get filtered out. Thus,
* asking for exactly maxMatches may result in fewer
* matching services than actually are contained in
* the lookup. Thus, all matching services are
* requested by passing in "infinity" for the maximum
* number of matches (Integer.MAX_VALUE).
*/
if(filter != null) max = Integer.MAX_VALUE;
/* Query the current lookup for matching service(s). */
ServiceMatches sm = proxy.lookup(tmpl, max);
int nItems = sm.items.length;
if(nItems == 0) continue;//no matches, query next lookup
/* Loop thru the matching services, randomly selecting
* each service, applying the filter if appropriate,
* and making sure the service has not already been