{
logger.debug("RegistryService: Updating the " + regName + " registry");
}
int count = 0;
LocalRegistry registry = (LocalRegistry) get(regName);
Vector toDelete = new Vector();
Iterator i = registry.listEntryNames();
while (i.hasNext())
{
toDelete.add(i.next());
}
if (registry == null)
{
logger.error("RegistryService: Null " + name + " registry in refresh");
return;
}
// for each fragment...
Enumeration en = fragments.keys();
while (en.hasMoreElements())
{
String location = (String) en.nextElement();
RegistryFragment fragment = (RegistryFragment) fragments.get(location);
int fragCount = 0;
if (!fragment.hasChanged())
{
if (logger.isDebugEnabled())
{
logger.debug("RegistryService: Skipping fragment " + location);
}
//remove this fragment entries from the delete list
Vector entries = fragment.getEntries(regName);
i = entries.iterator();
while (i.hasNext())
{
toDelete.remove(((RegistryEntry) i.next()).getName());
}
continue;
}
//the fragment has some changes, iterate over its entries...
Vector entries = fragment.getEntries(regName);
//... if it has entries related to this regsistry,
if (entries != null)
{
// for all these entries
Enumeration en2 = entries.elements();
while (en2.hasMoreElements())
{
RegistryEntry entry = (RegistryEntry) en2.nextElement();
// update or add the entry in the registry
try
{
if (registry.hasEntry(entry.getName()))
{
if (registry.getEntry(entry.getName()).equals(entry))
{
if (logger.isDebugEnabled())
{
logger.debug("RegistryService: No changes to entry " + entry.getName());
}
}
else
{
if (logger.isDebugEnabled())
{
logger.debug("RegistryService: Updating entry " + entry.getName()
+ " of class " + entry.getClass() + " to registry " + name);
}
registry.setLocalEntry(entry);
// Initialize the entry index
this.entryIndex.put(entry.getName(), location);
++fragCount;
}
}
else
{
registry.addLocalEntry(entry);
// Initialize the entry index
this.entryIndex.put(entry.getName(), location);
++fragCount;
if (logger.isDebugEnabled())
{
logger.debug("RegistryService: Adding entry " + entry.getName() + " of class "
+ entry.getClass() + " to registry " + name);
}
}
}
catch (RegistryException e)
{
logger.error("RegistryService: RegistryException while adding " + entry.getName() + "from " + location, e);
}
//remove this entry from the delete list
toDelete.remove(entry.getName());
}
}
count += fragCount;
}
//now delete the entries not found in any fragment
i = toDelete.iterator();
while (i.hasNext())
{
String entryName = (String) i.next();
if (logger.isDebugEnabled())
{
logger.debug("RegistryService: removing entry " + entryName);
}
registry.removeLocalEntry(entryName);
}
if (logger.isDebugEnabled())
{