diff --git a/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java b/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java index ce19be225..9061d78eb 100644 --- a/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java +++ b/common/src/main/java/com/alibaba/nacos/common/remote/client/RpcClient.java @@ -32,6 +32,7 @@ import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.common.lifecycle.Closeable; import com.alibaba.nacos.common.remote.ConnectionType; import com.alibaba.nacos.common.remote.PayloadRegistry; +import com.alibaba.nacos.common.remote.client.grpc.DefaultGrpcClientConfig; import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.common.utils.LoggerUtils; import com.alibaba.nacos.common.utils.NumberUtils; @@ -103,7 +104,8 @@ public abstract class RpcClient implements Closeable { PayloadRegistry.init(); } - public RpcClient() { + public RpcClient(RpcClientConfig rpcClientConfig) { + this(rpcClientConfig, null); } public RpcClient(RpcClientConfig rpcClientConfig, ServerListFactory serverListFactory) { @@ -112,10 +114,6 @@ public abstract class RpcClient implements Closeable { init(); } - public RpcClient(RpcClientConfig rpcClientConfig) { - this(rpcClientConfig, null); - } - protected void init() { if (this.serverListFactory != null) { rpcClientStatus.compareAndSet(RpcClientStatus.WAIT_INIT, RpcClientStatus.INITIALIZED); diff --git a/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/DefaultClientConfig.java b/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/DefaultGrpcClientConfig.java similarity index 98% rename from common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/DefaultClientConfig.java rename to common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/DefaultGrpcClientConfig.java index 2ade084a3..60f943a25 100644 --- a/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/DefaultClientConfig.java +++ b/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/DefaultGrpcClientConfig.java @@ -28,7 +28,7 @@ import java.util.Properties; * * @author karsonto */ -public class DefaultClientConfig implements GrpcClientConfig { +public class DefaultGrpcClientConfig implements GrpcClientConfig { private String name; @@ -61,9 +61,9 @@ public class DefaultClientConfig implements GrpcClientConfig { /** * constructor. * - * @param builder builder of DefaultClientConfig builder. + * @param builder builder of DefaultGrpcClientConfig builder. */ - private DefaultClientConfig(Builder builder) { + private DefaultGrpcClientConfig(Builder builder) { this.name = builder.name; this.retryTimes = builder.retryTimes; this.timeOutMills = builder.timeOutMills; @@ -379,7 +379,7 @@ public class DefaultClientConfig implements GrpcClientConfig { * build GrpcClientConfig. */ public GrpcClientConfig build() { - return new DefaultClientConfig(this); + return new DefaultGrpcClientConfig(this); } } diff --git a/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java b/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java index 4c370e6e9..1ad446fd0 100644 --- a/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java +++ b/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java @@ -58,17 +58,35 @@ import java.util.concurrent.TimeUnit; @SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule") public abstract class GrpcClient extends RpcClient { - static final Logger LOGGER = LoggerFactory.getLogger(GrpcClient.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GrpcClient.class); - private ThreadPoolExecutor grpcExecutor = null; + private final GrpcClientConfig clientConfig; - private GrpcClientConfig clientConfig = null; + private ThreadPoolExecutor grpcExecutor; @Override public ConnectionType getConnectionType() { return ConnectionType.GRPC; } + /** + * constructor. + * + * @param name . + */ + public GrpcClient(String name) { + this(DefaultGrpcClientConfig.newBuilder().setName(name).build()); + } + + /** + * constructor. + * + * @param properties . + */ + public GrpcClient(Properties properties) { + this(DefaultGrpcClientConfig.newBuilder().fromProperties(properties).build()); + } + /** * constructor. * @@ -79,23 +97,6 @@ public abstract class GrpcClient extends RpcClient { this.clientConfig = clientConfig; } - /** - * constructor. - * - * @param name . - * @param threadPoolCoreSize . - * @param threadPoolMaxSize . - * @param labels . - */ - public GrpcClient(String name, Integer threadPoolCoreSize, Integer threadPoolMaxSize, Map labels) { - super(); - GrpcClientConfig config = DefaultClientConfig.newBuilder().setName(name).setThreadPoolCoreSize(threadPoolCoreSize) - .setThreadPoolMaxSize(threadPoolMaxSize).setLabels(labels).build(); - rpcClientConfig = config; - this.clientConfig = config; - init(); - } - /** * constructor. * @@ -110,19 +111,14 @@ public abstract class GrpcClient extends RpcClient { /** * constructor. * - * @param name . + * @param name . + * @param threadPoolCoreSize . + * @param threadPoolMaxSize . + * @param labels . */ - public GrpcClient(String name) { - this(DefaultClientConfig.newBuilder().setName(name).build()); - } - - /** - * constructor. - * - * @param properties . - */ - public GrpcClient(Properties properties) { - this(DefaultClientConfig.newBuilder().fromProperties(properties).build()); + public GrpcClient(String name, Integer threadPoolCoreSize, Integer threadPoolMaxSize, Map labels) { + this(DefaultGrpcClientConfig.newBuilder().setName(name).setThreadPoolCoreSize(threadPoolCoreSize) + .setThreadPoolMaxSize(threadPoolMaxSize).setLabels(labels).build()); } protected ThreadPoolExecutor createGrpcExecutor(String serverIp) { diff --git a/common/src/test/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClientTest.java b/common/src/test/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClientTest.java index 90855471a..8b67b574a 100644 --- a/common/src/test/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClientTest.java +++ b/common/src/test/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClientTest.java @@ -46,7 +46,7 @@ public class GrpcClientTest { @Before public void setUp() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - GrpcClientConfig clientConfig = DefaultClientConfig.newBuilder().setName("testClient").build(); + GrpcClientConfig clientConfig = DefaultGrpcClientConfig.newBuilder().setName("testClient").build(); grpcClient = spy(new GrpcClient(clientConfig) { @Override public int rpcPortOffset() {