com.google.cloud.recommendationengine.v1beta1.stub.GrpcCatalogServiceStub Maven / Gradle / Ivy
Show all versions of google-cloud-recommendations-ai Show documentation
/*
* Copyright 2022 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.recommendationengine.v1beta1.stub;
import static com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient.ListCatalogItemsPagedResponse;
import com.google.api.core.BetaApi;
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.OperationCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.recommendationengine.v1beta1.CatalogItem;
import com.google.cloud.recommendationengine.v1beta1.CreateCatalogItemRequest;
import com.google.cloud.recommendationengine.v1beta1.DeleteCatalogItemRequest;
import com.google.cloud.recommendationengine.v1beta1.GetCatalogItemRequest;
import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsRequest;
import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsResponse;
import com.google.cloud.recommendationengine.v1beta1.ImportMetadata;
import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsRequest;
import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsResponse;
import com.google.cloud.recommendationengine.v1beta1.UpdateCatalogItemRequest;
import com.google.common.collect.ImmutableMap;
import com.google.longrunning.Operation;
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 CatalogService service API.
*
* This class is for advanced usage and reflects the underlying API directly.
*/
@BetaApi
@Generated("by gapic-generator-java")
public class GrpcCatalogServiceStub extends CatalogServiceStub {
private static final MethodDescriptor
createCatalogItemMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.cloud.recommendationengine.v1beta1.CatalogService/CreateCatalogItem")
.setRequestMarshaller(
ProtoUtils.marshaller(CreateCatalogItemRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(CatalogItem.getDefaultInstance()))
.build();
private static final MethodDescriptor
getCatalogItemMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.cloud.recommendationengine.v1beta1.CatalogService/GetCatalogItem")
.setRequestMarshaller(
ProtoUtils.marshaller(GetCatalogItemRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(CatalogItem.getDefaultInstance()))
.build();
private static final MethodDescriptor
listCatalogItemsMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.cloud.recommendationengine.v1beta1.CatalogService/ListCatalogItems")
.setRequestMarshaller(
ProtoUtils.marshaller(ListCatalogItemsRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(ListCatalogItemsResponse.getDefaultInstance()))
.build();
private static final MethodDescriptor
updateCatalogItemMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.cloud.recommendationengine.v1beta1.CatalogService/UpdateCatalogItem")
.setRequestMarshaller(
ProtoUtils.marshaller(UpdateCatalogItemRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(CatalogItem.getDefaultInstance()))
.build();
private static final MethodDescriptor
deleteCatalogItemMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.cloud.recommendationengine.v1beta1.CatalogService/DeleteCatalogItem")
.setRequestMarshaller(
ProtoUtils.marshaller(DeleteCatalogItemRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
.build();
private static final MethodDescriptor
importCatalogItemsMethodDescriptor =
MethodDescriptor.newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName(
"google.cloud.recommendationengine.v1beta1.CatalogService/ImportCatalogItems")
.setRequestMarshaller(
ProtoUtils.marshaller(ImportCatalogItemsRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
.build();
private final UnaryCallable createCatalogItemCallable;
private final UnaryCallable getCatalogItemCallable;
private final UnaryCallable
listCatalogItemsCallable;
private final UnaryCallable
listCatalogItemsPagedCallable;
private final UnaryCallable updateCatalogItemCallable;
private final UnaryCallable deleteCatalogItemCallable;
private final UnaryCallable importCatalogItemsCallable;
private final OperationCallable<
ImportCatalogItemsRequest, ImportCatalogItemsResponse, ImportMetadata>
importCatalogItemsOperationCallable;
private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
private final GrpcStubCallableFactory callableFactory;
public static final GrpcCatalogServiceStub create(CatalogServiceStubSettings settings)
throws IOException {
return new GrpcCatalogServiceStub(settings, ClientContext.create(settings));
}
public static final GrpcCatalogServiceStub create(ClientContext clientContext)
throws IOException {
return new GrpcCatalogServiceStub(
CatalogServiceStubSettings.newBuilder().build(), clientContext);
}
public static final GrpcCatalogServiceStub create(
ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
return new GrpcCatalogServiceStub(
CatalogServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
}
/**
* Constructs an instance of GrpcCatalogServiceStub, 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 GrpcCatalogServiceStub(CatalogServiceStubSettings settings, ClientContext clientContext)
throws IOException {
this(settings, clientContext, new GrpcCatalogServiceCallableFactory());
}
/**
* Constructs an instance of GrpcCatalogServiceStub, 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 GrpcCatalogServiceStub(
CatalogServiceStubSettings settings,
ClientContext clientContext,
GrpcStubCallableFactory callableFactory)
throws IOException {
this.callableFactory = callableFactory;
this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
GrpcCallSettings createCatalogItemTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(createCatalogItemMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder params = ImmutableMap.builder();
params.put("parent", String.valueOf(request.getParent()));
return params.build();
})
.build();
GrpcCallSettings getCatalogItemTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(getCatalogItemMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
})
.build();
GrpcCallSettings
listCatalogItemsTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(listCatalogItemsMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder params = ImmutableMap.builder();
params.put("parent", String.valueOf(request.getParent()));
return params.build();
})
.build();
GrpcCallSettings updateCatalogItemTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(updateCatalogItemMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
})
.build();
GrpcCallSettings deleteCatalogItemTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(deleteCatalogItemMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder params = ImmutableMap.builder();
params.put("name", String.valueOf(request.getName()));
return params.build();
})
.build();
GrpcCallSettings importCatalogItemsTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(importCatalogItemsMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder params = ImmutableMap.builder();
params.put("parent", String.valueOf(request.getParent()));
return params.build();
})
.build();
this.createCatalogItemCallable =
callableFactory.createUnaryCallable(
createCatalogItemTransportSettings,
settings.createCatalogItemSettings(),
clientContext);
this.getCatalogItemCallable =
callableFactory.createUnaryCallable(
getCatalogItemTransportSettings, settings.getCatalogItemSettings(), clientContext);
this.listCatalogItemsCallable =
callableFactory.createUnaryCallable(
listCatalogItemsTransportSettings, settings.listCatalogItemsSettings(), clientContext);
this.listCatalogItemsPagedCallable =
callableFactory.createPagedCallable(
listCatalogItemsTransportSettings, settings.listCatalogItemsSettings(), clientContext);
this.updateCatalogItemCallable =
callableFactory.createUnaryCallable(
updateCatalogItemTransportSettings,
settings.updateCatalogItemSettings(),
clientContext);
this.deleteCatalogItemCallable =
callableFactory.createUnaryCallable(
deleteCatalogItemTransportSettings,
settings.deleteCatalogItemSettings(),
clientContext);
this.importCatalogItemsCallable =
callableFactory.createUnaryCallable(
importCatalogItemsTransportSettings,
settings.importCatalogItemsSettings(),
clientContext);
this.importCatalogItemsOperationCallable =
callableFactory.createOperationCallable(
importCatalogItemsTransportSettings,
settings.importCatalogItemsOperationSettings(),
clientContext,
operationsStub);
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
public GrpcOperationsStub getOperationsStub() {
return operationsStub;
}
@Override
public UnaryCallable createCatalogItemCallable() {
return createCatalogItemCallable;
}
@Override
public UnaryCallable getCatalogItemCallable() {
return getCatalogItemCallable;
}
@Override
public UnaryCallable
listCatalogItemsCallable() {
return listCatalogItemsCallable;
}
@Override
public UnaryCallable
listCatalogItemsPagedCallable() {
return listCatalogItemsPagedCallable;
}
@Override
public UnaryCallable updateCatalogItemCallable() {
return updateCatalogItemCallable;
}
@Override
public UnaryCallable deleteCatalogItemCallable() {
return deleteCatalogItemCallable;
}
@Override
public UnaryCallable importCatalogItemsCallable() {
return importCatalogItemsCallable;
}
@Override
public OperationCallable
importCatalogItemsOperationCallable() {
return importCatalogItemsOperationCallable;
}
@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);
}
}