本文整理了Java中io.grpc.Metadata.merge()
方法的一些代码示例,展示了Metadata.merge()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.merge()
方法的具体详情如下:
包路径:io.grpc.Metadata
类名称:Metadata
方法名:merge
[英]Perform a simple merge of two sets of metadata.
This is a purely additive operation, because a single key can be associated with multiple values.
[中]执行两组元数据的简单合并。
这是一个纯粹的加法运算,因为一个键可以与多个值相关联。
代码示例来源:origin: com.salesforce.servicelibs/grpc-contrib
/**
* Copy constructor.
*/
AmbientContext(AmbientContext other) {
this();
this.contextMetadata.merge(other.contextMetadata);
}
代码示例来源:origin: salesforce/grpc-java-contrib
/**
* Copy constructor.
*/
AmbientContext(AmbientContext other) {
this();
this.contextMetadata.merge(other.contextMetadata);
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
headers.merge(extraHeaders);
super.start(responseListener, headers);
}
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/** Adds grpc-previous-rpc-attempts in the headers of a retry/hedging RPC. */
@VisibleForTesting
final Metadata updateHeaders(
Metadata originalHeaders, int previousAttempts) {
Metadata newHeaders = new Metadata();
newHeaders.merge(originalHeaders);
if (previousAttempts > 0) {
newHeaders.put(GRPC_PREVIOUS_RPC_ATTEMPTS, String.valueOf(previousAttempts));
}
return newHeaders;
}
代码示例来源:origin: io.grpc/grpc-core
/** Adds grpc-previous-rpc-attempts in the headers of a retry/hedging RPC. */
@VisibleForTesting
final Metadata updateHeaders(
Metadata originalHeaders, int previousAttemptCount) {
Metadata newHeaders = new Metadata();
newHeaders.merge(originalHeaders);
if (previousAttemptCount > 0) {
newHeaders.put(GRPC_PREVIOUS_RPC_ATTEMPTS, String.valueOf(previousAttemptCount));
}
return newHeaders;
}
代码示例来源:origin: io.grpc/grpc-core
@Override
public void apply(Metadata headers) {
checkState(!finalized, "apply() or fail() already called");
checkNotNull(headers, "headers");
origHeaders.merge(headers);
ClientStream realStream;
Context origCtx = ctx.attach();
try {
realStream = transport.newStream(method, origHeaders, callOptions);
} finally {
ctx.detach(origCtx);
}
finalizeWith(realStream);
}
代码示例来源:origin: io.grpc/grpc-auth
@Override
protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
throws StatusException {
Metadata cachedSaved;
URI uri = serviceUri(next, method);
synchronized (ClientAuthInterceptor.this) {
// TODO(louiscryan): This is icky but the current auth library stores the same
// metadata map until the next refresh cycle. This will be fixed once
// https://github.com/google/google-auth-library-java/issues/3
// is resolved.
// getRequestMetadata() may return a different map based on the provided URI, i.e., for
// JWT. However, today it does not cache JWT and so we won't bother tring to cache its
// return value based on the URI.
Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
if (lastMetadata == null || lastMetadata != latestMetadata) {
lastMetadata = latestMetadata;
cached = toHeaders(lastMetadata);
}
cachedSaved = cached;
}
headers.merge(cachedSaved);
delegate().start(responseListener, headers);
}
};
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
@Override
public void apply(Metadata headers) {
checkState(!finalized, "apply() or fail() already called");
checkNotNull(headers, "headers");
origHeaders.merge(headers);
ClientStream realStream;
Context origCtx = ctx.attach();
try {
realStream = transport.newStream(method, origHeaders, callOptions);
} finally {
ctx.detach(origCtx);
}
finalizeWith(realStream);
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
/**
* Calls {@link BigtableAsyncRpc#newCall(CallOptions)} and
* {@link BigtableAsyncRpc#start(Object, io.grpc.ClientCall.Listener, Metadata, ClientCall)} }
* with this as the listener so that retries happen correctly.
*/
protected void run() {
try (Scope scope = TRACER.withSpan(operationSpan)) {
rpcTimerContext = rpc.getRpcMetrics().timeRpc();
operationSpan.addAnnotation(Annotation.fromDescriptionAndAttributes("rpcStart",
ImmutableMap.of("attempt", AttributeValue.longAttributeValue(failedCount))));
Metadata metadata = new Metadata();
metadata.merge(originalMetadata);
callWrapper.setCallAndStart(rpc, getRpcCallOptions(), getRetryRequest(), this, metadata);
} catch (Exception e) {
setException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!