public static class SpannerOptions.SpannerCallContextTimeoutConfigurator implements SpannerOptions.CallContextConfigurator
Helper class to configure timeouts for specific Spanner RPCs. The 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.
}
}
}
Implements
SpannerOptions.CallContextConfiguratorStatic Methods
create()
public static SpannerOptions.SpannerCallContextTimeoutConfigurator create()
Returns | |
---|---|
Type | Description |
SpannerOptions.SpannerCallContextTimeoutConfigurator |
Methods
<ReqT,RespT>configure(ApiCallContext context, ReqT request, MethodDescriptor<ReqT,RespT> method)
public ApiCallContext <ReqT,RespT>configure(ApiCallContext context, ReqT