private Optional<String> findInMpSources(String propertyName) { String propertyValue = null; for (ConfigSource source : mpConfigSources) { propertyValue = source.getValue(propertyName); if (null != propertyValue) { break; } } return Optional.ofNullable(propertyValue); }
public String get(final Object key) { return key instanceof String ? delegate.getValue((String) key) : null; }
private Optional<String> findInMpSources(String propertyName) { String propertyValue = null; for (ConfigSource source : mpConfigSources) { propertyValue = source.getValue(propertyName); if (null != propertyValue) { break; } } return Optional.ofNullable(propertyValue); }
public String next() { return delegate.getValue(iterator.next()); } }
public Entry<String, String> next() { String name = iterator.next(); return new SimpleImmutableEntry<>(name, delegate.getValue(name)); } }
@Override public <T> Optional<T> getOptionalValue(String name, Class<T> aClass) { for (ConfigSource configSource : configSources) { String value = configSource.getValue(name); // treat empty value as null if (value != null && value.length() > 0) { return Optional.of(convert(value, aClass)); } } return Optional.empty(); }
public String getValue(String key) { for (ConfigSource configSource : configSources) { String value = configSource.getValue(key); if (value != null) { if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, "found value {0} for key {1} in ConfigSource {2}.", new Object[]{value, key, configSource.getName()}); } return value; } } return null; }
public void forEach(final BiConsumer<? super String, ? super String> action) { // superclass is implemented in terms of entry set - expensive! for (String name : keySet()) { action.accept(name, delegate.getValue(name)); } }
String configOrdinal = getValue(CONFIG_ORDINAL); if(configOrdinal != null) { try {
public <T, C extends Collection<T>> C getValues(String name, Class<T> itemClass, IntFunction<C> collectionFactory) { for (ConfigSource configSource : configSources) { String value = configSource.getValue(name); if (value != null) { String[] itemStrings = StringUtil.split(value); final C collection = collectionFactory.apply(itemStrings.length); for (String itemString : itemStrings) { collection.add(convert(itemString, itemClass)); } return collection; } } return collectionFactory.apply(0); }
@GET @Path("/key/{key}") @Operation(description = "Getting the value for a certain config key") @APIResponse(responseCode = "200", description = "Successful, returning the value") @Produces(MediaType.TEXT_PLAIN) public Response getValue(@Parameter(name = "key", description = "The key for this config", required = true, allowEmptyValue = false, example = "some.key") @PathParam("key") String key, @Parameter(name = "configsource", description = "Only look at a certain config source", required = false, allowEmptyValue = true, example = "MemoryConfigSource") @QueryParam("configsource") String configsource) { if(!enabled)return Response.status(Response.Status.FORBIDDEN).header(REASON, NOT_ENABLED).build(); if(configsource==null || configsource.isEmpty()){ return Response.ok(config.getOptionalValue(key, String.class).orElse(null)).build(); }else{ if(!configSourceMap.containsKey(configsource))return Response.noContent().header(REASON, NO_SUCH_CONFIGSOURCE).build(); ConfigSource source = configSourceMap.get(configsource); return Response.ok(source.getValue(key)).build(); } }
private String getPropertyValue(String key,String defaultValue){ Config config = ConfigProvider.getConfig(); Iterable<ConfigSource> configSources = config.getConfigSources(); for(ConfigSource configsource:configSources){ if(!configsource.getName().equals(NAME)){ String val = configsource.getValue(key); if(val!=null && !val.isEmpty())return val; } } return defaultValue; }
@Override public <T> T getValue(String name, Class<T> aClass) { for (ConfigSource configSource : configSources) { String value = configSource.getValue(name); if (value != null) { return convert(value, aClass); } } // check for Optional numerical types to return their empty() // if the property is not found if (aClass.isAssignableFrom(OptionalInt.class)) { return aClass.cast(OptionalInt.empty()); } else if (aClass.isAssignableFrom(OptionalLong.class)) { return aClass.cast(OptionalLong.empty()); } else if (aClass.isAssignableFrom(OptionalDouble.class)) { return aClass.cast(OptionalDouble.empty()); } throw new NoSuchElementException("Property " + name + " not found"); }
@Override public List<ConfigSource> getConfigSources(ClassLoader classLoader) { List<ConfigSource> configSources = new ArrayList<>(); ConfigSource cli = CLIPropertySource.parseMainArgs(Bootstrap.ARGS); configSources.add(cli); String propertyValue = cli.getValue("hammock.external.config"); if(propertyValue != null) { try { URL url = Paths.get(propertyValue).toUri().toURL(); configSources.add(new PropertyFileConfigSource(url)); } catch (MalformedURLException e) { throw new RuntimeException("Unable to load "+propertyValue,e); } } for(String prop : defaultPropertyFiles) { configSources.addAll(new PropertyFileConfigSourceProvider(prop, true, classLoader).getConfigSources(classLoader)); } return configSources; } }