com.google.cloud.dialogflow.v2.stub.EnvironmentsStubSettings Maven / Gradle / Ivy
Show all versions of google-cloud-dialogflow Show documentation
/*
* Copyright 2021 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.dialogflow.v2.stub;
import static com.google.cloud.dialogflow.v2.EnvironmentsClient.GetEnvironmentHistoryPagedResponse;
import static com.google.cloud.dialogflow.v2.EnvironmentsClient.ListEnvironmentsPagedResponse;
import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.PagedCallSettings;
import com.google.api.gax.rpc.PagedListDescriptor;
import com.google.api.gax.rpc.PagedListResponseFactory;
import com.google.api.gax.rpc.StatusCode;
import com.google.api.gax.rpc.StubSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.dialogflow.v2.CreateEnvironmentRequest;
import com.google.cloud.dialogflow.v2.DeleteEnvironmentRequest;
import com.google.cloud.dialogflow.v2.Environment;
import com.google.cloud.dialogflow.v2.EnvironmentHistory;
import com.google.cloud.dialogflow.v2.GetEnvironmentHistoryRequest;
import com.google.cloud.dialogflow.v2.GetEnvironmentRequest;
import com.google.cloud.dialogflow.v2.ListEnvironmentsRequest;
import com.google.cloud.dialogflow.v2.ListEnvironmentsResponse;
import com.google.cloud.dialogflow.v2.UpdateEnvironmentRequest;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.List;
import javax.annotation.Generated;
import org.threeten.bp.Duration;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
* Settings class to configure an instance of {@link EnvironmentsStub}.
*
* The default instance has everything set to sensible defaults:
*
*
* - The default service address (dialogflow.googleapis.com) and default port (443) are used.
*
- Credentials are acquired automatically through Application Default Credentials.
*
- Retries are configured for idempotent methods but not for non-idempotent methods.
*
*
* The builder of this class is recursive, so contained classes are themselves builders. When
* build() is called, the tree of builders is called to create the complete settings object.
*
*
For example, to set the total timeout of getEnvironment to 30 seconds:
*
*
{@code
* EnvironmentsStubSettings.Builder environmentsSettingsBuilder =
* EnvironmentsStubSettings.newBuilder();
* environmentsSettingsBuilder
* .getEnvironmentSettings()
* .setRetrySettings(
* environmentsSettingsBuilder
* .getEnvironmentSettings()
* .getRetrySettings()
* .toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30))
* .build());
* EnvironmentsStubSettings environmentsSettings = environmentsSettingsBuilder.build();
* }
*/
@Generated("by gapic-generator-java")
public class EnvironmentsStubSettings extends StubSettings {
/** The default scopes of the service. */
private static final ImmutableList DEFAULT_SERVICE_SCOPES =
ImmutableList.builder()
.add("https://www.googleapis.com/auth/cloud-platform")
.add("https://www.googleapis.com/auth/dialogflow")
.build();
private final PagedCallSettings<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
listEnvironmentsSettings;
private final UnaryCallSettings getEnvironmentSettings;
private final UnaryCallSettings createEnvironmentSettings;
private final UnaryCallSettings updateEnvironmentSettings;
private final UnaryCallSettings deleteEnvironmentSettings;
private final PagedCallSettings<
GetEnvironmentHistoryRequest, EnvironmentHistory, GetEnvironmentHistoryPagedResponse>
getEnvironmentHistorySettings;
private static final PagedListDescriptor<
ListEnvironmentsRequest, ListEnvironmentsResponse, Environment>
LIST_ENVIRONMENTS_PAGE_STR_DESC =
new PagedListDescriptor<
ListEnvironmentsRequest, ListEnvironmentsResponse, Environment>() {
@Override
public String emptyToken() {
return "";
}
@Override
public ListEnvironmentsRequest injectToken(
ListEnvironmentsRequest payload, String token) {
return ListEnvironmentsRequest.newBuilder(payload).setPageToken(token).build();
}
@Override
public ListEnvironmentsRequest injectPageSize(
ListEnvironmentsRequest payload, int pageSize) {
return ListEnvironmentsRequest.newBuilder(payload).setPageSize(pageSize).build();
}
@Override
public Integer extractPageSize(ListEnvironmentsRequest payload) {
return payload.getPageSize();
}
@Override
public String extractNextToken(ListEnvironmentsResponse payload) {
return payload.getNextPageToken();
}
@Override
public Iterable extractResources(ListEnvironmentsResponse payload) {
return payload.getEnvironmentsList() == null
? ImmutableList.of()
: payload.getEnvironmentsList();
}
};
private static final PagedListDescriptor<
GetEnvironmentHistoryRequest, EnvironmentHistory, EnvironmentHistory.Entry>
GET_ENVIRONMENT_HISTORY_PAGE_STR_DESC =
new PagedListDescriptor<
GetEnvironmentHistoryRequest, EnvironmentHistory, EnvironmentHistory.Entry>() {
@Override
public String emptyToken() {
return "";
}
@Override
public GetEnvironmentHistoryRequest injectToken(
GetEnvironmentHistoryRequest payload, String token) {
return GetEnvironmentHistoryRequest.newBuilder(payload).setPageToken(token).build();
}
@Override
public GetEnvironmentHistoryRequest injectPageSize(
GetEnvironmentHistoryRequest payload, int pageSize) {
return GetEnvironmentHistoryRequest.newBuilder(payload).setPageSize(pageSize).build();
}
@Override
public Integer extractPageSize(GetEnvironmentHistoryRequest payload) {
return payload.getPageSize();
}
@Override
public String extractNextToken(EnvironmentHistory payload) {
return payload.getNextPageToken();
}
@Override
public Iterable extractResources(EnvironmentHistory payload) {
return payload.getEntriesList() == null
? ImmutableList.of()
: payload.getEntriesList();
}
};
private static final PagedListResponseFactory<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
LIST_ENVIRONMENTS_PAGE_STR_FACT =
new PagedListResponseFactory<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>() {
@Override
public ApiFuture getFuturePagedResponse(
UnaryCallable callable,
ListEnvironmentsRequest request,
ApiCallContext context,
ApiFuture futureResponse) {
PageContext
pageContext =
PageContext.create(
callable, LIST_ENVIRONMENTS_PAGE_STR_DESC, request, context);
return ListEnvironmentsPagedResponse.createAsync(pageContext, futureResponse);
}
};
private static final PagedListResponseFactory<
GetEnvironmentHistoryRequest, EnvironmentHistory, GetEnvironmentHistoryPagedResponse>
GET_ENVIRONMENT_HISTORY_PAGE_STR_FACT =
new PagedListResponseFactory<
GetEnvironmentHistoryRequest,
EnvironmentHistory,
GetEnvironmentHistoryPagedResponse>() {
@Override
public ApiFuture getFuturePagedResponse(
UnaryCallable callable,
GetEnvironmentHistoryRequest request,
ApiCallContext context,
ApiFuture futureResponse) {
PageContext<
GetEnvironmentHistoryRequest, EnvironmentHistory, EnvironmentHistory.Entry>
pageContext =
PageContext.create(
callable, GET_ENVIRONMENT_HISTORY_PAGE_STR_DESC, request, context);
return GetEnvironmentHistoryPagedResponse.createAsync(pageContext, futureResponse);
}
};
/** Returns the object with the settings used for calls to listEnvironments. */
public PagedCallSettings<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
listEnvironmentsSettings() {
return listEnvironmentsSettings;
}
/** Returns the object with the settings used for calls to getEnvironment. */
public UnaryCallSettings getEnvironmentSettings() {
return getEnvironmentSettings;
}
/** Returns the object with the settings used for calls to createEnvironment. */
public UnaryCallSettings createEnvironmentSettings() {
return createEnvironmentSettings;
}
/** Returns the object with the settings used for calls to updateEnvironment. */
public UnaryCallSettings updateEnvironmentSettings() {
return updateEnvironmentSettings;
}
/** Returns the object with the settings used for calls to deleteEnvironment. */
public UnaryCallSettings deleteEnvironmentSettings() {
return deleteEnvironmentSettings;
}
/** Returns the object with the settings used for calls to getEnvironmentHistory. */
public PagedCallSettings<
GetEnvironmentHistoryRequest, EnvironmentHistory, GetEnvironmentHistoryPagedResponse>
getEnvironmentHistorySettings() {
return getEnvironmentHistorySettings;
}
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public EnvironmentsStub createStub() throws IOException {
if (getTransportChannelProvider()
.getTransportName()
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcEnvironmentsStub.create(this);
}
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
}
/** Returns a builder for the default ExecutorProvider for this service. */
public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() {
return InstantiatingExecutorProvider.newBuilder();
}
/** Returns the default service endpoint. */
public static String getDefaultEndpoint() {
return "dialogflow.googleapis.com:443";
}
/** Returns the default mTLS service endpoint. */
public static String getDefaultMtlsEndpoint() {
return "dialogflow.mtls.googleapis.com:443";
}
/** Returns the default service scopes. */
public static List getDefaultServiceScopes() {
return DEFAULT_SERVICE_SCOPES;
}
/** Returns a builder for the default credentials for this service. */
public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() {
return GoogleCredentialsProvider.newBuilder()
.setScopesToApply(DEFAULT_SERVICE_SCOPES)
.setUseJwtAccessWithScope(true);
}
/** Returns a builder for the default ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return InstantiatingGrpcChannelProvider.newBuilder()
.setMaxInboundMessageSize(Integer.MAX_VALUE);
}
public static TransportChannelProvider defaultTransportChannelProvider() {
return defaultGrpcTransportProviderBuilder().build();
}
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken(
"gapic", GaxProperties.getLibraryVersion(EnvironmentsStubSettings.class))
.setTransportToken(
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}
/** Returns a new builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
}
/** Returns a builder containing all the values of this settings class. */
public Builder toBuilder() {
return new Builder(this);
}
protected EnvironmentsStubSettings(Builder settingsBuilder) throws IOException {
super(settingsBuilder);
listEnvironmentsSettings = settingsBuilder.listEnvironmentsSettings().build();
getEnvironmentSettings = settingsBuilder.getEnvironmentSettings().build();
createEnvironmentSettings = settingsBuilder.createEnvironmentSettings().build();
updateEnvironmentSettings = settingsBuilder.updateEnvironmentSettings().build();
deleteEnvironmentSettings = settingsBuilder.deleteEnvironmentSettings().build();
getEnvironmentHistorySettings = settingsBuilder.getEnvironmentHistorySettings().build();
}
/** Builder for EnvironmentsStubSettings. */
public static class Builder extends StubSettings.Builder {
private final ImmutableList> unaryMethodSettingsBuilders;
private final PagedCallSettings.Builder<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
listEnvironmentsSettings;
private final UnaryCallSettings.Builder
getEnvironmentSettings;
private final UnaryCallSettings.Builder
createEnvironmentSettings;
private final UnaryCallSettings.Builder
updateEnvironmentSettings;
private final UnaryCallSettings.Builder
deleteEnvironmentSettings;
private final PagedCallSettings.Builder<
GetEnvironmentHistoryRequest, EnvironmentHistory, GetEnvironmentHistoryPagedResponse>
getEnvironmentHistorySettings;
private static final ImmutableMap>
RETRYABLE_CODE_DEFINITIONS;
static {
ImmutableMap.Builder> definitions =
ImmutableMap.builder();
definitions.put(
"retry_policy_0_codes",
ImmutableSet.copyOf(Lists.newArrayList(StatusCode.Code.UNAVAILABLE)));
RETRYABLE_CODE_DEFINITIONS = definitions.build();
}
private static final ImmutableMap RETRY_PARAM_DEFINITIONS;
static {
ImmutableMap.Builder definitions = ImmutableMap.builder();
RetrySettings settings = null;
settings =
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(100L))
.setRetryDelayMultiplier(1.3)
.setMaxRetryDelay(Duration.ofMillis(60000L))
.setInitialRpcTimeout(Duration.ofMillis(60000L))
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ofMillis(60000L))
.setTotalTimeout(Duration.ofMillis(60000L))
.build();
definitions.put("retry_policy_0_params", settings);
RETRY_PARAM_DEFINITIONS = definitions.build();
}
protected Builder() {
this(((ClientContext) null));
}
protected Builder(ClientContext clientContext) {
super(clientContext);
listEnvironmentsSettings = PagedCallSettings.newBuilder(LIST_ENVIRONMENTS_PAGE_STR_FACT);
getEnvironmentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
createEnvironmentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
updateEnvironmentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
deleteEnvironmentSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
getEnvironmentHistorySettings =
PagedCallSettings.newBuilder(GET_ENVIRONMENT_HISTORY_PAGE_STR_FACT);
unaryMethodSettingsBuilders =
ImmutableList.>of(
listEnvironmentsSettings,
getEnvironmentSettings,
createEnvironmentSettings,
updateEnvironmentSettings,
deleteEnvironmentSettings,
getEnvironmentHistorySettings);
initDefaults(this);
}
protected Builder(EnvironmentsStubSettings settings) {
super(settings);
listEnvironmentsSettings = settings.listEnvironmentsSettings.toBuilder();
getEnvironmentSettings = settings.getEnvironmentSettings.toBuilder();
createEnvironmentSettings = settings.createEnvironmentSettings.toBuilder();
updateEnvironmentSettings = settings.updateEnvironmentSettings.toBuilder();
deleteEnvironmentSettings = settings.deleteEnvironmentSettings.toBuilder();
getEnvironmentHistorySettings = settings.getEnvironmentHistorySettings.toBuilder();
unaryMethodSettingsBuilders =
ImmutableList.>of(
listEnvironmentsSettings,
getEnvironmentSettings,
createEnvironmentSettings,
updateEnvironmentSettings,
deleteEnvironmentSettings,
getEnvironmentHistorySettings);
}
private static Builder createDefault() {
Builder builder = new Builder(((ClientContext) null));
builder.setTransportChannelProvider(defaultTransportChannelProvider());
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build());
builder.setEndpoint(getDefaultEndpoint());
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
builder.setSwitchToMtlsEndpointAllowed(true);
return initDefaults(builder);
}
private static Builder initDefaults(Builder builder) {
builder
.listEnvironmentsSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
builder
.getEnvironmentSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
builder
.createEnvironmentSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
builder
.updateEnvironmentSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
builder
.deleteEnvironmentSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
builder
.getEnvironmentHistorySettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params"));
return builder;
}
/**
* Applies the given settings updater function to all of the unary API methods in this service.
*
* Note: This method does not support applying settings to streaming methods.
*/
public Builder applyToAllUnaryMethods(
ApiFunction, Void> settingsUpdater) {
super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater);
return this;
}
public ImmutableList> unaryMethodSettingsBuilders() {
return unaryMethodSettingsBuilders;
}
/** Returns the builder for the settings used for calls to listEnvironments. */
public PagedCallSettings.Builder<
ListEnvironmentsRequest, ListEnvironmentsResponse, ListEnvironmentsPagedResponse>
listEnvironmentsSettings() {
return listEnvironmentsSettings;
}
/** Returns the builder for the settings used for calls to getEnvironment. */
public UnaryCallSettings.Builder getEnvironmentSettings() {
return getEnvironmentSettings;
}
/** Returns the builder for the settings used for calls to createEnvironment. */
public UnaryCallSettings.Builder
createEnvironmentSettings() {
return createEnvironmentSettings;
}
/** Returns the builder for the settings used for calls to updateEnvironment. */
public UnaryCallSettings.Builder
updateEnvironmentSettings() {
return updateEnvironmentSettings;
}
/** Returns the builder for the settings used for calls to deleteEnvironment. */
public UnaryCallSettings.Builder deleteEnvironmentSettings() {
return deleteEnvironmentSettings;
}
/** Returns the builder for the settings used for calls to getEnvironmentHistory. */
public PagedCallSettings.Builder<
GetEnvironmentHistoryRequest, EnvironmentHistory, GetEnvironmentHistoryPagedResponse>
getEnvironmentHistorySettings() {
return getEnvironmentHistorySettings;
}
@Override
public EnvironmentsStubSettings build() throws IOException {
return new EnvironmentsStubSettings(this);
}
}
}