refactor:let the configuration SDK context stand alone.

pull/1266/head
Haotian Zhang 1 year ago
parent e87a3b8723
commit 8f98bc3ebb

@ -56,7 +56,7 @@ public class PolarisSDKContextManager {
*/ */
public volatile static boolean isRegistered = false; public volatile static boolean isRegistered = false;
private volatile static SDKContext configSDKContext; private volatile static SDKContext configSDKContext;
private volatile static SDKContext sdkContext; private volatile static SDKContext serviceSdkContext;
private volatile static ProviderAPI providerAPI; private volatile static ProviderAPI providerAPI;
private volatile static ConsumerAPI consumerAPI; private volatile static ConsumerAPI consumerAPI;
private volatile static LosslessAPI losslessAPI; private volatile static LosslessAPI losslessAPI;
@ -78,7 +78,7 @@ public class PolarisSDKContextManager {
* Don't call this method directly. * Don't call this method directly.
*/ */
public static void innerDestroy() { public static void innerDestroy() {
if (Objects.nonNull(sdkContext)) { if (Objects.nonNull(serviceSdkContext)) {
try { try {
// destroy ProviderAPI // destroy ProviderAPI
if (Objects.nonNull(providerAPI)) { if (Objects.nonNull(providerAPI)) {
@ -122,9 +122,9 @@ public class PolarisSDKContextManager {
assemblyAPI = null; assemblyAPI = null;
} }
if (Objects.nonNull(sdkContext)) { if (Objects.nonNull(serviceSdkContext)) {
sdkContext.destroy(); serviceSdkContext.destroy();
sdkContext = null; serviceSdkContext = null;
} }
LOG.info("Polaris SDK context is destroyed."); LOG.info("Polaris SDK context is destroyed.");
} }
@ -158,34 +158,34 @@ public class PolarisSDKContextManager {
} }
public void init() { public void init() {
if (null == sdkContext) { if (null == serviceSdkContext) {
try { try {
// init SDKContext // init SDKContext
sdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList, serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(modifierList,
() -> environment.getProperty("spring.cloud.client.ip-address"), () -> environment.getProperty("spring.cloud.client.ip-address"),
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0))); () -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0)));
sdkContext.init(); serviceSdkContext.init();
// init ProviderAPI // init ProviderAPI
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(sdkContext); providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(serviceSdkContext);
// init losslessAPI // init losslessAPI
losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(sdkContext); losslessAPI = DiscoveryAPIFactory.createLosslessAPIByContext(serviceSdkContext);
// init ConsumerAPI // init ConsumerAPI
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(sdkContext); consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(serviceSdkContext);
// init RouterAPI // init RouterAPI
routerAPI = RouterAPIFactory.createRouterAPIByContext(sdkContext); routerAPI = RouterAPIFactory.createRouterAPIByContext(serviceSdkContext);
// init CircuitBreakAPI // init CircuitBreakAPI
circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(sdkContext); circuitBreakAPI = CircuitBreakAPIFactory.createCircuitBreakAPIByContext(serviceSdkContext);
// init LimitAPI // init LimitAPI
limitAPI = LimitAPIFactory.createLimitAPIByContext(sdkContext); limitAPI = LimitAPIFactory.createLimitAPIByContext(serviceSdkContext);
// init AssemblyAPI // init AssemblyAPI
assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(sdkContext); assemblyAPI = AssemblyAPIFactory.createAssemblyAPIByContext(serviceSdkContext);
// add shutdown hook // add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@ -226,7 +226,7 @@ public class PolarisSDKContextManager {
public SDKContext getSDKContext() { public SDKContext getSDKContext() {
init(); init();
return sdkContext; return serviceSdkContext;
} }
public ProviderAPI getProviderAPI() { public ProviderAPI getProviderAPI() {

Loading…
Cancel
Save