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