Package com.google.cloud.spanner
Class SpannerOptions.SpannerCallContextTimeoutConfigurator
java.lang.Object
com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator
- All Implemented Interfaces:
SpannerOptions.CallContextConfigurator
- Enclosing class:
- SpannerOptions
public static class SpannerOptions.SpannerCallContextTimeoutConfigurator
extends Object
implements SpannerOptions.CallContextConfigurator
Helper class to configure timeouts for specific Spanner RPCs. The
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.
}
}
}
-
Method Summary
Modifier and TypeMethodDescription<ReqT,
RespT>
com.google.api.gax.rpc.ApiCallContextconfigure
(com.google.api.gax.rpc.ApiCallContext context, ReqT request, io.grpc.MethodDescriptor<ReqT, RespT> method) Configure aApiCallContext
for a specific RPC call.create()
org.threeten.bp.Duration
org.threeten.bp.Duration
org.threeten.bp.Duration
org.threeten.bp.Duration
org.threeten.bp.Duration
org.threeten.bp.Duration
org.threeten.bp.Duration
org.threeten.bp.Duration
withBatchUpdateTimeout
(org.threeten.bp.Duration batchUpdateTimeout) withCommitTimeout
(org.threeten.bp.Duration commitTimeout) withExecuteQueryTimeout
(org.threeten.bp.Duration executeQueryTimeout) withExecuteUpdateTimeout
(org.threeten.bp.Duration executeUpdateTimeout) withPartitionQueryTimeout
(org.threeten.bp.Duration partitionQueryTimeout) withPartitionReadTimeout
(org.threeten.bp.Duration partitionReadTimeout) withReadTimeout
(org.threeten.bp.Duration readTimeout) withRollbackTimeout
(org.threeten.bp.Duration rollbackTimeout)
-
Method Details
-
create
-
configure
public <ReqT,RespT> com.google.api.gax.rpc.ApiCallContext configure(com.google.api.gax.rpc.ApiCallContext context, ReqT request, io.grpc.MethodDescriptor<ReqT, RespT> method) Description copied from interface:SpannerOptions.CallContextConfigurator
Configure aApiCallContext
for a specific RPC call.- Specified by:
configure
in interfaceSpannerOptions.CallContextConfigurator
- Parameters:
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.- Returns:
- An
ApiCallContext
that will be merged with the defaultApiCallContext
. Ifnull
is returned, no changes to the defaultApiCallContext
will be made.
-
getCommitTimeout
public org.threeten.bp.Duration getCommitTimeout() -
withCommitTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withCommitTimeout(org.threeten.bp.Duration commitTimeout) -
getRollbackTimeout
public org.threeten.bp.Duration getRollbackTimeout() -
withRollbackTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withRollbackTimeout(org.threeten.bp.Duration rollbackTimeout) -
getExecuteQueryTimeout
public org.threeten.bp.Duration getExecuteQueryTimeout() -
withExecuteQueryTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withExecuteQueryTimeout(org.threeten.bp.Duration executeQueryTimeout) -
getExecuteUpdateTimeout
public org.threeten.bp.Duration getExecuteUpdateTimeout() -
withExecuteUpdateTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withExecuteUpdateTimeout(org.threeten.bp.Duration executeUpdateTimeout) -
getBatchUpdateTimeout
public org.threeten.bp.Duration getBatchUpdateTimeout() -
withBatchUpdateTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withBatchUpdateTimeout(org.threeten.bp.Duration batchUpdateTimeout) -
getReadTimeout
public org.threeten.bp.Duration getReadTimeout() -
withReadTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withReadTimeout(org.threeten.bp.Duration readTimeout) -
getPartitionQueryTimeout
public org.threeten.bp.Duration getPartitionQueryTimeout() -
withPartitionQueryTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withPartitionQueryTimeout(org.threeten.bp.Duration partitionQueryTimeout) -
getPartitionReadTimeout
public org.threeten.bp.Duration getPartitionReadTimeout() -
withPartitionReadTimeout
public SpannerOptions.SpannerCallContextTimeoutConfigurator withPartitionReadTimeout(org.threeten.bp.Duration partitionReadTimeout)
-