-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,6 @@ | |
package com.tencent.polaris.grpc.client; | ||
|
||
|
||
import static com.tencent.polaris.grpc.loadbalance.PolarisLoadBalancerProvider.LOADBALANCER_PROVIDER; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.tencent.polaris.api.pojo.ServiceKey; | ||
import com.tencent.polaris.client.api.SDKContext; | ||
|
@@ -34,7 +32,9 @@ | |
import io.grpc.ManagedChannelBuilder; | ||
import io.grpc.NameResolver.Factory; | ||
import io.grpc.ProxyDetector; | ||
import shade.polaris.com.google.gson.Gson; | ||
|
||
import javax.annotation.Nullable; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
|
@@ -44,9 +44,8 @@ | |
import java.util.concurrent.Executor; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import javax.annotation.Nullable; | ||
|
||
import shade.polaris.com.google.gson.Gson; | ||
import static com.tencent.polaris.grpc.loadbalance.PolarisLoadBalancerProvider.LOADBALANCER_PROVIDER; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">liaochuntao</a> | ||
|
@@ -79,7 +78,7 @@ public static PolarisManagedChannelBuilder forTarget(String target) { | |
/** | ||
* 增强 {@link ManagedChannelBuilder#forTarget(String)}, 在连接到目标服务时允许设置主调服务的相关信息 | ||
* | ||
* @param target 服务名 | ||
* @param target 服务名 | ||
* @param sourceService {@link ServiceKey} 主调服务信息以及标签 | ||
* @return {@link PolarisManagedChannelBuilder} | ||
*/ | ||
|
@@ -90,9 +89,9 @@ public static PolarisManagedChannelBuilder forTarget(String target, ServiceKey s | |
/** | ||
* 增强 {@link ManagedChannelBuilder#forTarget(String)}, 在连接到目标服务时允许设置主调服务的相关信息, 并且可以自定义北极星 SDK 的核心数据结构 {@link SDKContext} | ||
* | ||
* @param target 服务名 | ||
* @param target 服务名 | ||
* @param sourceService {@link ServiceKey} 主调服务信息以及标签 | ||
* @param sdkContext {@link SDKContext} 可以设置北极星 SDK 的相关配置以及行为, 例如服务治理中心地址等等 | ||
* @param sdkContext {@link SDKContext} 可以设置北极星 SDK 的相关配置以及行为, 例如服务治理中心地址等等 | ||
* @return {@link PolarisManagedChannelBuilder} | ||
*/ | ||
public static PolarisManagedChannelBuilder forTarget(String target, ServiceKey sourceService, SDKContext sdkContext) { | ||
|
@@ -220,8 +219,8 @@ public PolarisManagedChannelBuilder useTransportSecurity() { | |
return this; | ||
} | ||
|
||
@Deprecated | ||
public PolarisManagedChannelBuilder enableFullStreamDecompression() { | ||
this.builder.enableFullStreamDecompression(); | ||
return this; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import com.tencent.polaris.api.utils.StringUtils; | ||
import com.tencent.polaris.client.api.SDKContext; | ||
import com.tencent.polaris.grpc.interceptor.PolarisServerInterceptor; | ||
import io.grpc.BinaryLog; | ||
import io.grpc.BindableService; | ||
import io.grpc.CompressorRegistry; | ||
import io.grpc.DecompressorRegistry; | ||
|
@@ -28,15 +29,20 @@ | |
import io.grpc.ServerBuilder; | ||
import io.grpc.ServerInterceptor; | ||
import io.grpc.ServerServiceDefinition; | ||
import io.grpc.ServerStreamTracer; | ||
import io.grpc.ServerTransportFilter; | ||
|
||
import javax.annotation.Nullable; | ||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.Executor; | ||
import javax.annotation.Nullable; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">liaochuntao</a> | ||
|
@@ -90,7 +96,7 @@ public static PolarisGrpcServerBuilder forPort(int port) { | |
ServerBuilder<?> builder = ServerBuilder.forPort(port); | ||
return new PolarisGrpcServerBuilder(builder); | ||
} | ||
|
||
/** | ||
* PolarisGrpcServerBuilder Constructor. | ||
* | ||
|
@@ -110,7 +116,7 @@ public PolarisGrpcServerBuilder sdkContext(SDKContext context) { | |
this.context = context; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set grpc service name. | ||
* | ||
|
@@ -121,7 +127,7 @@ public PolarisGrpcServerBuilder applicationName(String applicationName) { | |
this.applicationName = applicationName; | ||
return this; | ||
} | ||
|
||
/** | ||
* Namespace registered by grpc service. | ||
* | ||
|
@@ -132,7 +138,7 @@ public PolarisGrpcServerBuilder namespace(String namespace) { | |
this.namespace = namespace; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set metadata. | ||
* | ||
|
@@ -170,7 +176,7 @@ public PolarisGrpcServerBuilder heartbeatInterval(int heartbeatInterval) { | |
this.heartbeatInterval = heartbeatInterval; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the local host. | ||
* | ||
|
@@ -250,6 +256,91 @@ public PolarisGrpcServerBuilder intercept(ServerInterceptor interceptor) { | |
return this; | ||
} | ||
|
||
|
||
@Override | ||
public PolarisGrpcServerBuilder addTransportFilter(ServerTransportFilter filter) { | ||
builder.addTransportFilter(filter); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder addStreamTracerFactory(ServerStreamTracer.Factory factory) { | ||
builder.addStreamTracerFactory(factory); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder useTransportSecurity(InputStream certChain, InputStream privateKey) { | ||
super.useTransportSecurity(certChain, privateKey); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder handshakeTimeout(long timeout, TimeUnit unit) { | ||
builder.handshakeTimeout(timeout, unit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { | ||
builder.keepAliveTime(keepAliveTime, timeUnit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) { | ||
builder.keepAliveTimeout(keepAliveTimeout, timeUnit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit) { | ||
builder.maxConnectionIdle(maxConnectionIdle, timeUnit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit) { | ||
builder.maxConnectionAge(maxConnectionAge, timeUnit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit) { | ||
builder.maxConnectionAgeGrace(maxConnectionAgeGrace, timeUnit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit) { | ||
builder.permitKeepAliveTime(keepAliveTime, timeUnit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder permitKeepAliveWithoutCalls(boolean permit) { | ||
builder.permitKeepAliveWithoutCalls(permit); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder maxInboundMessageSize(int bytes) { | ||
builder.maxInboundMessageSize(bytes); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder maxInboundMetadataSize(int bytes) { | ||
builder.maxInboundMetadataSize(bytes); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PolarisGrpcServerBuilder setBinaryLog(BinaryLog binaryLog) { | ||
builder.setBinaryLog(binaryLog); | ||
return this; | ||
} | ||
|
||
/** | ||
* 延迟注册, 用户可以通过设置 {@link DelayRegister} 来延迟 gRPC-server 注册到 polaris 对外提供服务的时间 | ||
* 默认支持策略 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters