io.grpc.Metadata.discardAll()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中io.grpc.Metadata.discardAll()方法的一些代码示例,展示了Metadata.discardAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.discardAll()方法的具体详情如下:
包路径:io.grpc.Metadata
类名称:Metadata
方法名:discardAll

Metadata.discardAll介绍

[英]Remove all values for the given key without returning them. This is a minor performance optimization if you do not need the previous values.
[中]删除给定键的所有值而不返回它们。如果不需要前面的值,这是一个较小的性能优化。

代码示例

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
  * 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);
 }
}

代码示例来源:origin: io.grpc/grpc-core

/**
  * 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);
 }
}

代码示例来源:origin: io.grpc/grpc-grpclb

@Override
public PickResult picked(Metadata headers) {
 headers.discardAll(GrpclbConstants.TOKEN_METADATA_KEY);
 if (token != null) {
  headers.put(GrpclbConstants.TOKEN_METADATA_KEY, token);
 }
 return result;
}

代码示例来源:origin: salesforce/grpc-java-contrib

/**
 * Remove all values for the given key without returning them. This is a minor performance
 * optimization if you do not need the previous values.
 *
 * @throws IllegalStateException  if the AmbientContext is frozen
 */
public <T> void discardAll(Metadata.Key<T> key) {
  checkFreeze();
  contextMetadata.discardAll(key);
}

代码示例来源:origin: com.salesforce.servicelibs/grpc-contrib

/**
 * Remove all values for the given key without returning them. This is a minor performance
 * optimization if you do not need the previous values.
 *
 * @throws IllegalStateException  if the AmbientContext is frozen
 */
public <T> void discardAll(Metadata.Key<T> key) {
  checkFreeze();
  contextMetadata.discardAll(key);
}

代码示例来源:origin: io.grpc/grpc-core

@Override
 public void setDeadline(Deadline deadline) {
  headers.discardAll(TIMEOUT_KEY);
  long effectiveTimeout = max(0, deadline.timeRemaining(TimeUnit.NANOSECONDS));
  headers.put(TIMEOUT_KEY, effectiveTimeout);
 }
}

代码示例来源:origin: io.grpc/grpc-core

@Override
public void setDeadline(Deadline deadline) {
 headers.discardAll(TIMEOUT_KEY);
 long effectiveTimeout = max(0, deadline.timeRemaining(TimeUnit.NANOSECONDS));
 headers.put(TIMEOUT_KEY, effectiveTimeout);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

@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);
 }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * 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);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

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());
 }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

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;
}

代码示例来源:origin: io.grpc/grpc-core

@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);
 }
}

代码示例来源:origin: io.grpc/grpc-core

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());
 }
}

代码示例来源:origin: io.grpc/grpc-core

@Override
public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) {
 if (span != BlankSpan.INSTANCE) {
  headers.discardAll(tracingHeader);
  headers.put(tracingHeader, span.getContext());
 }
 return new ClientTracer(span);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

@Override
public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) {
 headers.discardAll(tracingHeader);
 headers.put(tracingHeader, span.getContext());
 return new ClientTracer(span);
}

代码示例来源:origin: io.grpc/grpc-core

@Override
public ClientStreamTracer newClientStreamTracer(CallOptions callOptions, Metadata headers) {
 ClientTracer tracer = new ClientTracer(module, startCtx);
 // 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;
}

代码示例来源:origin: io.grpc/grpc-core

checkState(!closeCalled, "call is closed");
headers.discardAll(MESSAGE_ENCODING_KEY);
if (compressor == null) {
 compressor = Codec.Identity.NONE;
headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY);
byte[] advertisedEncodings =
  InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry);

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

@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;
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

checkState(!closeCalled, "call is closed");
headers.discardAll(MESSAGE_ENCODING_KEY);
if (compressor == null) {
 compressor = Codec.Identity.NONE;
headers.discardAll(MESSAGE_ACCEPT_ENCODING_KEY);
byte[] advertisedEncodings =
  InternalDecompressorRegistry.getRawAdvertisedMessageEncodings(decompressorRegistry);

相关文章