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


Java Config類代碼示例

本文整理匯總了Java中com.typesafe.config.Config的典型用法代碼示例。如果您正苦於以下問題:Java Config類的具體用法?Java Config怎麽用?Java Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: getConfig

import com.typesafe.config.Config; //導入依賴的package包/類
@Override
public Config getConfig() throws IOException {
  PathMatcher pathMatcher;

  try {
    pathMatcher = FileSystems.getDefault().getPathMatcher(inputFilePattern);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException(
        "Invalid input file pattern: " + inputFilePattern);
  }

  try (Stream<Path> pathStream = Files.walk(baseDirectory)) {
    return pathStream
        .filter(p -> Files.isRegularFile(p) && pathMatcher.matches(p))
        .map(p -> ConfigFactory.parseFile(p.toFile()))
        .reduce(ConfigFactory.empty(), Config::withFallback)
        .resolve(
            ConfigResolveOptions.defaults()
                .setAllowUnresolved(true)
                .setUseSystemEnvironment(false)
        );
  }
}
 
開發者ID:okvee,項目名稱:tscfg-docgen,代碼行數:24,代碼來源:PathMatcherConfigProvider.java

示例2: buildConfigIfAbsent

import com.typesafe.config.Config; //導入依賴的package包/類
private Config buildConfigIfAbsent(Config currentConfig) {
    if (currentConfig != null) return currentConfig;

    Optional<String> configurationFile = kvClient.getValueAsString(configurationFilePath).toJavaUtil();
    if (configurationFile.isPresent()) {
        return ConfigFactory.parseString(configurationFile.get());
    }

    logger.debug("Missing configuration file at path: {}, ignore flag set to: {}", configurationFilePath, ignoreMissingResource);

    if (ignoreMissingResource) {
        return ConfigFactory.empty();
    }

    throw new IllegalStateException("Missing required configuration resource at path: " + configurationFilePath);
}
 
開發者ID:conf4j,項目名稱:conf4j,代碼行數:17,代碼來源:ConsulFileConfigurationSource.java

示例3: loadQueryPlanPatterns

import com.typesafe.config.Config; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private Map<Language, List<QueryPlanPatterns>> loadQueryPlanPatterns(Config config) {
    Map<Language, List<QueryPlanPatterns>> rulesByLang = new LinkedHashMap<>();
    ConfigObject configObject = config.getObject("rules.planner-pattern");

    configObject.keySet().forEach(strLang -> {
        Language language = Language.valueOf(strLang.toUpperCase());
        List<QueryPlanPatterns> plans = new ArrayList<>();

        List<? extends ConfigObject> innerCfg = configObject.toConfig().getObjectList(strLang);
        innerCfg.forEach(e -> {
            Map<String, Object> plan = e.unwrapped();
            String planId = plan.keySet().toArray(new String[1])[0];
            List<String> triplePatterns = (List<String>)plan.values().toArray()[0];
            plans.add(new QueryPlanPatterns(planId,
                    triplePatterns.stream().map(TriplePattern::new).collect(Collectors.toList())));
        });

        rulesByLang.put(language, plans);
    });

    return rulesByLang;
}
 
開發者ID:Lambda-3,項目名稱:Stargraph,代碼行數:24,代碼來源:Rules.java

示例4: main

import com.typesafe.config.Config; //導入依賴的package包/類
public static void main(String []args) {
    Config config = ConfigFactory.parseFile(new File("config/model/fm.conf"));
    RandomParams randomParams = new RandomParams(config, "");
    RandomParamsUtils randomParamsUtils = new RandomParamsUtils(randomParams);

    System.out.println("normal sample:");
    for (int i = 0; i < 50; i++) {
        System.out.println(randomParamsUtils.next());
    }

    System.out.println("uniform sample:");
    for (int i = 0; i < 50000; i++) {
        double r = randomParamsUtils.next();
        if (r < -0.01 || r > 0.01) {
            System.out.println("error");
            break;
        }
    }
}
 
開發者ID:yuantiku,項目名稱:ytk-learn,代碼行數:20,代碼來源:RandomParamsUtils.java

示例5: getAppContext

import com.typesafe.config.Config; //導入依賴的package包/類
private static ListIterable<IntToObjectFunction<DbDeployerAppContext>> getAppContext(final Config config) {
    final String sourcePath = config.getString("sourcePath");
    String env = getStringOptional(config, "env");

    final String[] envArgs = env != null ? env.split(",") : new String[] { null };
    final String username = getStringOptional(config, "username");
    final String password = getStringOptional(config, "password");
    return ArrayAdapter.adapt(envArgs).collect(new Function<String, IntToObjectFunction<DbDeployerAppContext>>() {
        @Override
        public IntToObjectFunction<DbDeployerAppContext> valueOf(final String envArg) {
            return new IntToObjectFunction<DbDeployerAppContext>() {
                @Override
                public DbDeployerAppContext valueOf(int stepNumber) {
                    String stepSourcePath = replaceStepNumber(sourcePath, stepNumber, config);

                    DbEnvironment dbEnvironment = DbEnvironmentFactory.getInstance().readOneFromSourcePath(stepSourcePath, envArg != null ? new String[] {envArg} : new String[0]);
                    if (username != null && password != null) {
                        return dbEnvironment.buildAppContext(username, password);
                    } else {
                        return dbEnvironment.buildAppContext();
                    }
                }
            };
        }
    });
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:27,代碼來源:ParamReader.java

示例6: MLUpdate

import com.typesafe.config.Config; //導入依賴的package包/類
protected MLUpdate(Config config) {
  this.testFraction = config.getDouble("oryx.ml.eval.test-fraction");
  int candidates = config.getInt("oryx.ml.eval.candidates");
  this.evalParallelism = config.getInt("oryx.ml.eval.parallelism");
  this.threshold = ConfigUtils.getOptionalDouble(config, "oryx.ml.eval.threshold");
  this.maxMessageSize = config.getInt("oryx.update-topic.message.max-size");
  Preconditions.checkArgument(testFraction >= 0.0 && testFraction <= 1.0);
  Preconditions.checkArgument(candidates > 0);
  Preconditions.checkArgument(evalParallelism > 0);
  Preconditions.checkArgument(maxMessageSize > 0);
  if (testFraction == 0.0) {
    if (candidates > 1) {
      log.info("Eval is disabled (test fraction = 0) so candidates is overridden to 1");
      candidates = 1;
    }
  }
  this.candidates = candidates;
  this.hyperParamSearch = config.getString("oryx.ml.eval.hyperparam-search");
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:20,代碼來源:MLUpdate.java

示例7: getDataSourceFromConfig

import com.typesafe.config.Config; //導入依賴的package包/類
public static HikariDataSource getDataSourceFromConfig(
    Config conf
    , MetricRegistry metricRegistry
    , HealthCheckRegistry healthCheckRegistry) {

    HikariConfig jdbcConfig = new HikariConfig();
    jdbcConfig.setPoolName(conf.getString("poolName"));
    jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
    jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
    jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
    jdbcConfig.setUsername(conf.getString("username"));
    jdbcConfig.setPassword(conf.getString("password"));

    jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
    jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));

    // Add HealthCheck
    jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);

    // Add Metrics
    jdbcConfig.setMetricRegistry(metricRegistry);
    return new HikariDataSource(jdbcConfig);
}
 
開發者ID:StubbornJava,項目名稱:StubbornJava,代碼行數:26,代碼來源:ConnectionPool.java

示例8: dispatchConfig

import com.typesafe.config.Config; //導入依賴的package包/類
private void dispatchConfig(Config config, ConfigCallback callback) {
    for (Map.Entry<String, ConfigValue> entry : config.root().entrySet()) {
        final String id = entry.getKey();

        try {
            final Config entryConfig = ((ConfigObject) entry.getValue()).toConfig();
            final String type = entryConfig.getString("type");

            if (Strings.isNullOrEmpty(type)) {
                errors.add(new ConfigurationError("Missing type field for " + id + " (" + entryConfig + ")"));
                continue;
            }

            callback.call(type, id, entryConfig);
        } catch (ConfigException e) {
            errors.add(new ConfigurationError("[" + id + "] " + e.getMessage()));
        }
    }
}
 
開發者ID:DevOpsStudio,項目名稱:Re-Collector,代碼行數:20,代碼來源:ConfigurationRegistry.java

示例9: buildInputs

import com.typesafe.config.Config; //導入依賴的package包/類
private void buildInputs(final Config inputConfigs) {
    final Map<String, InputConfiguration.Factory<? extends InputConfiguration>> factories = ConfigurationRegistry.this.inputConfigFactories;

    dispatchConfig(inputConfigs, (type, id, config) -> {
        if (factories.containsKey(type)) {
            final InputConfiguration cfg = factories.get(type).create(id, config);

            if (validator.isValid(cfg)) {
                final InputService input = cfg.createInput();
                services.add(input);
                inputs.add(input);
            }
        } else {
            errors.add(new ConfigurationError("Unknown input type \"" + type + "\" for " + id));
        }
    });
}
 
開發者ID:DevOpsStudio,項目名稱:Re-Collector,代碼行數:18,代碼來源:ConfigurationRegistry.java

示例10: testDeleteOldData

import com.typesafe.config.Config; //導入依賴的package包/類
@Test
public void testDeleteOldData() throws Exception {
  Path tempDir = getTempDir();
  Path dataDir = tempDir.resolve("data");
  Path modelDir = tempDir.resolve("model");
  Map<String,Object> overlayConfig = new HashMap<>();
  overlayConfig.put("oryx.batch.update-class", MockBatchUpdate.class.getName());
  ConfigUtils.set(overlayConfig, "oryx.batch.storage.data-dir", dataDir);
  ConfigUtils.set(overlayConfig, "oryx.batch.storage.model-dir", modelDir);
  overlayConfig.put("oryx.batch.storage.max-age-data-hours", 0);
  overlayConfig.put("oryx.batch.storage.max-age-model-hours", 0);
  overlayConfig.put("oryx.batch.streaming.generation-interval-sec", GEN_INTERVAL_SEC);
  Config config = ConfigUtils.overlayOn(overlayConfig, getConfig());

  startMessaging();
  startServerProduceConsumeTopics(config, DATA_TO_WRITE, WRITE_INTERVAL_MSEC);
  assertEquals(0, IOUtils.listFiles(dataDir, "*").size());
  assertEquals(0, IOUtils.listFiles(modelDir, "*").size());
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:20,代碼來源:DeleteOldDataIT.java

示例11: getAppContextAndJdbcDsParams

import com.typesafe.config.Config; //導入依賴的package包/類
private Collection<Object[]> getAppContextAndJdbcDsParams(final int numConnections) {
    return getSysConfigs().flatCollect(new Function<Config, ListIterable<Object[]>>() {
        @Override
        public ListIterable<Object[]> valueOf(final Config config) {
            ListIterable<IntToObjectFunction<DbDeployerAppContext>> appContexts = getAppContext(config);
            return appContexts.collect(new Function<IntToObjectFunction<DbDeployerAppContext>, Object[]>() {
                @Override
                public Object[] valueOf(IntToObjectFunction<DbDeployerAppContext> appContext) {
                    return new Object[] {
                            appContext,
                            getJdbcDs(config, numConnections)
                    };
                }
            });
        }
    });
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:18,代碼來源:ParamReader.java

示例12: BatchUpdateFunction

import com.typesafe.config.Config; //導入依賴的package包/類
BatchUpdateFunction(Config config,
                    Class<K> keyClass,
                    Class<M> messageClass,
                    Class<? extends Writable> keyWritableClass,
                    Class<? extends Writable> messageWritableClass,
                    String dataDirString,
                    String modelDirString,
                    BatchLayerUpdate<K,M,U> updateInstance,
                    JavaStreamingContext streamingContext) {
  this.keyClass = keyClass;
  this.messageClass = messageClass;
  this.keyWritableClass = keyWritableClass;
  this.messageWritableClass = messageWritableClass;
  this.dataDirString = dataDirString;
  this.modelDirString = modelDirString;
  this.updateBroker = ConfigUtils.getOptionalString(config, "oryx.update-topic.broker");
  this.updateTopic = ConfigUtils.getOptionalString(config, "oryx.update-topic.message.topic");
  this.updateInstance = updateInstance;
  this.sparkContext = streamingContext.sparkContext();
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:21,代碼來源:BatchUpdateFunction.java

示例13: testConfigurationSourceMerging

import com.typesafe.config.Config; //導入依賴的package包/類
@Test
public void testConfigurationSourceMerging() {
    String filePath = getClass().getResource("fallback.conf").getPath();
    FilesystemConfigurationSource fallbackSource = FilesystemConfigurationSource.builder()
            .withFilePath(filePath)
            .build();

    ClasspathConfigurationSource source = ClasspathConfigurationSource.builder()
            .withResourcePath("org/conf4j/core/source/test.conf")
            .build();

    MergeConfigurationSource mergeSource = MergeConfigurationSource.builder()
            .withSource(source)
            .withFallback(fallbackSource)
            .build();

    Config config = mergeSource.getConfig();
    assertThat(config).isNotNull();
    assertThat(config.getString("message")).isEqualTo("config-loaded-successfully");
    assertThat(config.getString("override")).isEqualTo("overriding-works");
    assertThat(config.getInt("defaultProperty")).isEqualTo(555);
}
 
開發者ID:conf4j,項目名稱:conf4j,代碼行數:23,代碼來源:MergeConfigurationSourceTest.java

示例14: loadParams

import com.typesafe.config.Config; //導入依賴的package包/類
public static CommonParams loadParams(Config config) {

        CommonParams params = new CommonParams();

        params.dataParams = new DataParams(config, "");
        params.featureParams = new FeatureParams(config, "");
        params.lossParams = new LossParams(config, "");
        params.modelParams = new ModelParams(config, "");
        String optimizer = config.getString("optimization.optimizer");

        params.lsParams = new LineSearchParams(config, "optimization.");
        params.verbose = config.getBoolean("verbose");

        CheckUtils.check(optimizer.equals("line_search"), "optimization.optimizer only support:%s", "line_search");

        return params;
    }
 
開發者ID:yuantiku,項目名稱:ytk-learn,代碼行數:18,代碼來源:CommonParams.java

示例15: BatchLayer

import com.typesafe.config.Config; //導入依賴的package包/類
public BatchLayer(Config config) {
  super(config);
  this.keyWritableClass = ClassUtils.loadClass(
      config.getString("oryx.batch.storage.key-writable-class"), Writable.class);
  this.messageWritableClass = ClassUtils.loadClass(
      config.getString("oryx.batch.storage.message-writable-class"), Writable.class);
  this.updateClassName = config.getString("oryx.batch.update-class");
  this.dataDirString = config.getString("oryx.batch.storage.data-dir");
  this.modelDirString = config.getString("oryx.batch.storage.model-dir");
  this.maxDataAgeHours = config.getInt("oryx.batch.storage.max-age-data-hours");
  this.maxModelAgeHours = config.getInt("oryx.batch.storage.max-age-model-hours");
  Preconditions.checkArgument(!dataDirString.isEmpty());
  Preconditions.checkArgument(!modelDirString.isEmpty());
  Preconditions.checkArgument(maxDataAgeHours >= 0 || maxDataAgeHours == NO_MAX_AGE);
  Preconditions.checkArgument(maxModelAgeHours >= 0 || maxModelAgeHours == NO_MAX_AGE);
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:17,代碼來源:BatchLayer.java


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