public static class SpannerOptions.SpannerCallContextTimeoutConfigurator extends Object implements SpannerOptions.CallContextConfigurator
SpannerOptions.SpannerCallContextTimeoutConfigurator
must be set as a value on the Context
using the
SpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY
key.
Example usage:
// Create a context with a ExecuteQuery timeout of 10 seconds.
Context context =
Context.current()
.withValue(
SpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY,
SpannerCallContextTimeoutConfigurator.create()
.withExecuteQueryTimeout(Duration.ofSeconds(10L)));
context.run(
() -> {
try (ResultSet rs =
client
.singleUse()
.executeQuery(
Statement.of(
"SELECT SingerId, FirstName, LastName FROM Singers ORDER BY LastName"))) {
while (rs.next()) {
System.out.printf("%d %s %s%n", rs.getLong(0), rs.getString(1), rs.getString(2));
}
} catch (SpannerException e) {
if (e.getErrorCode() == ErrorCode.DEADLINE_EXCEEDED) {
// Handle timeout.
}
}
}
public static SpannerOptions.SpannerCallContextTimeoutConfigurator create()
public <ReqT,RespT> ApiCallContext configure(ApiCallContext context, ReqT request, MethodDescriptor<ReqT,RespT> method)
SpannerOptions.CallContextConfigurator
ApiCallContext
for a specific RPC call.configure
in interface SpannerOptions.CallContextConfigurator
context
- The default context. This can be used to inspect the current values.request
- The request that will be sent.method
- The method that is being called.ApiCallContext
that will be merged with the default ApiCallContext
. If null
is returned, no changes to the default ApiCallContext
will be made.public org.threeten.bp.Duration getCommitTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withCommitTimeout(org.threeten.bp.Duration commitTimeout)
public org.threeten.bp.Duration getRollbackTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withRollbackTimeout(org.threeten.bp.Duration rollbackTimeout)
public org.threeten.bp.Duration getExecuteQueryTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withExecuteQueryTimeout(org.threeten.bp.Duration executeQueryTimeout)
public org.threeten.bp.Duration getExecuteUpdateTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withExecuteUpdateTimeout(org.threeten.bp.Duration executeUpdateTimeout)
public org.threeten.bp.Duration getBatchUpdateTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withBatchUpdateTimeout(org.threeten.bp.Duration batchUpdateTimeout)
public org.threeten.bp.Duration getReadTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withReadTimeout(org.threeten.bp.Duration readTimeout)
public org.threeten.bp.Duration getPartitionQueryTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withPartitionQueryTimeout(org.threeten.bp.Duration partitionQueryTimeout)
public org.threeten.bp.Duration getPartitionReadTimeout()
public SpannerOptions.SpannerCallContextTimeoutConfigurator withPartitionReadTimeout(org.threeten.bp.Duration partitionReadTimeout)
Copyright © 2022 Google LLC. All rights reserved.