in config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java [44:110]
public void handle(ClusterConfigurationEvent event) {
// check if the handler is ON
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
LOGGER.debug("CELLAR CONFIG: {} switch is OFF, cluster event not handled", SWITCH_ID);
return;
}
if (groupManager == null) {
//in rare cases for example right after installation this happens!
LOGGER.error("CELLAR CONFIG: retrieved event {} while groupManager is not available yet!", event);
return;
}
// check if the group is local
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
LOGGER.debug("CELLAR CONFIG: node is not part of the event cluster group {}",event.getSourceGroup().getName());
return;
}
// check if it's not a "local" event
if (event.getLocal() != null && event.getLocal().getId().equalsIgnoreCase(clusterManager.getNode().getId())) {
LOGGER.trace("CELLAR CONFIG: cluster event is local (coming from local synchronizer or listener)");
return;
}
Group group = event.getSourceGroup();
String groupName = group.getName();
Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
String pid = event.getId();
if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) {
Dictionary clusterDictionary = clusterConfigurations.get(pid);
try {
// update the local configuration
Configuration localConfiguration = findLocalConfiguration(pid, clusterDictionary);
if (event.getType() != null && event.getType() == ConfigurationEvent.CM_DELETED) {
// delete the configuration
if (localConfiguration != null) {
deleteConfiguration(localConfiguration);
}
} else {
if (clusterDictionary != null && shouldReplicateConfig(clusterDictionary)) {
if (localConfiguration == null) {
// Create new configuration
localConfiguration = createLocalConfiguration(pid, clusterDictionary);
}
Dictionary localDictionary = localConfiguration.getProperties();
if (localDictionary == null)
localDictionary = new Properties();
localDictionary = filter(localDictionary);
if (!equals(clusterDictionary, localDictionary) && canDistributeConfig(localDictionary)) {
Dictionary convertedDictionary = convertPropertiesFromCluster(clusterDictionary);
localConfiguration.update(convertedDictionary);
persistConfiguration(localConfiguration, clusterDictionary);
}
}
}
} catch (Exception ex) {
LOGGER.error("CELLAR CONFIG: failed to read cluster configuration", ex);
}
} else LOGGER.trace("CELLAR CONFIG: configuration PID {} is marked BLOCKED INBOUND for cluster group {}", pid, groupName);
}