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.lifecycle.Closeable;
import com.alibaba.nacos.common.remote.ConnectionType; import com.alibaba.nacos.common.remote.ConnectionType;
import com.alibaba.nacos.common.remote.PayloadRegistry; 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.CollectionUtils;
import com.alibaba.nacos.common.utils.LoggerUtils; import com.alibaba.nacos.common.utils.LoggerUtils;
import com.alibaba.nacos.common.utils.NumberUtils; import com.alibaba.nacos.common.utils.NumberUtils;
@ -103,7 +104,8 @@ public abstract class RpcClient implements Closeable {
PayloadRegistry.init(); PayloadRegistry.init();
} }
public RpcClient() { public RpcClient(RpcClientConfig rpcClientConfig) {
this(rpcClientConfig, null);
} }
public RpcClient(RpcClientConfig rpcClientConfig, ServerListFactory serverListFactory) { public RpcClient(RpcClientConfig rpcClientConfig, ServerListFactory serverListFactory) {
@ -112,10 +114,6 @@ public abstract class RpcClient implements Closeable {
init(); init();
} }
public RpcClient(RpcClientConfig rpcClientConfig) {
this(rpcClientConfig, null);
}
protected void init() { protected void init() {
if (this.serverListFactory != null) { if (this.serverListFactory != null) {
rpcClientStatus.compareAndSet(RpcClientStatus.WAIT_INIT, RpcClientStatus.INITIALIZED); rpcClientStatus.compareAndSet(RpcClientStatus.WAIT_INIT, RpcClientStatus.INITIALIZED);

View File

@ -28,7 +28,7 @@ import java.util.Properties;
* *
* @author karsonto * @author karsonto
*/ */
public class DefaultClientConfig implements GrpcClientConfig { public class DefaultGrpcClientConfig implements GrpcClientConfig {
private String name; private String name;
@ -61,9 +61,9 @@ public class DefaultClientConfig implements GrpcClientConfig {
/** /**
* constructor. * 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.name = builder.name;
this.retryTimes = builder.retryTimes; this.retryTimes = builder.retryTimes;
this.timeOutMills = builder.timeOutMills; this.timeOutMills = builder.timeOutMills;
@ -379,7 +379,7 @@ public class DefaultClientConfig implements GrpcClientConfig {
* build GrpcClientConfig. * build GrpcClientConfig.
*/ */
public GrpcClientConfig build() { 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") @SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
public abstract class GrpcClient extends RpcClient { 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 @Override
public ConnectionType getConnectionType() { public ConnectionType getConnectionType() {
return ConnectionType.GRPC; 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. * constructor.
* *
@ -79,23 +97,6 @@ public abstract class GrpcClient extends RpcClient {
this.clientConfig = clientConfig; 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. * constructor.
* *
@ -111,18 +112,13 @@ public abstract class GrpcClient extends RpcClient {
* constructor. * constructor.
* *
* @param name . * @param name .
* @param threadPoolCoreSize .
* @param threadPoolMaxSize .
* @param labels .
*/ */
public GrpcClient(String name) { public GrpcClient(String name, Integer threadPoolCoreSize, Integer threadPoolMaxSize, Map<String, String> labels) {
this(DefaultClientConfig.newBuilder().setName(name).build()); this(DefaultGrpcClientConfig.newBuilder().setName(name).setThreadPoolCoreSize(threadPoolCoreSize)
} .setThreadPoolMaxSize(threadPoolMaxSize).setLabels(labels).build());
/**
* constructor.
*
* @param properties .
*/
public GrpcClient(Properties properties) {
this(DefaultClientConfig.newBuilder().fromProperties(properties).build());
} }
protected ThreadPoolExecutor createGrpcExecutor(String serverIp) { protected ThreadPoolExecutor createGrpcExecutor(String serverIp) {

View File

@ -46,7 +46,7 @@ public class GrpcClientTest {
@Before @Before
public void setUp() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { 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) { grpcClient = spy(new GrpcClient(clientConfig) {
@Override @Override
public int rpcPortOffset() { public int rpcPortOffset() {