|
| 1 | +/* |
| 2 | + * Copyright 2023 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.cloud.bigtable.data.v2.stub.metrics; |
| 17 | + |
| 18 | +import com.google.api.core.ApiFuture; |
| 19 | +import com.google.api.core.ApiFutures; |
| 20 | +import com.google.api.core.InternalApi; |
| 21 | +import com.google.api.gax.grpc.GrpcResponseMetadata; |
| 22 | +import com.google.api.gax.rpc.ApiCallContext; |
| 23 | +import com.google.api.gax.rpc.UnaryCallable; |
| 24 | +import com.google.common.util.concurrent.MoreExecutors; |
| 25 | +import javax.annotation.Nonnull; |
| 26 | + |
| 27 | +/** |
| 28 | + * This callable will do everything described in {@link BigtableTracerUnaryCallable} except that it |
| 29 | + * won't inject a {@link BigtableGrpcStreamTracer}. For batching calls, we only want to calculate |
| 30 | + * the total time client is blocked because of flow control. |
| 31 | + */ |
| 32 | +@InternalApi |
| 33 | +public class BigtableTracerBatchedUnaryCallable<RequestT, ResponseT> |
| 34 | + extends BigtableTracerUnaryCallable<RequestT, ResponseT> { |
| 35 | + |
| 36 | + private UnaryCallable<RequestT, ResponseT> innerCallable; |
| 37 | + |
| 38 | + public BigtableTracerBatchedUnaryCallable( |
| 39 | + @Nonnull UnaryCallable<RequestT, ResponseT> innerCallable) { |
| 40 | + super(innerCallable); |
| 41 | + this.innerCallable = innerCallable; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public ApiFuture futureCall(RequestT request, ApiCallContext context) { |
| 46 | + final GrpcResponseMetadata responseMetadata = new GrpcResponseMetadata(); |
| 47 | + BigtableTracerUnaryCallback<ResponseT> callback = |
| 48 | + new BigtableTracerUnaryCallback<ResponseT>( |
| 49 | + (BigtableTracer) context.getTracer(), responseMetadata); |
| 50 | + ApiFuture<ResponseT> future = |
| 51 | + innerCallable.futureCall(request, responseMetadata.addHandlers(context)); |
| 52 | + ApiFutures.addCallback(future, callback, MoreExecutors.directExecutor()); |
| 53 | + return future; |
| 54 | + } |
| 55 | +} |
0 commit comments