com.google.cloud.discoveryengine.v1.stub.HttpJsonConversationalSearchServiceStub Maven / Gradle / Ivy
Show all versions of google-cloud-discoveryengine Show documentation
/*
* Copyright 2024 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.discoveryengine.v1.stub;
import static com.google.cloud.discoveryengine.v1.ConversationalSearchServiceClient.ListConversationsPagedResponse;
import static com.google.cloud.discoveryengine.v1.ConversationalSearchServiceClient.ListSessionsPagedResponse;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.httpjson.ApiMethodDescriptor;
import com.google.api.gax.httpjson.HttpJsonCallSettings;
import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
import com.google.api.gax.httpjson.ProtoMessageResponseParser;
import com.google.api.gax.httpjson.ProtoRestSerializer;
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.discoveryengine.v1.Answer;
import com.google.cloud.discoveryengine.v1.AnswerQueryRequest;
import com.google.cloud.discoveryengine.v1.AnswerQueryResponse;
import com.google.cloud.discoveryengine.v1.Conversation;
import com.google.cloud.discoveryengine.v1.ConverseConversationRequest;
import com.google.cloud.discoveryengine.v1.ConverseConversationResponse;
import com.google.cloud.discoveryengine.v1.CreateConversationRequest;
import com.google.cloud.discoveryengine.v1.CreateSessionRequest;
import com.google.cloud.discoveryengine.v1.DeleteConversationRequest;
import com.google.cloud.discoveryengine.v1.DeleteSessionRequest;
import com.google.cloud.discoveryengine.v1.GetAnswerRequest;
import com.google.cloud.discoveryengine.v1.GetConversationRequest;
import com.google.cloud.discoveryengine.v1.GetSessionRequest;
import com.google.cloud.discoveryengine.v1.ListConversationsRequest;
import com.google.cloud.discoveryengine.v1.ListConversationsResponse;
import com.google.cloud.discoveryengine.v1.ListSessionsRequest;
import com.google.cloud.discoveryengine.v1.ListSessionsResponse;
import com.google.cloud.discoveryengine.v1.Session;
import com.google.cloud.discoveryengine.v1.UpdateConversationRequest;
import com.google.cloud.discoveryengine.v1.UpdateSessionRequest;
import com.google.protobuf.Empty;
import com.google.protobuf.TypeRegistry;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* REST stub implementation for the ConversationalSearchService service API.
*
* This class is for advanced usage and reflects the underlying API directly.
*/
@Generated("by gapic-generator-java")
public class HttpJsonConversationalSearchServiceStub extends ConversationalSearchServiceStub {
private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
private static final ApiMethodDescriptor<
ConverseConversationRequest, ConverseConversationResponse>
converseConversationMethodDescriptor =
ApiMethodDescriptor
.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/ConverseConversation")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/locations/*/dataStores/*/conversations/*}:converse",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setAdditionalPaths(
"/v1/{name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}:converse",
"/v1/{name=projects/*/locations/*/collections/*/engines/*/conversations/*}:converse")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearName().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ConverseConversationResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
createConversationMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/CreateConversation")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{parent=projects/*/locations/*/dataStores/*}/conversations",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setAdditionalPaths(
"/v1/{parent=projects/*/locations/*/collections/*/dataStores/*}/conversations",
"/v1/{parent=projects/*/locations/*/collections/*/engines/*}/conversations")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("conversation", request.getConversation(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Conversation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
deleteConversationMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/DeleteConversation")
.setHttpMethod("DELETE")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/locations/*/dataStores/*/conversations/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setAdditionalPaths(
"/v1/{name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}",
"/v1/{name=projects/*/locations/*/collections/*/engines/*/conversations/*}")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Empty.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
updateConversationMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/UpdateConversation")
.setHttpMethod("PATCH")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{conversation.name=projects/*/locations/*/dataStores/*/conversations/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(
fields, "conversation.name", request.getConversation().getName());
return fields;
})
.setAdditionalPaths(
"/v1/{conversation.name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}",
"/v1/{conversation.name=projects/*/locations/*/collections/*/engines/*/conversations/*}")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "updateMask", request.getUpdateMask());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("conversation", request.getConversation(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Conversation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
getConversationMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/GetConversation")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/locations/*/dataStores/*/conversations/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setAdditionalPaths(
"/v1/{name=projects/*/locations/*/collections/*/dataStores/*/conversations/*}",
"/v1/{name=projects/*/locations/*/collections/*/engines/*/conversations/*}")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Conversation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
listConversationsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/ListConversations")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{parent=projects/*/locations/*/dataStores/*}/conversations",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setAdditionalPaths(
"/v1/{parent=projects/*/locations/*/collections/*/dataStores/*}/conversations",
"/v1/{parent=projects/*/locations/*/collections/*/engines/*}/conversations")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "filter", request.getFilter());
serializer.putQueryParam(fields, "orderBy", request.getOrderBy());
serializer.putQueryParam(fields, "pageSize", request.getPageSize());
serializer.putQueryParam(fields, "pageToken", request.getPageToken());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ListConversationsResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
answerQueryMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/AnswerQuery")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{servingConfig=projects/*/locations/*/dataStores/*/servingConfigs/*}:answer",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(
fields, "servingConfig", request.getServingConfig());
return fields;
})
.setAdditionalPaths(
"/v1/{servingConfig=projects/*/locations/*/collections/*/dataStores/*/servingConfigs/*}:answer",
"/v1/{servingConfig=projects/*/locations/*/collections/*/engines/*/servingConfigs/*}:answer")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody(
"*", request.toBuilder().clearServingConfig().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(AnswerQueryResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor getAnswerMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/GetAnswer")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/locations/*/dataStores/*/sessions/*/answers/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setAdditionalPaths(
"/v1/{name=projects/*/locations/*/collections/*/dataStores/*/sessions/*/answers/*}",
"/v1/{name=projects/*/locations/*/collections/*/engines/*/sessions/*/answers/*}")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Answer.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
createSessionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/CreateSession")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{parent=projects/*/locations/*/dataStores/*}/sessions",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setAdditionalPaths(
"/v1/{parent=projects/*/locations/*/collections/*/dataStores/*}/sessions",
"/v1/{parent=projects/*/locations/*/collections/*/engines/*}/sessions")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("session", request.getSession(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Session.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
deleteSessionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/DeleteSession")
.setHttpMethod("DELETE")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/locations/*/dataStores/*/sessions/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setAdditionalPaths(
"/v1/{name=projects/*/locations/*/collections/*/dataStores/*/sessions/*}",
"/v1/{name=projects/*/locations/*/collections/*/engines/*/sessions/*}")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Empty.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
updateSessionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/UpdateSession")
.setHttpMethod("PATCH")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{session.name=projects/*/locations/*/dataStores/*/sessions/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(
fields, "session.name", request.getSession().getName());
return fields;
})
.setAdditionalPaths(
"/v1/{session.name=projects/*/locations/*/collections/*/dataStores/*/sessions/*}",
"/v1/{session.name=projects/*/locations/*/collections/*/engines/*/sessions/*}")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "updateMask", request.getUpdateMask());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("session", request.getSession(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Session.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor getSessionMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/GetSession")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{name=projects/*/locations/*/dataStores/*/sessions/*}",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.setAdditionalPaths(
"/v1/{name=projects/*/locations/*/collections/*/dataStores/*/sessions/*}",
"/v1/{name=projects/*/locations/*/collections/*/engines/*/sessions/*}")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Session.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
listSessionsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName(
"google.cloud.discoveryengine.v1.ConversationalSearchService/ListSessions")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v1/{parent=projects/*/locations/*/dataStores/*}/sessions",
request -> {
Map fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "parent", request.getParent());
return fields;
})
.setAdditionalPaths(
"/v1/{parent=projects/*/locations/*/collections/*/dataStores/*}/sessions",
"/v1/{parent=projects/*/locations/*/collections/*/engines/*}/sessions")
.setQueryParamsExtractor(
request -> {
Map> fields = new HashMap<>();
ProtoRestSerializer serializer =
ProtoRestSerializer.create();
serializer.putQueryParam(fields, "filter", request.getFilter());
serializer.putQueryParam(fields, "orderBy", request.getOrderBy());
serializer.putQueryParam(fields, "pageSize", request.getPageSize());
serializer.putQueryParam(fields, "pageToken", request.getPageToken());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(ListSessionsResponse.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private final UnaryCallable
converseConversationCallable;
private final UnaryCallable createConversationCallable;
private final UnaryCallable deleteConversationCallable;
private final UnaryCallable updateConversationCallable;
private final UnaryCallable getConversationCallable;
private final UnaryCallable
listConversationsCallable;
private final UnaryCallable
listConversationsPagedCallable;
private final UnaryCallable answerQueryCallable;
private final UnaryCallable getAnswerCallable;
private final UnaryCallable createSessionCallable;
private final UnaryCallable deleteSessionCallable;
private final UnaryCallable updateSessionCallable;
private final UnaryCallable getSessionCallable;
private final UnaryCallable listSessionsCallable;
private final UnaryCallable
listSessionsPagedCallable;
private final BackgroundResource backgroundResources;
private final HttpJsonStubCallableFactory callableFactory;
public static final HttpJsonConversationalSearchServiceStub create(
ConversationalSearchServiceStubSettings settings) throws IOException {
return new HttpJsonConversationalSearchServiceStub(settings, ClientContext.create(settings));
}
public static final HttpJsonConversationalSearchServiceStub create(ClientContext clientContext)
throws IOException {
return new HttpJsonConversationalSearchServiceStub(
ConversationalSearchServiceStubSettings.newHttpJsonBuilder().build(), clientContext);
}
public static final HttpJsonConversationalSearchServiceStub create(
ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
return new HttpJsonConversationalSearchServiceStub(
ConversationalSearchServiceStubSettings.newHttpJsonBuilder().build(),
clientContext,
callableFactory);
}
/**
* Constructs an instance of HttpJsonConversationalSearchServiceStub, 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 HttpJsonConversationalSearchServiceStub(
ConversationalSearchServiceStubSettings settings, ClientContext clientContext)
throws IOException {
this(settings, clientContext, new HttpJsonConversationalSearchServiceCallableFactory());
}
/**
* Constructs an instance of HttpJsonConversationalSearchServiceStub, 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 HttpJsonConversationalSearchServiceStub(
ConversationalSearchServiceStubSettings settings,
ClientContext clientContext,
HttpJsonStubCallableFactory callableFactory)
throws IOException {
this.callableFactory = callableFactory;
HttpJsonCallSettings
converseConversationTransportSettings =
HttpJsonCallSettings
.newBuilder()
.setMethodDescriptor(converseConversationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings
createConversationTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(createConversationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings deleteConversationTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(deleteConversationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings
updateConversationTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(updateConversationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add(
"conversation.name", String.valueOf(request.getConversation().getName()));
return builder.build();
})
.build();
HttpJsonCallSettings getConversationTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getConversationMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings
listConversationsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(listConversationsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings answerQueryTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(answerQueryMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("serving_config", String.valueOf(request.getServingConfig()));
return builder.build();
})
.build();
HttpJsonCallSettings getAnswerTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getAnswerMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings createSessionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(createSessionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings deleteSessionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(deleteSessionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings updateSessionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(updateSessionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("session.name", String.valueOf(request.getSession().getName()));
return builder.build();
})
.build();
HttpJsonCallSettings getSessionTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(getSessionMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("name", String.valueOf(request.getName()));
return builder.build();
})
.build();
HttpJsonCallSettings listSessionsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(listSessionsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
this.converseConversationCallable =
callableFactory.createUnaryCallable(
converseConversationTransportSettings,
settings.converseConversationSettings(),
clientContext);
this.createConversationCallable =
callableFactory.createUnaryCallable(
createConversationTransportSettings,
settings.createConversationSettings(),
clientContext);
this.deleteConversationCallable =
callableFactory.createUnaryCallable(
deleteConversationTransportSettings,
settings.deleteConversationSettings(),
clientContext);
this.updateConversationCallable =
callableFactory.createUnaryCallable(
updateConversationTransportSettings,
settings.updateConversationSettings(),
clientContext);
this.getConversationCallable =
callableFactory.createUnaryCallable(
getConversationTransportSettings, settings.getConversationSettings(), clientContext);
this.listConversationsCallable =
callableFactory.createUnaryCallable(
listConversationsTransportSettings,
settings.listConversationsSettings(),
clientContext);
this.listConversationsPagedCallable =
callableFactory.createPagedCallable(
listConversationsTransportSettings,
settings.listConversationsSettings(),
clientContext);
this.answerQueryCallable =
callableFactory.createUnaryCallable(
answerQueryTransportSettings, settings.answerQuerySettings(), clientContext);
this.getAnswerCallable =
callableFactory.createUnaryCallable(
getAnswerTransportSettings, settings.getAnswerSettings(), clientContext);
this.createSessionCallable =
callableFactory.createUnaryCallable(
createSessionTransportSettings, settings.createSessionSettings(), clientContext);
this.deleteSessionCallable =
callableFactory.createUnaryCallable(
deleteSessionTransportSettings, settings.deleteSessionSettings(), clientContext);
this.updateSessionCallable =
callableFactory.createUnaryCallable(
updateSessionTransportSettings, settings.updateSessionSettings(), clientContext);
this.getSessionCallable =
callableFactory.createUnaryCallable(
getSessionTransportSettings, settings.getSessionSettings(), clientContext);
this.listSessionsCallable =
callableFactory.createUnaryCallable(
listSessionsTransportSettings, settings.listSessionsSettings(), clientContext);
this.listSessionsPagedCallable =
callableFactory.createPagedCallable(
listSessionsTransportSettings, settings.listSessionsSettings(), clientContext);
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
@InternalApi
public static List getMethodDescriptors() {
List methodDescriptors = new ArrayList<>();
methodDescriptors.add(converseConversationMethodDescriptor);
methodDescriptors.add(createConversationMethodDescriptor);
methodDescriptors.add(deleteConversationMethodDescriptor);
methodDescriptors.add(updateConversationMethodDescriptor);
methodDescriptors.add(getConversationMethodDescriptor);
methodDescriptors.add(listConversationsMethodDescriptor);
methodDescriptors.add(answerQueryMethodDescriptor);
methodDescriptors.add(getAnswerMethodDescriptor);
methodDescriptors.add(createSessionMethodDescriptor);
methodDescriptors.add(deleteSessionMethodDescriptor);
methodDescriptors.add(updateSessionMethodDescriptor);
methodDescriptors.add(getSessionMethodDescriptor);
methodDescriptors.add(listSessionsMethodDescriptor);
return methodDescriptors;
}
@Override
public UnaryCallable
converseConversationCallable() {
return converseConversationCallable;
}
@Override
public UnaryCallable createConversationCallable() {
return createConversationCallable;
}
@Override
public UnaryCallable deleteConversationCallable() {
return deleteConversationCallable;
}
@Override
public UnaryCallable updateConversationCallable() {
return updateConversationCallable;
}
@Override
public UnaryCallable getConversationCallable() {
return getConversationCallable;
}
@Override
public UnaryCallable
listConversationsCallable() {
return listConversationsCallable;
}
@Override
public UnaryCallable
listConversationsPagedCallable() {
return listConversationsPagedCallable;
}
@Override
public UnaryCallable answerQueryCallable() {
return answerQueryCallable;
}
@Override
public UnaryCallable getAnswerCallable() {
return getAnswerCallable;
}
@Override
public UnaryCallable createSessionCallable() {
return createSessionCallable;
}
@Override
public UnaryCallable deleteSessionCallable() {
return deleteSessionCallable;
}
@Override
public UnaryCallable updateSessionCallable() {
return updateSessionCallable;
}
@Override
public UnaryCallable getSessionCallable() {
return getSessionCallable;
}
@Override
public UnaryCallable listSessionsCallable() {
return listSessionsCallable;
}
@Override
public UnaryCallable listSessionsPagedCallable() {
return listSessionsPagedCallable;
}
@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);
}
}