synchronized (this) {
Iterator it = templates.iterator();
while (it.hasNext()) {
ServiceTemplate test = (ServiceTemplate) it.next();
LookupCache lookupCache = (LookupCache) serviceCaches.remove(test);
ServiceItem[] services = lookupCache.lookup(null,
Integer.MAX_VALUE);
Debug.printDebugInfo(10,
"Services to discard (array object) " + services);
for (int i = 0; i < services.length; i++) {
Debug.printDebugInfo(10,
"Discarding Service : " + services[i].service);
lookupCache.discard(services[i].service);
}
/* Terminating the cache should wait until the internal discardTask Thread
* gets the chance to send the events to the Listener. Wait a reasanble time.
*/
try {
Thread.sleep(JiniDriverImpl.WAIT_TIME_MS);
} catch (InterruptedException ex) {
}
lookupCache.terminate();
Debug.printDebugInfo(10,
"LookupCache " + lookupCache + " terminated");
}
}