use of com.tencent.polaris.ratelimit.client.pb.RateLimitGRPCV2Grpc.RateLimitGRPCV2Stub in project polaris-java by polarismesh.
the class StreamCounterSet method checkAndCreateResource.
/**
* 获取同步阻塞的客户端
*
* @return 同步阻塞的客户端
*/
private StreamResource checkAndCreateResource(ServiceIdentifier serviceIdentifier, RateLimitWindow rateLimitWindow) {
StreamResource streamResource = currentStreamResource.get();
if (null != streamResource && !streamResource.endStream.get()) {
return streamResource;
}
long lastConnectFailTimeMilli = 0;
if (null != streamResource) {
lastConnectFailTimeMilli = streamResource.lastConnectFailTimeMilli.get();
}
ManagedChannel channel = createConnection(lastConnectFailTimeMilli);
if (null == channel) {
return null;
}
RateLimitGRPCV2Stub rateLimitGRPCV2Stub = RateLimitGRPCV2Grpc.newStub(channel);
StreamObserver<RateLimitRequest> streamClient = rateLimitGRPCV2Stub.service(streamResource);
RateLimitGRPCV2BlockingStub rateLimitGRPCV2BlockingStub = RateLimitGRPCV2Grpc.newBlockingStub(channel);
streamResource = new StreamResource(channel, streamClient, rateLimitGRPCV2BlockingStub);
currentStreamResource.set(streamResource);
if (initRecord.get(serviceIdentifier) == null) {
initRecord.putIfAbsent(serviceIdentifier, new InitializeRecord(rateLimitWindow));
}
return streamResource;
}
Aggregations