当前位置: 首页>>代码示例>>Java>>正文


Java ConfigValue类代码示例

本文整理汇总了Java中com.typesafe.config.ConfigValue的典型用法代码示例。如果您正苦于以下问题:Java ConfigValue类的具体用法?Java ConfigValue怎么用?Java ConfigValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConfigValue类属于com.typesafe.config包,在下文中一共展示了ConfigValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldThrowIfInvalidConfig

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
@Test(expected = RktLauncherServiceException.class)
public void shouldThrowIfInvalidConfig() {
  //language=JSON
  final String json = "{\n"
                      + "  \"rkt\": \"/usr/local/bin/rkt\",\n"
                      + "  \"daemon\": \"systemd-run\",\n"
                      + "  \"globalOptions\": {\n"
                      + "    \"insecureOptions\": [\"image\"]\n"
                      + "  }\n"
                      + "}\n";
  final Config config = mock(Config.class);
  final ConfigValue configValue = mock(ConfigValue.class);
  when(environment.config()).thenReturn(config);
  when(config.getValue("rktLauncher")).thenReturn(configValue);
  when(configValue.render(any())).thenReturn(json);

  rktLauncherApi.create(environment);
}
 
开发者ID:honnix,项目名称:rkt-launcher,代码行数:19,代码来源:RktLauncherApiTest.java

示例2: dispatchConfig

import com.typesafe.config.ConfigValue; //导入依赖的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

示例3: KeyValue

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
KeyValue(Map.Entry<String, ConfigValue> keyValue) {
  key = keyValue.getKey();
  description = createDescription(keyValue.getValue());
  try {
    if (keyValue.getValue().valueType() == ConfigValueType.NULL) {
      valueType = "N/A (null)";
      defaultValue = "null";
    } else {
      valueType = keyValue.getValue().valueType().name().toLowerCase();
      defaultValue = render(keyValue.getValue());
    }
  } catch (ConfigException.NotResolved e) {
    valueType = "N/A (unresolved)";
    defaultValue = keyValue.getValue().render();
  }
}
 
开发者ID:okvee,项目名称:tscfg-docgen,代码行数:17,代码来源:Configuration.java

示例4: get

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
@GetMapping
public String get(HttpServletRequest req, Model model) {
	if (!utils.isAuthenticated(req) || !utils.isAdmin(utils.getAuthUser(req))) {
		return "redirect:" + HOMEPAGE;
	}
	Map<String, Object> configMap = new LinkedHashMap<String, Object>();
	for (Map.Entry<String, ConfigValue> entry : Config.getConfig().entrySet()) {
		ConfigValue value = entry.getValue();
		configMap.put(Config.PARA + "_" + entry.getKey(), value != null ? value.unwrapped() : "-");
	}
	configMap.putAll(System.getenv());
	model.addAttribute("path", "admin.vm");
	model.addAttribute("title", utils.getLang(req).get("admin.title"));
	model.addAttribute("configMap", configMap);
	model.addAttribute("version", pc.getServerVersion());
	return "base";
}
 
开发者ID:Erudika,项目名称:scoold,代码行数:18,代码来源:AdminController.java

示例5: applySystemProperties

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
private static Config applySystemProperties(Config config, Config reference){
  for (Entry<String, ConfigValue> entry : reference.entrySet()) {
    String property = System.getProperty(entry.getKey());
    if (property != null && !property.isEmpty()) {
      // hack to deal with array of strings
      if (property.startsWith("[") && property.endsWith("]")) {
        property = property.substring(1, property.length()-1);
        if (property.trim().isEmpty()) {
          continue;
        }
        String[] strings = property.split(",");
        if (strings != null && strings.length > 0) {
          List<String> listStrings = new ArrayList<>();
          for (String str : strings) {
            listStrings.add(str.trim());
          }
          config = config.withValue(entry.getKey(), ConfigValueFactory.fromAnyRef(listStrings));
        }
      } else {
        config = config.withValue(entry.getKey(), ConfigValueFactory.fromAnyRef(property));
      }
      logger.info("Applying provided system property to config: -D{}={}", entry.getKey(), property);
    }
  }
  return config;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:27,代码来源:DremioConfig.java

示例6: create

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
/**
 * Create a {@link BaggageHandlerRegistry} instance by parsing the mappings configured in the provided
 * {@link Config}
 * 
 * @param config a typesafe config
 * @return a {@link BaggageHandlerRegistry} instance with handlers loaded for the configured bag keys
 */
static BaggageHandlerRegistry create(Config config) {
    Map<BagKey, BaggageHandler<?>> mapping = new TreeMap<>();
    for (Entry<String, ConfigValue> x : config.getConfig(BAGS_CONFIGURATION_KEY).entrySet()) {
        String bagHandlerClassName = x.getValue().unwrapped().toString();
        Integer bagNumber = parseBagKey(x.getKey(), bagHandlerClassName);

        if (bagNumber == null) continue;

        BagKey key = BagKey.indexed(bagNumber);
        BaggageHandler<?> handler = resolveHandler(bagHandlerClassName);
        if (handler == null) continue;

        mapping.put(key, handler);
    }
    if (mapping.size() == 0) {
        log.warn("No baggage handlers are registered -- if this is unexpected, ensure `bag` is correctly configured");
    } else {
        String handlersString = mapping.entrySet().stream()
                                       .map(e -> "\t" + e.getKey().toString() + ": " +
                                                 e.getValue().getClass().getName().toString())
                                       .collect(Collectors.joining("\n"));
        log.info(mapping.size() + " baggage handlers registered:\n" + handlersString);
    }
    return new BaggageHandlerRegistry(new Registrations(mapping));
}
 
开发者ID:tracingplane,项目名称:tracingplane-java,代码行数:33,代码来源:BaggageHandlerRegistry.java

示例7: testNestedObject

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
@Test
public void testNestedObject() throws Exception {
    final String JSON = "{\"array\":[1,2],\"obj\":{\"first\":true}}";
    ConfigObject value = MAPPER.readValue(JSON, ConfigObject.class);
    assertEquals(ConfigValueType.OBJECT, value.valueType());
    assertEquals(2, value.size());

    ConfigList array = (ConfigList) value.get("array");
    assertEquals(ConfigValueType.LIST, array.valueType());
    assertEquals(2, (array.unwrapped().size()));

    ConfigValue objValue = value.get("obj");
    assertEquals(ConfigValueType.OBJECT, objValue.valueType());
    ConfigObject obj = (ConfigObject) objValue;
    assertEquals(1, (obj.size()));
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:17,代码来源:HoconDeserializerTest.java

示例8: getEventClassifier

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <E> EventClassifier<E> getEventClassifier(Class<E> eventType) {
    return (EventClassifier<E>) classifiers.computeIfAbsent(eventType, t -> {
        ConfigValue value = config.getConfig("ts-reaktive.replication.event-classifiers").root().get(eventType.getName());
        if (value == null) {
            throw new IllegalArgumentException("You must configure ts-reaktive.replication.event-classifiers.\"" +
                eventType.getName() + "\" with an EventClassifier implementation.");
        }
        String className = (String) value.unwrapped();
        try {
            Class<?> type = getClass().getClassLoader().loadClass(className);
            Constructor<?> constr = type.getDeclaredConstructor();
            constr.setAccessible(true);
            return (EventClassifier<E>) constr.newInstance();
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    });
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:20,代码来源:Replication.java

示例9: HibernateService

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
/**
 * Create the hibernate service which initializes the session factory
 *
 * @param conf  application configuration
 * @throws UnsupportedOperationException if a mapping file is invalid
 */
public HibernateService(Config conf) {
    Configuration hibernateConf = new Configuration();
    Config hc = conf.getConfig(HIBERNATE_KEY).atPath(HIBERNATE_KEY);
    for (Map.Entry<String, ConfigValue> entry : hc.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith(MAPPING_KEY)) {
            logger.info("Loading hibernate map from " + conf.getString(key));
            try {
                hibernateConf.addResource(conf.getString(key));
            } catch (MappingException e) {
                String msg = "Something wrong with mapping: " + conf.getString(key);
                throw new UnsupportedOperationException(msg, e);
            }
        } else {
            logger.info("Setting hibernate property: " + key + "=" + conf.getString(key));
            hibernateConf.setProperty(key, conf.getString(key));
        }
    }
    sessionFactory = hibernateConf.buildSessionFactory();
}
 
开发者ID:DorsetProject,项目名称:dorset-framework,代码行数:27,代码来源:HibernateService.java

示例10: CustomTagMappings

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
/**
 * Creates a new custom tag mappings object from the given configuration. The keys of the
 * configuration are well-known tag names, and the values are the custom tag names.
 *
 * @param config config holding custom tags
 * @throws IllegalArgumentException if any configuration value is not a string or is empty
 */
public CustomTagMappings(Config config) {
  ImmutableMap.Builder<String, String> b = ImmutableMap.builder();

  if (config != null) {
    for (Map.Entry<String,ConfigValue> e : config.entrySet()) {
      String key = e.getKey();
      ConfigValue value = e.getValue();
      switch (value.valueType()) {
        case STRING:
          String customTagName = (String) value.unwrapped();
          if (customTagName.isEmpty()) {
            throw new IllegalArgumentException("Tag mapping " + key + " is empty");
          }
          b.put(key, customTagName);
          break;
        default:
          throw new IllegalArgumentException("Tag mapping " + key + " is not a string: " + value);
      }
    }
  }

  customTagNames = b.build();
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:31,代码来源:CustomTagMappings.java

示例11: AWSTimeouts

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
/**
 * Creates a new timeouts object from the given configuration. It is
 * expected that every value in the recursive tree of the configuration is
 * numeric. Each (recursive) key in the config serves as the key for a
 * timeout.
 *
 * @param config config holding timeouts
 * @throws IllegalArgumentException if any configuration value is non-numeric
 */
public AWSTimeouts(Config config) {
  ImmutableMap.Builder<String, Long> b = ImmutableMap.builder();

  if (config != null) {
    for (Map.Entry<String,ConfigValue> e : config.entrySet()) {
      String key = e.getKey();
      ConfigValue value = e.getValue();
      switch (value.valueType()) {
        case NUMBER:
          long num =((Number) value.unwrapped()).longValue();
          if (num <= 0L) {
            throw new IllegalArgumentException("Timeout " + key + " is negative: " + value);
          }
          b.put(key, num);
          break;
        default:
          throw new IllegalArgumentException("Timeout " + key + " is not a number: " + value);
      }
    }
  }

  timeouts = b.build();
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:33,代码来源:AWSTimeouts.java

示例12: getStringMap

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
/**
 * Returns a map view of the data associated with the specified key. If the key corresponds
 * to a string list, each element of the list will be mapped to itself. If the key corresponds
 * to a nested configuration, the map will contain those entries of the nested configuration which
 * have string values (but not, for example, further nested configurations). If the key
 * corresponds to some other type, throws an exception from the underlying typesafe config
 * implementation.
 *
 * @param config the configuration
 * @param key    the key
 * @return a map view of the data associated with the specified key
 */
public static Map<String, String> getStringMap(Config config, String key) {
  ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
  try {
    for (String value : config.getStringList(key)) {
      builder.put(value, value);
    }
  } catch (ConfigException.WrongType e) {
    Config nestedConfig = config.getConfig(key);
    for (Map.Entry<String, ConfigValue> entry : nestedConfig.root().entrySet()) {
      String nestedKey = entry.getKey();
      String quotelessKey = stripQuotes(nestedKey);
      try {
        builder.put(quotelessKey, nestedConfig.getString(nestedKey));
      } catch (ConfigException.WrongType ignore) {
        LOG.warn("Ignoring non-string-valued key: '{}'", quotelessKey);
      }
    }
  }
  return builder.build();
}
 
开发者ID:cloudera,项目名称:director-aws-plugin,代码行数:33,代码来源:HoconConfigUtils.java

示例13: main

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
public static void main(String[] args) {
	for (Entry<String, ConfigValue> configSet : U.getConfig().entrySet()) {
		log.debug("{} is {}", configSet.getKey(), configSet.getValue());
	}
	Runnable time = new Runnable() {
		@Override
		public void run() {
			log.debug("{}", new DateTime());
		}
	};
	U.schedule(time, 1, 6);
	
	Packet packet=Packet.newBuilder().setCmdId(11).setChatMsgAck(ChatMsgAck.newBuilder().setResult(123)).build();
	System.out.println(TextFormat.printToString(packet));
	System.out.println(packet.toString());
}
 
开发者ID:East196,项目名称:maker,代码行数:17,代码来源:Cs.java

示例14: PagerDutyHandler

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
public PagerDutyHandler(Config config) {

        // Load API key list pipeline_name=api_key
        Config apiKeyConfig = config.getConfig("pagerduty.pipeline_api_keys");
        for (Map.Entry<String, ConfigValue> entry : apiKeyConfig.entrySet()) {
            pipelineApiKeys.put(entry.getKey(), entry.getValue().unwrapped().toString());
        }

        statusesToAlertOn = config.getStringList("pagerduty.statuses_to_alert");

        try {
            hostname = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            LOGGER.warn("Unable to discern hostname, using blank hostname");
            hostname = "";
        }
    }
 
开发者ID:PagerDuty,项目名称:gocd-pagerduty-plugin,代码行数:18,代码来源:PagerDutyHandler.java

示例15: parseDefinedRoles

import com.typesafe.config.ConfigValue; //导入依赖的package包/类
/**
 * Parse the Roles specified in the Config object.
 *
 * @param config
 * @return a map of Name-Role
 */
protected Map<String, Role> parseDefinedRoles(Config config) {
    // Parse the defined Roles
    Map<String, Role> roleMap = new HashMap<>();
    if (!config.hasPath("roles")) {
        log.trace("'{}' has no roles", config);
    } else if (config.hasPath("roles")) {
        log.trace("Parsing Role definitions");
        Config roleConfig = config.getConfig("roles");
        for (Map.Entry<String, ConfigValue> entry : roleConfig.entrySet()) {
            String name = entry.getKey();
            List<String> permissions = roleConfig.getStringList(name);
            Role role = new Role(name, permissions.toArray(new String[permissions.size()]));
            roleMap.put(role.getName(), role);
        }
    }

    return Collections.unmodifiableMap(roleMap);
}
 
开发者ID:gitblit,项目名称:fathom,代码行数:25,代码来源:KeycloakRealm.java


注:本文中的com.typesafe.config.ConfigValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。