Interface SpannerOptions.CallContextConfigurator (6.56.0)

public static interface SpannerOptions.CallContextConfigurator

CallContextConfigurator can be used to modify the ApiCallContext for one or more specific RPCs. This can be used to set specific timeout value for RPCs or use specific CallCredentials for an RPC. The CallContextConfigurator must be set as a value on the Context using the SpannerOptions#CALL_CONTEXT_CONFIGURATOR_KEY key.

This API is meant for advanced users. Most users should instead use the 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

Methods

<ReqT,RespT>configure(ApiCallContext context, ReqT request, MethodDescriptor<ReqT,RespT> method)

public abstract ApiCallContext <ReqT,RespT>configure(ApiCallContext context, ReqT request, MethodDescriptor<ReqT,RespT> method)

Configure a ApiCallContext for a specific RPC call.

Parameters
NameDescription
contextApiCallContext

The default context. This can be used to inspect the current values.

requestReqT

The request that will be sent.

methodio.grpc.MethodDescriptor<ReqT,RespT>

The method that is being called.

Returns
TypeDescription
ApiCallContext

An ApiCallContext that will be merged with the default ApiCallContext. If null is returned, no changes to the default ApiCallContext will be made.