Search in sources :

Example 1 with RateLimitGRPCV2Stub

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;
}
Also used : RateLimitGRPCV2BlockingStub(com.tencent.polaris.ratelimit.client.pb.RateLimitGRPCV2Grpc.RateLimitGRPCV2BlockingStub) RateLimitGRPCV2Stub(com.tencent.polaris.ratelimit.client.pb.RateLimitGRPCV2Grpc.RateLimitGRPCV2Stub) ManagedChannel(io.grpc.ManagedChannel) RateLimitRequest(com.tencent.polaris.ratelimit.client.pb.RatelimitV2.RateLimitRequest)

Aggregations

RateLimitGRPCV2BlockingStub (com.tencent.polaris.ratelimit.client.pb.RateLimitGRPCV2Grpc.RateLimitGRPCV2BlockingStub)1 RateLimitGRPCV2Stub (com.tencent.polaris.ratelimit.client.pb.RateLimitGRPCV2Grpc.RateLimitGRPCV2Stub)1 RateLimitRequest (com.tencent.polaris.ratelimit.client.pb.RatelimitV2.RateLimitRequest)1 ManagedChannel (io.grpc.ManagedChannel)1