From b6113f7c414884590549c28d8d183db96123f7b0 Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Tue, 15 Aug 2023 17:42:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:provider=E6=94=AF=E6=8C=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AESDKContext=20(#48)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../provider/src/main/resources/polaris.yml | 2 +- .../client/PolarisManagedChannelBuilder.java | 21 +++++++++++++++++++ .../grpc/loadbalance/PolarisPicker.java | 3 --- .../polaris/grpc/server/GraceOffline.java | 7 ++++++- .../grpc/server/PolarisGrpcServer.java | 4 +++- .../grpc/server/PolarisGrpcServerBuilder.java | 19 +++++++++++++++-- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/grpc-java-polaris-examples/quickstart-example/provider/src/main/resources/polaris.yml b/grpc-java-polaris-examples/quickstart-example/provider/src/main/resources/polaris.yml index 3432e5f..f360118 100644 --- a/grpc-java-polaris-examples/quickstart-example/provider/src/main/resources/polaris.yml +++ b/grpc-java-polaris-examples/quickstart-example/provider/src/main/resources/polaris.yml @@ -1,7 +1,7 @@ global: serverConnector: addresses: - - 127.0.0.1:8091 + - 119.91.66.223:8091 statReporter: enable: true plugin: diff --git a/grpc-java-polaris/src/main/java/com/tencent/polaris/grpc/client/PolarisManagedChannelBuilder.java b/grpc-java-polaris/src/main/java/com/tencent/polaris/grpc/client/PolarisManagedChannelBuilder.java index 66bad9f..c99c10a 100644 --- a/grpc-java-polaris/src/main/java/com/tencent/polaris/grpc/client/PolarisManagedChannelBuilder.java +++ b/grpc-java-polaris/src/main/java/com/tencent/polaris/grpc/client/PolarisManagedChannelBuilder.java @@ -66,14 +66,35 @@ public class PolarisManagedChannelBuilder extends ManagedChannelBuilder interceptors = new ArrayList<>(); - private final SDKContext context = SDKContext.initContext(); + private SDKContext context; /** * Static factory for creating a new PolarisGrpcServerBuilder. @@ -98,6 +99,17 @@ public static PolarisGrpcServerBuilder forPort(int port) { public PolarisGrpcServerBuilder(ServerBuilder builder) { this.builder = builder; } + + /** + * Set polaris SDK Context + * + * @param context polaris sdk core object + * @return PolarisGrpcServerBuilder + */ + public PolarisGrpcServerBuilder sdkContext(SDKContext context) { + this.context = context; + return this; + } /** * Set grpc service name. @@ -136,7 +148,7 @@ public PolarisGrpcServerBuilder metadata(Map metadata) { * set instance weight * * @param weight - * @return + * @return PolarisGrpcServerBuilder */ public PolarisGrpcServerBuilder weight(int weight) { this.weight = weight; @@ -290,6 +302,9 @@ public Server build() { } private void setDefault() { + if (Objects.isNull(context)) { + context = SDKContext.initContext(); + } if (StringUtils.isBlank(namespace)) { this.namespace = DEFAULT_NAMESPACE; }