io.inverno.mod.configuration.ConfigurationSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of inverno-configuration Show documentation
Show all versions of inverno-configuration Show documentation
Inverno configuration module
/*
* Copyright 2020 Jeremy KUHN
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.inverno.mod.configuration;
/**
*
* A configuration source gives access to configuration properties.
*
*
*
* Configuration properties can be queries as follows:
*
* {@code
* ConfigurationSource,?,?> source = ...
*
* Map propertiesAsString = source
* .get("prop1", "prop2")
* .execute()
* .collect(Collectors.toMap(
* result -> result.getQueryKey().getName(),
* result -> result.getResult()
* .flatMap(property -> property.asString()).orElse(null)
* )
* )
* .block();
* }
*
*
* Parameters can be specified on a query to specify the context for which values must be retrieved:
*
* {@code
* Map propertiesAsString = source
* .get("prop1", "prop2")
* .withParameters("environment", "test")
* .execute()
* .collect(Collectors.toMap(
* result -> result.getQueryKey().getName(),
* result -> result.getResult()
* .flatMap(property -> property.asString()).orElse(null)
* )
* )
* .block();
* }
*
*
* Queries can be executed in a batch:
*
* {@code
* Map propertiesAsString = source
* .get("prop1", "prop2").and()
* .get("prop3", "prop4")
* .withParameters("customer", "abc")
* .execute()
* .collect(Collectors.toMap(
* result -> result.getQueryKey().getName(),
* result -> result.getResult()
* .flatMap(property -> property.asString()).orElse(null)
* )
* )
* .block();
* }
*
* @author Jeremy Kuhn
* @since 1.0
*
* @param source specific query type
* @param source specific executable query type
* @param source specific list query type
*/
public interface ConfigurationSource, B extends ExecutableConfigurationQuery, C extends ListConfigurationQuery> {
/**
*
* Creates a configuration query to retrieve the specified properties.
*
*
* @param names an array of property names
*
* @return an executable configuration query
*
* @throws IllegalArgumentException if the array of names is null or empty
*/
B get(String... names) throws IllegalArgumentException;
/**
*
* Creates a list configuration query to list configuration properties defined with the specified property name.
*
*
* @param name a property name
*
* @return a list configuration query
* @throws IllegalArgumentException if the name is null or empty
*/
C list(String name) throws IllegalArgumentException;
}