io.grpc.NameResolverProvider Java Examples

The following examples show how to use io.grpc.NameResolverProvider. 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: DefaultChannelFactory.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
DefaultChannelFactory(String factoryName,
                             int executorQueueSize,
                             HeaderFactory headerFactory,
                             NameResolverProvider nameResolverProvider,
                             ClientOption clientOption,
                             List<ClientInterceptor> clientInterceptorList) {
    this.factoryName = Assert.requireNonNull(factoryName, "factoryName");
    this.executorQueueSize = executorQueueSize;
    this.headerFactory = Assert.requireNonNull(headerFactory, "headerFactory");
    // @Nullable
    this.nameResolverProvider = nameResolverProvider;
    this.clientOption = Assert.requireNonNull(clientOption, "clientOption");

    Assert.requireNonNull(clientInterceptorList, "clientInterceptorList");
    this.clientInterceptorList = new ArrayList<ClientInterceptor>(clientInterceptorList);


    this.eventLoopExecutor = newCachedExecutorService(factoryName + "-Channel-Worker");
    this.eventLoopGroup = newEventLoopGroup(eventLoopExecutor);
    this.executorService = newExecutorService(factoryName + "-Channel-Executor", this.executorQueueSize);
}
 
Example #2
Source File: AgentGrpcDataSenderTestMain.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public void request() throws Exception {
    MessageConverter<GeneratedMessageV3> messageConverter = new GrpcMetadataMessageConverter();
    HeaderFactory headerFactory = new AgentHeaderFactory(AGENT_ID, APPLICATION_NAME, START_TIME);

    DnsExecutorServiceProvider dnsExecutorServiceProvider = new DnsExecutorServiceProvider();
    GrpcNameResolverProvider grpcNameResolverProvider = new GrpcNameResolverProvider(dnsExecutorServiceProvider);
    NameResolverProvider nameResolverProvider = grpcNameResolverProvider.get();

    ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder("TestAgentGrpcDataSender");
    channelFactoryBuilder.setHeaderFactory(headerFactory);
    channelFactoryBuilder.setNameResolverProvider(nameResolverProvider);
    channelFactoryBuilder.setClientOption(new ClientOption.Builder().build());
    ChannelFactory channelFactory = channelFactoryBuilder.build();

    AgentGrpcDataSender sender = new AgentGrpcDataSender("localhost", 9997, 1, messageConverter,
            reconnectExecutor, scheduledExecutorService, channelFactory, null);

    AgentInfo agentInfo = newAgentInfo();

    sender.request(agentInfo);

    TimeUnit.SECONDS.sleep(60);
    sender.stop();
}
 
Example #3
Source File: AgentGrpcDataSenderProvider.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Inject
public AgentGrpcDataSenderProvider(GrpcTransportConfig grpcTransportConfig,
                                   @MetadataConverter MessageConverter<GeneratedMessageV3> messageConverter,
                                   HeaderFactory headerFactory,
                                   Provider<ReconnectExecutor> reconnectExecutor,
                                   ScheduledExecutorService retransmissionExecutor,
                                   NameResolverProvider nameResolverProvider,
                                   ActiveTraceRepository activeTraceRepository) {
    this.grpcTransportConfig = Assert.requireNonNull(grpcTransportConfig, "grpcTransportConfig");
    this.messageConverter = Assert.requireNonNull(messageConverter, "messageConverter");
    this.headerFactory = Assert.requireNonNull(headerFactory, "headerFactory");

    this.reconnectExecutorProvider = Assert.requireNonNull(reconnectExecutor, "reconnectExecutorProvider");
    this.retransmissionExecutor = Assert.requireNonNull(retransmissionExecutor, "retransmissionExecutor");


    this.nameResolverProvider = Assert.requireNonNull(nameResolverProvider, "nameResolverProvider");
    this.activeTraceRepository = Assert.requireNonNull(activeTraceRepository, "activeTraceRepository");
}
 
Example #4
Source File: NameResolverRegistration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
/**
 * Register all NameResolverProviders in the given registry and store a reference to it for later de-registration.
 *
 * @param registry The registry to add the providers to.
 */
public void register(NameResolverRegistry registry) {
    this.registries.add(registry);
    for (NameResolverProvider provider : this.providers) {
        try {
            registry.register(provider);
            log.info("{} is available -> Added to the NameResolverRegistry", provider);
        } catch (IllegalArgumentException e) {
            log.info("{} is not available -> Not added to the NameResolverRegistry", provider);
        }
    }
}
 
Example #5
Source File: XdsNameResolverProviderTest.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 XdsNameResolverProvider) {
      return;
    }
  }
  fail("XdsNameResolverProvider not registered");
}
 
Example #6
Source File: XdsExperimentalNameResolverProviderTest.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 XdsExperimentalNameResolverProvider) {
      return;
    }
  }
  fail("XdsExperimentalNameResolverProvider not registered");
}
 
Example #7
Source File: MetadataGrpcDataSenderProvider.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Inject
public MetadataGrpcDataSenderProvider(GrpcTransportConfig grpcTransportConfig,
                                      @MetadataConverter MessageConverter<GeneratedMessageV3> messageConverter,
                                      HeaderFactory headerFactory,
                                      NameResolverProvider nameResolverProvider) {
    this.grpcTransportConfig = Assert.requireNonNull(grpcTransportConfig, "grpcTransportConfig");
    this.messageConverter = Assert.requireNonNull(messageConverter, "messageConverter");
    this.headerFactory = Assert.requireNonNull(headerFactory, "headerFactory");
    this.nameResolverProvider = Assert.requireNonNull(nameResolverProvider, "nameResolverProvider");
}
 
Example #8
Source File: StatGrpcDataSenderProvider.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Inject
public StatGrpcDataSenderProvider(GrpcTransportConfig grpcTransportConfig,
                                  @StatConverter MessageConverter<GeneratedMessageV3> messageConverter,
                                  HeaderFactory headerFactory,
                                  Provider<ReconnectExecutor> reconnectExecutor,
                                  NameResolverProvider nameResolverProvider) {
    this.grpcTransportConfig = Assert.requireNonNull(grpcTransportConfig, "profilerConfig");
    this.messageConverter = Assert.requireNonNull(messageConverter, "messageConverter");
    this.headerFactory = Assert.requireNonNull(headerFactory, "agentHeaderFactory");
    this.reconnectExecutorProvider = Assert.requireNonNull(reconnectExecutor, "reconnectExecutorProvider");
    this.nameResolverProvider = Assert.requireNonNull(nameResolverProvider, "nameResolverProvider");
}
 
Example #9
Source File: SpanGrpcDataSenderProvider.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Inject
public SpanGrpcDataSenderProvider(GrpcTransportConfig grpcTransportConfig,
                                  @SpanConverter MessageConverter<GeneratedMessageV3> messageConverter,
                                  HeaderFactory headerFactory,
                                  Provider<ReconnectExecutor> reconnectExecutor,
                                  NameResolverProvider nameResolverProvider) {
    this.grpcTransportConfig = Assert.requireNonNull(grpcTransportConfig, "grpcTransportConfig");
    this.messageConverter = Assert.requireNonNull(messageConverter, "messageConverter");
    this.headerFactory = Assert.requireNonNull(headerFactory, "headerFactory");

    this.reconnectExecutor = Assert.requireNonNull(reconnectExecutor, "reconnectExecutor");

    this.nameResolverProvider = Assert.requireNonNull(nameResolverProvider, "nameResolverProvider");
}
 
Example #10
Source File: GrpcClientAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
/**
 * Creates a new NameResolverRegistration. This ensures that the NameResolverProvider's get unregistered when spring
 * shuts down. This is mostly required for tests/when running multiple application contexts within the same JVM.
 *
 * @param nameResolverProviders The spring managed providers to manage.
 * @return The newly created NameResolverRegistration bean.
 */
@ConditionalOnMissingBean
@Lazy
@Bean
NameResolverRegistration grpcNameResolverRegistration(
        @Autowired(required = false) final List<NameResolverProvider> nameResolverProviders) {
    NameResolverRegistration nameResolverRegistration = new NameResolverRegistration(nameResolverProviders);
    nameResolverRegistration.register(NameResolverRegistry.getDefaultRegistry());
    return nameResolverRegistration;
}
 
Example #11
Source File: NameResolverRegistration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
@Override
public void destroy() {
    for (NameResolverRegistry registry : this.registries) {
        for (NameResolverProvider provider : this.providers) {
            registry.deregister(provider);
            log.info("{} was removed from the NameResolverRegistry", provider);
        }
    }
    this.registries.clear();
}
 
Example #12
Source File: NameResolverRegistration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
/**
 * Register all NameResolverProviders in the given registry and store a reference to it for later de-registration.
 *
 * @param registry The registry to add the providers to.
 */
public void register(NameResolverRegistry registry) {
    this.registries.add(registry);
    for (NameResolverProvider provider : this.providers) {
        try {
            registry.register(provider);
            log.info("{} is available -> Added to the NameResolverRegistry", provider);
        } catch (IllegalArgumentException e) {
            log.info("{} is not available -> Not added to the NameResolverRegistry", provider);
        }
    }
}
 
Example #13
Source File: GrpcClientAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
/**
 * Creates a new NameResolverRegistration. This ensures that the NameResolverProvider's get unregistered when spring
 * shuts down. This is mostly required for tests/when running multiple application contexts within the same JVM.
 *
 * @param nameResolverProviders The spring managed providers to manage.
 * @return The newly created NameResolverRegistration bean.
 */
@ConditionalOnMissingBean
@Lazy
@Bean
NameResolverRegistration grpcNameResolverRegistration(
        @Autowired(required = false) final List<NameResolverProvider> nameResolverProviders) {
    NameResolverRegistration nameResolverRegistration = new NameResolverRegistration(nameResolverProviders);
    nameResolverRegistration.register(NameResolverRegistry.getDefaultRegistry());
    return nameResolverRegistration;
}
 
Example #14
Source File: NameResolverRegistration.java    From grpc-spring-boot-starter with MIT License 5 votes vote down vote up
@Override
public void destroy() {
    for (NameResolverRegistry registry : this.registries) {
        for (NameResolverProvider provider : this.providers) {
            registry.deregister(provider);
            log.info("{} was removed from the NameResolverRegistry", provider);
        }
    }
    this.registries.clear();
}
 
Example #15
Source File: GrpcModule.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    logger.info("configure {}", this.getClass().getSimpleName());

    bind(GrpcTransportConfig.class).toProvider(GrpcTransportConfigProvider.class).in(Scopes.SINGLETON);
    // dns executor
    bind(ExecutorService.class).toProvider(DnsExecutorServiceProvider.class).in(Scopes.SINGLETON);
    bind(NameResolverProvider.class).toProvider(GrpcNameResolverProvider.class).in(Scopes.SINGLETON);
    bind(HeaderFactory.class).toProvider(AgentHeaderFactoryProvider.class).in(Scopes.SINGLETON);

    bind(ScheduledExecutorService.class).toProvider(ReconnectSchedulerProvider.class).in(Scopes.SINGLETON);

    // not singleton
    bind(ReconnectExecutor.class).toProvider(ReconnectExecutorProvider.class);

    // Agent
    TypeLiteral<MessageConverter<GeneratedMessageV3>> metadataMessageConverter = new TypeLiteral<MessageConverter<GeneratedMessageV3>>() {};
    Key<MessageConverter<GeneratedMessageV3>> metadataMessageConverterKey = Key.get(metadataMessageConverter, MetadataConverter.class);
    bind(metadataMessageConverterKey).toProvider(GrpcMetadataMessageConverterProvider.class ).in(Scopes.SINGLETON);

    TypeLiteral<MessageConverter<ResultResponse>> resultMessageConverter = new TypeLiteral<MessageConverter<ResultResponse>>() {};
    Key<MessageConverter<ResultResponse>> resultMessageConverterKey = Key.get(resultMessageConverter, ResultConverter.class);
    bind(resultMessageConverterKey).toProvider(GrpcMessageToResultConverterProvider.class ).in(Scopes.SINGLETON);
    expose(resultMessageConverterKey);

    TypeLiteral<EnhancedDataSender<Object>> dataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<Object>>() {};
    Key<EnhancedDataSender<Object>> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class);
    bind(agentDataSender).toProvider(AgentGrpcDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(agentDataSender);

    Key<EnhancedDataSender<Object>> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class);
    bind(metadataDataSender).toProvider(MetadataGrpcDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(metadataDataSender);

    // Span
    TypeLiteral<MessageConverter<GeneratedMessageV3>> protoMessageConverter = new TypeLiteral<MessageConverter<GeneratedMessageV3>>() {};
    Key<MessageConverter<GeneratedMessageV3>> spanMessageConverterKey = Key.get(protoMessageConverter, SpanConverter.class);
    // not singleton
    bind(spanMessageConverterKey).toProvider(GrpcSpanMessageConverterProvider.class);

    TypeLiteral<SpanProcessor<PSpan.Builder, PSpanChunk.Builder>> spanPostProcessorType = new TypeLiteral<SpanProcessor<PSpan.Builder, PSpanChunk.Builder>>() {};
    bind(spanPostProcessorType).toProvider(GrpcSpanProcessorProvider.class).in(Scopes.SINGLETON);

    Key<DataSender> spanDataSender = Key.get(DataSender.class, SpanDataSender.class);
    bind(spanDataSender).toProvider(SpanGrpcDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(spanDataSender);

    // Stat
    TypeLiteral<MessageConverter<GeneratedMessageV3>> statMessageConverter = new TypeLiteral<MessageConverter<GeneratedMessageV3>>() {};
    Key<MessageConverter<GeneratedMessageV3>> statMessageConverterKey = Key.get(statMessageConverter, StatConverter.class);
    bind(statMessageConverterKey).toProvider(GrpcStatMessageConverterProvider.class ).in(Scopes.SINGLETON);

    Key<DataSender> statDataSender = Key.get(DataSender.class, StatDataSender.class);
    bind(DataSender.class).annotatedWith(StatDataSender.class).toProvider(StatGrpcDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(statDataSender);

    Key<ModuleLifeCycle> rpcModuleLifeCycleKey = Key.get(ModuleLifeCycle.class, Names.named("RPC-MODULE"));
    bind(rpcModuleLifeCycleKey).to(GrpcModuleLifeCycle.class).in(Scopes.SINGLETON);
    expose(rpcModuleLifeCycleKey);

    NettyPlatformDependent nettyPlatformDependent = new NettyPlatformDependent(profilerConfig, System.getProperties());
    nettyPlatformDependent.setup();
}
 
Example #16
Source File: GrpcNameResolverProvider.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public NameResolverProvider get() {
    ExecutorService executorService = dnsExecutorService.get();
    NameResolverProvider nameResolverProvider = new PinpointDnsNameResolverProvider("pinpoint-dns", executorService);
    return nameResolverProvider;
}
 
Example #17
Source File: DefaultChannelFactoryBuilder.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public void setNameResolverProvider(NameResolverProvider nameResolverProvider) {
    this.nameResolverProvider = Assert.requireNonNull(nameResolverProvider, "nameResolverProvider");
}
 
Example #18
Source File: NameResolverRegistration.java    From grpc-spring-boot-starter with MIT License 2 votes vote down vote up
/**
 * Creates a new NameResolverRegistration with the given list of providers.
 *
 * @param providers The providers that should be managed.
 */
public NameResolverRegistration(List<NameResolverProvider> providers) {
    this.providers = providers == null ? ImmutableList.of() : ImmutableList.copyOf(providers);
}
 
Example #19
Source File: NameResolverRegistration.java    From grpc-spring-boot-starter with MIT License 2 votes vote down vote up
/**
 * Creates a new NameResolverRegistration with the given list of providers.
 *
 * @param providers The providers that should be managed.
 */
public NameResolverRegistration(List<NameResolverProvider> providers) {
    this.providers = providers == null ? ImmutableList.of() : ImmutableList.copyOf(providers);
}
 
Example #20
Source File: ChannelFactoryBuilder.java    From pinpoint with Apache License 2.0 votes vote down vote up
void setNameResolverProvider(NameResolverProvider nameResolverProvider);