|
|
@ -158,57 +158,7 @@ public class PolarisSDKContextManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
public void init() {
|
|
|
|
if (null == serviceSdkContext) {
|
|
|
|
initService();
|
|
|
|
try {
|
|
|
|
|
|
|
|
// init SDKContext
|
|
|
|
|
|
|
|
serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList,
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.client.ip-address"),
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
|
|
|
|
|
|
|
|
serviceSdkContext.init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init ProviderAPI
|
|
|
|
|
|
|
|
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init losslessAPI
|
|
|
|
|
|
|
|
losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init ConsumerAPI
|
|
|
|
|
|
|
|
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init RouterAPI
|
|
|
|
|
|
|
|
routerAPI = RouterAPIFactory.createRouterAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init CircuitBreakAPI
|
|
|
|
|
|
|
|
circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init LimitAPI
|
|
|
|
|
|
|
|
limitAPI = LimitAPIFactory.createLimitAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init AssemblyAPI
|
|
|
|
|
|
|
|
assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add shutdown hook
|
|
|
|
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
|
|
|
|
|
long startTimestamp = System.currentTimeMillis();
|
|
|
|
|
|
|
|
long delay = 0;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
if (!isRegistered || delay >= 60000) {
|
|
|
|
|
|
|
|
innerDestroy();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
delay = System.currentTimeMillis() - startTimestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
LOG.info("create Polaris SDK context successfully. properties: {}, ", properties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable throwable) {
|
|
|
|
|
|
|
|
LOG.error("create Polaris SDK context failed. properties: {}, ", properties, throwable);
|
|
|
|
|
|
|
|
throw throwable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initConfig();
|
|
|
|
initConfig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -225,37 +175,37 @@ public class PolarisSDKContextManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SDKContext getSDKContext() {
|
|
|
|
public SDKContext getSDKContext() {
|
|
|
|
init();
|
|
|
|
initService();
|
|
|
|
return serviceSdkContext;
|
|
|
|
return serviceSdkContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ProviderAPI getProviderAPI() {
|
|
|
|
public ProviderAPI getProviderAPI() {
|
|
|
|
init();
|
|
|
|
initService();
|
|
|
|
return providerAPI;
|
|
|
|
return providerAPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LosslessAPI getLosslessAPI() {
|
|
|
|
public LosslessAPI getLosslessAPI() {
|
|
|
|
init();
|
|
|
|
initService();
|
|
|
|
return losslessAPI;
|
|
|
|
return losslessAPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ConsumerAPI getConsumerAPI() {
|
|
|
|
public ConsumerAPI getConsumerAPI() {
|
|
|
|
init();
|
|
|
|
initService();
|
|
|
|
return consumerAPI;
|
|
|
|
return consumerAPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RouterAPI getRouterAPI() {
|
|
|
|
public RouterAPI getRouterAPI() {
|
|
|
|
init();
|
|
|
|
initService();
|
|
|
|
return routerAPI;
|
|
|
|
return routerAPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public CircuitBreakAPI getCircuitBreakAPI() {
|
|
|
|
public CircuitBreakAPI getCircuitBreakAPI() {
|
|
|
|
init();
|
|
|
|
initService();
|
|
|
|
return circuitBreakAPI;
|
|
|
|
return circuitBreakAPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LimitAPI getLimitAPI() {
|
|
|
|
public LimitAPI getLimitAPI() {
|
|
|
|
init();
|
|
|
|
initService();
|
|
|
|
return limitAPI;
|
|
|
|
return limitAPI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -268,6 +218,59 @@ public class PolarisSDKContextManager {
|
|
|
|
return configSDKContext;
|
|
|
|
return configSDKContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void initService() {
|
|
|
|
|
|
|
|
if (null == serviceSdkContext) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// init SDKContext
|
|
|
|
|
|
|
|
serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList,
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.client.ip-address"),
|
|
|
|
|
|
|
|
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
|
|
|
|
|
|
|
|
serviceSdkContext.init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init ProviderAPI
|
|
|
|
|
|
|
|
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init losslessAPI
|
|
|
|
|
|
|
|
losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init ConsumerAPI
|
|
|
|
|
|
|
|
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init RouterAPI
|
|
|
|
|
|
|
|
routerAPI = RouterAPIFactory.createRouterAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init CircuitBreakAPI
|
|
|
|
|
|
|
|
circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init LimitAPI
|
|
|
|
|
|
|
|
limitAPI = LimitAPIFactory.createLimitAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init AssemblyAPI
|
|
|
|
|
|
|
|
assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(serviceSdkContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add shutdown hook
|
|
|
|
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
|
|
|
|
|
long startTimestamp = System.currentTimeMillis();
|
|
|
|
|
|
|
|
long delay = 0;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
if (!isRegistered || delay >= 60000) {
|
|
|
|
|
|
|
|
innerDestroy();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
delay = System.currentTimeMillis() - startTimestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
LOG.info("create Polaris SDK context successfully. properties: {}, ", properties);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable throwable) {
|
|
|
|
|
|
|
|
LOG.error("create Polaris SDK context failed. properties: {}, ", properties, throwable);
|
|
|
|
|
|
|
|
throw throwable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void initConfig() {
|
|
|
|
public void initConfig() {
|
|
|
|
// get modifiers for configuration.
|
|
|
|
// get modifiers for configuration.
|
|
|
|
List<PolarisConfigModifier> configModifierList = new ArrayList<>();
|
|
|
|
List<PolarisConfigModifier> configModifierList = new ArrayList<>();
|
|
|
|