in src/main/java/org/apache/sling/discovery/commons/providers/spi/base/IdMapService.java [260:299]
public synchronized String toSlingId(int clusterNodeId, ResourceResolver resourceResolver) throws PersistenceException {
if (System.currentTimeMillis() - lastCacheInvalidation > 30000) {
// since upon a restart of an instance it could opt to have changed
// the slingId, we might not be able to catch that change if we
// noticed the view change before that (the view change would
// force a cache invalidation).
// we can either rely on observation - or combine that with
// an invalidation of once per minute
// (note that this means we'll be reading
// /var/discovery/oak/idMap once per minute - but that sounds
// perfectly fine)
clearCache();
}
String slingId = idMapCache.get(clusterNodeId);
if (slingId!=null) {
// cache-hit
return slingId;
}
// cache-miss
logger.debug("toSlingId: cache miss, refreshing idmap cache");
Map<Integer, String> readMap = readIdMap(resourceResolver);
Set<Entry<Integer, String>> newEntries = readMap.entrySet();
for (Entry<Integer, String> newEntry : newEntries) {
String oldValue = oldIdMapCache.get(newEntry.getKey());
if (oldValue == null || !oldValue.equals(newEntry.getValue())) {
logger.info("toSlingId: mapping for "+newEntry.getKey()+" to "+newEntry.getValue() + " was newly added.");
} else if (!oldValue.equals(newEntry.getValue())) {
logger.info("toSlingId: mapping for "+newEntry.getKey()+" changed from "+oldValue+" to "+newEntry.getValue());
}
idMapCache.put(newEntry.getKey(), newEntry.getValue());
}
Set<Entry<Integer, String>> oldEntries = oldIdMapCache.entrySet();
for (Entry<Integer, String> oldEntry : oldEntries) {
if (!idMapCache.containsKey(oldEntry.getKey())) {
logger.info("toSlingId: mapping for "+oldEntry.getKey()+" to "+oldEntry.getValue()+" disappeared.");
}
}
return idMapCache.get(clusterNodeId);
}