Package com.google.cloud.spanner
Interface SpannerOptions.CallContextConfigurator
-
- All Known Implementing Classes:
SpannerOptions.SpannerCallContextTimeoutConfigurator
- Enclosing class:
- SpannerOptions
public static interface SpannerOptions.CallContextConfigurator
SpannerOptions.CallContextConfigurator
can be used to modify theApiCallContext
for one or more specific RPCs. This can be used to set specific timeout value for RPCs or use specificCallCredentials
for an RPC. TheSpannerOptions.CallContextConfigurator
must be set as a value on theContext
using theSpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY
key.This API is meant for advanced users. Most users should instead use the
SpannerOptions.SpannerCallContextTimeoutConfigurator
for setting timeouts per RPC.Example usage:
CallContextConfigurator configurator = new CallContextConfigurator() { public <ReqT, RespT> ApiCallContext configure( ApiCallContext context, ReqT request, MethodDescriptor<ReqT, RespT> method) { if (method == SpannerGrpc.getExecuteBatchDmlMethod()) { return GrpcCallContext.createDefault() .withCallOptions(CallOptions.DEFAULT.withDeadlineAfter(60L, TimeUnit.SECONDS)); } return null; } }; Context context = Context.current().withValue(SpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY, configurator); context.run( () -> { try { client .readWriteTransaction() .run( new TransactionCallable<long[]>() { public long[] run(TransactionContext transaction) throws Exception { return transaction.batchUpdate( ImmutableList.of(statement1, statement2)); } }); } catch (SpannerException e) { if (e.getErrorCode() == ErrorCode.DEADLINE_EXCEEDED) { // handle timeout exception. } } }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <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.
-
-
-
Method Detail
-
configure
@Nullable <ReqT,RespT> com.google.api.gax.rpc.ApiCallContext configure(com.google.api.gax.rpc.ApiCallContext context, ReqT request, io.grpc.MethodDescriptor<ReqT,RespT> method)
Configure aApiCallContext
for a specific RPC call.- 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.
-
-