|
|
@ -145,12 +145,17 @@ public class PolarisSDKContextManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void innerConfigDestroy() {
|
|
|
|
public static void innerConfigDestroy() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (Objects.nonNull(configSDKContext)) {
|
|
|
|
if (Objects.nonNull(configSDKContext)) {
|
|
|
|
configSDKContext.destroy();
|
|
|
|
configSDKContext.destroy();
|
|
|
|
configSDKContext = null;
|
|
|
|
configSDKContext = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG.info("Polaris SDK config context is destroyed.");
|
|
|
|
LOG.info("Polaris SDK config context is destroyed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable throwable) {
|
|
|
|
|
|
|
|
LOG.info("Polaris SDK config context is destroyed failed.", throwable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
public void init() {
|
|
|
|
if (null == sdkContext) {
|
|
|
|
if (null == sdkContext) {
|
|
|
@ -207,42 +212,15 @@ public class PolarisSDKContextManager {
|
|
|
|
initConfig();
|
|
|
|
initConfig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void initConfig() {
|
|
|
|
/**
|
|
|
|
// get modifiers for configuration.
|
|
|
|
* Used for config data.
|
|
|
|
List<PolarisConfigModifier> configModifierList = new ArrayList<>();
|
|
|
|
*/
|
|
|
|
for (PolarisConfigModifier modifier : modifierList) {
|
|
|
|
public static void setConfigSDKContext(SDKContext context) {
|
|
|
|
if (modifier instanceof PolarisConfigurationConfigModifier) {
|
|
|
|
if (configSDKContext == null) {
|
|
|
|
configModifierList.add(modifier);
|
|
|
|
configSDKContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null == configSDKContext && CollectionUtils.isNotEmpty(configModifierList)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// init config SDKContext
|
|
|
|
|
|
|
|
configSDKContext = SDKContext.initContextByConfig(properties.configuration(configModifierList,
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.client.ip-address"),
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
|
|
|
|
|
|
|
|
configSDKContext.init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add shutdown hook
|
|
|
|
// add shutdown hook
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(PolarisSDKContextManager::innerConfigDestroy));
|
|
|
|
long startTimestamp = System.currentTimeMillis();
|
|
|
|
LOG.info("create Polaris config SDK context successfully.");
|
|
|
|
long delay = 0;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
if (delay >= 10000) {
|
|
|
|
|
|
|
|
innerConfigDestroy();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
delay = System.currentTimeMillis() - startTimestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
LOG.info("create Polaris config SDK context successfully. properties: {}, ", properties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable throwable) {
|
|
|
|
|
|
|
|
LOG.error("create Polaris config SDK context failed. properties: {}, ", properties, throwable);
|
|
|
|
|
|
|
|
throw throwable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -290,27 +268,30 @@ public class PolarisSDKContextManager {
|
|
|
|
return configSDKContext;
|
|
|
|
return configSDKContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
public void initConfig() {
|
|
|
|
* Used for config data.
|
|
|
|
// get modifiers for configuration.
|
|
|
|
*/
|
|
|
|
List<PolarisConfigModifier> configModifierList = new ArrayList<>();
|
|
|
|
public static void setConfigSDKContext(SDKContext context) {
|
|
|
|
for (PolarisConfigModifier modifier : modifierList) {
|
|
|
|
if (configSDKContext == null) {
|
|
|
|
if (modifier instanceof PolarisConfigurationConfigModifier) {
|
|
|
|
configSDKContext = context;
|
|
|
|
configModifierList.add(modifier);
|
|
|
|
// add shutdown hook
|
|
|
|
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
|
|
|
|
|
long startTimestamp = System.currentTimeMillis();
|
|
|
|
|
|
|
|
long delay = 0;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
if (delay >= 10000) {
|
|
|
|
|
|
|
|
innerConfigDestroy();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
delay = System.currentTimeMillis() - startTimestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null == configSDKContext && CollectionUtils.isNotEmpty(configModifierList)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// init config SDKContext
|
|
|
|
|
|
|
|
configSDKContext = SDKContext.initContextByConfig(properties.configuration(configModifierList,
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.client.ip-address"),
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
|
|
|
|
|
|
|
|
configSDKContext.init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add shutdown hook
|
|
|
|
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(PolarisSDKContextManager::innerConfigDestroy));
|
|
|
|
|
|
|
|
LOG.info("create Polaris config SDK context successfully. properties: {}, ", properties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable throwable) {
|
|
|
|
|
|
|
|
LOG.error("create Polaris config SDK context failed. properties: {}, ", properties, throwable);
|
|
|
|
|
|
|
|
throw throwable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
LOG.info("create Polaris config SDK context successfully.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|