io.grpc.internal.DnsNameResolverProvider Java Examples

The following examples show how to use io.grpc.internal.DnsNameResolverProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpeechService.java    From black-mirror with MIT License 6 votes vote down vote up
@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));
    }
}
 
Example #2
Source File: SpeechService.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@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));
    }
}
 
Example #3
Source File: NameResolverProviderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #4
Source File: NameResolverProviderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void provided() {
  for (NameResolverProvider current
      : InternalServiceProviders.getCandidatesViaServiceLoader(
      NameResolverProvider.class, getClass().getClassLoader())) {
    if (current instanceof DnsNameResolverProvider) {
      return;
    }
  }
  fail("DnsNameResolverProvider not registered");
}
 
Example #5
Source File: NameResolverProviderTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void providedHardCoded() {
  for (NameResolverProvider current : InternalServiceProviders.getCandidatesViaHardCoded(
      NameResolverProvider.class, NameResolverProvider.HARDCODED_CLASSES)) {
    if (current instanceof DnsNameResolverProvider) {
      return;
    }
  }
  fail("DnsNameResolverProvider not registered");
}
 
Example #6
Source File: GrpcServerProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #7
Source File: ClientSideLoadBalancedEchoClient.java    From grpc-by-example-java with Apache License 2.0 5 votes vote down vote up
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));
      }
    });
  }
}
 
Example #8
Source File: GRPCNoServerTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #9
Source File: StorageTTLE2E.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #10
Source File: NameResolverRegistryTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void provided() {
  for (NameResolverProvider current
      : InternalServiceProviders.getCandidatesViaServiceLoader(
      NameResolverProvider.class, getClass().getClassLoader())) {
    if (current instanceof DnsNameResolverProvider) {
      return;
    }
  }
  fail("DnsNameResolverProvider not registered");
}
 
Example #11
Source File: StandardChannelBuilder.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public ManagedChannelBuilder build(ManagedChannelBuilder managedChannelBuilder) {
    return managedChannelBuilder.nameResolverFactory(new DnsNameResolverProvider())
                                .maxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
                                .usePlaintext();
}
 
Example #12
Source File: GeoWaveGrpcTestClient.java    From geowave with Apache License 2.0 4 votes vote down vote up
public GeoWaveGrpcTestClient(final String host, final int port) {
  this(
      NettyChannelBuilder.forAddress(host, port).nameResolverFactory(
          new DnsNameResolverProvider()).usePlaintext(true));
}
 
Example #13
Source File: SecretGrpclbNameResolverProviderTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void priority_shouldBeHigherThanDefaultDnsNameResolver() {
  DnsNameResolverProvider defaultDnsNameResolver = new DnsNameResolverProvider();

  assertThat(provider.priority()).isGreaterThan(defaultDnsNameResolver.priority());
}
 
Example #14
Source File: NameResolverRegistryTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void getClassesViaHardcoded_classesPresent() throws Exception {
  List<Class<?>> classes = NameResolverRegistry.getHardCodedClasses();
  assertThat(classes).containsExactly(io.grpc.internal.DnsNameResolverProvider.class);
}