All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.cloud.language.spi.v1beta1.LanguageServiceSettings Maven / Gradle / Ivy

There is a newer version: 2.57.0
Show newest version
/*
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * 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
 *
 * http://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.language.spi.v1beta1;

import com.google.api.gax.core.ConnectionSettings;
import com.google.api.gax.core.RetrySettings;
import com.google.api.gax.grpc.ApiCallSettings;
import com.google.api.gax.grpc.PageStreamingDescriptor;
import com.google.api.gax.grpc.ServiceApiSettings;
import com.google.api.gax.grpc.SimpleCallSettings;
import com.google.auth.Credentials;
import com.google.cloud.language.v1beta1.AnalyzeEntitiesRequest;
import com.google.cloud.language.v1beta1.AnalyzeEntitiesResponse;
import com.google.cloud.language.v1beta1.AnalyzeSentimentRequest;
import com.google.cloud.language.v1beta1.AnalyzeSentimentResponse;
import com.google.cloud.language.v1beta1.AnnotateTextRequest;
import com.google.cloud.language.v1beta1.AnnotateTextResponse;
import com.google.cloud.language.v1beta1.LanguageServiceGrpc;
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.common.collect.Sets;
import io.grpc.ManagedChannel;
import io.grpc.Status;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import org.joda.time.Duration;

// AUTO-GENERATED DOCUMENTATION AND CLASS
/**
 * Settings class to configure an instance of {@link LanguageServiceApi}.
 *
 * 

The default instance has everything set to sensible defaults: * *

    *
  • The default service address (language.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 analyzeSentiment to 30 seconds: * *

 * 
 * LanguageServiceSettings.Builder languageServiceSettingsBuilder =
 *     LanguageServiceSettings.defaultBuilder();
 * languageServiceSettingsBuilder.analyzeSentimentSettings().getRetrySettingsBuilder()
 *     .setTotalTimeout(Duration.standardSeconds(30));
 * LanguageServiceSettings languageServiceSettings = languageServiceSettingsBuilder.build();
 * 
 * 
*/ @javax.annotation.Generated("by GAPIC") public class LanguageServiceSettings extends ServiceApiSettings { /** * The default address of the service. */ private static final String DEFAULT_SERVICE_ADDRESS = "language.googleapis.com"; /** * The default port of the service. */ private static final int DEFAULT_SERVICE_PORT = 443; /** * The default scopes of the service. */ private static final ImmutableList DEFAULT_SERVICE_SCOPES = ImmutableList.builder().add("https://www.googleapis.com/auth/cloud-platform").build(); /** * The default connection settings of the service. */ public static final ConnectionSettings DEFAULT_CONNECTION_SETTINGS = ConnectionSettings.newBuilder() .setServiceAddress(DEFAULT_SERVICE_ADDRESS) .setPort(DEFAULT_SERVICE_PORT) .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) .build(); private final SimpleCallSettings analyzeSentimentSettings; private final SimpleCallSettings analyzeEntitiesSettings; private final SimpleCallSettings annotateTextSettings; /** * Returns the object with the settings used for calls to analyzeSentiment. */ public SimpleCallSettings analyzeSentimentSettings() { return analyzeSentimentSettings; } /** * Returns the object with the settings used for calls to analyzeEntities. */ public SimpleCallSettings analyzeEntitiesSettings() { return analyzeEntitiesSettings; } /** * Returns the object with the settings used for calls to annotateText. */ public SimpleCallSettings annotateTextSettings() { return annotateTextSettings; } /** * Returns the default service address. */ public static String getDefaultServiceAddress() { return DEFAULT_SERVICE_ADDRESS; } /** * Returns the default service port. */ public static int getDefaultServicePort() { return DEFAULT_SERVICE_PORT; } /** * Returns the default service scopes. */ public static ImmutableList getDefaultServiceScopes() { return DEFAULT_SERVICE_SCOPES; } /** * Returns a builder for this class with recommended defaults. */ public static Builder defaultBuilder() { return Builder.createDefault(); } /** * Returns a new builder for this class. */ public static Builder newBuilder() { return new Builder(); } /** * Returns a builder containing all the values of this settings class. */ public Builder toBuilder() { return new Builder(this); } private LanguageServiceSettings(Builder settingsBuilder) throws IOException { super( settingsBuilder.getChannelProvider(), settingsBuilder.getExecutorProvider(), settingsBuilder.getGeneratorName(), settingsBuilder.getGeneratorVersion(), settingsBuilder.getClientLibName(), settingsBuilder.getClientLibVersion()); analyzeSentimentSettings = settingsBuilder.analyzeSentimentSettings().build(); analyzeEntitiesSettings = settingsBuilder.analyzeEntitiesSettings().build(); annotateTextSettings = settingsBuilder.annotateTextSettings().build(); } /** * Builder for LanguageServiceSettings. */ public static class Builder extends ServiceApiSettings.Builder { private final ImmutableList methodSettingsBuilders; private SimpleCallSettings.Builder analyzeSentimentSettings; private SimpleCallSettings.Builder analyzeEntitiesSettings; private SimpleCallSettings.Builder annotateTextSettings; private static final ImmutableMap> RETRYABLE_CODE_DEFINITIONS; static { ImmutableMap.Builder> definitions = ImmutableMap.builder(); definitions.put( "idempotent", Sets.immutableEnumSet( Lists.newArrayList( Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE))); definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.newArrayList())); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } private static final ImmutableMap RETRY_PARAM_DEFINITIONS; static { ImmutableMap.Builder definitions = ImmutableMap.builder(); RetrySettings.Builder settingsBuilder = null; settingsBuilder = RetrySettings.newBuilder() .setInitialRetryDelay(Duration.millis(100L)) .setRetryDelayMultiplier(1.3) .setMaxRetryDelay(Duration.millis(60000L)) .setInitialRpcTimeout(Duration.millis(60000L)) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.millis(60000L)) .setTotalTimeout(Duration.millis(600000L)); definitions.put("default", settingsBuilder); RETRY_PARAM_DEFINITIONS = definitions.build(); } private Builder() { super(DEFAULT_CONNECTION_SETTINGS); analyzeSentimentSettings = SimpleCallSettings.newBuilder(LanguageServiceGrpc.METHOD_ANALYZE_SENTIMENT); analyzeEntitiesSettings = SimpleCallSettings.newBuilder(LanguageServiceGrpc.METHOD_ANALYZE_ENTITIES); annotateTextSettings = SimpleCallSettings.newBuilder(LanguageServiceGrpc.METHOD_ANNOTATE_TEXT); methodSettingsBuilders = ImmutableList.of( analyzeSentimentSettings, analyzeEntitiesSettings, annotateTextSettings); } private static Builder createDefault() { Builder builder = new Builder(); builder .analyzeSentimentSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); builder .analyzeEntitiesSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); builder .annotateTextSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettingsBuilder(RETRY_PARAM_DEFINITIONS.get("default")); return builder; } private Builder(LanguageServiceSettings settings) { super(settings); analyzeSentimentSettings = settings.analyzeSentimentSettings.toBuilder(); analyzeEntitiesSettings = settings.analyzeEntitiesSettings.toBuilder(); annotateTextSettings = settings.annotateTextSettings.toBuilder(); methodSettingsBuilders = ImmutableList.of( analyzeSentimentSettings, analyzeEntitiesSettings, annotateTextSettings); } @Override protected ConnectionSettings getDefaultConnectionSettings() { return DEFAULT_CONNECTION_SETTINGS; } @Override public Builder provideExecutorWith(ScheduledExecutorService executor, boolean shouldAutoClose) { super.provideExecutorWith(executor, shouldAutoClose); return this; } @Override public Builder provideChannelWith(ManagedChannel channel, boolean shouldAutoClose) { super.provideChannelWith(channel, shouldAutoClose); return this; } @Override public Builder provideChannelWith(ConnectionSettings settings) { super.provideChannelWith(settings); return this; } @Override public Builder provideChannelWith(Credentials credentials) { super.provideChannelWith(credentials); return this; } @Override public Builder provideChannelWith(List scopes) { super.provideChannelWith(scopes); return this; } @Override public Builder setGeneratorHeader(String name, String version) { super.setGeneratorHeader(name, version); return this; } @Override public Builder setClientLibHeader(String name, String version) { super.setClientLibHeader(name, version); return this; } /** * Applies the given settings to all of the API methods in this service. Only * values that are non-null will be applied, so this method is not capable * of un-setting any values. */ public Builder applyToAllApiMethods(ApiCallSettings.Builder apiCallSettings) throws Exception { super.applyToAllApiMethods(methodSettingsBuilders, apiCallSettings); return this; } /** * Returns the builder for the settings used for calls to analyzeSentiment. */ public SimpleCallSettings.Builder analyzeSentimentSettings() { return analyzeSentimentSettings; } /** * Returns the builder for the settings used for calls to analyzeEntities. */ public SimpleCallSettings.Builder analyzeEntitiesSettings() { return analyzeEntitiesSettings; } /** * Returns the builder for the settings used for calls to annotateText. */ public SimpleCallSettings.Builder annotateTextSettings() { return annotateTextSettings; } @Override public LanguageServiceSettings build() throws IOException { return new LanguageServiceSettings(this); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy