本文整理汇总了Java中io.grpc.Metadata.discardAll方法的典型用法代码示例。如果您正苦于以下问题:Java Metadata.discardAll方法的具体用法?Java Metadata.discardAll怎么用?Java Metadata.discardAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.Metadata
的用法示例。
在下文中一共展示了Metadata.discardAll方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertClientHeaders
import io.grpc.Metadata; //导入方法依赖的package包/类
public static Http2Headers convertClientHeaders(Metadata headers,
AsciiString scheme,
AsciiString defaultPath,
AsciiString authority,
AsciiString method,
AsciiString userAgent) {
Preconditions.checkNotNull(defaultPath, "defaultPath");
Preconditions.checkNotNull(authority, "authority");
Preconditions.checkNotNull(method, "method");
// Discard any application supplied duplicates of the reserved headers
headers.discardAll(CONTENT_TYPE_KEY);
headers.discardAll(GrpcUtil.TE_HEADER);
headers.discardAll(GrpcUtil.USER_AGENT_KEY);
return GrpcHttp2OutboundHeaders.clientRequestHeaders(
toHttp2Headers(headers),
authority,
defaultPath,
method,
scheme,
userAgent);
}
示例2: newClientStreamTracer
import io.grpc.Metadata; //导入方法依赖的package包/类
@Override
public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) {
ClientTracer tracer = new ClientTracer();
// TODO(zhangkun83): Once retry or hedging is implemented, a ClientCall may start more than
// one streams. We will need to update this file to support them.
if (streamTracerUpdater != null) {
checkState(
streamTracerUpdater.compareAndSet(this, null, tracer),
"Are you creating multiple streams per call? This class doesn't yet support this case");
} else {
checkState(
streamTracer == null,
"Are you creating multiple streams per call? This class doesn't yet support this case");
streamTracer = tracer;
}
if (module.propagateTags) {
headers.discardAll(module.statsHeader);
if (!module.tagger.empty().equals(parentCtx)) {
headers.put(module.statsHeader, parentCtx);
}
}
return tracer;
}
示例3: prepareHeaders
import io.grpc.Metadata; //导入方法依赖的package包/类
@VisibleForTesting
static void prepareHeaders(
Metadata headers,
DecompressorRegistry decompressorRegistry,
Compressor compressor,
boolean fullStreamDecompression) {
headers.discardAll(MESSAGE_ENCODING_KEY);
if (compressor != Codec.Identity.NONE) {
headers.put(MESSAGE_ENCODING_KEY, compressor.getMessageEncoding());
}
headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY);
byte[] advertisedEncodings =
InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry);
if (advertisedEncodings.length != 0) {
headers.put(MESSAGE_ACCEPT_ENCODING_KEY, advertisedEncodings);
}
headers.discardAll(CONTENT_ENCODING_KEY);
headers.discardAll(CONTENT_ACCEPT_ENCODING_KEY);
if (fullStreamDecompression) {
headers.put(CONTENT_ACCEPT_ENCODING_KEY, FULL_STREAM_DECOMPRESSION_ENCODINGS);
}
}
示例4: picked
import io.grpc.Metadata; //导入方法依赖的package包/类
@Override
public PickResult picked(Metadata headers) {
headers.discardAll(GrpclbConstants.TOKEN_METADATA_KEY);
if (token != null) {
headers.put(GrpclbConstants.TOKEN_METADATA_KEY, token);
}
return result;
}
示例5: convertServerHeaders
import io.grpc.Metadata; //导入方法依赖的package包/类
public static Http2Headers convertServerHeaders(Metadata headers) {
// Discard any application supplied duplicates of the reserved headers
headers.discardAll(CONTENT_TYPE_KEY);
headers.discardAll(GrpcUtil.TE_HEADER);
headers.discardAll(GrpcUtil.USER_AGENT_KEY);
return GrpcHttp2OutboundHeaders.serverResponseHeaders(toHttp2Headers(headers));
}
示例6: sendHeaders
import io.grpc.Metadata; //导入方法依赖的package包/类
@Override
public void sendHeaders(Metadata headers) {
checkState(!sendHeadersCalled, "sendHeaders has already been called");
checkState(!closeCalled, "call is closed");
headers.discardAll(MESSAGE_ENCODING_KEY);
if (compressor == null) {
compressor = Codec.Identity.NONE;
} else {
if (messageAcceptEncoding != null) {
// TODO(carl-mastrangelo): remove the string allocation.
if (!GrpcUtil.iterableContains(
ACCEPT_ENCODING_SPLITTER.split(new String(messageAcceptEncoding, GrpcUtil.US_ASCII)),
compressor.getMessageEncoding())) {
// resort to using no compression.
compressor = Codec.Identity.NONE;
}
} else {
compressor = Codec.Identity.NONE;
}
}
// Always put compressor, even if it's identity.
headers.put(MESSAGE_ENCODING_KEY, compressor.getMessageEncoding());
stream.setCompressor(compressor);
headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY);
byte[] advertisedEncodings =
InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry);
if (advertisedEncodings.length != 0) {
headers.put(MESSAGE_ACCEPT_ENCODING_KEY, advertisedEncodings);
}
// Don't check if sendMessage has been called, since it requires that sendHeaders was already
// called.
sendHeadersCalled = true;
stream.writeHeaders(headers);
}
示例7: addStatusToTrailers
import io.grpc.Metadata; //导入方法依赖的package包/类
private void addStatusToTrailers(Metadata trailers, Status status) {
trailers.discardAll(InternalStatus.CODE_KEY);
trailers.discardAll(InternalStatus.MESSAGE_KEY);
trailers.put(InternalStatus.CODE_KEY, status);
if (status.getDescription() != null) {
trailers.put(InternalStatus.MESSAGE_KEY, status.getDescription());
}
}
示例8: updateTimeoutHeaders
import io.grpc.Metadata; //导入方法依赖的package包/类
/**
* Based on the deadline, calculate and set the timeout to the given headers.
*/
private static void updateTimeoutHeaders(@Nullable Deadline effectiveDeadline,
@Nullable Deadline callDeadline, @Nullable Deadline outerCallDeadline, Metadata headers) {
headers.discardAll(TIMEOUT_KEY);
if (effectiveDeadline == null) {
return;
}
long effectiveTimeout = max(0, effectiveDeadline.timeRemaining(TimeUnit.NANOSECONDS));
headers.put(TIMEOUT_KEY, effectiveTimeout);
logIfContextNarrowedTimeout(effectiveTimeout, effectiveDeadline, outerCallDeadline,
callDeadline);
}
示例9: toMetadata
import io.grpc.Metadata; //导入方法依赖的package包/类
private static Metadata toMetadata(com.google.rpc.Status statusProto, Metadata metadata) {
checkNotNull(metadata, "metadata must not be null");
metadata.discardAll(STATUS_DETAILS_KEY);
metadata.put(STATUS_DETAILS_KEY, statusProto);
return metadata;
}
示例10: createRequestHeaders
import io.grpc.Metadata; //导入方法依赖的package包/类
/**
* Serializes the given headers and creates a list of OkHttp {@link Header}s to be used when
* creating a stream. Since this serializes the headers, this method should be called in the
* application thread context.
*/
public static List<Header> createRequestHeaders(
Metadata headers, String defaultPath, String authority, String userAgent, boolean useGet) {
Preconditions.checkNotNull(headers, "headers");
Preconditions.checkNotNull(defaultPath, "defaultPath");
Preconditions.checkNotNull(authority, "authority");
// Discard any application supplied duplicates of the reserved headers
headers.discardAll(GrpcUtil.CONTENT_TYPE_KEY);
headers.discardAll(GrpcUtil.TE_HEADER);
headers.discardAll(GrpcUtil.USER_AGENT_KEY);
// 7 is the number of explicit add calls below.
List<Header> okhttpHeaders = new ArrayList<Header>(7 + InternalMetadata.headerCount(headers));
// Set GRPC-specific headers.
okhttpHeaders.add(SCHEME_HEADER);
if (useGet) {
okhttpHeaders.add(METHOD_GET_HEADER);
} else {
okhttpHeaders.add(METHOD_HEADER);
}
okhttpHeaders.add(new Header(Header.TARGET_AUTHORITY, authority));
String path = defaultPath;
okhttpHeaders.add(new Header(Header.TARGET_PATH, path));
okhttpHeaders.add(new Header(GrpcUtil.USER_AGENT_KEY.name(), userAgent));
// All non-pseudo headers must come after pseudo headers.
okhttpHeaders.add(CONTENT_TYPE_HEADER);
okhttpHeaders.add(TE_HEADER);
// Now add any application-provided headers.
byte[][] serializedHeaders = TransportFrameUtil.toHttp2Headers(headers);
for (int i = 0; i < serializedHeaders.length; i += 2) {
ByteString key = ByteString.of(serializedHeaders[i]);
String keyString = key.utf8();
if (isApplicationHeader(keyString)) {
ByteString value = ByteString.of(serializedHeaders[i + 1]);
okhttpHeaders.add(new Header(key, value));
}
}
return okhttpHeaders;
}
示例11: stripTransportDetails
import io.grpc.Metadata; //导入方法依赖的package包/类
/**
* Strip HTTP transport implementation details so they don't leak via metadata into
* the application layer.
*/
private static void stripTransportDetails(Metadata metadata) {
metadata.discardAll(HTTP2_STATUS);
metadata.discardAll(InternalStatus.CODE_KEY);
metadata.discardAll(InternalStatus.MESSAGE_KEY);
}
示例12: newClientStreamTracer
import io.grpc.Metadata; //导入方法依赖的package包/类
@Override
public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) {
headers.discardAll(tracingHeader);
headers.put(tracingHeader, span.getContext());
return new ClientTracer(span);
}