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 | |
---|---|
Name | Description |
context | ApiCallContext The default context. This can be used to inspect the current values. |
request | ReqT The request that will be sent. |
method | io.grpc.MethodDescriptor<ReqT,RespT> The method that is being called. |
Returns | |
---|---|
Type | Description |
ApiCallContext | An ApiCallContext that will be merged with the default ApiCallContext. If |