Commit 7168ec64 by Jason Song Committed by GitHub

Merge pull request #268 from nobodyiam/refactor-demo

refactor demo
parents 5021009a 3a71a4e8
...@@ -14,20 +14,19 @@ import java.io.InputStreamReader; ...@@ -14,20 +14,19 @@ import java.io.InputStreamReader;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
public class ApolloConfigDemo implements ConfigChangeListener { public class ApolloConfigDemo {
private static final Logger logger = LoggerFactory.getLogger(ApolloConfigDemo.class); private static final Logger logger = LoggerFactory.getLogger(ApolloConfigDemo.class);
private Config config; private Config config;
public ApolloConfigDemo() { public ApolloConfigDemo() {
config = ConfigService.getAppConfig(); config = ConfigService.getAppConfig();
config.addChangeListener(this);
config.addChangeListener(new ConfigChangeListener() { config.addChangeListener(new ConfigChangeListener() {
@Override @Override
public void onChange(ConfigChangeEvent changeEvent) { public void onChange(ConfigChangeEvent changeEvent) {
logger.info("Changes2 for namespace {}", changeEvent.getNamespace()); logger.info("Changes for namespace {}", changeEvent.getNamespace());
for (String key : changeEvent.changedKeys()) { for (String key : changeEvent.changedKeys()) {
ConfigChange change = changeEvent.getChange(key); ConfigChange change = changeEvent.getChange(key);
logger.info("Change2 - key: {}, oldValue: {}, newValue: {}, changeType: {}", logger.info("Change - key: {}, oldValue: {}, newValue: {}, changeType: {}",
change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getPropertyName(), change.getOldValue(), change.getNewValue(),
change.getChangeType()); change.getChangeType());
} }
...@@ -58,15 +57,4 @@ public class ApolloConfigDemo implements ConfigChangeListener { ...@@ -58,15 +57,4 @@ public class ApolloConfigDemo implements ConfigChangeListener {
apolloConfigDemo.getConfig(input); apolloConfigDemo.getConfig(input);
} }
} }
@Override
public void onChange(ConfigChangeEvent changeEvent) {
logger.info("Changes for namespace {}", changeEvent.getNamespace());
for (String key : changeEvent.changedKeys()) {
ConfigChange change = changeEvent.getChange(key);
logger.info("Change - key: {}, oldValue: {}, newValue: {}, changeType: {}",
change.getPropertyName(), change.getOldValue(), change.getNewValue(),
change.getChangeType());
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment