Class SpannerClients
One helper rather than one copy per direction, because the emulator-versus-credentials branch is exactly the code that reads green on a developer machine and red in CI: a handle built without the emulator host reaches for application default credentials, which a workstation has and a build agent does not.
Nothing else about the connection is configured. Spanner's own setEmulatorHost
switches the channel to plaintext and the credentials to none in one call, so this connector
never goes through the shared plaintext-channel helpers the other connectors need.
The same call puts the client in its emulator mode, where it records no client metrics into a
provider (SpannerOptions.isEmulatorEnabled(), 6.124.0), so an emulator job reports its
rpcMethod series at zero. The emulator branch also turns the built-in Cloud Monitoring
export off. In emulator mode the client never starts it anyway, and saying so explicitly keeps
the test switch below from starting the process-wide exporter against an emulator.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanWhether a client takes part in its built-in Cloud Monitoring export when nothing chooses; one place, asDEFAULT_EXPORT_CLIENT_METRICS_TO_FLINKis.static final booleanWhether a component exports its client's own metrics to Flink when nothing chooses: every builder starts from it, and a Table component without a builder resolves an unset option to it, so the default lives in one place (ADR-0139). -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(com.google.cloud.spanner.Spanner spanner, ClientMetrics clientMetrics) Closes a handle, then the client metrics its client recorded into, whatever the handle's close did.static com.google.cloud.spanner.Spanneropen(DatabaseDestination database, com.google.cloud.spanner.SpannerOptions settings) Opens a handle from settings already assembled by the owning runtime component.static com.google.cloud.spanner.Spanneropen(DatabaseDestination database, com.google.cloud.spanner.SpannerOptions settings, ClientMetrics clientMetrics) Opens a handle whose client records into client metrics the caller hands over with it, closing the client metrics if the handle cannot be created: nothing else would.static com.google.cloud.spanner.SpannerOpens a handle from settings, naming what it reaches in the failure message.static com.google.cloud.spanner.SpannerOptionssettings(DatabaseDestination database, EmulatorEndpoint emulatorEndpoint) Builds the client settings for a database.static com.google.cloud.spanner.SpannerOptionssettings(DatabaseDestination database, EmulatorEndpoint emulatorEndpoint, com.google.auth.Credentials credentialsOverride) Builds client settings with an optional runtime-loaded credential override.static com.google.cloud.spanner.SpannerOptionssettings(DatabaseDestination database, EmulatorEndpoint emulatorEndpoint, com.google.auth.Credentials credentialsOverride, ClientMetrics clientMetrics, boolean exportClientMetricsToCloudMonitoring) Builds client settings for a runtime component, with its client-metrics choices.static com.google.cloud.spanner.SpannerOptionssettings(String project, EmulatorEndpoint emulatorEndpoint, com.google.auth.Credentials credentialsOverride) Builds client settings for a project, for a caller that reaches more than one database, as the catalog does: the handle carries only the project, and each database is named per call.
-
Field Details
-
DEFAULT_EXPORT_CLIENT_METRICS_TO_FLINK
public static final boolean DEFAULT_EXPORT_CLIENT_METRICS_TO_FLINKWhether a component exports its client's own metrics to Flink when nothing chooses: every builder starts from it, and a Table component without a builder resolves an unset option to it, so the default lives in one place (ADR-0139).- See Also:
-
DEFAULT_EXPORT_CLIENT_METRICS_TO_CLOUD_MONITORING
public static final boolean DEFAULT_EXPORT_CLIENT_METRICS_TO_CLOUD_MONITORINGWhether a client takes part in its built-in Cloud Monitoring export when nothing chooses; one place, asDEFAULT_EXPORT_CLIENT_METRICS_TO_FLINKis.- See Also:
-
-
Method Details
-
settings
public static com.google.cloud.spanner.SpannerOptions settings(DatabaseDestination database, @Nullable EmulatorEndpoint emulatorEndpoint) Builds the client settings for a database.Separate from
open(DatabaseDestination, SpannerOptions)so that the mapping is testable without opening a channel.- Parameters:
database- the database the handle will reachemulatorEndpoint- the emulator to reach, ornullfor the real service- Returns:
- the settings
-
settings
public static com.google.cloud.spanner.SpannerOptions settings(DatabaseDestination database, @Nullable EmulatorEndpoint emulatorEndpoint, @Nullable com.google.auth.Credentials credentialsOverride) Builds client settings with an optional runtime-loaded credential override.- Parameters:
database- the database the handle will reachemulatorEndpoint- the emulator to reach, ornullfor the real servicecredentialsOverride- credentials loaded by the runtime component, ornullfor ADC- Returns:
- the settings
-
settings
public static com.google.cloud.spanner.SpannerOptions settings(String project, @Nullable EmulatorEndpoint emulatorEndpoint, @Nullable com.google.auth.Credentials credentialsOverride) Builds client settings for a project, for a caller that reaches more than one database, as the catalog does: the handle carries only the project, and each database is named per call.- Parameters:
project- the project the handle will reachemulatorEndpoint- the emulator to reach, ornullfor the real servicecredentialsOverride- credentials loaded by the runtime component, ornullfor ADC- Returns:
- the settings
-
settings
public static com.google.cloud.spanner.SpannerOptions settings(DatabaseDestination database, @Nullable EmulatorEndpoint emulatorEndpoint, @Nullable com.google.auth.Credentials credentialsOverride, @Nullable ClientMetrics clientMetrics, boolean exportClientMetricsToCloudMonitoring) Builds client settings for a runtime component, with its client-metrics choices.- Parameters:
database- the database the handle will reachemulatorEndpoint- the emulator to reach, ornullfor the real servicecredentialsOverride- credentials loaded by the runtime component, ornullfor ADCclientMetrics- the client metrics the client records into, ornullto export nothing to FlinkexportClientMetricsToCloudMonitoring- whether the client keeps its built-in Cloud Monitoring export- Returns:
- the settings
-
open
public static com.google.cloud.spanner.Spanner open(DatabaseDestination database, com.google.cloud.spanner.SpannerOptions settings) throws IOException Opens a handle from settings already assembled by the owning runtime component.- Parameters:
database- the database to reach, for the failure messagesettings- the settings to open the handle from- Returns:
- the handle, which the caller owns and must close
- Throws:
IOException- if the handle cannot be created
-
open
public static com.google.cloud.spanner.Spanner open(DatabaseDestination database, com.google.cloud.spanner.SpannerOptions settings, @Nullable ClientMetrics clientMetrics) throws IOException Opens a handle whose client records into client metrics the caller hands over with it, closing the client metrics if the handle cannot be created: nothing else would.- Parameters:
database- the database to reach, for the failure messagesettings- the settings to open the handle from, carrying the client metricsclientMetrics- the client metrics the settings carry, ornull- Returns:
- the handle, which the caller owns and closes with
close(Spanner, ClientMetrics) - Throws:
IOException- if the handle cannot be created
-
close
public static void close(com.google.cloud.spanner.Spanner spanner, @Nullable ClientMetrics clientMetrics) Closes a handle, then the client metrics its client recorded into, whatever the handle's close did. In this order because closed client metrics drop what they are given, so a client still closing would lose whatever it recorded meanwhile.- Parameters:
spanner- the handle to closeclientMetrics- the client metrics to close after it, ornull
-
open
public static com.google.cloud.spanner.Spanner open(String target, com.google.cloud.spanner.SpannerOptions settings) throws IOException Opens a handle from settings, naming what it reaches in the failure message.- Parameters:
target- what the handle reaches, for the failure messagesettings- the settings to open the handle from- Returns:
- the handle, which the caller owns and must close
- Throws:
IOException- if the handle cannot be created
-