Java 类com.typesafe.config.ConfigUtil 实例源码

项目:tracing-framework    文件:RetroSchedulers.java   
/**
 * This method is used to create all actual scheduler implementations.
 * Change the behavior here to change whatever type of scheduler is actually
 * used.
 */
private static Scheduler createPoint(String schedulerName) {
    Config config = ConfigFactory.load();

    // The default scheduler type to use
    String schedulerType = config.getString(DEFAULT_SCHEDULER_KEY);

    // Check to see whether this named throttling point is individually
    // configured
    String customConfigPath = ConfigUtil.joinPath(schedulerName);
    if (config.getConfig(CUSTOM_SCHEDULERS_KEY).hasPath(customConfigPath)) {
        schedulerType = config.getConfig(CUSTOM_SCHEDULERS_KEY).getString(customConfigPath);
    }

    // Get the instance and throw an exception if incorrectly configured
    Scheduler instance = getSchedulerInstance(schedulerType, schedulerName);
    if (instance == null) {
        throw new IllegalArgumentException("Invalid throttling point type for " + schedulerName + ": " + schedulerType);
    }
    return instance;
}
项目:tracing-framework    文件:LocalThrottlingPoints.java   
/**
 * This method is used to create all actual throttling point
 * implementations. Change the behavior here to change whatever type of
 * throttling point is actually used.
 */
private static ThrottlingPoint createPoint(String throttlingPointName) {
    Config config = ConfigFactory.load();

    // The default throttling point type to use
    String throttlingPointType = config.getString(DEFAULT_THROTTLINGPOINT_PROPERTY_KEY);

    // Check to see whether this named throttling point is individually
    // configured
    String customConfigPath = ConfigUtil.joinPath(throttlingPointName);
    if (config.getConfig(CUSTOM_THROTTLINGPOINT_KEY_PREFIX).hasPath(customConfigPath)) {
        throttlingPointType = config.getConfig(CUSTOM_THROTTLINGPOINT_KEY_PREFIX).getString(customConfigPath);
    }

    // Get the instance and throw an exception if incorrectly configured
    ThrottlingPoint instance = getThrottlingPointInstance(throttlingPointType, throttlingPointName);
    if (instance == null) {
        throw new IllegalArgumentException("Invalid throttling point type for " + throttlingPointName + ": " + throttlingPointType);
    }
    return instance;
}
项目:tracing-framework    文件:LocalThrottlingPoints.java   
/**
 * This method is used to create all actual throttling point
 * implementations. Change the behavior here to change whatever type of
 * throttling point is actually used.
 */
private static <T> ThrottlingQueue<T> createQueue(String throttlingQueueName) {
    Config config = ConfigFactory.load();

    // The default throttling point type to use
    String throttlingQueueType = config.getString(DEFAULT_THROTTLINGQUEUE_PROPERTY_KEY);

    // Check to see whether this named throttling point is individually
    // configured
    String customConfigPath = ConfigUtil.joinPath(throttlingQueueName);
    if (config.getConfig(CUSTOM_THROTTLINGQUEUE_KEY_PREFIX).hasPath(customConfigPath)) {
        throttlingQueueType = config.getConfig(CUSTOM_THROTTLINGQUEUE_KEY_PREFIX).getString(customConfigPath);
    }

    // Get the instance and throw an exception if incorrectly configured
    ThrottlingQueue<T> instance = getThrottlingQueueInstance(throttlingQueueType, throttlingQueueName);
    if (instance == null) {
        throw new IllegalArgumentException("Invalid throttling queue type for " + throttlingQueueName + ": " + throttlingQueueType);
    }
    return instance;
}
项目:runrightfast-vertx    文件:HazelcastConfigFactoryTest.java   
/**
 * Test of hazelcastConfigFactory method, of class HazelcastConfigFactory.
 */
@Test
public void testHazelcastConfigFactory() {
    LOG.info("hazelcastConfigFactory");
    String hazelcastInstanceName = "testHazelcastConfigFactory";

    final HazelcastConfigFactory factory1 = HazelcastConfigFactory.hazelcastConfigFactory(hazelcastInstanceName + 1);
    final com.hazelcast.config.Config hazelcastConfig1 = factory1.apply(config.getConfig(ConfigUtil.joinPath("Hazelcast", "application-1")));
    final HazelcastInstance hazelcast1 = Hazelcast.newHazelcastInstance(hazelcastConfig1);

    final HazelcastConfigFactory factory2 = HazelcastConfigFactory.hazelcastConfigFactory(hazelcastInstanceName + 2);
    final com.hazelcast.config.Config hazelcastConfig2 = factory2.apply(config.getConfig(ConfigUtil.joinPath("Hazelcast", "application-2")));
    final HazelcastInstance hazelcast2 = Hazelcast.newHazelcastInstance(hazelcastConfig2);

    test(hazelcast1, hazelcast2);
}
项目:cdk    文件:MorphlineTest.java   
private void internalExtractURIQueryParams(String paramName, String url, List expected, int maxParams) throws Exception {
  String fileName = "test-morphlines/extractURIQueryParameters";
  String overridesStr = "queryParam : " + ConfigUtil.quoteString(paramName);
  if (maxParams >= 0) {
    fileName += "WithMaxParameters";
    overridesStr += "\nmaxParameters : " + maxParams;
  }
  Config override = ConfigFactory.parseString(overridesStr);
  morphline = createMorphline(fileName, override);
  Record record = new Record();
  record.put("in", url);
  Record expectedRecord = new Record();
  expectedRecord.put("in", url);
  expectedRecord.getFields().putAll("out", expected);
  processAndVerifySuccess(record, expectedRecord);
}
项目:Night-Config    文件:HoconParser.java   
private static void put(com.typesafe.config.Config typesafeConfig, Config destination,
                        ParsingMode parsingMode) {
    for (Map.Entry<String, ConfigValue> entry : typesafeConfig.entrySet()) {
        List<String> path = ConfigUtil.splitPath(entry.getKey());
        parsingMode.put(destination, path, unwrap(entry.getValue().unwrapped()));
    }
}
项目:Night-Config    文件:HoconParser.java   
private static void put(com.typesafe.config.Config typesafeConfig, CommentedConfig destination,
                        ParsingMode parsingMode) {
    for (Map.Entry<String, ConfigValue> entry : typesafeConfig.entrySet()) {
        List<String> path = ConfigUtil.splitPath(entry.getKey());
        ConfigValue value = entry.getValue();
        parsingMode.put(destination, path, unwrap(value.unwrapped()));
        List<String> comments = value.origin().comments();
        if (!comments.isEmpty()) {
            destination.setComment(path, String.join("\n", value.origin().comments()));
        }
    }
}
项目:runrightfast-vertx    文件:ConfigUtils.java   
static String configPath(final String name, final String... names) {
    checkArgument(StringUtils.isNotBlank(name));
    if (ArrayUtils.isNotEmpty(names)) {
        return ConfigUtil.joinPath(ImmutableList.<String>builder().add(name).add(names).build());
    }
    return name;
}
项目:runrightfast-vertx    文件:HazelcastConfigFactoryTest.java   
/**
 * Test of hazelcastConfigFactory method, of class HazelcastConfigFactory.
 */
@Test
public void testHazelcastConfigFactory_withSerializers() {
    LOG.info("hazelcastConfigFactory");
    String hazelcastInstanceName = "testHazelcastConfigFactory_withSerializers";
    final Set<SerializerConfig> serializerConfigs = ImmutableSet.of(
            new SerializerConfig().setImplementation(new JsonObjectSerializer()).setTypeClass(JsonObject.class)
    );
    final HazelcastConfigFactory factory1 = HazelcastConfigFactory.hazelcastConfigFactory(hazelcastInstanceName + 1, serializerConfigs);
    final com.hazelcast.config.Config hazelcastConfig1 = factory1.apply(config.getConfig(ConfigUtil.joinPath("Hazelcast", "application-1")));
    final HazelcastInstance hazelcast1 = Hazelcast.newHazelcastInstance(hazelcastConfig1);

    final HazelcastConfigFactory factory2 = HazelcastConfigFactory.hazelcastConfigFactory(hazelcastInstanceName + 2, serializerConfigs);
    final com.hazelcast.config.Config hazelcastConfig2 = factory2.apply(config.getConfig(ConfigUtil.joinPath("Hazelcast", "application-2")));
    final HazelcastInstance hazelcast2 = Hazelcast.newHazelcastInstance(hazelcastConfig2);

    test(hazelcast1, hazelcast2);

    final JsonObject json = Json.createObjectBuilder().add("a", 1).build();
    final String mapName = "testHazelcastConfigFactory_withSerializers_map";
    final Map<String, Object> map1 = hazelcast1.getMap(mapName);
    map1.put("json", json);

    final Map<String, Object> map2 = hazelcast2.getMap(mapName);
    final JsonObject json2 = (JsonObject) map2.get("json");
    assertThat(json2.getInt("a"), is(1));
}
项目:runrightfast-vertx    文件:TypesafeHazelcastConfigTest.java   
/**
 * Test of getHazelcastConfig method, of class TypesafeHazelcastConfig.
 */
@Test
public void testGetHazelcastConfig() {
    System.out.println("getConfig");
    final TypesafeHazelcastConfig typesafeHazelcastConfig = new TypesafeHazelcastConfig("testGetConfig", config.getConfig(ConfigUtil.joinPath("Hazelcast", "application-1")));
    final Config hazelcastConfig = typesafeHazelcastConfig.getHazelcastConfig();
    assertThat(hazelcastConfig, is(notNullValue()));
    assertThat(hazelcastConfig.getInstanceName(), is("testGetConfig"));
}
项目:StreamSis    文件:CuteConfig.java   
/**
 * Sets the String value for current configuration's variable to config.
 *
 * @param key
 *            The name of settings section.
 * @param subKey
 *            The name of needed variable.
 * @param value
 *            The value to set.
 */
private static void setStringToConfig(String key, String subKey, String newValue,
        boolean hideValue) {
    String fullPath = MAINKEY + "." + key + "." + subKey;
    if (getString(key, subKey).equals(newValue)) {
        String messageToLog = hideValue
                ? String.format("Setting secret configuration value. Key: %s.%s", key, subKey)
                : String.format("Configuration value unchanged. Key: %s.%s Value: %s", key,
                        subKey, newValue);
        logger.info(messageToLog);
        return;
    }
    String processedNewValue = ConfigUtil.quoteString(newValue);
    // Lets make new Config object with just a single variable.
    // Also lets preserve the comments from the original Config.
    ConfigOrigin or = conf.getValue(fullPath).origin();
    StringBuilder toParse = new StringBuilder();
    for (String comment : or.comments()) {
        toParse.append("#").append(comment).append("\n");
    }
    toParse.append(fullPath).append("=").append(processedNewValue);
    Config newLittleConfig = ConfigFactory.parseString(toParse.toString());
    // Now we have our little Config with the single variable and old comments.
    // Let's merge it with the old Config.
    conf = newLittleConfig.withFallback(conf);
    if (!hideValue) {
        logger.info(String.format("Configuration update in RAM. Key: %s.%s Value: %s", key, subKey, newValue));
    }
    needsSave = true;
}
项目:search    文件:SolrLocator.java   
private String toJson(Object key) {
  String str = key == null ? "" : key.toString();
  str = ConfigUtil.quoteString(str);
  return str;
}
项目:read-open-source-code    文件:SolrLocator.java   
private String toJson(Object key) {
  String str = key == null ? "" : key.toString();
  str = ConfigUtil.quoteString(str);
  return str;
}
项目:jooby    文件:EhCacheBuilder.java   
private Iterable<String> names(final Config conf) {
  Set<String> result = new LinkedHashSet<>();
  conf.root().forEach((k, v) -> result.add(ConfigUtil.splitPath(k).get(0)));
  return result;
}
项目:cdk    文件:SolrLocator.java   
private String toJson(Object key) {
  String str = key == null ? "" : key.toString();
  str = ConfigUtil.quoteString(str);
  return str;
}
项目:zookeeper-lite    文件:ClientAddressConfiguration.java   
public static Configuration set(Configuration configuration, ServerInetAddressView value) {
    Configurable configurable = getConfigurable();
    return configuration.withConfig(ConfigFactory.parseMap(ImmutableMap.<String,Object>builder().put(ConfigUtil.joinPath(configurable.path(), configurable.arg()), value.toString()).build()));
}
项目:zookeeper-lite    文件:EnsembleViewConfiguration.java   
public static Configuration set(Configuration configuration, EnsembleView<ServerInetAddressView> value) {
    Configurable configurable = getConfigurable();
    return configuration.withConfig(ConfigFactory.parseMap(ImmutableMap.<String,Object>builder().put(ConfigUtil.joinPath(configurable.path(), configurable.arg()), EnsembleView.toString(value)).build()));
}
项目:zookeeper-proxy    文件:ProxyServerExecutorBuilder.java   
public static Configuration set(Configuration configuration, EnsembleView<ServerInetAddressView> value) {
    Configurable configurable = getConfigurable();
    return configuration.withConfig(ConfigFactory.parseMap(ImmutableMap.<String,Object>builder().put(ConfigUtil.joinPath(configurable.path(), configurable.key()), EnsembleView.toString(value)).build()));
}