• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Grpc类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中io.grpc.Grpc的典型用法代码示例。如果您正苦于以下问题:Java Grpc类的具体用法?Java Grpc怎么用?Java Grpc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

Grpc类属于io.grpc包,在下文中一共展示了Grpc类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: assertX500SubjectDn

点赞 3

import io.grpc.Grpc; //导入依赖的package包/类
/** Helper for asserting TLS info in SSLSession {@link io.grpc.ServerCall#getAttributes()} */
protected void assertX500SubjectDn(String tlsInfo) {
  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withDeadlineAfter(5, TimeUnit.SECONDS);

  stub.unaryCall(SimpleRequest.getDefaultInstance());

  List<Certificate> certificates = Lists.newArrayList();
  SSLSession sslSession =
      serverCallCapture.get().getAttributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION);
  try {
    certificates = Arrays.asList(sslSession.getPeerCertificates());
  } catch (SSLPeerUnverifiedException e) {
    // Should never happen
    throw new AssertionError(e);
  }

  X509Certificate x509cert = (X509Certificate) certificates.get(0);

  assertEquals(1, certificates.size());
  assertEquals(tlsInfo, x509cert.getSubjectDN().toString());
}
 

开发者ID:grpc,
项目名称:grpc-java
代码行数:23,
代码来源:AbstractInteropTest.java

示例2: serverPlaintext

点赞 3

import io.grpc.Grpc; //导入依赖的package包/类
/**
 * Create a server plaintext handler for gRPC.
 */
public static ProtocolNegotiator serverPlaintext() {
  return new ProtocolNegotiator() {
    @Override
    public Handler newHandler(final GrpcHttp2ConnectionHandler handler) {
      class PlaintextHandler extends ChannelHandlerAdapter implements Handler {
        @Override
        public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
          // Set sttributes before replace to be sure we pass it before accepting any requests.
          handler.handleProtocolNegotiationCompleted(Attributes.newBuilder()
              .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress())
              .build());
          // Just replace this handler with the gRPC handler.
          ctx.pipeline().replace(this, null, handler);
        }

        @Override
        public AsciiString scheme() {
          return Utils.HTTP;
        }
      }

      return new PlaintextHandler();
    }
  };
}
 

开发者ID:grpc,
项目名称:grpc-java
代码行数:29,
代码来源:ProtocolNegotiators.java

示例3: userEventTriggered

点赞 3

import io.grpc.Grpc; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
  if (evt instanceof SslHandshakeCompletionEvent) {
    SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt;
    if (handshakeEvent.isSuccess()) {
      if (NEXT_PROTOCOL_VERSIONS.contains(sslHandler(ctx.pipeline()).applicationProtocol())) {
        // Successfully negotiated the protocol.
        // Notify about completion and pass down SSLSession in attributes.
        grpcHandler.handleProtocolNegotiationCompleted(
            Attributes.newBuilder()
                .set(Grpc.TRANSPORT_ATTR_SSL_SESSION,
                    sslHandler(ctx.pipeline()).engine().getSession())
                .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress())
                .build());
        // Replace this handler with the GRPC handler.
        ctx.pipeline().replace(this, null, grpcHandler);
      } else {
        fail(ctx, new Exception(
            "Failed protocol negotiation: Unable to find compatible protocol."));
      }
    } else {
      fail(ctx, handshakeEvent.cause());
    }
  }
  super.userEventTriggered(ctx, evt);
}
 

开发者ID:grpc,
项目名称:grpc-java
代码行数:27,
代码来源:ProtocolNegotiators.java

示例4: onClose

点赞 2

import io.grpc.Grpc; //导入依赖的package包/类
@Override
public void onClose(Status status, Metadata trailers) {
  try {
    SocketAddress remoteServer = clientCall.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
    callOptions.getOption(GrpcCallOptions.CALLOPTIONS_CUSTOME_KEY)
        .put(GrpcCallOptions.GRPC_CURRENT_ADDR_KEY, remoteServer);
  } finally {
    if (status.isOk()) {
      statusOk(trailers);
    } else {
      statusError(status, trailers);
    }
  }
}
 

开发者ID:venus-boot,
项目名称:saluki,
代码行数:15,
代码来源:FailOverUnaryFuture.java

示例5: obtainRemoteClientAddr

点赞 2

import io.grpc.Grpc; //导入依赖的package包/类
/** Helper for getting remote address {@link io.grpc.ServerCall#getAttributes()} */
protected SocketAddress obtainRemoteClientAddr() {
  TestServiceGrpc.TestServiceBlockingStub stub =
      blockingStub.withDeadlineAfter(5, TimeUnit.SECONDS);

  stub.unaryCall(SimpleRequest.getDefaultInstance());

  return serverCallCapture.get().getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
}
 

开发者ID:grpc,
项目名称:grpc-java
代码行数:10,
代码来源:AbstractInteropTest.java

示例6: clientStreamGetsAttributes

点赞 2

import io.grpc.Grpc; //导入依赖的package包/类
@Test
public void clientStreamGetsAttributes() throws Exception {
  startServer();
  NettyClientTransport transport = newTransport(newNegotiator());
  callMeMaybe(transport.start(clientTransportListener));
  Rpc rpc = new Rpc(transport).halfClose();
  rpc.waitForResponse();

  assertNotNull(rpc.stream.getAttributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION));
  assertEquals(address, rpc.stream.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR));
}
 

开发者ID:grpc,
项目名称:grpc-java
代码行数:12,
代码来源:NettyClientTransportTest.java

示例7: start

点赞 2

import io.grpc.Grpc; //导入依赖的package包/类
@CheckReturnValue
@Override
public synchronized Runnable start(ManagedClientTransport.Listener listener) {
  this.clientTransportListener = listener;
  InProcessServer server = InProcessServer.findServer(name);
  if (server != null) {
    serverSchedulerPool = server.getScheduledExecutorServicePool();
    serverScheduler = serverSchedulerPool.getObject();
    serverStreamTracerFactories = server.getStreamTracerFactories();
    // Must be semi-initialized; past this point, can begin receiving requests
    serverTransportListener = server.register(this);
  }
  if (serverTransportListener == null) {
    shutdownStatus = Status.UNAVAILABLE.withDescription("Could not find server: " + name);
    final Status localShutdownStatus = shutdownStatus;
    return new Runnable() {
      @Override
      public void run() {
        synchronized (InProcessTransport.this) {
          notifyShutdown(localShutdownStatus);
          notifyTerminated();
        }
      }
    };
  }
  return new Runnable() {
    @Override
    @SuppressWarnings("deprecation")
    public void run() {
      synchronized (InProcessTransport.this) {
        Attributes serverTransportAttrs = Attributes.newBuilder()
            .set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, new InProcessSocketAddress(name))
            .build();
        serverStreamAttributes = serverTransportListener.transportReady(serverTransportAttrs);
        clientTransportListener.transportReady();
      }
    }
  };
}
 

开发者ID:grpc,
项目名称:grpc-java
代码行数:40,
代码来源:InProcessTransport.java

示例8: contextCopy

点赞 2

import io.grpc.Grpc; //导入依赖的package包/类
private void contextCopy(ServerCall<?, ?> call, final Metadata headers) {
  copyMetadataToThreadLocal(headers);
  InetSocketAddress remoteAddress =
      (InetSocketAddress) call.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR);
  RpcContext.getContext().setAttachment(Constants.REMOTE_ADDRESS, remoteAddress.getHostString());
}
 

开发者ID:venus-boot,
项目名称:saluki,
代码行数:7,
代码来源:HeaderServerInterceptor.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)