com.google.cloud.speech.v1.stub.GrpcAdaptationStub Maven / Gradle / Ivy
Show all versions of google-cloud-speech Show documentation
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.speech.v1.stub;
import static com.google.cloud.speech.v1.AdaptationClient.ListCustomClassesPagedResponse;
import static com.google.cloud.speech.v1.AdaptationClient.ListPhraseSetPagedResponse;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.RequestParamsBuilder;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.speech.v1.CreateCustomClassRequest;
import com.google.cloud.speech.v1.CreatePhraseSetRequest;
import com.google.cloud.speech.v1.CustomClass;
import com.google.cloud.speech.v1.DeleteCustomClassRequest;
import com.google.cloud.speech.v1.DeletePhraseSetRequest;
import com.google.cloud.speech.v1.GetCustomClassRequest;
import com.google.cloud.speech.v1.GetPhraseSetRequest;
import com.google.cloud.speech.v1.ListCustomClassesRequest;
import com.google.cloud.speech.v1.ListCustomClassesResponse;
import com.google.cloud.speech.v1.ListPhraseSetRequest;
import com.google.cloud.speech.v1.ListPhraseSetResponse;
import com.google.cloud.speech.v1.PhraseSet;
import com.google.cloud.speech.v1.UpdateCustomClassRequest;
import com.google.cloud.speech.v1.UpdatePhraseSetRequest;
import com.google.longrunning.stub.GrpcOperationsStub;
import com.google.protobuf.Empty;
import io.grpc.MethodDescriptor;
import io.grpc.protobuf.ProtoUtils;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* gRPC stub implementation for the Adaptation service API.
*
* This class is for advanced usage and reflects the underlying API directly.
*/
@Generated("by gapic-generator-java")
public class GrpcAdaptationStub extends AdaptationStub {
private static final MethodDescriptor
createPhraseSetMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/CreatePhraseSet")
.setRequestMarshaller(
ProtoUtils.marshaller(CreatePhraseSetRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(PhraseSet.getDefaultInstance()))
.build();
private static final MethodDescriptor
getPhraseSetMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/GetPhraseSet")
.setRequestMarshaller(ProtoUtils.marshaller(GetPhraseSetRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(PhraseSet.getDefaultInstance()))
.build();
private static final MethodDescriptor
listPhraseSetMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/ListPhraseSet")
.setRequestMarshaller(
ProtoUtils.marshaller(ListPhraseSetRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(ListPhraseSetResponse.getDefaultInstance()))
.build();
private static final MethodDescriptor
updatePhraseSetMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/UpdatePhraseSet")
.setRequestMarshaller(
ProtoUtils.marshaller(UpdatePhraseSetRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(PhraseSet.getDefaultInstance()))
.build();
private static final MethodDescriptor
deletePhraseSetMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/DeletePhraseSet")
.setRequestMarshaller(
ProtoUtils.marshaller(DeletePhraseSetRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
.build();
private static final MethodDescriptor
createCustomClassMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/CreateCustomClass")
.setRequestMarshaller(
ProtoUtils.marshaller(CreateCustomClassRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(CustomClass.getDefaultInstance()))
.build();
private static final MethodDescriptor
getCustomClassMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/GetCustomClass")
.setRequestMarshaller(
ProtoUtils.marshaller(GetCustomClassRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(CustomClass.getDefaultInstance()))
.build();
private static final MethodDescriptor
listCustomClassesMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/ListCustomClasses")
.setRequestMarshaller(
ProtoUtils.marshaller(ListCustomClassesRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(ListCustomClassesResponse.getDefaultInstance()))
.build();
private static final MethodDescriptor
updateCustomClassMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/UpdateCustomClass")
.setRequestMarshaller(
ProtoUtils.marshaller(UpdateCustomClassRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(CustomClass.getDefaultInstance()))
.build();
private static final MethodDescriptor
deleteCustomClassMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.speech.v1.Adaptation/DeleteCustomClass")
.setRequestMarshaller(
ProtoUtils.marshaller(DeleteCustomClassRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
.build();
private final UnaryCallable createPhraseSetCallable;
private final UnaryCallable getPhraseSetCallable;
private final UnaryCallable listPhraseSetCallable;
private final UnaryCallable
listPhraseSetPagedCallable;
private final UnaryCallable updatePhraseSetCallable;
private final UnaryCallable deletePhraseSetCallable;
private final UnaryCallable createCustomClassCallable;
private final UnaryCallable getCustomClassCallable;
private final UnaryCallable
listCustomClassesCallable;
private final UnaryCallable
listCustomClassesPagedCallable;
private final UnaryCallable updateCustomClassCallable;
private final UnaryCallable deleteCustomClassCallable;
private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
private final GrpcStubCallableFactory callableFactory;
public static final GrpcAdaptationStub create(AdaptationStubSettings settings)
throws IOException {
return new GrpcAdaptationStub(settings, ClientContext.create(settings));
}
public static final GrpcAdaptationStub create(ClientContext clientContext) throws IOException {
return new GrpcAdaptationStub(AdaptationStubSettings.newBuilder().build(), clientContext);
}
public static final GrpcAdaptationStub create(
ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
return new GrpcAdaptationStub(
AdaptationStubSettings.newBuilder().build(), clientContext, callableFactory);
}
/**
* Constructs an instance of GrpcAdaptationStub, using the given settings. This is protected so
* that it is easy to make a subclass, but otherwise, the static factory methods should be
* preferred.
*/
protected GrpcAdaptationStub(AdaptationStubSettings settings, ClientContext clientContext)
throws IOException {
this(settings, clientContext, new GrpcAdaptationCallableFactory());
}
/**
* Constructs an instance of GrpcAdaptationStub, using the given settings. This is protected so
* that it is easy to make a subclass, but otherwise, the static factory methods should be
* preferred.
*/
protected GrpcAdaptationStub(
AdaptationStubSettings settings,
ClientContext clientContext,
GrpcStubCallableFactory callableFactory)
throws IOException {
this.callableFactory = callableFactory;
this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
GrpcCallSettings createPhraseSetTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(createPhraseSetMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
GrpcCallSettings getPhraseSetTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(getPhraseSetMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
GrpcCallSettings listPhraseSetTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(listPhraseSetMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
GrpcCallSettings updatePhraseSetTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(updatePhraseSetMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("phrase_set.name", String.valueOf(request.getPhraseSet().getName()));
return builder.build();
})
.build();
GrpcCallSettings deletePhraseSetTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(deletePhraseSetMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
GrpcCallSettings createCustomClassTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(createCustomClassMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
GrpcCallSettings getCustomClassTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(getCustomClassMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
GrpcCallSettings
listCustomClassesTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(listCustomClassesMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
GrpcCallSettings updateCustomClassTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(updateCustomClassMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add(
"custom_class.name", String.valueOf(request.getCustomClass().getName()));
return builder.build();
})
.build();
GrpcCallSettings deleteCustomClassTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(deleteCustomClassMethodDescriptor)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
this.createPhraseSetCallable =
callableFactory.createUnaryCallable(
createPhraseSetTransportSettings, settings.createPhraseSetSettings(), clientContext);
this.getPhraseSetCallable =
callableFactory.createUnaryCallable(
getPhraseSetTransportSettings, settings.getPhraseSetSettings(), clientContext);
this.listPhraseSetCallable =
callableFactory.createUnaryCallable(
listPhraseSetTransportSettings, settings.listPhraseSetSettings(), clientContext);
this.listPhraseSetPagedCallable =
callableFactory.createPagedCallable(
listPhraseSetTransportSettings, settings.listPhraseSetSettings(), clientContext);
this.updatePhraseSetCallable =
callableFactory.createUnaryCallable(
updatePhraseSetTransportSettings, settings.updatePhraseSetSettings(), clientContext);
this.deletePhraseSetCallable =
callableFactory.createUnaryCallable(
deletePhraseSetTransportSettings, settings.deletePhraseSetSettings(), clientContext);
this.createCustomClassCallable =
callableFactory.createUnaryCallable(
createCustomClassTransportSettings,
settings.createCustomClassSettings(),
clientContext);
this.getCustomClassCallable =
callableFactory.createUnaryCallable(
getCustomClassTransportSettings, settings.getCustomClassSettings(), clientContext);
this.listCustomClassesCallable =
callableFactory.createUnaryCallable(
listCustomClassesTransportSettings,
settings.listCustomClassesSettings(),
clientContext);
this.listCustomClassesPagedCallable =
callableFactory.createPagedCallable(
listCustomClassesTransportSettings,
settings.listCustomClassesSettings(),
clientContext);
this.updateCustomClassCallable =
callableFactory.createUnaryCallable(
updateCustomClassTransportSettings,
settings.updateCustomClassSettings(),
clientContext);
this.deleteCustomClassCallable =
callableFactory.createUnaryCallable(
deleteCustomClassTransportSettings,
settings.deleteCustomClassSettings(),
clientContext);
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
public GrpcOperationsStub getOperationsStub() {
return operationsStub;
}
@Override
public UnaryCallable createPhraseSetCallable() {
return createPhraseSetCallable;
}
@Override
public UnaryCallable getPhraseSetCallable() {
return getPhraseSetCallable;
}
@Override
public UnaryCallable listPhraseSetCallable() {
return listPhraseSetCallable;
}
@Override
public UnaryCallable
listPhraseSetPagedCallable() {
return listPhraseSetPagedCallable;
}
@Override
public UnaryCallable updatePhraseSetCallable() {
return updatePhraseSetCallable;
}
@Override
public UnaryCallable deletePhraseSetCallable() {
return deletePhraseSetCallable;
}
@Override
public UnaryCallable createCustomClassCallable() {
return createCustomClassCallable;
}
@Override
public UnaryCallable getCustomClassCallable() {
return getCustomClassCallable;
}
@Override
public UnaryCallable
listCustomClassesCallable() {
return listCustomClassesCallable;
}
@Override
public UnaryCallable
listCustomClassesPagedCallable() {
return listCustomClassesPagedCallable;
}
@Override
public UnaryCallable updateCustomClassCallable() {
return updateCustomClassCallable;
}
@Override
public UnaryCallable deleteCustomClassCallable() {
return deleteCustomClassCallable;
}
@Override
public final void close() {
try {
backgroundResources.close();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
}
}
@Override
public void shutdown() {
backgroundResources.shutdown();
}
@Override
public boolean isShutdown() {
return backgroundResources.isShutdown();
}
@Override
public boolean isTerminated() {
return backgroundResources.isTerminated();
}
@Override
public void shutdownNow() {
backgroundResources.shutdownNow();
}
@Override
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return backgroundResources.awaitTermination(duration, unit);
}
}