Package com.google.cloud.spanner
Interface SpannerOptions.CallContextConfigurator
-
- All Known Implementing Classes:
SpannerOptions.SpannerCallContextTimeoutConfigurator
- Enclosing class:
- SpannerOptions
public static interface SpannerOptions.CallContextConfiguratorSpannerOptions.CallContextConfiguratorcan be used to modify theApiCallContextfor one or more specific RPCs. This can be used to set specific timeout value for RPCs or use specificCallCredentialsfor an RPC. TheSpannerOptions.CallContextConfiguratormust be set as a value on theContextusing theSpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEYkey.This API is meant for advanced users. Most users should instead use the
SpannerOptions.SpannerCallContextTimeoutConfiguratorfor 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 aApiCallContextfor 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 aApiCallContextfor 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
ApiCallContextthat will be merged with the defaultApiCallContext. Ifnullis returned, no changes to the defaultApiCallContextwill be made.
-
-