This commit is contained in:
parent
a763f8a8bb
commit
57aedb8017
|
|
@ -64,12 +64,12 @@ public abstract class ConfigWatcherRegister implements DynamicConfigurationServi
|
|||
logger.info("Current configurations after the bootstrap sync." + LINE_SEPARATOR + register.toString());
|
||||
|
||||
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(
|
||||
new RunnableWithExceptionProtection(() -> configSync(),
|
||||
new RunnableWithExceptionProtection(this::configSync,
|
||||
t -> logger.error("Sync config center error.", t)), syncPeriod, syncPeriod, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
void configSync() {
|
||||
ConfigTable configTable = readConfig();
|
||||
ConfigTable configTable = readConfig(register.keys());
|
||||
|
||||
configTable.getItems().forEach(item -> {
|
||||
String itemName = item.getName();
|
||||
|
|
@ -99,7 +99,7 @@ public abstract class ConfigWatcherRegister implements DynamicConfigurationServi
|
|||
logger.trace("Current configurations after the sync." + LINE_SEPARATOR + register.toString());
|
||||
}
|
||||
|
||||
public abstract ConfigTable readConfig();
|
||||
public abstract ConfigTable readConfig(Set<String> keys);
|
||||
|
||||
public class Register {
|
||||
private Map<String, WatcherHolder> register = new HashMap<>();
|
||||
|
|
@ -116,6 +116,10 @@ public abstract class ConfigWatcherRegister implements DynamicConfigurationServi
|
|||
return register.get(name);
|
||||
}
|
||||
|
||||
public Set<String> keys() {
|
||||
return register.keySet();
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
StringBuilder registerTableDescription = new StringBuilder();
|
||||
registerTableDescription.append("Following dynamic config items are available.").append(LINE_SEPARATOR);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import org.apache.skywalking.oap.server.library.module.*;
|
|||
import org.junit.*;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
|
|
@ -80,7 +82,7 @@ public class ConfigWatcherRegisterTest {
|
|||
|
||||
public static class MockConfigWatcherRegister extends ConfigWatcherRegister {
|
||||
|
||||
@Override public ConfigTable readConfig() {
|
||||
@Override public ConfigTable readConfig(Set<String> keys) {
|
||||
ConfigTable.ConfigItem item1 = new ConfigTable.ConfigItem("module.provider.prop1", "abc");
|
||||
ConfigTable.ConfigItem item2 = new ConfigTable.ConfigItem("MockModule.provider.prop2", "abc2");
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import org.apache.skywalking.oap.server.configuration.api.*;
|
|||
import org.apache.skywalking.oap.server.configuration.service.*;
|
||||
import org.slf4j.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author wusheng
|
||||
*/
|
||||
|
|
@ -38,12 +40,15 @@ public class GRPCConfigWatcherRegister extends ConfigWatcherRegister {
|
|||
stub = ConfigurationServiceGrpc.newBlockingStub(NettyChannelBuilder.forAddress(settings.getHost(), settings.getPort()).usePlaintext().build());
|
||||
}
|
||||
|
||||
@Override public ConfigTable readConfig() {
|
||||
@Override public ConfigTable readConfig(Set<String> keys) {
|
||||
ConfigTable table = new ConfigTable();
|
||||
try {
|
||||
ConfigurationResponse response = stub.call(ConfigurationRequest.newBuilder().setClusterName(settings.getClusterName()).build());
|
||||
response.getConfigTableList().forEach(config -> {
|
||||
table.add(new ConfigTable.ConfigItem(config.getName(), config.getValue()));
|
||||
final String name = config.getName();
|
||||
if (keys.contains(name)) {
|
||||
table.add(new ConfigTable.ConfigItem(name, config.getValue()));
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("Remote config center [" + settings + "] is not available.", e);
|
||||
|
|
|
|||
Loading…
Reference in New Issue