You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ya...@apache.org on 2019/08/29 12:39:11 UTC

[servicecomb-java-chassis] 03/03: [SCB-1450] fix code review comments

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

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

commit 686395ad888414e0e4079892a03e0d7ea304e108
Author: Liu Huaizhou <li...@163.com>
AuthorDate: Mon Aug 26 16:52:03 2019 +0800

    [SCB-1450] fix code review comments
---
 .../client/http/AbstractClientPool.java            | 20 +++++-------------
 .../client/http/HttpClientPool.java                |  4 ++--
 .../client/http/WebsocketClientPool.java           |  2 +-
 .../config/ServiceRegistryConfig.java              | 24 ++++++++++++++++------
 4 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/AbstractClientPool.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/AbstractClientPool.java
index 846fea8..5992c05 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/AbstractClientPool.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/AbstractClientPool.java
@@ -41,17 +41,7 @@ import io.vertx.core.http.HttpClientOptions;
 public abstract class AbstractClientPool implements ClientPool {
   private static final Logger LOGGER = LoggerFactory.getLogger(AbstractClientPool.class);
 
-  protected static final String SSL_KEY = "sc.consumer";
-
-  public static final String PROXY_KEY = "sc.consumer";
-
-  private static final String EVENT_LOOP_POOL_SIZE = "servicecomb.service.registry.client.eventLoopPoolSize";
-
-  private static final String WORKER_POOL_SIZE = "servicecomb.service.registry.client.workerPoolSize";
-
-  private static final String WORKER_POOL_NAME = "registry-vert.x-worker-thread";
-
-  private ClientPoolManager<HttpClientWithContext> clientMgr;
+    private ClientPoolManager<HttpClientWithContext> clientMgr;
 
   public AbstractClientPool() {
     create();
@@ -64,12 +54,12 @@ public abstract class AbstractClientPool implements ClientPool {
   }
 
   public void create() {
-    DynamicIntProperty property = DynamicPropertyFactory.getInstance().getIntProperty(EVENT_LOOP_POOL_SIZE, 4);
-    DynamicIntProperty workerPoolSize = DynamicPropertyFactory.getInstance().getIntProperty(WORKER_POOL_SIZE, 4);
+    DynamicIntProperty property = DynamicPropertyFactory.getInstance().getIntProperty(ServiceRegistryConfig.EVENT_LOOP_POOL_SIZE, 4);
+    DynamicIntProperty workerPoolSize = DynamicPropertyFactory.getInstance().getIntProperty(ServiceRegistryConfig.WORKER_POOL_SIZE, 4);
 
     // 这里面是同步接口,且好像直接在事件线程中用,保险起见,先使用独立的vertx实例
     VertxOptions vertxOptions = new VertxOptions()
-            .setAddressResolverOptions(AddressResolverConfig.getAddressResover(SSL_KEY))
+            .setAddressResolverOptions(AddressResolverConfig.getAddressResover(ServiceRegistryConfig.SSL_KEY))
             .setEventLoopPoolSize(property.get());
     Vertx vertx = VertxUtils.getOrCreateVertxByName("registry", vertxOptions);
     HttpClientOptions httpClientOptions = createHttpClientOptions();
@@ -78,7 +68,7 @@ public abstract class AbstractClientPool implements ClientPool {
     DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(this.clientMgr,
             ServiceRegistryConfig.INSTANCE.getInstances())
             .setWorker(isWorker())
-            .setWorkerPoolName(WORKER_POOL_NAME)
+            .setWorkerPoolName(ServiceRegistryConfig.WORKER_POOL_NAME)
             .setWorkerPoolSize(workerPoolSize.get());
     try {
       VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions);
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/HttpClientPool.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/HttpClientPool.java
index 71b400b..a313669 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/HttpClientPool.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/HttpClientPool.java
@@ -56,7 +56,7 @@ public final class HttpClientPool extends AbstractClientPool {
       proxy.setHost(ServiceRegistryConfig.INSTANCE.getProxyHost());
       proxy.setPort(ServiceRegistryConfig.INSTANCE.getProxyPort());
       proxy.setUsername(ServiceRegistryConfig.INSTANCE.getProxyUsername());
-      proxy.setPassword(Encryptions.decode(ServiceRegistryConfig.INSTANCE.getProxyPasswd(), PROXY_KEY));
+      proxy.setPassword(Encryptions.decode(ServiceRegistryConfig.INSTANCE.getProxyPasswd(), ServiceRegistryConfig.PROXY_KEY));
       httpClientOptions.setProxyOptions(proxy);
     }
     if (ver == HttpVersion.HTTP_2) {
@@ -65,7 +65,7 @@ public final class HttpClientPool extends AbstractClientPool {
     }
     if (ServiceRegistryConfig.INSTANCE.isSsl()) {
       LOGGER.debug("service center client performs requests over TLS");
-      VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions);
+      VertxTLSBuilder.buildHttpClientOptions(ServiceRegistryConfig.SSL_KEY, httpClientOptions);
     }
     return httpClientOptions;
   }
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/WebsocketClientPool.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/WebsocketClientPool.java
index 3242043..2c96f5b 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/WebsocketClientPool.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/WebsocketClientPool.java
@@ -55,7 +55,7 @@ public final class WebsocketClientPool extends AbstractClientPool {
     }
     if (ServiceRegistryConfig.INSTANCE.isSsl()) {
       LOGGER.debug("service center ws client performs requests over TLS");
-      VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions);
+      VertxTLSBuilder.buildHttpClientOptions(ServiceRegistryConfig.SSL_KEY, httpClientOptions);
     }
     return httpClientOptions;
   }
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
index 13a19e9..dc5847a 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/config/ServiceRegistryConfig.java
@@ -87,6 +87,18 @@ public final class ServiceRegistryConfig {
 
   public static final String PROXY_PASSWD = PROXY_PRE_NAME + "passwd";
 
+  public static final String SSL_KEY = "sc.consumer";
+
+  public static final String PROXY_KEY = "sc.consumer";
+
+  public static final String VERTICLE_INSTANCES = "servicecomb.service.registry.client.instances";
+
+  public static final String EVENT_LOOP_POOL_SIZE = "servicecomb.service.registry.client.eventLoopPoolSize";
+
+  public static final String WORKER_POOL_SIZE = "servicecomb.service.registry.client.workerPoolSize";
+
+  public static final String WORKER_POOL_NAME = "registry-vert.x-worker-thread";
+
   private ServiceRegistryConfig() {
 
   }
@@ -110,16 +122,15 @@ public final class ServiceRegistryConfig {
   }
 
   public int getInstances() {
-    String instances = "servicecomb.service.registry.client.instances ";
     DynamicIntProperty property =
-            DynamicPropertyFactory.getInstance()
-                    .getIntProperty(instances, 1);
+        DynamicPropertyFactory.getInstance()
+            .getIntProperty(VERTICLE_INSTANCES, 1);
     int deployInstances = property.get();
     if (deployInstances <= 0) {
       int nAvailableProcessors = Runtime.getRuntime().availableProcessors();
       LOGGER.warn("The property `{}` must be positive integer, fallback to use number of available processors: {}",
-              instances,
-              nAvailableProcessors);
+          VERTICLE_INSTANCES,
+          nAvailableProcessors);
       return nAvailableProcessors;
     }
     return deployInstances;
@@ -132,7 +143,8 @@ public final class ServiceRegistryConfig {
   }
 
   public ArrayList<IpPort> getIpPort() {
-    List<String> uriList = Deployment.getSystemBootStrapInfo(DeploymentProvider.SYSTEM_KEY_SERVICE_CENTER).getAccessURL();
+    List<String> uriList = Deployment.getSystemBootStrapInfo(DeploymentProvider.SYSTEM_KEY_SERVICE_CENTER)
+        .getAccessURL();
     ArrayList<IpPort> ipPortList = new ArrayList<>();
     uriList.forEach(anUriList -> {
       try {