Package com.google.cloud
Class ServiceOptions<ServiceT extends Service<OptionsT>,OptionsT extends ServiceOptions<ServiceT,OptionsT>>
- java.lang.Object
-
- com.google.cloud.ServiceOptions<ServiceT,OptionsT>
-
- Type Parameters:
ServiceT
- the service subclassOptionsT
- theServiceOptions
subclass corresponding to the service
- All Implemented Interfaces:
Serializable
public abstract class ServiceOptions<ServiceT extends Service<OptionsT>,OptionsT extends ServiceOptions<ServiceT,OptionsT>> extends Object implements Serializable
Abstract class representing service options.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ServiceOptions.Builder<ServiceT extends Service<OptionsT>,OptionsT extends ServiceOptions<ServiceT,OptionsT>,B extends ServiceOptions.Builder<ServiceT,OptionsT,B>>
Builder forServiceOptions
.
-
Field Summary
Fields Modifier and Type Field Description protected String
clientLibToken
static String
CREDENTIAL_ENV_NAME
protected com.google.auth.Credentials
credentials
-
Constructor Summary
Constructors Modifier Constructor Description protected
ServiceOptions(Class<? extends ServiceFactory<ServiceT,OptionsT>> serviceFactoryClass, Class<? extends ServiceRpcFactory<OptionsT>> rpcFactoryClass, ServiceOptions.Builder<ServiceT,OptionsT,?> builder, ServiceDefaults<ServiceT,OptionsT> serviceDefaults)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
baseEquals(ServiceOptions<?,?> other)
protected int
baseHashCode()
protected com.google.api.gax.retrying.RetrySettings
defaultRetrySettings()
Some services may have different backoff requirements listed in their SLAs.static String
getAppEngineAppId()
protected static String
getAppEngineProjectId()
protected static String
getAppEngineProjectIdFromAppId()
String
getApplicationName()
Returns the application's name as a string in the formatgcloud-java/[version]
, optionally prepended with externally supplied User-Agent header value (via setting custom header provider).String
getClientLibToken()
com.google.api.core.ApiClock
getClock()
Returns the service's clock.com.google.auth.Credentials
getCredentials()
Returns the authentication credentials.protected String
getDefaultHost()
protected String
getDefaultProject()
static String
getDefaultProjectId()
Returns the default project ID, ornull
if no default project ID could be found.static com.google.api.gax.retrying.RetrySettings
getDefaultRetrySettings()
static <T> T
getFromServiceLoader(Class<? extends T> clazz, T defaultInstance)
static String
getGoogApiClientLibName()
Returns the library's name used by x-goog-api-client header as a string.protected static String
getGoogleCloudProjectId()
String
getHost()
Returns the service host.static String
getLibraryName()
Returns the library's name,gcloud-java
, as a string.String
getLibraryVersion()
Returns the library's version as a string.com.google.api.gax.rpc.HeaderProvider
getMergedHeaderProvider(com.google.api.gax.rpc.HeaderProvider internalHeaderProvider)
static com.google.api.gax.retrying.RetrySettings
getNoRetrySettings()
String
getProjectId()
Returns the project ID.String
getQuotaProjectId()
Returns the quotaProjectId that specifies the project used for quota and billing purposes.com.google.api.gax.retrying.RetrySettings
getRetrySettings()
Returns configuration parameters for request retries.ServiceRpc
getRpc()
Returns a Service RPC object for the current service.com.google.auth.Credentials
getScopedCredentials()
Returns the authentication credentials.protected abstract Set<String>
getScopes()
ServiceT
getService()
Returns a Service object for the current service.protected static String
getServiceAccountProjectId()
TransportOptions
getTransportOptions()
Returns the transport-specific options for this service.String
getUserAgent()
static <T> T
newInstance(String className)
protected boolean
projectIdRequired()
Returns whether a service requires a project ID.protected boolean
shouldRefreshRpc(ServiceRpc cachedRpc)
protected boolean
shouldRefreshService(ServiceT cachedService)
abstract <B extends ServiceOptions.Builder<ServiceT,OptionsT,B>>
BtoBuilder()
-
-
-
Field Detail
-
CREDENTIAL_ENV_NAME
public static final String CREDENTIAL_ENV_NAME
- See Also:
- Constant Field Values
-
clientLibToken
protected final String clientLibToken
-
credentials
protected com.google.auth.Credentials credentials
-
-
Constructor Detail
-
ServiceOptions
@InternalApi("This class should only be extended within google-cloud-java") protected ServiceOptions(Class<? extends ServiceFactory<ServiceT,OptionsT>> serviceFactoryClass, Class<? extends ServiceRpcFactory<OptionsT>> rpcFactoryClass, ServiceOptions.Builder<ServiceT,OptionsT,?> builder, ServiceDefaults<ServiceT,OptionsT> serviceDefaults)
-
-
Method Detail
-
projectIdRequired
protected boolean projectIdRequired()
Returns whether a service requires a project ID. This method may be overridden in service-specific Options objects.- Returns:
- true if a project ID is required to use the service, false if not
-
getDefaultHost
protected String getDefaultHost()
-
getDefaultProject
protected String getDefaultProject()
-
getDefaultProjectId
public static String getDefaultProjectId()
Returns the default project ID, ornull
if no default project ID could be found. This method returns the first available project ID among the following sources:- The project ID specified by the GOOGLE_CLOUD_PROJECT environment variable
- The App Engine project ID
- The project ID specified in the JSON credentials file pointed by the
GOOGLE_APPLICATION_CREDENTIALS
environment variable - The Google Cloud SDK project ID
- The Compute Engine project ID
-
getAppEngineAppId
public static String getAppEngineAppId()
-
getGoogleCloudProjectId
protected static String getGoogleCloudProjectId()
-
getAppEngineProjectId
protected static String getAppEngineProjectId()
-
getAppEngineProjectIdFromAppId
protected static String getAppEngineProjectIdFromAppId()
-
getServiceAccountProjectId
protected static String getServiceAccountProjectId()
-
getService
public ServiceT getService()
Returns a Service object for the current service. For instance, when using Google Cloud Storage, it returns a Storage object.
-
shouldRefreshService
protected boolean shouldRefreshService(ServiceT cachedService)
- Parameters:
cachedService
- The currently cached service object- Returns:
- true if the currently cached service object should be refreshed.
-
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.
-
shouldRefreshRpc
protected boolean shouldRefreshRpc(ServiceRpc cachedRpc)
- Parameters:
cachedRpc
- The currently cached service object- Returns:
- true if the currently cached service object should be refreshed.
-
getProjectId
public String getProjectId()
Returns the project ID. Return value can be null (for services that don't require a project ID).
-
getHost
public String getHost()
Returns the service host.
-
getCredentials
public com.google.auth.Credentials getCredentials()
Returns the authentication credentials.
-
getScopedCredentials
public com.google.auth.Credentials getScopedCredentials()
Returns the authentication credentials. If required, credentials are scoped.
-
getRetrySettings
public com.google.api.gax.retrying.RetrySettings getRetrySettings()
Returns configuration parameters for request retries.
-
getClock
public com.google.api.core.ApiClock getClock()
Returns the service's clock. Default time source usesSystem.currentTimeMillis()
to get current time.
-
getTransportOptions
public TransportOptions getTransportOptions()
Returns the transport-specific options for this service.
-
getApplicationName
public String getApplicationName()
Returns the application's name as a string in the formatgcloud-java/[version]
, optionally prepended with externally supplied User-Agent header value (via setting custom header provider).
-
getLibraryName
public static String getLibraryName()
Returns the library's name,gcloud-java
, as a string.
-
getGoogApiClientLibName
public static String getGoogApiClientLibName()
Returns the library's name used by x-goog-api-client header as a string.
-
getLibraryVersion
public String getLibraryVersion()
Returns the library's version as a string.
-
getMergedHeaderProvider
@InternalApi public final com.google.api.gax.rpc.HeaderProvider getMergedHeaderProvider(com.google.api.gax.rpc.HeaderProvider internalHeaderProvider)
-
getUserAgent
@InternalApi public final String getUserAgent()
-
baseHashCode
protected int baseHashCode()
-
baseEquals
protected boolean baseEquals(ServiceOptions<?,?> other)
-
newInstance
@InternalApi public static <T> T newInstance(String className) throws IOException, ClassNotFoundException
- Throws:
IOException
ClassNotFoundException
-
getDefaultRetrySettings
public static com.google.api.gax.retrying.RetrySettings getDefaultRetrySettings()
-
getNoRetrySettings
public static com.google.api.gax.retrying.RetrySettings getNoRetrySettings()
-
toBuilder
public abstract <B extends ServiceOptions.Builder<ServiceT,OptionsT,B>> B toBuilder()
-
defaultRetrySettings
protected com.google.api.gax.retrying.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 inRetrySettings
.
-
getFromServiceLoader
@InternalApi public static <T> T getFromServiceLoader(Class<? extends T> clazz, T defaultInstance)
-
getClientLibToken
public String getClientLibToken()
-
getQuotaProjectId
public String getQuotaProjectId()
Returns the quotaProjectId that specifies the project used for quota and billing purposes.
-
-