Rename DefaultClientConfig > DefaultGrpcClientConfig

This commit is contained in:
KomachiSion 2022-09-07 10:21:36 +08:00
parent fb71b4ccd9
commit 3d7bda84f7
4 changed files with 36 additions and 42 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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<String, String> 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<String, String> labels) {
this(DefaultGrpcClientConfig.newBuilder().setName(name).setThreadPoolCoreSize(threadPoolCoreSize)
.setThreadPoolMaxSize(threadPoolMaxSize).setLabels(labels).build());
}
protected ThreadPoolExecutor createGrpcExecutor(String serverIp) {

View File

@ -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() {