本文整理汇总了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)
);
}
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例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();
}
}
};
}
});
}
示例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");
}
示例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);
}
示例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()));
}
}
}
示例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));
}
});
}
示例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());
}
示例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)
};
}
});
}
});
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}