in src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java [481:565]
private void doUpdateProperties() {
// SLING-5382 : the caller must ensure that this method
// is not invoked after deactivation or before activation.
// so this method doesn't have to do any further synchronization.
// what we do nevertheless is a paranoia way of checking if
// all variables are available and do a NOOP if that's not the case.
final ResourceResolverFactory rrf = resourceResolverFactory;
final Config c = config;
final String sid = slingId;
if (rrf == null || c == null || sid == null) {
// cannot update the properties then..
logger.debug("doUpdateProperties: too early to update the properties. "
+ "resourceResolverFactory ({}), config ({}) or slingId ({}) not yet set.",
new Object[]{rrf, c, sid});
return;
} else {
logger.debug("doUpdateProperties: updating properties now..");
}
final Map<String, String> newProps = new HashMap<>();
for (final ProviderInfo info : this.providerInfos) {
info.refreshProperties();
newProps.putAll(info.properties);
}
ResourceResolver resourceResolver = null;
try {
resourceResolver = rrf.getServiceResourceResolver(null);
Resource myInstance = ResourceHelper
.getOrCreateResource(resourceResolver, c.getClusterInstancesPath() + "/" + sid + "/properties");
// SLING-2879 - revert/refresh resourceResolver here to work
// around a potential issue with jackrabbit in a clustered environment
resourceResolver.revert();
resourceResolver.refresh();
final ModifiableValueMap myInstanceMap = myInstance.adaptTo(ModifiableValueMap.class);
final Set<String> keys = new HashSet<String>(myInstanceMap.keySet());
for (final String key : keys) {
if (newProps.containsKey(key)) {
// perfect
continue;
} else if (key.indexOf(":") != -1) {
// ignore
continue;
} else {
// remove
myInstanceMap.remove(key);
}
}
boolean anyChanges = false;
for (final Entry<String, String> entry : newProps.entrySet()) {
Object existingValue = myInstanceMap.get(entry.getKey());
if (entry.getValue().equals(existingValue)) {
// SLING-3389: dont rewrite the properties if nothing changed!
if (logger.isDebugEnabled()) {
logger.debug("doUpdateProperties: unchanged: {}={}", entry.getKey(), entry.getValue());
}
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("doUpdateProperties: changed: {}={}", entry.getKey(), entry.getValue());
}
anyChanges = true;
myInstanceMap.put(entry.getKey(), entry.getValue());
}
if (anyChanges) {
resourceResolver.commit();
}
} catch (LoginException e) {
logger.error("handleEvent: could not log in administratively: " + e, e);
throw new RuntimeException("Could not log in to repository (" + e + ")", e);
} catch (PersistenceException e) {
logger.error("handleEvent: got a PersistenceException: " + e, e);
throw new RuntimeException( "Exception while talking to repository (" + e + ")", e);
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
logger.debug("doUpdateProperties: updating properties done.");
}