當前位置: 首頁>>代碼示例>>Java>>正文


Java AppInfo.environment方法代碼示例

本文整理匯總了Java中com.nike.riposte.server.config.AppInfo.environment方法的典型用法代碼示例。如果您正苦於以下問題:Java AppInfo.environment方法的具體用法?Java AppInfo.environment怎麽用?Java AppInfo.environment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.nike.riposte.server.config.AppInfo的用法示例。


在下文中一共展示了AppInfo.environment方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: metricsReporters

import com.nike.riposte.server.config.AppInfo; //導入方法依賴的package包/類
@Provides
@Singleton
public List<ReporterFactory> metricsReporters(
    @Named("metrics.slf4j.reporting.enabled") boolean slf4jReportingEnabled,
    @Named("metrics.jmx.reporting.enabled") boolean jmxReportingEnabled,
    @Named("metrics.graphite.url") String graphiteUrl,
    @Named("metrics.graphite.port") int graphitePort,
    @Named("metrics.graphite.reporting.enabled") boolean graphiteEnabled,
    @Named("appInfoFuture") CompletableFuture<AppInfo> appInfoFuture
) {
    List<ReporterFactory> reporters = new ArrayList<>();

    if (slf4jReportingEnabled)
        reporters.add(new DefaultSLF4jReporterFactory());

    if (jmxReportingEnabled)
        reporters.add(new DefaultJMXReporterFactory());

    if (graphiteEnabled) {
        AppInfo appInfo = appInfoFuture.join();
        String graphitePrefix = appInfo.appId() + "." + appInfo.dataCenter() + "." + appInfo.environment()
                                + "." + appInfo.instanceId();
        reporters.add(new DefaultGraphiteReporterFactory(graphitePrefix, graphiteUrl, graphitePort));
    }

    if (reporters.isEmpty()) {
        logger.info("No metrics reporters enabled - disabling metrics entirely.");
        return null;
    }

    String metricReporterTypes = reporters.stream()
                                          .map(rf -> rf.getClass().getSimpleName())
                                          .collect(Collectors.joining(",", "[", "]"));
    logger.info("Metrics reporters enabled. metric_reporter_types={}", metricReporterTypes);

    return reporters;
}
 
開發者ID:Nike-Inc,項目名稱:riposte-microservice-template,代碼行數:38,代碼來源:AppGuiceModule.java

示例2: metricsReporters

import com.nike.riposte.server.config.AppInfo; //導入方法依賴的package包/類
@Provides
@Singleton
public List<ReporterFactory> metricsReporters(
        @Named("metrics.slf4j.reporting.enabled") boolean slf4jReportingEnabled,
        @Named("metrics.jmx.reporting.enabled") boolean jmxReportingEnabled,
        @Named("metrics.signalfx.reporting.enabled") boolean signalFxEnabled,
        @Named("graphite.url") String graphiteUrl,
        @Named("graphite.port") int graphitePort,
        @Named("graphite.reporting.enabled") boolean graphiteEnabled,
        @Named("appInfoFuture") CompletableFuture<AppInfo> appInfoFuture,
        @Nullable SignalFxReporterFactory signalFxReporterFactory
) {
    List<ReporterFactory> reporters = new ArrayList<>();

    if (slf4jReportingEnabled)
        reporters.add(new DefaultSLF4jReporterFactory());

    if (jmxReportingEnabled)
        reporters.add(new DefaultJMXReporterFactory());

    if (signalFxEnabled && signalFxReporterFactory != null)
        reporters.add(signalFxReporterFactory);

    if (graphiteEnabled) {
        AppInfo appInfo = appInfoFuture.join();
        String graphitePrefix = appInfo.appId() + "." + appInfo.dataCenter() + "." + appInfo.environment()
                + "." + appInfo.instanceId();
        reporters.add(new DefaultGraphiteReporterFactory(graphitePrefix, graphiteUrl, graphitePort));
    }

    if (reporters.isEmpty()) {
        logger.info("No metrics reporters enabled - disabling metrics entirely.");
        return null;
    }

    String metricReporterTypes = reporters.stream()
            .map(rf -> rf.getClass().getSimpleName())
            .collect(Collectors.joining(",", "[", "]"));
    logger.info("Metrics reporters enabled. metric_reporter_types={}", metricReporterTypes);

    return reporters;
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-management-service,代碼行數:43,代碼來源:MetricsGuiceModule.java

示例3: metricsReporters_are_added_as_expected

import com.nike.riposte.server.config.AppInfo; //導入方法依賴的package包/類
@DataProvider(value = {
    "true   |   false   |   false",
    "false  |   true    |   false",
    "false  |   false   |   true",
    "true   |   true    |   true",
}, splitBy = "\\|")
@Test
public void metricsReporters_are_added_as_expected(boolean enableSlf4jReporter, boolean enableJmxReporter,
                                                   boolean enableGraphiteReporter) {
    // given
    configForTesting = generateAppConfigWithMetricsEnabledOrDisabled(enableSlf4jReporter, enableJmxReporter,
                                                                     enableGraphiteReporter);
    appGuiceModule = new AppGuiceModule(configForTesting);
    injector = generateInjector(appGuiceModule, configForTesting);

    // when
    List<ReporterFactory> reporters = injector.getInstance(Key.get(new TypeLiteral<List<ReporterFactory>>() {}));
    List<Class<? extends ReporterFactory>> reporterClasses = reporters.stream()
                                                            .map(ReporterFactory::getClass)
                                                            .collect(Collectors.toList());

    // then
    if (enableSlf4jReporter)
        assertThat(reporterClasses).contains(DefaultSLF4jReporterFactory.class);
    else
        assertThat(reporterClasses).doesNotContain(DefaultSLF4jReporterFactory.class);

    if (enableJmxReporter)
        assertThat(reporterClasses).contains(DefaultJMXReporterFactory.class);
    else
        assertThat(reporterClasses).doesNotContain(DefaultJMXReporterFactory.class);

    if (enableGraphiteReporter) {
        assertThat(reporterClasses).contains(DefaultGraphiteReporterFactory.class);
        DefaultGraphiteReporterFactory graphiteReporter = (DefaultGraphiteReporterFactory)reporters
            .stream().filter(r -> r instanceof DefaultGraphiteReporterFactory).findFirst().get();
        AppInfo appInfo = injector.getInstance(Key.get(new TypeLiteral<CompletableFuture<AppInfo>>() {},
                                                       Names.named("appInfoFuture"))).join();
        String expectedPrefix = appInfo.appId() + "." + appInfo.dataCenter() + "." + appInfo.environment()
                                + "." + appInfo.instanceId();
        String expectedGraphiteUrl = configForTesting.getString("metrics.graphite.url");
        int expectedPort = configForTesting.getInt("metrics.graphite.port");
        assertThat(Whitebox.getInternalState(graphiteReporter, "prefix")).isEqualTo(expectedPrefix);
        assertThat(Whitebox.getInternalState(graphiteReporter, "graphiteURL")).isEqualTo(expectedGraphiteUrl);
        assertThat(Whitebox.getInternalState(graphiteReporter, "graphitePort")).isEqualTo(expectedPort);
    }
    else
        assertThat(reporterClasses).doesNotContain(DefaultGraphiteReporterFactory.class);
}
 
開發者ID:Nike-Inc,項目名稱:riposte-microservice-template,代碼行數:50,代碼來源:AppGuiceModuleTest.java


注:本文中的com.nike.riposte.server.config.AppInfo.environment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。