|
@@ -20,6 +20,7 @@ import com.google.common.collect.Sets; |
|
|
* When the rule is changed in Apollo, it will take effect in real time. |
|
|
* When the rule is changed in Apollo, it will take effect in real time. |
|
|
* |
|
|
* |
|
|
* @author Jason Song |
|
|
* @author Jason Song |
|
|
|
|
|
* @author Haojun Ren |
|
|
*/ |
|
|
*/ |
|
|
public class ApolloDataSource<T> extends AbstractDataSource<String, T> { |
|
|
public class ApolloDataSource<T> extends AbstractDataSource<String, T> { |
|
|
|
|
|
|
|
@@ -27,6 +28,8 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> { |
|
|
private final String flowRulesKey; |
|
|
private final String flowRulesKey; |
|
|
private final String defaultFlowRuleValue; |
|
|
private final String defaultFlowRuleValue; |
|
|
|
|
|
|
|
|
|
|
|
private ConfigChangeListener configChangeListener; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Constructs the Apollo data source |
|
|
* Constructs the Apollo data source |
|
|
* |
|
|
* |
|
@@ -72,7 +75,7 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void initializeConfigChangeListener() { |
|
|
private void initializeConfigChangeListener() { |
|
|
config.addChangeListener(new ConfigChangeListener() { |
|
|
|
|
|
|
|
|
configChangeListener = new ConfigChangeListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void onChange(ConfigChangeEvent changeEvent) { |
|
|
public void onChange(ConfigChangeEvent changeEvent) { |
|
|
ConfigChange change = changeEvent.getChange(flowRulesKey); |
|
|
ConfigChange change = changeEvent.getChange(flowRulesKey); |
|
@@ -82,7 +85,8 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> { |
|
|
} |
|
|
} |
|
|
loadAndUpdateRules(); |
|
|
loadAndUpdateRules(); |
|
|
} |
|
|
} |
|
|
}, Sets.newHashSet(flowRulesKey)); |
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
config.addChangeListener(configChangeListener, Sets.newHashSet(flowRulesKey)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@@ -92,6 +96,6 @@ public class ApolloDataSource<T> extends AbstractDataSource<String, T> { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void close() throws Exception { |
|
|
public void close() throws Exception { |
|
|
// nothing to destroy |
|
|
|
|
|
|
|
|
config.removeChangeListener(configChangeListener); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |