This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git

commit dc13103a1be367c53a0e8053fda0759bbd1a03d1
Author: liubao <bi...@qq.com>
AuthorDate: Mon Sep 4 19:42:53 2023 +0800

    [SCB-2008]change DynamicPropertyFactory to Environment: transport manager
---
 .../common/rest/TestRestEngineSchemaListener.java            |  7 +++++++
 .../common/rest/definition/TestRestOperationMeta.java        |  6 ++++++
 .../common/rest/locator/TestMicroservicePaths.java           |  6 ++++++
 .../common/rest/locator/TestServicePathManager.java          | 11 +++++++++++
 .../src/main/java/org/apache/servicecomb/core/SCBEngine.java | 12 ++++++------
 .../servicecomb/core/ServiceCombCoreConfiguration.java       |  6 ++++++
 .../src/main/java/org/apache/servicecomb/core/Transport.java |  4 ++++
 .../org/apache/servicecomb/core/bootstrap/SCBBootstrap.java  |  4 ++++
 .../apache/servicecomb/core/transport/AbstractTransport.java |  8 ++++++++
 .../apache/servicecomb/core/transport/TransportManager.java  | 10 ++++++++++
 .../test/java/org/apache/servicecomb/core/TestTransport.java |  5 +++++
 .../servicecomb/transport/rest/vertx/VertxRestTransport.java |  5 +----
 .../transport/rest/vertx/TestVertxRestTransport.java         |  8 ++++++++
 13 files changed, 82 insertions(+), 10 deletions(-)

diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
index 83175f18e..b0be818f6 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/TestRestEngineSchemaListener.java
@@ -27,12 +27,15 @@ import org.apache.servicecomb.config.ConfigUtil;
 import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
+import org.apache.servicecomb.core.executor.ExecutorManager;
+import org.apache.servicecomb.core.transport.TransportManager;
 import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 public class TestRestEngineSchemaListener {
   static SCBEngine scbEngine;
@@ -43,6 +46,10 @@ public class TestRestEngineSchemaListener {
   public static void setup() {
     ConfigUtil.installDynamicConfig();
     scbEngine = SCBBootstrap.createSCBEngineForTest();
+    ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
+    TransportManager transportManager = Mockito.mock(TransportManager.class);
+    scbEngine.setTransportManager(transportManager);
+    scbEngine.setExecutorManager(executorManager);
     List<BootListener> listeners = new ArrayList<>();
     listeners.add(new RestEngineSchemaListener());
     scbEngine.setBootListeners(listeners);
diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
index 911bf2c6f..f32638d3a 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/definition/TestRestOperationMeta.java
@@ -31,6 +31,8 @@ import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
 import org.apache.servicecomb.core.definition.OperationMeta;
 import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.apache.servicecomb.core.executor.ExecutorManager;
+import org.apache.servicecomb.core.transport.TransportManager;
 import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
 import org.hamcrest.MatcherAssert;
 import org.junit.jupiter.api.AfterAll;
@@ -165,6 +167,10 @@ public class TestRestOperationMeta {
   public static void classSetup() {
     ConfigUtil.installDynamicConfig();
     scbEngine = SCBBootstrap.createSCBEngineForTest();
+    ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
+    TransportManager transportManager = Mockito.mock(TransportManager.class);
+    scbEngine.setTransportManager(transportManager);
+    scbEngine.setExecutorManager(executorManager);
     List<BootListener> listeners = new ArrayList<>();
     listeners.add(new RestEngineSchemaListener());
     scbEngine.setBootListeners(listeners);
diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
index 2886f0091..705da565a 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestMicroservicePaths.java
@@ -26,6 +26,8 @@ import org.apache.servicecomb.config.ConfigUtil;
 import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
+import org.apache.servicecomb.core.executor.ExecutorManager;
+import org.apache.servicecomb.core.transport.TransportManager;
 import 
org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
 import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
 import org.junit.jupiter.api.AfterAll;
@@ -45,6 +47,10 @@ public class TestMicroservicePaths {
     scbEngine = SCBBootstrap.createSCBEngineForTest();
     List<BootListener> listeners = new ArrayList<>();
     listeners.add(new RestEngineSchemaListener());
+    ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
+    TransportManager transportManager = Mockito.mock(TransportManager.class);
+    scbEngine.setTransportManager(transportManager);
+    scbEngine.setExecutorManager(executorManager);
     scbEngine.setBootListeners(listeners);
     scbEngine.addProducerMeta("sid1", new TestPathSchema())
         .run();
diff --git 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
index 6c51a2c11..8efb5198e 100644
--- 
a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
+++ 
b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/locator/TestServicePathManager.java
@@ -25,6 +25,8 @@ import org.apache.servicecomb.config.ConfigUtil;
 import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.core.bootstrap.SCBBootstrap;
+import org.apache.servicecomb.core.executor.ExecutorManager;
+import org.apache.servicecomb.core.transport.TransportManager;
 import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
 import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils;
 import org.apache.servicecomb.registry.definition.DefinitionConst;
@@ -32,6 +34,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 public class TestServicePathManager {
   SCBEngine scbEngine;
@@ -51,6 +54,10 @@ public class TestServicePathManager {
   @Test
   public void testBuildProducerPathsNoPrefix() {
     scbEngine = SCBBootstrap.createSCBEngineForTest();
+    ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
+    TransportManager transportManager = Mockito.mock(TransportManager.class);
+    scbEngine.setTransportManager(transportManager);
+    scbEngine.setExecutorManager(executorManager);
     List<BootListener> listeners = new ArrayList<>();
     listeners.add(new RestEngineSchemaListener());
     scbEngine.setBootListeners(listeners);
@@ -68,6 +75,10 @@ public class TestServicePathManager {
   public void testBuildProducerPathsHasPrefix() {
     
ClassLoaderScopeContext.setClassLoaderScopeProperty(DefinitionConst.URL_PREFIX, 
"/root/rest");
     scbEngine = SCBBootstrap.createSCBEngineForTest();
+    ExecutorManager executorManager = Mockito.mock(ExecutorManager.class);
+    TransportManager transportManager = Mockito.mock(TransportManager.class);
+    scbEngine.setTransportManager(transportManager);
+    scbEngine.setExecutorManager(executorManager);
     List<BootListener> listeners = new ArrayList<>();
     listeners.add(new RestEngineSchemaListener());
     scbEngine.setBootListeners(listeners);
diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java 
b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index 8bd321728..3aebe8224 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -90,7 +90,7 @@ public class SCBEngine {
 
   private MicroserviceMeta producerMicroserviceMeta;
 
-  private TransportManager transportManager = new TransportManager();
+  private TransportManager transportManager;
 
   private List<BootListener> bootListeners;
 
@@ -187,6 +187,11 @@ public class SCBEngine {
     this.executorManager = executorManager;
   }
 
+  @Autowired
+  public void setTransportManager(TransportManager transportManager) {
+    this.transportManager = transportManager;
+  }
+
   public RegistrationManager getRegistrationManager() {
     return this.registrationManager;
   }
@@ -266,11 +271,6 @@ public class SCBEngine {
     return transportManager;
   }
 
-  public SCBEngine setTransportManager(TransportManager transportManager) {
-    this.transportManager = transportManager;
-    return this;
-  }
-
   public SwaggerEnvironment getSwaggerEnvironment() {
     return swaggerEnvironment;
   }
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
 
b/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
index 0963963a0..55338ea25 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/ServiceCombCoreConfiguration.java
@@ -23,6 +23,7 @@ import org.apache.servicecomb.core.executor.ExecutorManager;
 import org.apache.servicecomb.core.executor.GroupExecutor;
 import org.apache.servicecomb.core.provider.producer.ProducerBootListener;
 import org.apache.servicecomb.core.registry.discovery.SwaggerLoader;
+import org.apache.servicecomb.core.transport.TransportManager;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -80,4 +81,9 @@ public class ServiceCombCoreConfiguration {
     groupExecutor.init();
     return groupExecutor;
   }
+
+  @Bean
+  public TransportManager transportManager() {
+    return new TransportManager();
+  }
 }
diff --git a/core/src/main/java/org/apache/servicecomb/core/Transport.java 
b/core/src/main/java/org/apache/servicecomb/core/Transport.java
index b419d3d4c..4777a5ca0 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Transport.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Transport.java
@@ -17,6 +17,8 @@
 
 package org.apache.servicecomb.core;
 
+import org.springframework.core.env.Environment;
+
 // TODO:感觉要拆成显式的client、server才好些
 public interface Transport {
   String getName();
@@ -31,6 +33,8 @@ public interface Transport {
 
   boolean init() throws Exception;
 
+  void setEnvironment(Environment environment);
+
   /*
    * endpoint的格式为 URI,比如rest://192.168.1.1:8080
    */
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java 
b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
index 56c89f0cc..395760160 100644
--- a/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
+++ b/core/src/main/java/org/apache/servicecomb/core/bootstrap/SCBBootstrap.java
@@ -21,6 +21,8 @@ import java.util.List;
 
 import org.apache.servicecomb.config.MicroserviceProperties;
 import org.apache.servicecomb.core.SCBEngine;
+import org.apache.servicecomb.core.executor.ExecutorManager;
+import org.apache.servicecomb.core.transport.TransportManager;
 import org.apache.servicecomb.registry.DiscoveryManager;
 import org.apache.servicecomb.registry.RegistrationManager;
 import org.apache.servicecomb.registry.discovery.TelnetInstancePing;
@@ -43,6 +45,8 @@ public class SCBBootstrap {
     result.setBootListeners(Collections.emptyList());
     result.setMicroserviceProperties(microserviceProperties);
     result.setBootUpInformationCollectors(Collections.emptyList());
+    result.setExecutorManager(new ExecutorManager());
+    result.setTransportManager(new TransportManager());
     return result;
   }
 }
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
 
b/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
index 6cada1ba0..de9926fa8 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/transport/AbstractTransport.java
@@ -36,6 +36,7 @@ import 
org.apache.servicecomb.foundation.common.net.URIEndpointObject;
 import org.apache.servicecomb.foundation.vertx.SharedVertxFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.core.env.Environment;
 
 import com.netflix.config.DynamicPropertyFactory;
 
@@ -59,6 +60,8 @@ public abstract class AbstractTransport implements Transport {
 
   protected Endpoint publishEndpoint;
 
+  protected Environment environment;
+
   @Override
   public Endpoint getPublishEndpoint() {
     return publishEndpoint;
@@ -69,6 +72,11 @@ public abstract class AbstractTransport implements Transport 
{
     return endpoint;
   }
 
+  @Override
+  public void setEnvironment(Environment environment) {
+    this.environment = environment;
+  }
+
   protected void setListenAddressWithoutSchema(String addressWithoutSchema) {
     setListenAddressWithoutSchema(addressWithoutSchema, null);
   }
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/transport/TransportManager.java
 
b/core/src/main/java/org/apache/servicecomb/core/transport/TransportManager.java
index e644df55b..e957fbd75 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/transport/TransportManager.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/transport/TransportManager.java
@@ -31,6 +31,8 @@ import 
org.apache.servicecomb.foundation.common.exceptions.ServiceCombException;
 import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
 
 public class TransportManager {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(TransportManager.class);
@@ -43,6 +45,13 @@ public class TransportManager {
     return transportMap;
   }
 
+  private Environment environment;
+
+  @Autowired
+  public void setEnvironment(Environment environment) {
+    this.environment = environment;
+  }
+
   public void clearTransportBeforeInit() {
     transports.clear();
   }
@@ -59,6 +68,7 @@ public class TransportManager {
     buildTransportMap();
 
     for (Transport transport : transportMap.values()) {
+      transport.setEnvironment(environment);
       if (transport.init()) {
         Endpoint endpoint = transport.getPublishEndpoint();
         if (endpoint != null && endpoint.getEndpoint() != null) {
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java 
b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
index c31e42de4..4ab2f99ff 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.springframework.core.env.Environment;
 
 public class TestTransport {
   @BeforeAll
@@ -40,6 +41,10 @@ public class TestTransport {
         return "127.0.0.1";
       }
 
+      @Override
+      public void setEnvironment(Environment environment) {
+
+      }
       @Override
       public boolean init() {
         return true;
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
index 6f39e3c66..32b0c1fc1 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/VertxRestTransport.java
@@ -33,8 +33,6 @@ import 
org.apache.servicecomb.registry.definition.DefinitionConst;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.netflix.config.DynamicPropertyFactory;
-
 import io.vertx.core.DeploymentOptions;
 import io.vertx.core.VertxOptions;
 
@@ -53,8 +51,7 @@ public class VertxRestTransport extends AbstractTransport {
 
   @Override
   public boolean canInit() {
-    String pattern = DynamicPropertyFactory.getInstance()
-        .getStringProperty(VertxRestDispatcher.KEY_PATTERN, null).get();
+    String pattern = environment.getProperty(VertxRestDispatcher.KEY_PATTERN, 
String.class);
     String urlPrefix = null;
     if (pattern == null || pattern.length() <= 5) {
       setListenAddressWithoutSchema(TransportConfig.getAddress());
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
index 6a40287b7..8bec21af7 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestVertxRestTransport.java
@@ -23,6 +23,8 @@ import java.net.ServerSocket;
 import org.apache.servicecomb.foundation.vertx.VertxUtils;
 import org.junit.Test;
 import org.junit.jupiter.api.Assertions;
+import org.mockito.Mockito;
+import org.springframework.core.env.Environment;
 
 import io.vertx.core.AbstractVerticle;
 import io.vertx.core.DeploymentOptions;
@@ -85,6 +87,8 @@ public class TestVertxRestTransport {
     };
 
     VertxRestTransport transport = new VertxRestTransport();
+    Environment environment = Mockito.mock(Environment.class);
+    transport.setEnvironment(environment);
     Assertions.assertTrue(transport.canInit());
   }
 
@@ -101,6 +105,8 @@ public class TestVertxRestTransport {
     };
 
     VertxRestTransport transport = new VertxRestTransport();
+    Environment environment = Mockito.mock(Environment.class);
+    transport.setEnvironment(environment);
     Assertions.assertFalse(transport.canInit());
 
     ss.close();
@@ -120,6 +126,8 @@ public class TestVertxRestTransport {
     };
 
     VertxRestTransport transport = new VertxRestTransport();
+    Environment environment = Mockito.mock(Environment.class);
+    transport.setEnvironment(environment);
     Assertions.assertTrue(transport.canInit());
   }
 }

Reply via email to