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

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

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

Metadata.<init>介绍

[英]Constructor called by the application layer when it wants to send metadata.
[中]当应用程序层想要发送元数据时调用的构造函数。

代码示例

代码示例来源:origin: weibocom/motan

@Override
public void onCompleted() {
  if (cancelled) {
    throw Status.CANCELLED.asRuntimeException();
  } else {
    call.close(Status.OK, new Metadata());
  }
}

代码示例来源:origin: openzipkin/brave

@Benchmark public void inject_both_no_tags() {
 Metadata carrier = new Metadata();
 bothInjector.inject(context, carrier);
}

代码示例来源:origin: openzipkin/brave

@Benchmark public void inject_b3() {
 Metadata carrier = new Metadata();
 b3Injector.inject(context, carrier);
}

代码示例来源:origin: openzipkin/brave

@Benchmark public void inject_both() {
 Metadata carrier = new Metadata();
 bothInjector.inject(contextWithTags, carrier);
}

代码示例来源:origin: weibocom/motan

@Override
public void onNext(RespT response) {
  if (cancelled) {
    throw Status.CANCELLED.asRuntimeException();
  }
  if (!sentHeaders) {
    call.sendHeaders(new Metadata());
    sentHeaders = true;
  }
  //TODO send header from here..
  call.sendMessage(response);
}

代码示例来源:origin: googleapis/google-cloud-java

Metadata newMetadata(String resourceTokenTemplate, String defaultResourceToken) {
 Metadata metadata = new Metadata();
 for (Map.Entry<Metadata.Key<String>, String> header : headers.entrySet()) {
  metadata.put(header.getKey(), header.getValue());
 }
 metadata.put(
   Key.of(resourceHeaderKey, Metadata.ASCII_STRING_MARSHALLER),
   getResourceHeaderValue(resourceTokenTemplate, defaultResourceToken));
 return metadata;
}

代码示例来源:origin: weibocom/motan

@Override
public void onError(Throwable t) {
  Metadata metadata = Status.trailersFromThrowable(t);
  if (metadata == null) {
    metadata = new Metadata();
  }
  if (t instanceof MotanBizException) {
    call.close(Status.INTERNAL.withDescription(t.getMessage()).withCause(t), metadata);
  } else {
    call.close(Status.UNAVAILABLE.withDescription(t.getMessage()).withCause(t), metadata);
  }
}

代码示例来源:origin: line/armeria

@Test
public void notReadyAfterClose() {
  assertThat(call.isReady()).isTrue();
  call.close(Status.OK, new Metadata());
  await().untilAsserted(() -> assertThat(call.isReady()).isFalse());
}

代码示例来源:origin: Alluxio/alluxio

Metadata trailers = new Metadata();

代码示例来源:origin: line/armeria

@Test
public void messageReadAfterClose_byteBuf() {
  call.close(Status.ABORTED, new Metadata());
  // messageRead is always called from the event loop.
  eventLoop.get().submit(() -> {
    call.messageRead(new ByteBufOrStream(GrpcTestUtil.requestByteBuf()));
    verify(listener, never()).onMessage(any());
  }).syncUninterruptibly();
}

代码示例来源:origin: alibaba/Sentinel

serverCall.close(FLOW_CONTROL_BLOCK, new Metadata());
  return new ServerCall.Listener<ReqT>() {};
} finally {

代码示例来源:origin: Netflix/conductor

Metadata metadata = new Metadata();
metadata.put(STATUS_DETAILS_KEY,
    DebugInfo.newBuilder()

代码示例来源:origin: line/armeria

@Test
public void messageReadAfterClose_stream() {
  call.close(Status.ABORTED, new Metadata());
  // messageRead is always called from the event loop.
  eventLoop.get().submit(() -> {
    call.messageRead(new ByteBufOrStream(new ByteBufInputStream(GrpcTestUtil.requestByteBuf(), true)));
    verify(listener, never()).onMessage(any());
  }).syncUninterruptibly();
}

代码示例来源:origin: Netflix/concurrency-limits

public Driver(Builder builder) {
  this.segments = builder.segments;
  this.runtime = builder.runtimeSeconds;
  this.latencyAccumulator = builder.latencyAccumulator;
  Metadata metadata = new Metadata();
  metadata.put(ID_HEADER, builder.id);
  this.channel = ClientInterceptors.intercept(NettyChannelBuilder.forTarget("localhost:" + builder.port)
      .usePlaintext(true)
      .build(),
        MetadataUtils.newAttachHeadersInterceptor(metadata));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
 public void abortWithoutDuration() {
  Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
  Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
  Metadata trailers = new Metadata();
  trailers.put(key, RetryInfo.getDefaultInstance());
  SpannerException e =
    SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers));
  assertThat(e).isInstanceOf(AbortedException.class);
  assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(-1L);
 }
}

代码示例来源:origin: line/armeria

@After
public void tearDown() {
  // HttpStreamReader must be invoked from an event loop.
  eventLoop.get().submit(() -> call.messageReader().cancel()).syncUninterruptibly();
  if (!call.isCloseCalled()) {
    call.close(Status.OK, new Metadata());
  }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void abortWithRetryInfo() {
 Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
 Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
 Metadata trailers = new Metadata();
 RetryInfo retryInfo =
   RetryInfo.newBuilder()
     .setRetryDelay(Duration.newBuilder().setNanos(1000000).setSeconds(1L))
     .build();
 trailers.put(key, retryInfo);
 SpannerException e =
   SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers));
 assertThat(e).isInstanceOf(AbortedException.class);
 assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(1001L);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void resourceExhaustedWithBackoff() {
 Status status =
   Status.fromCodeValue(Status.Code.RESOURCE_EXHAUSTED.value())
     .withDescription("Memory pushback");
 Metadata trailers = new Metadata();
 Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
 RetryInfo retryInfo =
   RetryInfo.newBuilder()
     .setRetryDelay(Duration.newBuilder().setNanos(1000000).setSeconds(1L))
     .build();
 trailers.put(key, retryInfo);
 SpannerException e =
   SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers));
 assertThat(e.isRetryable()).isTrue();
 assertThat(e.getRetryDelayInMillis()).isEqualTo(1001);
}

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

/**
 * Close the call with {@link Status#PERMISSION_DENIED}.
 *
 * @param call The call to close.
 * @param aex The exception that was the cause.
 */
protected void closeCallAccessDenied(final ServerCall<?, ?> call, final AccessDeniedException aex) {
  call.close(Status.PERMISSION_DENIED.withCause(aex).withDescription(ACCESS_DENIED_DESCRIPTION), new Metadata());
}

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

/**
 * Close the call with {@link Status#UNAUTHENTICATED}.
 *
 * @param call The call to close.
 * @param aex The exception that was the cause.
 */
protected void closeCallUnauthenticated(final ServerCall<?, ?> call, final AuthenticationException aex) {
  call.close(Status.UNAUTHENTICATED.withCause(aex).withDescription(UNAUTHENTICATED_DESCRIPTION), new Metadata());
}

相关文章