Class ServiceOptions<ServiceT,OptionsT> (2.31.0)

public abstract class ServiceOptions<ServiceT,OptionsT> implements Serializable

Abstract class representing service options.

Inheritance

java.lang.Object > ServiceOptions<ServiceT,OptionsT>

Implements

Serializable

Type Parameters

NameDescription
ServiceT
OptionsT

Static Fields

CREDENTIAL_ENV_NAME

public static final String CREDENTIAL_ENV_NAME
Field Value
TypeDescription
String

Static Methods

<T>getFromServiceLoader(Class<? extends T> clazz, T defaultInstance)

public static T <T>getFromServiceLoader(Class<? extends T> clazz, T defaultInstance)
Parameters
NameDescription
clazzClass<? extends T>
defaultInstanceT
Returns
TypeDescription
T

<T>newInstance(String className)

public static T <T>newInstance(String className)
Parameter
NameDescription
classNameString
Returns
TypeDescription
T
Exceptions
TypeDescription
IOException
ClassNotFoundException

getAppEngineAppId()

public static String getAppEngineAppId()
Returns
TypeDescription
String

getAppEngineProjectId()

protected static String getAppEngineProjectId()
Returns
TypeDescription
String

getAppEngineProjectIdFromAppId()

protected static String getAppEngineProjectIdFromAppId()
Returns
TypeDescription
String

getDefaultProjectId()

public static String getDefaultProjectId()

Returns the default project ID, or null if no default project ID could be found. This method returns the first available project ID among the following sources:

  1. The project ID specified by the GOOGLE_CLOUD_PROJECT environment variable
  2. The App Engine project ID
  3. The project ID specified in the JSON credentials file pointed by the GOOGLE_APPLICATION_CREDENTIALS environment variable
  4. The Google Cloud SDK project ID
  5. The Compute Engine project ID
Returns
TypeDescription
String

getDefaultRetrySettings()

public static RetrySettings getDefaultRetrySettings()
Returns
TypeDescription
RetrySettings

getGoogApiClientLibName()

public static String getGoogApiClientLibName()

Returns the library's name used by x-goog-api-client header as a string.

Returns
TypeDescription
String

getGoogleCloudProjectId()

protected static String getGoogleCloudProjectId()
Returns
TypeDescription
String

getLibraryName()

public static String getLibraryName()

Returns the library's name, gcloud-java, as a string.

Returns
TypeDescription
String

getNoRetrySettings()

public static RetrySettings getNoRetrySettings()
Returns
TypeDescription
RetrySettings

getServiceAccountProjectId()

protected static String getServiceAccountProjectId()
Returns
TypeDescription
String

Constructors

ServiceOptions(Class<? extends ServiceFactory<ServiceT,OptionsT>> serviceFactoryClass, Class<? extends ServiceRpcFactory<OptionsT>> rpcFactoryClass, ServiceOptions.Builder<ServiceT,OptionsT,?> builder, ServiceDefaults<ServiceT,OptionsT> serviceDefaults)

protected ServiceOptions(Class<? extends ServiceFactory<ServiceT,OptionsT>> serviceFactoryClass, Class<? extends ServiceRpcFactory<OptionsT>> rpcFactoryClass, ServiceOptions.Builder<ServiceT,OptionsT,?> builder, ServiceDefaults<ServiceT,OptionsT> serviceDefaults)
Parameters
NameDescription
serviceFactoryClassClass<? extends com.google.cloud.ServiceFactory<ServiceT,OptionsT>>
rpcFactoryClassClass<? extends com.google.cloud.spi.ServiceRpcFactory<OptionsT>>
builderBuilder<ServiceT,OptionsT,?>
serviceDefaultsServiceDefaults<ServiceT,OptionsT>

Fields

clientLibToken

protected final String clientLibToken
Field Value
TypeDescription
String

credentials

protected Credentials credentials
Field Value
TypeDescription
com.google.auth.Credentials

Methods

<B>toBuilder()

public abstract B <B>toBuilder()
Returns
TypeDescription
B

baseEquals(ServiceOptions<?,?> other)

protected boolean baseEquals(ServiceOptions<?,?> other)
Parameter
NameDescription
otherServiceOptions<?,?>
Returns
TypeDescription
boolean

baseHashCode()

protected int baseHashCode()
Returns
TypeDescription
int

defaultRetrySettings()

protected RetrySettings defaultRetrySettings()

Some services may have different backoff requirements listed in their SLAs. Be sure to override this method in options subclasses when the service's backoff requirement differs from the default parameters listed in RetrySettings.

Returns
TypeDescription
RetrySettings

getApiTracerFactory()

public ApiTracerFactory getApiTracerFactory()
Returns
TypeDescription
ApiTracerFactory

getApplicationName()

public String getApplicationName()

Returns the application's name as a string in the format gcloud-java/[version], optionally prepended with externally supplied User-Agent header value (via setting custom header provider).

Returns
TypeDescription
String

getClientLibToken()

public String getClientLibToken()
Returns
TypeDescription
String

getClock()

public ApiClock getClock()

Returns the service's clock. Default time source uses System#currentTimeMillis() to get current time.

Returns
TypeDescription
ApiClock

getCredentials()

public Credentials getCredentials()

Returns the authentication credentials.

Returns
TypeDescription
com.google.auth.Credentials

getDefaultHost()

protected String getDefaultHost()
Returns
TypeDescription
String

getDefaultProject()

protected String getDefaultProject()
Returns
TypeDescription
String

getHost()

public String getHost()

Returns the service host.

Returns
TypeDescription
String

getLibraryVersion()

public String getLibraryVersion()

Returns the library's version as a string.

Returns
TypeDescription
String

getMergedHeaderProvider(HeaderProvider internalHeaderProvider)

public final HeaderProvider getMergedHeaderProvider(HeaderProvider internalHeaderProvider)
Parameter
NameDescription
internalHeaderProviderHeaderProvider
Returns
TypeDescription
HeaderProvider

getProjectId()

public String getProjectId()

Returns the project ID. Return value can be null (for services that don't require a project ID).

Returns
TypeDescription
String

getQuotaProjectId()

public String getQuotaProjectId()

Returns the quotaProjectId that specifies the project used for quota and billing purposes.

Returns
TypeDescription
String

getResolvedApiaryHost(String serviceName)

public String getResolvedApiaryHost(String serviceName)

Temporarily used for BigQuery and Storage Apiary Wrapped Libraries. To be removed in the future when Apiary clients can resolve their endpoints. Returns the host to be used as the rootUrl.

The resolved host will be in https://{serviceName}.{resolvedUniverseDomain}/ format. The resolvedUniverseDomain will be set to googleapis.com if universeDomain is null. See Also: rootUrl

Parameter
NameDescription
serviceNameString
Returns
TypeDescription
String

getResolvedHost(String serviceName)

public String getResolvedHost(String serviceName)

Returns the resolved host for the Service to connect to Google Cloud

The resolved host will be in https://{serviceName}.{resolvedUniverseDomain} format. The resolvedUniverseDomain will be set to googleapis.com if universeDomain is null. The format is similar to the DEFAULT_HOST value in java-core. See Also: DEFAULT_HOST

Parameter
NameDescription
serviceNameString
Returns
TypeDescription
String

getRetrySettings()

public RetrySettings getRetrySettings()

Returns configuration parameters for request retries.

Returns
TypeDescription
RetrySettings

getRpc()

public ServiceRpc getRpc()

Returns a Service RPC object for the current service. For instance, when using Google Cloud Storage, it returns a StorageRpc object.

Returns
TypeDescription
ServiceRpc

getScopedCredentials()

public Credentials getScopedCredentials()

Returns the authentication credentials. If required, credentials are scoped.

Returns
TypeDescription
com.google.auth.Credentials

getScopes()

protected abstract Set<String> getScopes()
Returns
TypeDescription
Set<String>

getService()

public ServiceT getService()

Returns a Service object for the current service. For instance, when using Google Cloud Storage, it returns a Storage object.

Returns
TypeDescription
ServiceT

getTransportOptions()

public TransportOptions getTransportOptions()

Returns the transport-specific options for this service.

Returns
TypeDescription
TransportOptions

getUniverseDomain()

public String getUniverseDomain()

Universe Domain is the domain for Google Cloud Services. A Google Cloud endpoint follows the format of {ServiceName}.{UniverseDomain}. For example, speech.googleapis.com would have a Universe Domain value of googleapis.com and cloudasset.test.com would have a Universe Domain of test.com.

Returns
TypeDescription
String

The universe domain value set in the Builder's setter. This is not the resolved Universe Domain

getUserAgent()

public final String getUserAgent()
Returns
TypeDescription
String

hasValidUniverseDomain()

public boolean hasValidUniverseDomain()

Validates that Credentials' Universe Domain matches the resolved Universe Domain. Currently, this is only intended for BigQuery and Storage Apiary Wrapped Libraries.

This validation call should be made prior to any RPC invocation. This call is used to gate the RPC invocation if there is no valid universe domain.

Returns
TypeDescription
boolean
Exceptions
TypeDescription
IOException

projectIdRequired()

protected boolean projectIdRequired()

Returns whether a service requires a project ID. This method may be overridden in service-specific Options objects.

Returns
TypeDescription
boolean

true if a project ID is required to use the service, false if not

shouldRefreshRpc(ServiceRpc cachedRpc)

protected boolean shouldRefreshRpc(ServiceRpc cachedRpc)
Parameter
NameDescription
cachedRpcServiceRpc

The currently cached service object

Returns
TypeDescription
boolean

true if the currently cached service object should be refreshed.

shouldRefreshService(ServiceT cachedService)

protected boolean shouldRefreshService(ServiceT cachedService)
Parameter
NameDescription
cachedServiceServiceT

The currently cached service object

Returns
TypeDescription
boolean

true if the currently cached service object should be refreshed.