io.grpc.internal.DnsNameResolverProvider源码实例Demo

类io.grpc.internal.DnsNameResolverProvider源码实例Demo

下面列出了io.grpc.internal.DnsNameResolverProvider 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: black-mirror   文件: SpeechService.java
@Override
protected void onPostExecute(AccessToken accessToken) {
    mAccessTokenTask = null;
    final ManagedChannel channel = new OkHttpChannelProvider()
            .builderForAddress(HOSTNAME, PORT)
            .nameResolverFactory(new DnsNameResolverProvider())
            .intercept(new GoogleCredentialsInterceptor(new GoogleCredentials(accessToken)
                    .createScoped(SCOPE)))
            .build();
    mApi = SpeechGrpc.newStub(channel);

    // Schedule access token refresh before it expires
    if (mHandler != null) {
        mHandler.postDelayed(mFetchAccessTokenRunnable,
                Math.max(accessToken.getExpirationTime().getTime()
                        - System.currentTimeMillis()
                        - ACCESS_TOKEN_FETCH_MARGIN, ACCESS_TOKEN_EXPIRATION_TOLERANCE));
    }
}
 
源代码2 项目: android-docs-samples   文件: SpeechService.java
@Override
protected void onPostExecute(AccessToken accessToken) {
    mAccessTokenTask = null;
    final ManagedChannel channel = new OkHttpChannelProvider()
            .builderForAddress(HOSTNAME, PORT)
            .nameResolverFactory(new DnsNameResolverProvider())
            .intercept(new GoogleCredentialsInterceptor(new GoogleCredentials(accessToken)
                    .createScoped(SCOPE)))
            .build();
    mApi = SpeechGrpc.newStub(channel);

    // Schedule access token refresh before it expires
    if (mHandler != null) {
        mHandler.postDelayed(mFetchAccessTokenRunnable,
                Math.max(accessToken.getExpirationTime().getTime()
                        - System.currentTimeMillis()
                        - ACCESS_TOKEN_FETCH_MARGIN, ACCESS_TOKEN_EXPIRATION_TOLERANCE));
    }
}
 
@Test
public void baseProviders() {
  List<NameResolverProvider> providers = NameResolverProvider.providers();
  assertEquals(1, providers.size());
  assertSame(DnsNameResolverProvider.class, providers.get(0).getClass());
  assertEquals("dns", NameResolverProvider.asFactory().getDefaultScheme());
}
 
@Test
public void provided() {
  for (NameResolverProvider current
      : InternalServiceProviders.getCandidatesViaServiceLoader(
      NameResolverProvider.class, getClass().getClassLoader())) {
    if (current instanceof DnsNameResolverProvider) {
      return;
    }
  }
  fail("DnsNameResolverProvider not registered");
}
 
@Test
public void providedHardCoded() {
  for (NameResolverProvider current : InternalServiceProviders.getCandidatesViaHardCoded(
      NameResolverProvider.class, NameResolverProvider.HARDCODED_CLASSES)) {
    if (current instanceof DnsNameResolverProvider) {
      return;
    }
  }
  fail("DnsNameResolverProvider not registered");
}
 
源代码6 项目: quarkus   文件: GrpcServerProcessor.java
@BuildStep
public void configureNativeExecutable(CombinedIndexBuildItem combinedIndex,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
        BuildProducer<ExtensionSslNativeSupportBuildItem> extensionSslNativeSupport) {

    // we force the usage of the reflection invoker.
    Collection<ClassInfo> messages = combinedIndex.getIndex()
            .getAllKnownSubclasses(GrpcDotNames.GENERATED_MESSAGE_V3);
    for (ClassInfo message : messages) {
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, message.name().toString()));
    }
    Collection<ClassInfo> builders = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.MESSAGE_BUILDER);
    for (ClassInfo builder : builders) {
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, builder.name().toString()));
    }

    Collection<ClassInfo> lbs = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.LOAD_BALANCER_PROVIDER);
    for (ClassInfo lb : lbs) {
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, lb.name().toString()));
    }

    Collection<ClassInfo> nrs = combinedIndex.getIndex().getAllKnownSubclasses(GrpcDotNames.NAME_RESOLVER_PROVIDER);
    for (ClassInfo nr : nrs) {
        reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, nr.name().toString()));
    }

    // Built-In providers:
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, DnsNameResolverProvider.class));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, PickFirstLoadBalancerProvider.class));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false,
            "io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider"));
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, false, NettyChannelProvider.class));

    extensionSslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(GRPC_SERVER));
}
 
public static void main(String[] args) throws InterruptedException, UnknownHostException {
  String target = System.getenv("ECHO_SERVICE_TARGET");
  if (target == null || target.isEmpty()) {
    target = "localhost:8080";
  }
  final ManagedChannel channel = ManagedChannelBuilder.forTarget(target)
      .nameResolverFactory(new DnsNameResolverProvider())  // this is on by default
      .loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance())
      .usePlaintext(true)
      .build();

  final String self = InetAddress.getLocalHost().getHostName();

  ExecutorService executorService = Executors.newFixedThreadPool(THREADS);
  for (int i = 0; i < THREADS; i++) {
    EchoServiceGrpc.EchoServiceBlockingStub stub = EchoServiceGrpc.newBlockingStub(channel);
    executorService.submit(() -> {
      while (true) {
        EchoResponse response = stub.echo(EchoRequest.newBuilder()
            .setMessage(self + ": " + Thread.currentThread().getName())
            .build());
        System.out.println(response.getFrom() + " echoed");

        Thread.sleep(RANDOM.nextInt(700));
      }
    });
  }
}
 
源代码8 项目: skywalking   文件: GRPCNoServerTest.java
public static void main(String[] args) throws InterruptedException {
    ManagedChannelBuilder<?> channelBuilder = NettyChannelBuilder.forAddress("127.0.0.1", 8080)
                                                                 .nameResolverFactory(new DnsNameResolverProvider())
                                                                 .maxInboundMessageSize(1024 * 1024 * 50)
                                                                 .usePlaintext();
    ManagedChannel channel = channelBuilder.build();
    TraceSegmentReportServiceGrpc.TraceSegmentReportServiceStub serviceStub = TraceSegmentReportServiceGrpc.newStub(channel);
    final Status[] status = {null};
    StreamObserver<SegmentObject> streamObserver = serviceStub.collect(new StreamObserver<Commands>() {
        @Override
        public void onNext(Commands value) {

        }

        @Override
        public void onError(Throwable t) {
            status[0] = ((StatusRuntimeException) t).getStatus();
        }

        @Override
        public void onCompleted() {

        }
    });

    streamObserver.onNext(null);
    streamObserver.onCompleted();

    Thread.sleep(2 * 1000);

    Assert.assertEquals(status[0].getCode(), Status.UNAVAILABLE.getCode());
}
 
源代码9 项目: skywalking   文件: StorageTTLE2E.java
@BeforeAll
public void setUp() {
    queryClient(swWebappHostPort);

    final ManagedChannel channel = NettyChannelBuilder.forAddress(oapHostPort.host(), oapHostPort.port())
                                                      .nameResolverFactory(new DnsNameResolverProvider())
                                                      .maxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
                                                      .usePlaintext()
                                                      .build();

    grpcStub = ServiceMeshMetricServiceGrpc.newStub(channel);
}
 
源代码10 项目: grpc-java   文件: NameResolverRegistryTest.java
@Test
public void provided() {
  for (NameResolverProvider current
      : InternalServiceProviders.getCandidatesViaServiceLoader(
      NameResolverProvider.class, getClass().getClassLoader())) {
    if (current instanceof DnsNameResolverProvider) {
      return;
    }
  }
  fail("DnsNameResolverProvider not registered");
}
 
源代码11 项目: skywalking   文件: StandardChannelBuilder.java
@Override
public ManagedChannelBuilder build(ManagedChannelBuilder managedChannelBuilder) {
    return managedChannelBuilder.nameResolverFactory(new DnsNameResolverProvider())
                                .maxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
                                .usePlaintext();
}
 
源代码12 项目: geowave   文件: GeoWaveGrpcTestClient.java
public GeoWaveGrpcTestClient(final String host, final int port) {
  this(
      NettyChannelBuilder.forAddress(host, port).nameResolverFactory(
          new DnsNameResolverProvider()).usePlaintext(true));
}
 
@Test
public void priority_shouldBeHigherThanDefaultDnsNameResolver() {
  DnsNameResolverProvider defaultDnsNameResolver = new DnsNameResolverProvider();

  assertThat(provider.priority()).isGreaterThan(defaultDnsNameResolver.priority());
}
 
源代码14 项目: grpc-java   文件: NameResolverRegistryTest.java
@Test
public void getClassesViaHardcoded_classesPresent() throws Exception {
  List<Class<?>> classes = NameResolverRegistry.getHardCodedClasses();
  assertThat(classes).containsExactly(io.grpc.internal.DnsNameResolverProvider.class);
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法