1 /* 2 * Copyright 2022 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 17 package com.google.cloud.trace.v1.stub; 18 19 import static com.google.cloud.trace.v1.TraceServiceClient.ListTracesPagedResponse; 20 21 import com.google.api.gax.core.BackgroundResource; 22 import com.google.api.gax.core.BackgroundResourceAggregation; 23 import com.google.api.gax.grpc.GrpcCallSettings; 24 import com.google.api.gax.grpc.GrpcStubCallableFactory; 25 import com.google.api.gax.rpc.ClientContext; 26 import com.google.api.gax.rpc.UnaryCallable; 27 import com.google.common.collect.ImmutableMap; 28 import com.google.devtools.cloudtrace.v1.GetTraceRequest; 29 import com.google.devtools.cloudtrace.v1.ListTracesRequest; 30 import com.google.devtools.cloudtrace.v1.ListTracesResponse; 31 import com.google.devtools.cloudtrace.v1.PatchTracesRequest; 32 import com.google.devtools.cloudtrace.v1.Trace; 33 import com.google.longrunning.stub.GrpcOperationsStub; 34 import com.google.protobuf.Empty; 35 import io.grpc.MethodDescriptor; 36 import io.grpc.protobuf.ProtoUtils; 37 import java.io.IOException; 38 import java.util.concurrent.TimeUnit; 39 import javax.annotation.Generated; 40 41 // AUTO-GENERATED DOCUMENTATION AND CLASS. 42 /** 43 * gRPC stub implementation for the TraceService service API. 44 * 45 * <p>This class is for advanced usage and reflects the underlying API directly. 46 */ 47 @Generated("by gapic-generator-java") 48 public class GrpcTraceServiceStub extends TraceServiceStub { 49 private static final MethodDescriptor<ListTracesRequest, ListTracesResponse> 50 listTracesMethodDescriptor = 51 MethodDescriptor.<ListTracesRequest, ListTracesResponse>newBuilder() 52 .setType(MethodDescriptor.MethodType.UNARY) 53 .setFullMethodName("google.devtools.cloudtrace.v1.TraceService/ListTraces") 54 .setRequestMarshaller(ProtoUtils.marshaller(ListTracesRequest.getDefaultInstance())) 55 .setResponseMarshaller(ProtoUtils.marshaller(ListTracesResponse.getDefaultInstance())) 56 .build(); 57 58 private static final MethodDescriptor<GetTraceRequest, Trace> getTraceMethodDescriptor = 59 MethodDescriptor.<GetTraceRequest, Trace>newBuilder() 60 .setType(MethodDescriptor.MethodType.UNARY) 61 .setFullMethodName("google.devtools.cloudtrace.v1.TraceService/GetTrace") 62 .setRequestMarshaller(ProtoUtils.marshaller(GetTraceRequest.getDefaultInstance())) 63 .setResponseMarshaller(ProtoUtils.marshaller(Trace.getDefaultInstance())) 64 .build(); 65 66 private static final MethodDescriptor<PatchTracesRequest, Empty> patchTracesMethodDescriptor = 67 MethodDescriptor.<PatchTracesRequest, Empty>newBuilder() 68 .setType(MethodDescriptor.MethodType.UNARY) 69 .setFullMethodName("google.devtools.cloudtrace.v1.TraceService/PatchTraces") 70 .setRequestMarshaller(ProtoUtils.marshaller(PatchTracesRequest.getDefaultInstance())) 71 .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) 72 .build(); 73 74 private final UnaryCallable<ListTracesRequest, ListTracesResponse> listTracesCallable; 75 private final UnaryCallable<ListTracesRequest, ListTracesPagedResponse> listTracesPagedCallable; 76 private final UnaryCallable<GetTraceRequest, Trace> getTraceCallable; 77 private final UnaryCallable<PatchTracesRequest, Empty> patchTracesCallable; 78 79 private final BackgroundResource backgroundResources; 80 private final GrpcOperationsStub operationsStub; 81 private final GrpcStubCallableFactory callableFactory; 82 create(TraceServiceStubSettings settings)83 public static final GrpcTraceServiceStub create(TraceServiceStubSettings settings) 84 throws IOException { 85 return new GrpcTraceServiceStub(settings, ClientContext.create(settings)); 86 } 87 create(ClientContext clientContext)88 public static final GrpcTraceServiceStub create(ClientContext clientContext) throws IOException { 89 return new GrpcTraceServiceStub(TraceServiceStubSettings.newBuilder().build(), clientContext); 90 } 91 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)92 public static final GrpcTraceServiceStub create( 93 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 94 return new GrpcTraceServiceStub( 95 TraceServiceStubSettings.newBuilder().build(), clientContext, callableFactory); 96 } 97 98 /** 99 * Constructs an instance of GrpcTraceServiceStub, using the given settings. This is protected so 100 * that it is easy to make a subclass, but otherwise, the static factory methods should be 101 * preferred. 102 */ GrpcTraceServiceStub(TraceServiceStubSettings settings, ClientContext clientContext)103 protected GrpcTraceServiceStub(TraceServiceStubSettings settings, ClientContext clientContext) 104 throws IOException { 105 this(settings, clientContext, new GrpcTraceServiceCallableFactory()); 106 } 107 108 /** 109 * Constructs an instance of GrpcTraceServiceStub, using the given settings. This is protected so 110 * that it is easy to make a subclass, but otherwise, the static factory methods should be 111 * preferred. 112 */ GrpcTraceServiceStub( TraceServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)113 protected GrpcTraceServiceStub( 114 TraceServiceStubSettings settings, 115 ClientContext clientContext, 116 GrpcStubCallableFactory callableFactory) 117 throws IOException { 118 this.callableFactory = callableFactory; 119 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 120 121 GrpcCallSettings<ListTracesRequest, ListTracesResponse> listTracesTransportSettings = 122 GrpcCallSettings.<ListTracesRequest, ListTracesResponse>newBuilder() 123 .setMethodDescriptor(listTracesMethodDescriptor) 124 .setParamsExtractor( 125 request -> { 126 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 127 params.put("project_id", String.valueOf(request.getProjectId())); 128 return params.build(); 129 }) 130 .build(); 131 GrpcCallSettings<GetTraceRequest, Trace> getTraceTransportSettings = 132 GrpcCallSettings.<GetTraceRequest, Trace>newBuilder() 133 .setMethodDescriptor(getTraceMethodDescriptor) 134 .setParamsExtractor( 135 request -> { 136 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 137 params.put("project_id", String.valueOf(request.getProjectId())); 138 params.put("trace_id", String.valueOf(request.getTraceId())); 139 return params.build(); 140 }) 141 .build(); 142 GrpcCallSettings<PatchTracesRequest, Empty> patchTracesTransportSettings = 143 GrpcCallSettings.<PatchTracesRequest, Empty>newBuilder() 144 .setMethodDescriptor(patchTracesMethodDescriptor) 145 .setParamsExtractor( 146 request -> { 147 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 148 params.put("project_id", String.valueOf(request.getProjectId())); 149 return params.build(); 150 }) 151 .build(); 152 153 this.listTracesCallable = 154 callableFactory.createUnaryCallable( 155 listTracesTransportSettings, settings.listTracesSettings(), clientContext); 156 this.listTracesPagedCallable = 157 callableFactory.createPagedCallable( 158 listTracesTransportSettings, settings.listTracesSettings(), clientContext); 159 this.getTraceCallable = 160 callableFactory.createUnaryCallable( 161 getTraceTransportSettings, settings.getTraceSettings(), clientContext); 162 this.patchTracesCallable = 163 callableFactory.createUnaryCallable( 164 patchTracesTransportSettings, settings.patchTracesSettings(), clientContext); 165 166 this.backgroundResources = 167 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 168 } 169 getOperationsStub()170 public GrpcOperationsStub getOperationsStub() { 171 return operationsStub; 172 } 173 174 @Override listTracesCallable()175 public UnaryCallable<ListTracesRequest, ListTracesResponse> listTracesCallable() { 176 return listTracesCallable; 177 } 178 179 @Override listTracesPagedCallable()180 public UnaryCallable<ListTracesRequest, ListTracesPagedResponse> listTracesPagedCallable() { 181 return listTracesPagedCallable; 182 } 183 184 @Override getTraceCallable()185 public UnaryCallable<GetTraceRequest, Trace> getTraceCallable() { 186 return getTraceCallable; 187 } 188 189 @Override patchTracesCallable()190 public UnaryCallable<PatchTracesRequest, Empty> patchTracesCallable() { 191 return patchTracesCallable; 192 } 193 194 @Override close()195 public final void close() { 196 try { 197 backgroundResources.close(); 198 } catch (RuntimeException e) { 199 throw e; 200 } catch (Exception e) { 201 throw new IllegalStateException("Failed to close resource", e); 202 } 203 } 204 205 @Override shutdown()206 public void shutdown() { 207 backgroundResources.shutdown(); 208 } 209 210 @Override isShutdown()211 public boolean isShutdown() { 212 return backgroundResources.isShutdown(); 213 } 214 215 @Override isTerminated()216 public boolean isTerminated() { 217 return backgroundResources.isTerminated(); 218 } 219 220 @Override shutdownNow()221 public void shutdownNow() { 222 backgroundResources.shutdownNow(); 223 } 224 225 @Override awaitTermination(long duration, TimeUnit unit)226 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 227 return backgroundResources.awaitTermination(duration, unit); 228 } 229 } 230