Permalink
Browse files

[KARAF-1434] Introduce the karaf.cellar.sync property to broadcast cl…

…uster event depending of the origin

git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/trunk@1338040 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 57ab939 commit afa7b8a093628681251ac7ef0ef57c175fa7d986 @jbonofre jbonofre committed May 14, 2012
@@ -72,7 +72,7 @@ public void handle(RemoteConfigurationEvent event) {
conf.delete();
} else {
if (remoteDictionary != null) {
- Dictionary localDictionary = conf.getProperties();
+ remoteDictionary.put(Constants.SYNC_PROPERTY, new Long(System.currentTimeMillis()).toString());
conf.update(filter(remoteDictionary));
}
}
@@ -88,6 +88,7 @@ public void pull(Group group) {
try {
// update the local configuration if needed
Configuration conf = configurationAdmin.getConfiguration(pid);
+ remoteDictionary.put(Constants.SYNC_PROPERTY, new Long(System.currentTimeMillis()).toString());
conf.update(filter(remoteDictionary));
} catch (IOException ex) {
LOGGER.error("CELLAR CONFIG: failed to read distributed map", ex);
@@ -20,5 +20,6 @@
public static final String CATEGORY = "config";
public static final String CONFIGURATION_MAP = "org.apache.karaf.cellar.configuration.map";
+ public static final String SYNC_PROPERTY = "karaf.cellar.sync";
}
@@ -36,6 +36,8 @@
private static final transient Logger LOGGER = LoggerFactory.getLogger(LocalConfigurationListener.class);
+ private static final long SYNC_TIMEOUT = 200;
+
private EventProducer eventProducer;
/**
@@ -53,6 +55,22 @@ public void configurationEvent(ConfigurationEvent event) {
}
String pid = event.getPid();
+ Configuration conf = null;
+ try {
+ conf = configurationAdmin.getConfiguration(pid);
+ } catch (Exception e) {
+ LOGGER.error("CELLAR CONFIG: can't retrieve configuration with PID {}", pid, e);
+ return;
+ }
+
+ Dictionary localDictionary = conf.getProperties();
+ if (localDictionary.get(Constants.SYNC_PROPERTY) != null) {
+ Long syncTimestamp = new Long((String) localDictionary.get(Constants.SYNC_PROPERTY));
+ Long currentTimestamp = System.currentTimeMillis();
+ if ((currentTimestamp - syncTimestamp) <= SYNC_TIMEOUT) {
+ return;
+ }
+ }
Set<Group> groups = groupManager.listLocalGroups();
@@ -69,11 +87,14 @@ public void configurationEvent(ConfigurationEvent event) {
configurationTable.remove(pid);
// TODO broadcast the cluster event
} else {
- Configuration conf = configurationAdmin.getConfiguration(pid);
- Properties localDictionary = dictionaryToProperties(filter(conf.getProperties()));
+ //Configuration conf = configurationAdmin.getConfiguration(pid);
+ Properties localProperties = dictionaryToProperties(filter(localDictionary));
// update the distributed map
- configurationTable.put(pid, localDictionary);
- // TODO broadcast a cluster event but it creates a loop
+ configurationTable.put(pid, localProperties);
+ // broadcast the cluster event
+ RemoteConfigurationEvent remoteConfigurationEvent = new RemoteConfigurationEvent(pid);
+ remoteConfigurationEvent.setSourceGroup(group);
+ eventProducer.produce(remoteConfigurationEvent);
}
} catch (Exception e) {
LOGGER.error("CELLAR CONFIG: failed to push configuration with PID {} to the distributed map", pid, e);

0 comments on commit afa7b8a

Please sign in to comment.