You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2016/05/01 21:02:30 UTC
[1/3] incubator-tamaya git commit: TAMAYA-158: Aligned metadata
format for model extension with defaults: updated docs.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master c16b0d534 -> 09b648abe
TAMAYA-158: Aligned metadata format for model extension with defaults: updated docs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/09b648ab
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/09b648ab
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/09b648ab
Branch: refs/heads/master
Commit: 09b648abe5624aac65e7cf6efd83411018e77e1e
Parents: e022c49
Author: anatole <an...@apache.org>
Authored: Sun May 1 20:51:02 2016 +0200
Committer: anatole <an...@apache.org>
Committed: Sun May 1 21:02:06 2016 +0200
----------------------------------------------------------------------
src/site/asciidoc/extensions/mod_model.adoc | 79 ++++++++++++------------
1 file changed, 40 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/09b648ab/src/site/asciidoc/extensions/mod_model.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_model.adoc b/src/site/asciidoc/extensions/mod_model.adoc
index 9e25d0f..4a501ee 100644
--- a/src/site/asciidoc/extensions/mod_model.adoc
+++ b/src/site/asciidoc/extensions/mod_model.adoc
@@ -57,7 +57,7 @@ Basically configuration is modelled using key, value-pairs. Looking at a keys
configuration:
. the _configuration section:_ In our case this equals to +a.b.c+, which itself also includes the
- tranitive entries +a.b+ and +a+.
+ transitive entries +a.b+ and +a+.
. the _configuration parameter:_ Basically parameters are adressed using their fully qualified names,
which equals to the containing section name and the relative parameter name, separated by the dor separator.
In the above example +a.b.c.param1+ and +a.b.c.param2+ are the fully qualified parameter names.
@@ -68,15 +68,15 @@ Now with only these 2 concepts a simple configuration meta-model can be defined
descriptions, e.g. in a management console or generated configuration documentation site.
* a set of sections.
* a set of parameters.
-* Both, sections as well as parameter models
- ** can be modelled by a met-data entry, by default +_{key}.model+.
- ** may be required, or optional
+* Both, sections (+.model.target=Section+) as well as parameter models (+.model.target=Parameter+)
+ ** can be modelled by a meta-data entry, by default +_my.config.key.model+.
+ ** may be required, or optional (+.model.required=true|false+)
** may have an optional description
* Parameters additionally have
- ** a _type_, described by the fully qualified class name, into which any configured (String) value must be
- convertable into. If no type is configured +java.lang.String+ is assumed as default.
+ ** a _type_ (+.model.type=Classname+), described by the fully qualified class name, into which any configured (String)
+ value must be convertable into. If no type is configured +java.lang.String+ is assumed as default.
** an optional regular expression that can be used to validate the +String+ values returned from a
- configuration.
+ configuration (+.model.expression=regexpression+).
Given these concepts a configuration can be fully described. Entries that are not contained in one of the given
sections (or its children), or parameters not described or marked as valid (e.g. for dynamic configModels of
@@ -94,9 +94,10 @@ its parent, or child section.
=== Defining Meta-Configuration Model
-The configuration meta-model is defined by simple configuration entries. The root section for all model configuration
-by default is called +{model}+. Within this section fully qualified configuration keys defines which part of the
-configuration is targeted by certain entries.
+The configuration meta-model is defined by simple configuration meta-data entries. The section for all model
+configuration by default is called +model+, which results in entries such as +_my.config.key.model.target=Section+.
+Within this section fully qualified configuration keys defines
+which part of the configuration is targeted by certain entries.
==== Defining Sections
@@ -106,24 +107,24 @@ variants supported:
[source,listing]
-------------------------------------------------------------------------------
# Metamodel information
-_config-model.provider=ConfigModel Extension
+_model.provider=ConfigModel Extension
# org.mycompany.root (optional section)
-_org.mycompany.root.model-type=Section
-_org.mycompany.root.model-description=Root section defining my company configuration.
+_org.mycompany.root.model.target=Section
+_org.mycompany.root.model.description=Root section defining my company configuration.
# org.mycompany.security (required section)
-_org.mycompany.security.model-type=Section
-_org.mycompany.security.model-required=true
-_org.mycompany.security.model-description=Security related settings.\
+_org.mycompany.security.model.target=Section
+_org.mycompany.security.model.required=true
+_org.mycompany.security.model.description=Security related settings.\
refer for further details to XXX.
# minmal section
-_minimal.model-class=Section
+_minimal.model.target=Section
# custom validated section
-_validated.model-type=Section
-_validated.model-validator=org.apache.tamaya.model.TestValidator
+_validated.model.target=Section
+_validated.model.validator=org.apache.tamaya.model.TestValidator
-------------------------------------------------------------------------------
Above +org.mycompany.root+ transitively defines 3 sections:
@@ -151,20 +152,20 @@ Similarly parameters also can be defined:
[source,listing]
-------------------------------------------------------------------------------
# org.mycompany.root.name (required parameter)
-_org.mycompany.root.name.model-type=Parameter
-_org.mycompany.root.name.model-required=true
-_org.mycompany.root.name.model-description=The company's name, also used in the application's main header.
+_org.mycompany.root.name.model.target=Parameter
+_org.mycompany.root.name.model.required=true
+_org.mycompany.root.name.model.description=The company's name, also used in the application's main header.
# org.mycompany.security (required parameters)
-_org.mycompany.security.uid.model-required=true
-_org.mycompany.security.uid.model-description=The user id.
-_org.mycompany.security.realm.model-required=true
-_org.mycompany.security.realm.model-validator=org.apache.tamaya.model.RealmValidator
-_org.mycompany.security.realm.model-description=The security realm required.
-_org.mycompany.security.tokenid.model-description=The token id, if the token service is used (optional).
+_org.mycompany.security.uid.model.required=true
+_org.mycompany.security.uid.model.description=The user id.
+_org.mycompany.security.realm.model.required=true
+_org.mycompany.security.realm.model.validator=org.apache.tamaya.model.RealmValidator
+_org.mycompany.security.realm.model.description=The security realm required.
+_org.mycompany.security.tokenid.model.description=The token id, if the token service is used (optional).
# A minmal parameter
-_minimalClass.model-type=Class
+_minimalClass.model.target=Class
-------------------------------------------------------------------------------
Similarly as when defining section also parameter entries define transitively its containing sections. E.g.
@@ -211,7 +212,7 @@ statistics for calling +Configuration.getProperties()+ can be obtained calling +
Usage tracking is disabled by default. It can be enabled by calling +ConfigUsageStats.enableUsageTracking(true);+.
+ConfigUsageStats.isUsageTrackingEnabled()+ returns the current tracking status.
-The +Usage+ class itself provides access to further fainer grained usage data (+AccessDetail+) cotaining:
+The +Usage+ class itself provides access to further fainer grained usage data (+AccessDetail+) containing:
* the access point (+fqn.ClassName#method(line: xxx)+).
* the number of accesses
@@ -429,8 +430,8 @@ New instances implementing this interface must be registered into the current +S
=== The ConfigUsageStatsSpi
-The methods for managing and tracking of configuration changes are delegated to the current
-most sinificant implementation of the +org.apache.tamaya.model.spi.ConfigUsageStatsSpi+ SPI.
+The methods for managing and tracking of configuration changes are similarly delegated to an
+implementation of the +org.apache.tamaya.model.spi.ConfigUsageStatsSpi+ SPI.
By implementing this SPI and registerting it with the +ServiceContext+ the usage tracking
logic can be adapted or replaced.
@@ -453,12 +454,12 @@ The module also provides further utility classes that may be useful for implemen
The model module provides different switches that can be used to activate or deactivate features:
-* +org.apache.tamaya.model.integrated.enabled+ allows to deactivate reading inline metaconfiguration delivered with
- the normal Tamaya Configuration. By default inline entries (+{meta}...+) are evaluated.
-* +org.apache.tamaya.model.default.enabled+ allows to deactivate reading metamodel information from
+* +tamaya.model.integrated.enabled+ allows to deactivate reading inline metaconfiguration delivered with
+ the normal Tamaya Configuration. By default inline entries (+_.abcd.model.*+) are evaluated.
+* +tamaya.model.default.enabled+ allows to deactivate reading metamodel information from
+classpath:META-INF/configmodel.properties+. By default it is active.
-* +org.apache.tamaya.model.resources+ allows to defie additional resources (loaded through the resources extension),
+* +tamaya.model.resources+ allows to define additional resources (loaded through the resources extension),
that can be used to read metamodel information in any format using Tamaya's format module.
-* the system property +org.apache.tamaya.model.autoModelEvents+ allows to activate/deactivate the automatic documentation of
- classes configured and published by Tamaya +ConfiguredType+ event instances (e.g. published by Tamaya's injection
- modules).
+* the system property +tamaya.model.autoModelEvents+ allows to activate/deactivate the automatic
+ documentation of classes configured and published by Tamaya +ConfiguredType+ event instances (e.g. published by
+ Tamaya's injection modules).
[2/3] incubator-tamaya git commit: TAMAYA-158: Aligned metadata
format for model extension with defaults.
Posted by an...@apache.org.
TAMAYA-158: Aligned metadata format for model extension with defaults.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/e022c495
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/e022c495
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/e022c495
Branch: refs/heads/master
Commit: e022c49558cfe2c44d3c274ced1b4f073c437780
Parents: 8d29a71
Author: anatole <an...@apache.org>
Authored: Sun May 1 20:36:30 2016 +0200
Committer: anatole <an...@apache.org>
Committed: Sun May 1 21:02:06 2016 +0200
----------------------------------------------------------------------
.../model/internal/ConfigDocumentationBean.java | 4 +-
.../ConfiguredInlineModelProviderSpi.java | 3 +-
.../ConfiguredResourcesModelProviderSpi.java | 2 +-
.../tamaya/model/spi/ConfigModelReader.java | 82 ++++++--------------
.../apache/tamaya/model/spi/SectionModel.java | 3 +
.../resources/META-INF/configmodel.properties | 32 ++++----
.../internal/ConfigDocumentationBeanTest.java | 20 ++---
.../resources/META-INF/configmodel.properties | 78 +++++++++----------
8 files changed, 95 insertions(+), 129 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
index 2d40ac0..3298025 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfigDocumentationBean.java
@@ -161,7 +161,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
private JsonObject toJsonObject(ConfigModel val) {
- JsonObjectBuilder valJson = Json.createObjectBuilder().add("type", val.getType().toString())
+ JsonObjectBuilder valJson = Json.createObjectBuilder().add("target", val.getType().toString())
.add("name", val.getName());
if(val.getDescription()!=null) {
valJson.add("description", val.getDescription());
@@ -173,7 +173,7 @@ public class ConfigDocumentationBean implements ConfigDocumentationMBean{
}
private JsonObject toJsonObject(Validation val) {
- JsonObjectBuilder valJson = Json.createObjectBuilder().add("type", val.getConfigModel().getType().toString())
+ JsonObjectBuilder valJson = Json.createObjectBuilder().add("target", val.getConfigModel().getType().toString())
.add("name", val.getConfigModel().getName());
if(val.getConfigModel().isRequired()){
valJson.add("required",true);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
index a15ce05..8111491 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredInlineModelProviderSpi.java
@@ -53,8 +53,7 @@ public class ConfiguredInlineModelProviderSpi implements ModelProviderSpi {
if (enabled) {
LOG.info("Reading model configuration from config...");
Map<String,String> config = ConfigurationProvider.getConfiguration().getProperties();
- configModels.addAll(ConfigModelReader.loadValidations(config,
- "<Inline Configuration Model>"));
+ configModels.addAll(ConfigModelReader.loadValidations(config));
}
configModels = Collections.unmodifiableList(configModels);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
index 2a136aa..7c5836e 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
@@ -141,7 +141,7 @@ public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi {
for (final URL config : urls) {
try (InputStream is = config.openStream()) {
final ConfigurationData data = ConfigurationFormats.readConfigurationData(config);
- configModels.addAll(ConfigModelReader.loadValidations(data.getCombinedProperties(), config.toString()));
+ configModels.addAll(ConfigModelReader.loadValidations(data.getCombinedProperties()));
} catch (final Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE,
"Error loading config model data from " + config, e);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
index b380051..b8d95d0 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigModelReader.java
@@ -35,7 +35,7 @@ import org.apache.tamaya.model.ConfigModel;
public final class ConfigModelReader {
/** The default model entries selector. */
- private static final String DEFAULT_META_INFO_SELECTOR = "{model}";
+ private static final String DEFAULT_META_INFO_SELECTOR = ".model";
/** parameter to change the selector to be used for filtering out the target values to be used. */
private static final String META_INFO_SELECTOR_PARAM = "org.apache.tamaya.model.integrated.selector";
@@ -43,84 +43,48 @@ public final class ConfigModelReader {
* Utility class only.
*/
private ConfigModelReader(){}
-///*
-// *//**
-// * Loads validations as configured in the given properties.
-// * @param props the properties to be read
-// * @param selector
-// * @return a collection of config validations.
-// *//*
-// public static Collection<ConfigModel> loadValidations(Map<String,String> props, String selector) {
-// Map<String,String> map = new HashMap<>();
-// for(Map.Entry<String, String> en: props.entrySet()){
-// if(!selector.matches(en.getKey())){
-// map.put(en.getKey().toString(), props.get(en.getKey().toString()));
-// }
-// }
-// return loadValidations(map);
-// }*/
- /**
- * Loads validations as configured in the given properties.
- * @param props the properties to be read
- * @return a collection of config validations.
- */
- public static Collection<ConfigModel> loadValidations(Map<String,String> props) {
- return loadValidations(props, getSelector(props));
- }
-
- /**
- * Evaluates the correct selector.
- * @param props
- * @return
- */
- private static String getSelector(Map<String,String> props){
- String selector = props.get(META_INFO_SELECTOR_PARAM);
- if(selector==null){
- selector = DEFAULT_META_INFO_SELECTOR;
- }
- return selector;
- }
/**
* Loads validations as configured in the given properties.
* @param props the properties to be read
- * @param selector the selector (default is {model}), that identifies the model entries.
* @return a collection of config validations.
*/
- public static Collection<ConfigModel> loadValidations(Map<String,String> props, String selector) {
+ public static Collection<ConfigModel> loadValidations(Map<String,String> props) {
List<ConfigModel> result = new ArrayList<>();
Set<String> itemKeys = new HashSet<>();
for (Object key : props.keySet()) {
- if (key.toString().endsWith(".class")) {
- itemKeys.add(key.toString().substring(0, key.toString().length() - ".class".length()));
+ if (key.toString().startsWith("_") &&
+ key.toString().endsWith(DEFAULT_META_INFO_SELECTOR + ".target")) {
+ itemKeys.add(key.toString().substring(0, key.toString().length() - ".model.target".length()));
}
}
for (String baseKey : itemKeys) {
- String clazz = props.get(baseKey + ".class");
- String type = props.get(baseKey + ".type");
+ String target = props.get(baseKey + ".model.target");
+ String type = props.get(baseKey + ".model.type");
if (type == null) {
type = String.class.getName();
}
- String value = props.get(baseKey + ".transitive");
+ String value = props.get(baseKey + ".model.transitive");
boolean transitive = false;
if(value!=null) {
transitive = Boolean.parseBoolean(value);
}
- String description = props.get(baseKey + ".description");
- String regEx = props.get(baseKey + ".expression");
- String validations = props.get(baseKey + ".validations");
- String requiredVal = props.get(baseKey + ".required");
- if ("Parameter".equalsIgnoreCase(clazz)) {
- result.add(createParameterValidation(baseKey.substring(selector.length() + 1), description, type,
- requiredVal, regEx, validations));
- } else if ("Section".equalsIgnoreCase(clazz)) {
+ String description = props.get(baseKey + ".model.description");
+ String regEx = props.get(baseKey + ".model.expression");
+ String validations = props.get(baseKey + ".model.validations");
+ String requiredVal = props.get(baseKey + ".model.required");
+ String targetKey = baseKey.substring(1);
+ if ("Parameter".equalsIgnoreCase(target)) {
+ result.add(createParameterValidation(targetKey,
+ description, type, requiredVal, regEx, validations));
+ } else if ("Section".equalsIgnoreCase(target)) {
if(transitive){
- result.add(createSectionValidation(baseKey.substring(selector.length() + 1)+".*", description, requiredVal,
- validations));
+ result.add(createSectionValidation(targetKey+".*",
+ description, requiredVal, validations));
} else {
- result.add(createSectionValidation(baseKey.substring(selector.length() + 1), description, requiredVal,
- validations));
+ result.add(createSectionValidation(targetKey,
+ description, requiredVal, validations));
}
}
}
@@ -144,7 +108,7 @@ public final class ConfigModelReader {
.setDescription(description).setExpression(regEx).setType(type);
// if (validations != null) {
// try {
-// // TODO defined validator API
+// // TODO define validator API
//// builder.addValidations(loadValidations(validations));
// } catch (Exception e) {
// LOGGER.log(Level.WARNING, "Failed to load validations for " + paramName, e);
@@ -168,7 +132,7 @@ public final class ConfigModelReader {
.setDescription(description);
// if (validations != null) {
// try {
-// // TODO defined validator API
+// // TODO define validator API
//// builder.addValidations(loadValidations(valiadtions));
// } catch (Exception e) {
// LOGGER.log(Level.WARNING, "Failed to load validations for " + sectionName, e);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
index 9f55a2b..31eaa51 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/SectionModel.java
@@ -84,6 +84,9 @@ public class SectionModel extends GroupModel {
String lookupKey = getName() + '.';
boolean present = false;
for(String key:map.keySet()){
+ if(key.startsWith("_")){
+ continue;
+ }
if(key.startsWith(lookupKey)){
present = true;
break;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/main/resources/META-INF/configmodel.properties
----------------------------------------------------------------------
diff --git a/modules/model/src/main/resources/META-INF/configmodel.properties b/modules/model/src/main/resources/META-INF/configmodel.properties
index 7861c9e..3381a09 100644
--- a/modules/model/src/main/resources/META-INF/configmodel.properties
+++ b/modules/model/src/main/resources/META-INF/configmodel.properties
@@ -17,19 +17,19 @@
# under the License.
#
# Contains definitions for default system property areas.
-{model}.awt.class=Section
-{model}.awt.transitive=true
-{model}.file.class=Section
-{model}.file.transitive=true
-{model}.java.class=Section
-{model}.java.transitive=true
-{model}.line.class=Section
-{model}.line.transitive=true
-{model}.os.class=Section
-{model}.os.transitive=true
-{model}.path.class=Section
-{model}.path.transitive=true
-{model}.sun.class=Section
-{model}.sun.transitive=true
-{model}.user.class=Section
-{model}.user.transitive=true
+_awt.model.target=Section
+_awt.model.transitive=true
+_file.model.target=Section
+_file.model.transitive=true
+_java.model.target=Section
+_java.model.transitive=true
+_line.model.target=Section
+_line.model.transitive=true
+_os.model.target=Section
+_os.model.transitive=true
+_path.model.target=Section
+_path.model.transitive=true
+_sun.model.target=Section
+_sun.model.transitive=true
+_user.model.target=Section
+_user.model.transitive=true
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java b/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
index d60e902..e791417 100644
--- a/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
+++ b/modules/model/src/test/java/org/apache/tamaya/model/internal/ConfigDocumentationBeanTest.java
@@ -37,7 +37,7 @@ public class ConfigDocumentationBeanTest {
String results = mbean.validate(false);
assertNotNull(results);
assertFalse(results.trim().isEmpty());
- assertTrue(results.contains("\"type\":\"Parameter\""));
+ assertTrue(results.contains("\"target\":\"Parameter\""));
assertTrue(results.contains("\"result\":\"MISSING\""));
assertFalse(results.contains("\"description\":\"Undefined key: "));
assertFalse(results.contains(" \"result\":\"UNDEFINED\""));
@@ -53,8 +53,8 @@ public class ConfigDocumentationBeanTest {
assertFalse(results.contains("\"name\":\"sun."));
assertFalse(results.contains("\"name\":\"file."));
// test others
- assertTrue(results.contains("\"type\":\"Parameter\""));
- assertTrue(results.contains("\"type\":\"Section\""));
+ assertTrue(results.contains("\"target\":\"Parameter\""));
+ assertTrue(results.contains("\"target\":\"Section\""));
assertTrue(results.contains("\"result\":\"MISSING\""));
assertTrue(results.contains("\"description\":\"Undefined key: "));
assertTrue(results.contains(" \"result\":\"UNDEFINED\""));
@@ -65,7 +65,7 @@ public class ConfigDocumentationBeanTest {
String results = mbean.getConfigurationModel();
assertNotNull(results);
assertFalse(results.trim().isEmpty());
- assertTrue(results.contains("\"type\":\"Parameter\""));
+ assertTrue(results.contains("\"target\":\"Parameter\""));
assertTrue(results.contains("\"name\":\"MyNumber\""));
assertTrue(results.contains("\"name\":\"a.b.c\""));
assertTrue(results.contains("\"required\":true"));
@@ -76,8 +76,8 @@ public class ConfigDocumentationBeanTest {
String results = mbean.getConfigurationModel(ModelTarget.Parameter);
assertNotNull(results);
assertFalse(results.trim().isEmpty());
- assertTrue(results.contains("\"type\":\"Parameter\""));
- assertFalse(results.contains("\"type\":\"Section\""));
+ assertTrue(results.contains("\"target\":\"Parameter\""));
+ assertFalse(results.contains("\"target\":\"Section\""));
assertTrue(results.contains("\"required\":true"));
}
@@ -86,8 +86,8 @@ public class ConfigDocumentationBeanTest {
String results = mbean.findConfigurationModels("a");
assertNotNull(results);
assertFalse(results.trim().isEmpty());
- assertFalse(results.contains("\"type\":\"Parameter\""));
- assertTrue(results.contains("\"type\":\"Section\""));
+ assertFalse(results.contains("\"target\":\"Parameter\""));
+ assertTrue(results.contains("\"target\":\"Section\""));
}
@Test
@@ -95,8 +95,8 @@ public class ConfigDocumentationBeanTest {
String results = mbean.findValidationModels("a", ModelTarget.Section);
assertNotNull(results);
assertFalse(results.trim().isEmpty());
- assertFalse(results.contains("\"type\":\"Parameter\""));
- assertTrue(results.contains("\"type\":\"Section\""));
+ assertFalse(results.contains("\"target\":\"Parameter\""));
+ assertTrue(results.contains("\"target\":\"Section\""));
System.out.println(results);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e022c495/modules/model/src/test/resources/META-INF/configmodel.properties
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/META-INF/configmodel.properties b/modules/model/src/test/resources/META-INF/configmodel.properties
index 4561f3f..a7956dc 100644
--- a/modules/model/src/test/resources/META-INF/configmodel.properties
+++ b/modules/model/src/test/resources/META-INF/configmodel.properties
@@ -22,12 +22,12 @@
####################################################################################
# Metamodel information
-{model}.provider=ConfigModel Extension
+_model.provider=ConfigModel Extension
# reusable parameter definition, referenceable as MyNumber
-{model}.MyNumber.class=Parameter
-{model}.MyNumber.type=Integer
-{model}.MyNumber.description=a (reusable) number type parameter (optional)
+_MyNumber.model.target=Parameter
+_MyNumber.model.type=Integer
+_MyNumber.model.description=a (reusable) number type parameter (optional)
####################################################################################
# Description of Configuration Sections (minimal, can be extended by other modules).
@@ -35,61 +35,61 @@
####################################################################################
# a (section)
-{model}.a.class=Section
-{model}.a.params2.class=Parameter
-{model}.a.params2.type=String
-{model}.a.params2.required=true
-{model}.a.params2.description=a required parameter
+_a.model.target=Section
+_a.params2.model.target=Parameter
+_a.params2.model.type=String
+_a.params2.model.required=true
+_a.params2.model.description=a required parameter
-{model}.a.paramInt.class=Parameter
-{model}.a.paramInt.type=ref:MyNumber
-{model}.a.paramInt.description=an optional parameter (default)
+_a.paramInt.model.target=Parameter
+_a.paramInt.model.type=ref:MyNumber
+_a.paramInt.model.description=an optional parameter (default)
-{model}.a._number.class=Parameter
-{model}.a._number.type=Integer
-{model}.a._number.deprecated=true
-{model}.a._number.mappedTo=a.paramInt
+_a._number.model.target=Parameter
+_a._number.model.type=Integer
+_a._number.model.deprecated=true
+_a._number.model.mappedTo=a.paramInt
# a.b.c (section)
-{model}.a.b.c.class=Section
-{model}.a.b.c.description=Just a test section
+_a.b.c.model.target=Section
+_a.b.c.model.description=Just a test section
# a.b.c.aRequiredSection (section)
-{model}.a.b.c.aRequiredSection.class=Section
-{model}.a.b.c.aRequiredSection.required=true
-{model}.a.b.c.aRequiredSection.description=A section containing required parameters is called a required section.\
+_a.b.c.aRequiredSection.model.target=Section
+_a.b.c.aRequiredSection.model.required=true
+_a.b.c.aRequiredSection.model.description=A section containing required parameters is called a required section.\
Sections can also explicitly be defined to be required, but without\
specifying the paramteres to be contained.,
# a.b.c.aRequiredSection.subsection (section)
-{model}.a.b.c.aRequiredSection.subsection.class=Section
+_a.b.c.aRequiredSection.subsection.model.target=Section
-{model}.a.b.c.aRequiredSection.subsection.param0.class=Parameter
-{model}.a.b.c.aRequiredSection.subsection.param0.type=String
-{model}.a.b.c.aRequiredSection.subsection.param0.description=a minmally documented String parameter
+_a.b.c.aRequiredSection.subsection.param0.model.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.param0.type=String
+_a.b.c.aRequiredSection.subsection.param0.model.description=a minmally documented String parameter
# A minmal String parameter
-{model}.a.b.c.aRequiredSection.subsection.param00.class=Parameter
-{model}.a.b.c.aRequiredSection.subsection.param00.type=String
+_a.b.c.aRequiredSection.subsection.param00.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.param00.model.type=String
# a.b.c.aRequiredSection.subsection (section)
-{model}.a.b.c.aRequiredSection.subsection.param1.class=Parameter
-{model}.a.b.c.aRequiredSection.subsection.param1.type = String
-{model}.a.b.c.aRequiredSection.subsection.param1.required = true
-{model}.a.b.c.aRequiredSection.subsection.intParam.class=Parameter
-{model}.a.b.c.aRequiredSection.subsection.intParam.type = Integer
-{model}.a.b.c.aRequiredSection.subsection.intParam.description=an optional parameter (default)
+_a.b.c.aRequiredSection.subsection.param1.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.param1.model.type = String
+_a.b.c.aRequiredSection.subsection.param1.model.required = true
+_a.b.c.aRequiredSection.subsection.intParam.model.target=Parameter
+_a.b.c.aRequiredSection.subsection.intParam.model.type = Integer
+_a.b.c.aRequiredSection.subsection.intParam.model.description=an optional parameter (default)
# a.b.c.aRequiredSection.nonempty-subsection (section)
-{model}.a.b.c.aRequiredSection.nonempty-subsection.class=Section
-{model}.a.b.c.aRequiredSection.nonempty-subsection.required=true
+_a.b.c.aRequiredSection.nonempty-subsection.model.target=Section
+_a.b.c.aRequiredSection.nonempty-subsection.model.required=true
# a.b.c.aRequiredSection.optional-subsection (section)
-{model}.a.b.c.aRequiredSection.optional-subsection.class=Section
+_a.b.c.aRequiredSection.optional-subsection.model.target=Section
# a.b.c.aValidatedSection (section)
-{model}.a.b.c.aValidatedSection.class=Section
-{model}.a.b.c.aValidatedSection.description=A validated section.
-{model}.a.b.c.aValidatedSection.configModels=org.apache.tamaya.model.TestValidator
+_a.b.c.aValidatedSection.model.target=Section
+_a.b.c.aValidatedSection.model.description=A validated section.
+_a.b.c.aValidatedSection.model.validator=org.apache.tamaya.model.TestValidator
[3/3] incubator-tamaya git commit: Added docs for usage module.
Posted by an...@apache.org.
Added docs for usage module.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/8d29a711
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/8d29a711
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/8d29a711
Branch: refs/heads/master
Commit: 8d29a7116a0cad927ecbc985ba3c24460a1187d4
Parents: c16b0d5
Author: anatole <an...@apache.org>
Authored: Sun May 1 18:03:34 2016 +0200
Committer: anatole <an...@apache.org>
Committed: Sun May 1 21:02:06 2016 +0200
----------------------------------------------------------------------
.../apache/tamaya/model/ConfigModelManager.java | 54 +-----
.../apache/tamaya/model/ConfigUsageStats.java | 128 +++++++++++++
.../java/org/apache/tamaya/model/Usage.java | 76 +++++---
.../model/internal/DefaultConfigUsageStats.java | 176 ++++++++++++++++++
.../model/internal/DefaultUsageTracker.java | 166 -----------------
.../model/internal/UsageTrackerFilter.java | 4 +-
.../tamaya/model/spi/ConfigUsageStatsSpi.java | 98 ++++++++++
.../tamaya/model/spi/UsageTrackerSpi.java | 83 ---------
....apache.tamaya.model.spi.ConfigUsageStatsSpi | 19 ++
.../org.apache.tamaya.model.spi.UsageTrackerSpi | 19 --
.../tamaya/model/ConfigModelProviderTest.java | 67 +++++++
.../tamaya/model/ConfigUsageStatsTest.java | 113 ++++++++++++
.../tamaya/model/TestConfigModelProvider.java | 115 ------------
...org.apache.tamaya.model.spi.ModelProviderSpi | 2 +-
src/site/asciidoc/extensions/mod_model.adoc | 179 ++++++++++++++-----
15 files changed, 793 insertions(+), 506 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
index b066366..8723527 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.model.spi.ConfigDocumentationMBean;
import org.apache.tamaya.model.spi.ModelProviderSpi;
-import org.apache.tamaya.model.spi.UsageTrackerSpi;
import org.apache.tamaya.spi.ServiceContextManager;
import javax.management.InstanceNotFoundException;
@@ -39,10 +38,7 @@ import java.util.logging.Logger;
public final class ConfigModelManager {
/** The logger used. */
- private final static Logger LOG = Logger.getLogger(ConfigModelManager.class.getName());
-
- private static UsageTrackerSpi usageTracker = ServiceContextManager
- .getServiceContext().getService(UsageTrackerSpi.class);
+ private static final Logger LOG = Logger.getLogger(ConfigModelManager.class.getName());
/**
* Singleton constructor.
@@ -51,31 +47,6 @@ public final class ConfigModelManager {
}
/**
- * Enables/disables usage tracking.
- * @param enabled set to true to enable usage tracking.
- */
- public static void enableUsageTracking(boolean enabled){
- Objects.requireNonNull(usageTracker, "No UsageTrackerSpi component available.")
- .enableUsageTracking(enabled);
- }
-
- /**
- * Allows to check if usage tracking is enabled /should be disbled by default).
- * @return true, if usage tracking is enabled.
- */
- public static boolean isUsageTrackingEnabled(){
- return Objects.requireNonNull(usageTracker, "No UsageTrackerSpi component available.")
- .isUsageTrackingEnabled();
- }
-
- /**
- * Access the usage statistics for the recorded uses of configuration.
- */
- public static String getUsageInfo(){
- return Objects.requireNonNull(usageTracker, "No UsageTrackerSpi component available.").getUsageInfo();
- }
-
- /**
* Access the usage statistics for the recorded uses of configuration.
*/
public static String getConfigInfoText(){
@@ -230,14 +201,6 @@ public final class ConfigModelManager {
return result;
}
- /**
- * Get the list of package, which are not evaluated for tracking configuration access and usage statistics.
- * @return the set of ignored package names.
- */
- public static Set<String> getIgnoredPackages(){
- return usageTracker.getIgnoredPackages();
- }
-
private static java.util.Set<java.lang.String> extractTransitiveAreas(Set<String> keys) {
Set<String> transitiveClosure = new HashSet<>();
for(String key:keys){
@@ -286,19 +249,4 @@ public final class ConfigModelManager {
}
}
- /**
- * Get the recorded usage references of configuration.
- * @return the recorded usge references, never null.
- */
- public static Collection<Usage> getUsages() {
- return Objects.requireNonNull(usageTracker, "No UsageTrackerSpi component available.").getUsages();
- }
-
- /**
- * Clears all collected usage statistics.
- */
- public static void clearUsageStats() {
- Objects.requireNonNull(usageTracker, "No UsageTrackerSpi component available.")
- .clearUsageStats();
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/ConfigUsageStats.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigUsageStats.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigUsageStats.java
new file mode 100644
index 0000000..372150d
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigUsageStats.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.tamaya.model;
+
+import org.apache.tamaya.model.spi.ConfigUsageStatsSpi;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Set;
+import java.util.logging.Logger;
+
+/**
+ * Validator accessor to validate the current configuration.
+ */
+public final class ConfigUsageStats {
+
+ /** The logger used. */
+ private static final Logger LOG = Logger.getLogger(ConfigUsageStats.class.getName());
+ private static final String NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE = "No UsageTrackerSpi component available.";
+
+ /** The loaded usage tracking SPI. */
+ private static ConfigUsageStatsSpi usageTracker = ServiceContextManager
+ .getServiceContext().getService(ConfigUsageStatsSpi.class);
+
+ /**
+ * Singleton constructor.
+ */
+ private ConfigUsageStats() {
+ }
+
+ /**
+ * Returnes a set fo package names tha are to be ignored when collecting usage data.
+ * @return the ignored package names, not null.
+ */
+ public static Set<String> getIgnoredUsagePackages(){
+ return Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE)
+ .getIgnoredPackages();
+ }
+
+ /**
+ * Adds the given packageNames to the list of packages to be ignored when collecting usage data.
+ * @param packageName the package names to be added, not null.
+ */
+ public static void addIgnoredUsagePackages(String... packageName){
+ Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE)
+ .addIgnoredUsagePackages(packageName);
+ }
+
+ /**
+ * Enables/disables usage tracking.
+ * @param enabled set to true to enable usage tracking.
+ */
+ public static void enableUsageTracking(boolean enabled){
+ Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE)
+ .enableUsageTracking(enabled);
+ }
+
+ /**
+ * Access the usage statistics for a given key. If usage stats collection is not
+ * activated (default), this method returns null.
+ * @param key the fully qualified configuration key, not null.
+ * @return the stats collected, or null.
+ */
+ public static Usage getUsage(String key){
+ return Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE)
+ .getUsage(key);
+ }
+
+ /**
+ * Get the recorded usage references of configuration.
+ * @return the recorded usge references, never null.
+ */
+ public static Collection<Usage> getUsages() {
+ return Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE).getUsages();
+ }
+
+ /**
+ * Clears all collected usage statistics.
+ */
+ public static void clearUsageStats() {
+ Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE)
+ .clearUsageStats();
+ }
+
+ /**
+ * Access the usage statistics for accessing {@link org.apache.tamaya.Configuration#getProperties()}.
+ * If usage stats collection is not activated (default), this method returns null.
+ * @return the stats collected, or null.
+ */
+ public static Usage getUsageAllProperties(){
+ return Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE)
+ .getUsageAllProperties();
+ }
+
+ /**
+ * Allows to check if usage tracking is enabled /should be disbled by default).
+ * @return true, if usage tracking is enabled.
+ */
+ public static boolean isUsageTrackingEnabled(){
+ return Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE)
+ .isUsageTrackingEnabled();
+ }
+
+ /**
+ * Access the usage statistics for the recorded uses of configuration.
+ */
+ public static String getUsageInfo(){
+ return Objects.requireNonNull(usageTracker, NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE).getUsageInfo();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/Usage.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/Usage.java b/modules/model/src/main/java/org/apache/tamaya/model/Usage.java
index d5625f3..08358af 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/Usage.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/Usage.java
@@ -35,6 +35,7 @@ import java.util.logging.Logger;
*/
public final class Usage {
private static final Logger LOG = Logger.getLogger(Usage.class.getName());
+ private static final String[] EMPTY_TRACE = new String[0];
/**
* the config section.
*/
@@ -44,6 +45,10 @@ public final class Usage {
* Maps with usage references, key is the fully qualified package name.
*/
private final Map<String,AccessDetail> accessDetails = new ConcurrentHashMap<>();
+ /**
+ * The maximal length of the stacktrace stored.
+ */
+ private static int maxTrace = 10;
/**
* Creates a usage metric container for a given key.
@@ -54,6 +59,23 @@ public final class Usage {
}
/**
+ * Get the maximal length of the stack traces recorded, default is 10.
+ * @return the maximal length of the stack traces recorded
+ */
+ public static int getMaxTraceLength(){
+ return Usage.maxTrace;
+ }
+
+ /**
+ * Sets the maximal length of the stacktraces stored when tracking configuration
+ * usage. Setting it to a negative value, disabled stacktrace logging.
+ * @param maxTrace the maximal recorded stack length.
+ */
+ public static void setMaxTraceLength(int maxTrace){
+ Usage.maxTrace =maxTrace;
+ }
+
+ /**
* Get the configModel section.
*
* @return the section, never null.
@@ -144,7 +166,7 @@ public final class Usage {
* @param value the value returned, not null.
*/
public void trackUsage(String value){
- trackUsage(value, 10);
+ trackUsage(value, maxTrace);
}
/**
@@ -154,31 +176,37 @@ public final class Usage {
* @param maxTraceLength the maximal length of the stored stacktrace.
*/
public void trackUsage(String value, int maxTraceLength){
-
- Exception e = new Exception();
- List<String> trace = new ArrayList<>();
String accessPoint = null;
- stack:for(StackTraceElement ste:e.getStackTrace()){
- for(String ignored: ConfigModelManager.getIgnoredPackages()) {
- if (ste.getClassName().startsWith(ignored)) {
- continue stack;
+ if(maxTraceLength>0) {
+ Exception e = new Exception();
+ List<String> trace = new ArrayList<>();
+ stack:
+ for (StackTraceElement ste : e.getStackTrace()) {
+ for (String ignored : ConfigUsageStats.getIgnoredUsagePackages()) {
+ if (ste.getClassName().startsWith(ignored)) {
+ continue stack;
+ }
+ }
+ String ref = ste.getClassName() + '#' + ste.getMethodName() + "(line:" + ste.getLineNumber() + ')';
+ trace.add(ref);
+ if (accessPoint == null) {
+ accessPoint = ref;
+ }
+ if (trace.size() >= maxTraceLength) {
+ break;
}
}
- String ref = ste.getClassName() + '#' + ste.getMethodName() + "(line:" + ste.getLineNumber() + ')';
- trace.add(ref);
if (accessPoint == null) {
- accessPoint = ref;
- }
- if(trace.size()>=maxTraceLength){
- break;
+ // all ignored, take first one, with different package
+ accessPoint = "<unknown/filtered/internal>";
}
+ AccessDetail details = getAccessDetails(accessPoint, trace.toArray(new String[trace.size()]));
+ details.trackAccess(value);
+ }else{
+ accessPoint = "<disabled>";
+ AccessDetail details = getAccessDetails(accessPoint, EMPTY_TRACE);
+ details.trackAccess(value);
}
- if (accessPoint == null) {
- // all ignored, take first one, with different package
- accessPoint = "<unknown/filtered/internal>";
- }
- AccessDetail details = getAccessDetails(accessPoint, trace.toArray(new String[trace.size()]));
- details.trackAccess(value);
}
private AccessDetail getAccessDetails(String accessPoint, String[] trace) {
@@ -250,10 +278,10 @@ public final class Usage {
}
public Map<Long, String> getTrackedValues(){
- if(trackedValues==null){
- return Collections.emptyMap();
- }else{
- synchronized (this) {
+ synchronized (this) {
+ if (trackedValues == null) {
+ return Collections.emptyMap();
+ } else {
return new HashMap<>(trackedValues);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultConfigUsageStats.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultConfigUsageStats.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultConfigUsageStats.java
new file mode 100644
index 0000000..3ba1d4c
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultConfigUsageStats.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.tamaya.model.internal;
+
+import org.apache.tamaya.model.Usage;
+import org.apache.tamaya.model.spi.ConfigUsageStatsSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by atsticks on 29.04.16.
+ */
+public class DefaultConfigUsageStats implements ConfigUsageStatsSpi {
+
+ private Set<String> ignoredPackages = new HashSet<>();
+
+ private Map<String, Usage> usages = new ConcurrentHashMap<>();
+
+ /** By default usage tracking is not enabled. */
+ private boolean usageTrackingEnabled = initEnabled();
+
+ /**
+ * Method that checks the 'tamaya.usage-report' system property for
+ * enabling tamaya usage reporting initially.
+ * @return
+ */
+ private boolean initEnabled() {
+ String val = System.getProperty("tamaya.usage-report");
+ if(Boolean.parseBoolean(val)){
+ return true;
+ }
+ return false;
+ }
+
+ public DefaultConfigUsageStats(){
+ ignoredPackages.add("com.intellij");
+ ignoredPackages.add("java");
+ ignoredPackages.add("org.junit");
+ ignoredPackages.add("junit");
+ ignoredPackages.add("javax");
+ ignoredPackages.add("sun");
+ ignoredPackages.add("oracle");
+ ignoredPackages.add("com.sun");
+ ignoredPackages.add("com.oracle");
+ ignoredPackages.add("org.apache.tamaya");
+ }
+
+ @Override
+ public void enableUsageTracking(boolean enabled){
+ this.usageTrackingEnabled = enabled;
+ }
+
+ @Override
+ public boolean isUsageTrackingEnabled(){
+ return usageTrackingEnabled;
+ }
+
+ @Override
+ public Set<String> getIgnoredPackages() {
+ return Collections.unmodifiableSet(ignoredPackages);
+ }
+
+ @Override
+ public void addIgnoredUsagePackages(String... packageName) {
+
+ }
+
+ @Override
+ public Usage getUsage(String key) {
+ return this.usages.get(key);
+ }
+
+ @Override
+ public Usage getUsageAllProperties() {
+ return this.usages.get("<<all>>");
+ }
+
+ /**
+ * Get the recorded usage references of configuration.
+ * @return the recorded usge references, never null.
+ */
+ @Override
+ public Collection<Usage> getUsages() {
+ return usages.values();
+ }
+
+ @Override
+ public void trackAllPropertiesAccess(){
+ trackSingleKeyAccess("<<all>>", "<not stored>");
+ }
+
+ @Override
+ public void trackSingleKeyAccess(String key, String value){
+ // Ignore meta-entries
+ if(!isUsageTrackingEnabled() || key.startsWith("_")){
+ return;
+ }
+ Usage usage = this.usages.get(key);
+ if(usage==null){
+ usage = new Usage(key);
+ this.usages.put(key, usage);
+ }
+ usage.trackUsage(value);
+ }
+
+
+ /**
+ * Access the usage statistics for the recorded uses of configuration.
+ */
+ @Override
+ public String getUsageInfo(){
+ StringBuilder b = new StringBuilder();
+ b.append("Apache Tamaya Configuration Usage Metrics\n");
+ b.append("=========================================\n");
+ b.append("DATE: " + new Date()).append("\n\n");
+ List<Usage> usages = new ArrayList<>(getUsages());
+ Collections.sort(usages, new Comparator<Usage>() {
+ @Override
+ public int compare(Usage k1, Usage k2) {
+ return k2.getUsageCount() - k1.getUsageCount();
+ }
+ });
+ for(Usage usage:usages){
+ String usageCount = String.valueOf(usage.getUsageCount());
+ b.append(usageCount);
+ b.append(" ".substring(0, 7-usageCount.length()));
+ b.append(usage.getKey()).append(":\n");
+ for(Usage.AccessDetail details: usage.getAccessDetails()) {
+ String accessCount = String.valueOf(details.getAccessCount());
+ b.append(" - ").append(accessCount);
+ b.append(" ".substring(0, 6-usageCount.length()));
+ b.append(details.getAccessPoint());
+ int endIndex = 50-details.getAccessPoint().length();
+ if(endIndex<0){
+ endIndex = 0;
+ }
+ b.append(" ".substring(0, endIndex));
+ b.append(",");b.append(" first=").append(new Date(details.getFirstAccessTS()))
+ .append(",");b.append(" last=").append(new Date(details.getLastAccessTS()))
+ .append('\n');
+ }
+ }
+ return b.toString();
+ }
+
+ @Override
+ public void clearUsageStats() {
+ this.usages.clear();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
deleted file mode 100644
index 9a502a4..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.tamaya.model.internal;
-
-import org.apache.tamaya.model.Usage;
-import org.apache.tamaya.model.spi.UsageTrackerSpi;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Created by atsticks on 29.04.16.
- */
-public class DefaultUsageTracker implements UsageTrackerSpi{
-
- private Set<String> ignoredPackages = new HashSet<>();
-
- private Map<String, Usage> usages = new ConcurrentHashMap<>();
-
- /** By default usage tracking is not enabled. */
- private boolean usageTrackingEnabled = initEnabled();
-
- /**
- * Method that checks the 'tamaya.usage-report' system property for
- * enabling tamaya usage reporting initially.
- * @return
- */
- private boolean initEnabled() {
- String val = System.getProperty("tamaya.usage-report");
- if(Boolean.parseBoolean(val)){
- return true;
- }
- return false;
- }
-
- public DefaultUsageTracker(){
- ignoredPackages.add("com.intellij");
- ignoredPackages.add("java");
- ignoredPackages.add("org.junit");
- ignoredPackages.add("junit");
- ignoredPackages.add("javax");
- ignoredPackages.add("sun");
- ignoredPackages.add("oracle");
- ignoredPackages.add("com.sun");
- ignoredPackages.add("com.oracle");
- ignoredPackages.add("org.apache.tamaya");
- }
-
- @Override
- public void enableUsageTracking(boolean enabled){
- this.usageTrackingEnabled = enabled;
- }
-
- @Override
- public boolean isUsageTrackingEnabled(){
- return usageTrackingEnabled;
- }
-
- @Override
- public Set<String> getIgnoredPackages() {
- return Collections.unmodifiableSet(ignoredPackages);
- }
-
- /**
- * Get the recorded usage references of configuration.
- * @return the recorded usge references, never null.
- */
- @Override
- public Collection<Usage> getUsages() {
- return usages.values();
- }
-
- @Override
- public void trackConfigurationAccess(){
- trackSingleKeyAccess("[[Configuration]]", "<not stored>");
- }
-
- @Override
- public void trackAllPropertiesAccess(){
- trackSingleKeyAccess("<<all>>", "<not stored>");
- }
-
- @Override
- public void trackSingleKeyAccess(String key, String value){
- // Ignore meta-entries
- if(!isUsageTrackingEnabled() || key.startsWith("_")){
- return;
- }
- Usage usage = this.usages.get(key);
- if(usage==null){
- usage = new Usage(key);
- this.usages.put(key, usage);
- }
- usage.trackUsage(value);
- }
-
-
- /**
- * Access the usage statistics for the recorded uses of configuration.
- */
- @Override
- public String getUsageInfo(){
- StringBuilder b = new StringBuilder();
- b.append("Apache Tamaya Configuration Usage Metrics\n");
- b.append("=========================================\n");
- b.append("DATE: " + new Date()).append("\n\n");
- List<Usage> usages = new ArrayList<>(getUsages());
- Collections.sort(usages, new Comparator<Usage>() {
- @Override
- public int compare(Usage k1, Usage k2) {
- return k2.getUsageCount() - k1.getUsageCount();
- }
- });
- for(Usage usage:usages){
- String usageCount = String.valueOf(usage.getUsageCount());
- b.append(usageCount);
- b.append(" ".substring(0, 7-usageCount.length()));
- b.append(usage.getKey()).append(":\n");
- for(Usage.AccessDetail details: usage.getAccessDetails()) {
- String accessCount = String.valueOf(details.getAccessCount());
- b.append(" - ").append(accessCount);
- b.append(" ".substring(0, 6-usageCount.length()));
- b.append(details.getAccessPoint());
- int endIndex = 50-details.getAccessPoint().length();
- if(endIndex<0){
- endIndex = 0;
- }
- b.append(" ".substring(0, endIndex));
- b.append(",");b.append(" first=").append(new Date(details.getFirstAccessTS()))
- .append(",");b.append(" last=").append(new Date(details.getLastAccessTS()))
- .append('\n');
- }
- }
- return b.toString();
- }
-
- @Override
- public void clearUsageStats() {
- this.usages.clear();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/internal/UsageTrackerFilter.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/UsageTrackerFilter.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/UsageTrackerFilter.java
index 6dac53f..d27491e 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/UsageTrackerFilter.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/UsageTrackerFilter.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.model.internal;
-import org.apache.tamaya.model.spi.UsageTrackerSpi;
+import org.apache.tamaya.model.spi.ConfigUsageStatsSpi;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.ServiceContextManager;
@@ -35,7 +35,7 @@ public class UsageTrackerFilter implements PropertyFilter{
@Override
public String filterProperty(String value, FilterContext context) {
- UsageTrackerSpi tracker = ServiceContextManager.getServiceContext().getService(UsageTrackerSpi.class);
+ ConfigUsageStatsSpi tracker = ServiceContextManager.getServiceContext().getService(ConfigUsageStatsSpi.class);
if (context.isSinglePropertyScoped()) {
tracker.trackSingleKeyAccess(context.getKey(), value);
} else {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigUsageStatsSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigUsageStatsSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigUsageStatsSpi.java
new file mode 100644
index 0000000..90753d2
--- /dev/null
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigUsageStatsSpi.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.tamaya.model.spi;
+
+import org.apache.tamaya.model.Usage;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * SPI to implemented by the component responsible for usage tracking of
+ * configuration.
+ */
+public interface ConfigUsageStatsSpi {
+
+ /**
+ * Enables/disables usage tracking.
+ * @param enable set to true to enable usage tracking.
+ */
+ void enableUsageTracking(boolean enable);
+
+ /**
+ * Allows to check if usage tracking is enabled /should be disbled by default).
+ * @return true, if usage tracking is enabled.
+ */
+ boolean isUsageTrackingEnabled();
+
+ /**
+ * Get the list of package, which are not evaluated for tracking configuration access and usage statistics.
+ * @return the set of ignored package names.
+ */
+ Set<String> getIgnoredPackages();
+
+ /**
+ * Adds the given packageNames to the list of packages to be ignored when collecting usage data.
+ * @param packageName the package names to be added, not null.
+ */
+ void addIgnoredUsagePackages(String... packageName);
+
+ /**
+ * Access the usage statistics for a given key. If usage stats collection is not
+ * activated (default), this method returns null.
+ * @param key the fully qualified configuration key, not null.
+ * @return the stats collected, or null.
+ */
+ Usage getUsage(String key);
+
+ /**
+ * Access the usage statistics for accessing {@link org.apache.tamaya.Configuration#getProperties()}.
+ * If usage stats collection is not activated (default), this method returns null.
+ * @return the stats collected, or null.
+ */
+ Usage getUsageAllProperties();
+
+ /**
+ * Get the recorded usage references of configuration.
+ * @return the recorded usge references, never null.
+ */
+ Collection<Usage> getUsages();
+
+ /**
+ * Track the access of {@code Configuration#getProperties()} for
+ * usage statistics.
+ */
+ void trackAllPropertiesAccess();
+
+ /**
+ * Track the access of {@code Configuration#get(String)} for
+ * usage statistics.
+ */
+ void trackSingleKeyAccess(String key, String value);
+
+ /**
+ * Access the usage statistics for the recorded uses of configuration.
+ */
+ String getUsageInfo();
+
+ /**
+ * Clears all collected usage statistics.
+ */
+ void clearUsageStats();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java
deleted file mode 100644
index d84b636..0000000
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.tamaya.model.spi;
-
-import org.apache.tamaya.model.Usage;
-
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * SPI to implemented by the component responsible for usage tracking of
- * configuration.
- */
-public interface UsageTrackerSpi {
-
- /**
- * Enables/disables usage tracking.
- * @param enable set to true to enable usage tracking.
- */
- void enableUsageTracking(boolean enable);
-
- /**
- * Allows to check if usage tracking is enabled /should be disbled by default).
- * @return true, if usage tracking is enabled.
- */
- boolean isUsageTrackingEnabled();
-
- /**
- * Get the list of package, which are not evaluated for tracking configuration access and usage statistics.
- * @return the set of ignored package names.
- */
- Set<String> getIgnoredPackages();
-
- /**
- * Get the recorded usage references of configuration.
- * @return the recorded usge references, never null.
- */
- Collection<Usage> getUsages();
-
- /**
- * Track the access of {@code ConfigurationProvider#getConfiguration()} for
- * usage statistics.
- */
- void trackConfigurationAccess();
-
- /**
- * Track the access of {@code Configuration#getProperties()} for
- * usage statistics.
- */
- void trackAllPropertiesAccess();
-
- /**
- * Track the access of {@code Configuration#get(String)} for
- * usage statistics.
- */
- void trackSingleKeyAccess(String key, String value);
-
- /**
- * Access the usage statistics for the recorded uses of configuration.
- */
- String getUsageInfo();
-
- /**
- * Clears all collected usage statistics.
- */
- void clearUsageStats();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ConfigUsageStatsSpi
----------------------------------------------------------------------
diff --git a/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ConfigUsageStatsSpi b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ConfigUsageStatsSpi
new file mode 100644
index 0000000..92299da
--- /dev/null
+++ b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.ConfigUsageStatsSpi
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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 current 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.
+#
+org.apache.tamaya.model.internal.DefaultConfigUsageStats
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.UsageTrackerSpi
----------------------------------------------------------------------
diff --git a/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.UsageTrackerSpi b/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.UsageTrackerSpi
deleted file mode 100644
index 1a87f60..0000000
--- a/modules/model/src/main/resources/META-INF/services/org.apache.tamaya.model.spi.UsageTrackerSpi
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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 current 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.
-#
-org.apache.tamaya.model.internal.DefaultUsageTracker
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/test/java/org/apache/tamaya/model/ConfigModelProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/ConfigModelProviderTest.java b/modules/model/src/test/java/org/apache/tamaya/model/ConfigModelProviderTest.java
new file mode 100644
index 0000000..32c8774
--- /dev/null
+++ b/modules/model/src/test/java/org/apache/tamaya/model/ConfigModelProviderTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.tamaya.model;
+
+import org.apache.tamaya.model.spi.SectionModel;
+import org.apache.tamaya.model.spi.ParameterModel;
+import org.apache.tamaya.model.spi.GroupModel;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * Created by Anatole on 09.08.2015.
+ */
+public class ConfigModelProviderTest implements ModelProviderSpi {
+
+ private List<ConfigModel> configModels = new ArrayList<>(1);
+
+ public ConfigModelProviderTest(){
+ configModels.add(new TestConfigModel());
+ configModels = Collections.unmodifiableList(configModels);
+ }
+
+ public Collection<ConfigModel> getConfigModels() {
+ return configModels;
+ }
+
+ private static final class TestConfigModel extends GroupModel {
+
+ public TestConfigModel(){
+ super("TestConfig", new SectionModel.Builder("a.test.existing").setRequired(true).build(),
+ ParameterModel.of("a.test.existing.aParam", true),
+ ParameterModel.of("a.test.existing.optionalParam"),
+ ParameterModel.of("a.test.existing.aABCParam", false, "[ABC].*"),
+ new SectionModel.Builder("a.test.notexisting").setRequired(true).build(),
+ ParameterModel.of("a.test.notexisting.aParam", true),
+ ParameterModel.of("a.test.notexisting.optionalParam"),
+ ParameterModel.of("a.test.existing.aABCParam2", false, "[ABC].*"));
+ }
+ @Override
+ public String getName() {
+ return "TestConfigConfigModel";
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java b/modules/model/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java
new file mode 100644
index 0000000..ef56e73
--- /dev/null
+++ b/modules/model/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.tamaya.model;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.model.spi.GroupModel;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
+import org.apache.tamaya.model.spi.ParameterModel;
+import org.apache.tamaya.model.spi.SectionModel;
+import org.junit.Test;
+import test.model.TestConfigAccessor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by Anatole on 09.08.2015.
+ */
+public class ConfigUsageStatsTest implements ModelProviderSpi {
+
+ private List<ConfigModel> configModels = new ArrayList<>(1);
+
+ public ConfigUsageStatsTest(){
+ configModels.add(new TestConfigModel());
+ configModels = Collections.unmodifiableList(configModels);
+ }
+
+ public Collection<ConfigModel> getConfigModels() {
+ return configModels;
+ }
+
+ private static final class TestConfigModel extends GroupModel {
+
+ public TestConfigModel(){
+ super("TestConfig", new SectionModel.Builder("a.test.existing").setRequired(true).build(),
+ ParameterModel.of("a.test.existing.aParam", true),
+ ParameterModel.of("a.test.existing.optionalParam"),
+ ParameterModel.of("a.test.existing.aABCParam", false, "[ABC].*"),
+ new SectionModel.Builder("a.test.notexisting").setRequired(true).build(),
+ ParameterModel.of("a.test.notexisting.aParam", true),
+ ParameterModel.of("a.test.notexisting.optionalParam"),
+ ParameterModel.of("a.test.existing.aABCParam2", false, "[ABC].*"));
+ }
+ @Override
+ public String getName() {
+ return "TestConfigConfigModel";
+ }
+
+ }
+
+ @Test
+ public void testUsageWhenEnabled(){
+ ConfigUsageStats.enableUsageTracking(true);
+ TestConfigAccessor.readConfiguration();
+ Configuration config = ConfigurationProvider.getConfiguration();
+ String info = ConfigUsageStats.getUsageInfo();
+ assertFalse(info.contains("java.version"));
+ assertNotNull(info);
+ config = TestConfigAccessor.readConfiguration();
+ config.getProperties();
+ TestConfigAccessor.readProperty(config, "java.locale");
+ TestConfigAccessor.readProperty(config, "java.version");
+ TestConfigAccessor.readProperty(config, "java.version");
+ config.get("java.version");
+ info = ConfigUsageStats.getUsageInfo();
+ System.out.println(info);
+ assertTrue(info.contains("java.version"));
+ assertNotNull(info);
+ ConfigUsageStats.enableUsageTracking(false);
+ }
+
+ @Test
+ public void testUsageWhenDisabled(){
+ ConfigUsageStats.enableUsageTracking(false);
+ ConfigUsageStats.clearUsageStats();
+ TestConfigAccessor.readConfiguration();
+ Configuration config = ConfigurationProvider.getConfiguration();
+ String info = ConfigUsageStats.getUsageInfo();
+ assertNotNull(info);
+ assertFalse(info.contains("java.version"));
+ config = TestConfigAccessor.readConfiguration();
+ config.getProperties();
+ TestConfigAccessor.readProperty(config, "java.locale");
+ TestConfigAccessor.readProperty(config, "java.version");
+ TestConfigAccessor.readProperty(config, "java.version");
+ config.get("java.version");
+ info = ConfigUsageStats.getUsageInfo();
+ assertFalse(info.contains("java.version"));
+ assertNotNull(info);
+ ConfigUsageStats.enableUsageTracking(false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
----------------------------------------------------------------------
diff --git a/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java b/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
deleted file mode 100644
index 70ca611..0000000
--- a/modules/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.tamaya.model;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.model.spi.SectionModel;
-import org.apache.tamaya.model.spi.ParameterModel;
-import org.apache.tamaya.model.spi.GroupModel;
-import org.apache.tamaya.model.spi.ModelProviderSpi;
-import org.junit.Test;
-import test.model.TestConfigAccessor;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Created by Anatole on 09.08.2015.
- */
-public class TestConfigModelProvider implements ModelProviderSpi {
-
- private List<ConfigModel> configModels = new ArrayList<>(1);
-
- public TestConfigModelProvider(){
- configModels.add(new TestConfigModel());
- configModels = Collections.unmodifiableList(configModels);
- }
-
- public Collection<ConfigModel> getConfigModels() {
- return configModels;
- }
-
- private static final class TestConfigModel extends GroupModel {
-
- public TestConfigModel(){
- super("TestConfig", new SectionModel.Builder("a.test.existing").setRequired(true).build(),
- ParameterModel.of("a.test.existing.aParam", true),
- ParameterModel.of("a.test.existing.optionalParam"),
- ParameterModel.of("a.test.existing.aABCParam", false, "[ABC].*"),
- new SectionModel.Builder("a.test.notexisting").setRequired(true).build(),
- ParameterModel.of("a.test.notexisting.aParam", true),
- ParameterModel.of("a.test.notexisting.optionalParam"),
- ParameterModel.of("a.test.existing.aABCParam2", false, "[ABC].*"));
- }
- @Override
- public String getName() {
- return "TestConfigConfigModel";
- }
-
- }
-
- @Test
- public void testUsageWhenEnabled(){
- ConfigModelManager.enableUsageTracking(true);
- TestConfigAccessor.readConfiguration();
- Configuration config = ConfigurationProvider.getConfiguration();
- String info = ConfigModelManager.getUsageInfo();
- assertFalse(info.contains("java.version"));
- assertNotNull(info);
- config = TestConfigAccessor.readConfiguration();
- config.getProperties();
- TestConfigAccessor.readProperty(config, "java.locale");
- TestConfigAccessor.readProperty(config, "java.version");
- TestConfigAccessor.readProperty(config, "java.version");
- config.get("java.version");
- info = ConfigModelManager.getUsageInfo();
- System.out.println(info);
- assertTrue(info.contains("java.version"));
- assertNotNull(info);
- ConfigModelManager.enableUsageTracking(false);
- }
-
- @Test
- public void testUsageWhenDisabled(){
- ConfigModelManager.enableUsageTracking(false);
- ConfigModelManager.clearUsageStats();
- TestConfigAccessor.readConfiguration();
- Configuration config = ConfigurationProvider.getConfiguration();
- String info = ConfigModelManager.getUsageInfo();
- assertNotNull(info);
- assertFalse(info.contains("java.version"));
- config = TestConfigAccessor.readConfiguration();
- config.getProperties();
- TestConfigAccessor.readProperty(config, "java.locale");
- TestConfigAccessor.readProperty(config, "java.version");
- TestConfigAccessor.readProperty(config, "java.version");
- config.get("java.version");
- info = ConfigModelManager.getUsageInfo();
- assertFalse(info.contains("java.version"));
- assertNotNull(info);
- ConfigModelManager.enableUsageTracking(false);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi b/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
index e2d3350..9b29fda 100644
--- a/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
+++ b/modules/model/src/test/resources/META-INF/services/org.apache.tamaya.model.spi.ModelProviderSpi
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.model.TestConfigModelProvider
\ No newline at end of file
+org.apache.tamaya.model.ConfigModelProviderTest
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8d29a711/src/site/asciidoc/extensions/mod_model.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_model.adoc b/src/site/asciidoc/extensions/mod_model.adoc
index b1cb3af..9e25d0f 100644
--- a/src/site/asciidoc/extensions/mod_model.adoc
+++ b/src/site/asciidoc/extensions/mod_model.adoc
@@ -52,7 +52,7 @@ To benefit from configuration builder support you only must add the correspondin
=== Describing the Configuration Meta-Model
-Basically configuration is modelled using key, valuje-pairs of Strings. Looking at a keys
+Basically configuration is modelled using key, value-pairs. Looking at a keys
+a.b.c.param1+ and +a.b.c.param2+ the following concepts can be used to defined/describe
configuration:
@@ -68,16 +68,13 @@ Now with only these 2 concepts a simple configuration meta-model can be defined
descriptions, e.g. in a management console or generated configuration documentation site.
* a set of sections.
* a set of parameters.
-* Both, sections as well as parameters,
- ** are prefixed with the meta-model selector, by default +{model}.+.
- ** are identified by their _fully qualified names_, where '.' is used as
- a separator character.
+* Both, sections as well as parameter models
+ ** can be modelled by a met-data entry, by default +_{key}.model+.
** may be required, or optional
** may have an optional description
- ** may have additional custom configModels configured.
* Parameters additionally have
** a _type_, described by the fully qualified class name, into which any configured (String) value must be
- convertable into. If no type is configured +java.lang.String+ should be assumed as default.
+ convertable into. If no type is configured +java.lang.String+ is assumed as default.
** an optional regular expression that can be used to validate the +String+ values returned from a
configuration.
@@ -87,7 +84,7 @@ a section), are called _undefined_. Undefined parameters should be grouped with
well as all parent sections, including transitive) of any parametet read, should similarly marked as undefined, if and
only if
-. the section itself is (directly) undefined
+. the section itself is (directly) _undefined_
. the section is not a _super section_ of a defined section.
As en example the section definition of +a.b.c+ also implicitly includes the sections +a.b+ and +a+ to be defined
@@ -109,24 +106,24 @@ variants supported:
[source,listing]
-------------------------------------------------------------------------------
# Metamodel information
-{model}.provider=ConfigModel Extension
+_config-model.provider=ConfigModel Extension
# org.mycompany.root (optional section)
-{model}.org.mycompany.root.class=Section
-{model}.org.mycompany.root.description=Root section defining my company configuration.
+_org.mycompany.root.model-type=Section
+_org.mycompany.root.model-description=Root section defining my company configuration.
# org.mycompany.security (required section)
-{model}.org.mycompany.security.class=Section
-{model}.org.mycompany.security.required=true
-{model}.org.mycompany.security.description=Security related settings.\
+_org.mycompany.security.model-type=Section
+_org.mycompany.security.model-required=true
+_org.mycompany.security.model-description=Security related settings.\
refer for further details to XXX.
# minmal section
-{model}.minimal.class=Section
+_minimal.model-class=Section
# custom validated section
-{model}.validated.class=Section
-{model}.validated.configModels=org.apache.tamaya.model.TestValidator
+_validated.model-type=Section
+_validated.model-validator=org.apache.tamaya.model.TestValidator
-------------------------------------------------------------------------------
Above +org.mycompany.root+ transitively defines 3 sections:
@@ -154,20 +151,20 @@ Similarly parameters also can be defined:
[source,listing]
-------------------------------------------------------------------------------
# org.mycompany.root.name (required parameter)
-{model}.org.mycompany.root.name.class=Parameter
-{model}.org.mycompany.root.name.required=true
-{model}.org.mycompany.root.name.description=The company's name, also used in the application's main header.
+_org.mycompany.root.name.model-type=Parameter
+_org.mycompany.root.name.model-required=true
+_org.mycompany.root.name.model-description=The company's name, also used in the application's main header.
# org.mycompany.security (required parameters)
-{model}.org.mycompany.security.uid.required=true
-{model}.org.mycompany.security.uid.description=The user id.
-{model}.org.mycompany.security.realm.required=true
-{model}.org.mycompany.security.realm.configModels=org.apache.tamaya.model.RealmValidator
-{model}.org.mycompany.security.real.description=The security realm required.
-{model}.org.mycompany.security.tokenid.description=The token id, if the token service is used (optional).
+_org.mycompany.security.uid.model-required=true
+_org.mycompany.security.uid.model-description=The user id.
+_org.mycompany.security.realm.model-required=true
+_org.mycompany.security.realm.model-validator=org.apache.tamaya.model.RealmValidator
+_org.mycompany.security.realm.model-description=The security realm required.
+_org.mycompany.security.tokenid.model-description=The token id, if the token service is used (optional).
# A minmal parameter
-{model}.minimalClass.class.type=Class
+_minimalClass.model-type=Class
-------------------------------------------------------------------------------
Similarly as when defining section also parameter entries define transitively its containing sections. E.g.
@@ -202,6 +199,107 @@ By default the configuration model can be defined at the following locations:
data. This extension also allows you to use alternate representation formats such as +ini, xml, yml, json+.
+=== Tracking Configuration Access
+
+The model module also allows tracking which code accesses configuration properties or configuration parameters.
+It checks the stacktrace to evaluate the calling code location, hereby any unwanted packages can be implicitly
+ommitted from the stacktrace. Also the maximal length of the stacktrace retained can be constraint in length.
+The usages are recorded as +Usage+ instances. Hereby for each parameter accessed a corresponding +Usage+
+instance is created. It can be accessed by calling +Usage ConfigUsageStats.getUsage(String key)+. Usage
+statistics for calling +Configuration.getProperties()+ can be obtained calling +Usage getUsageAllProps();+.
+
+Usage tracking is disabled by default. It can be enabled by calling +ConfigUsageStats.enableUsageTracking(true);+.
++ConfigUsageStats.isUsageTrackingEnabled()+ returns the current tracking status.
+
+The +Usage+ class itself provides access to further fainer grained usage data (+AccessDetail+) cotaining:
+
+* the access point (+fqn.ClassName#method(line: xxx)+).
+* the number of accesses
+* the first an last access
+* the values read
+* the access stacktrace (filtered by ignored packages).
+
+[source,java]
+-----------------------------------------------------------
+public final class Usage {
+ [...]
+ public String getKey();
+ public void clearMetrics();
+ public int getReferenceCount();
+ public int getUsageCount();
+ public Collection<AccessDetail> getAccessDetails(Class type);
+ public Collection<AccessDetail> getAccessDetails(Package pack);
+ public Collection<AccessDetail> getAccessDetails(String lookupExpression);
+ public Collection<AccessDetail> getAccessDetails();
+ public void trackUsage(String value);
+ public void trackUsage(String value, int maxTraceLength);
+
+
+ public static final class AccessDetail {
+ [...]
+ public void clearStats();
+ public long trackAccess(String value);
+ public long getAccessCount();
+ public String getAccessPoint();
+ public long getFirstAccessTS();
+ public long getLastAccessTS();
+ public String[] getStackTrace();
+ public Map<Long, String> getTrackedValues();
+ }
+
+}
+-----------------------------------------------------------
+
+With +ConfigUsageStats.clearUsageStats()+ the collected statistics can be reset at any time. Summarizing the main
+singleton for configuration statistics is defined as follows:
+
+[source,java]
+-----------------------------------------------------------
+public final class ConfigUsageStats{
+ public static Set<String> getIgnoredUsagePackages();
+ public static void addIgnoredUsagePackages(String... packageName);
+ public static void enableUsageTracking(boolean enabled);
+ public static Usage getUsage(String key);
+ public static Collection<Usage> getUsages();
+ public static void clearUsageStats();
+ public static Usage getUsageAllProperties();
+ public static boolean isUsageTrackingEnabled();
+ public static String getUsageInfo();
+}
+-----------------------------------------------------------
+
+==== Customizing the Stacktrage for Usage Reporting
+
+The stacktrace tracked by the system can be customized in several ways:
+
+* +ConfigUsageStats.addIgnoredPackageNames(String...)+ allows to add additional ignored package names.
+* With +Usage.setMaxTraceLength(int)+ the maximal size of the stacktraces logged can be set. Setting a
+ negative value will disable stacktrace logging completelely.
+
+
+=== Accessing Usage Statistics
+
+Bascially usage statistics are available in two forms:
+
+* The +Usage/AccessDetail+ object tree can be accessed programmatically from the +ConfigUsageStats+
+ singleton.
+* With +ConfigUsageStats.getUsageInfo()+ also a textual representation of the usage statistics
+ can be obtained, as illustrated below (a snipped from the current test output):
+
+[source,listing]
+-----------------------------------------------------------
+Apache Tamaya Configuration Usage Metrics
+=========================================
+DATE: Sat Apr 30 21:51:09 CEST 2016
+
+220 <<all>>:
+ - 220 <unknown/filtered/internal> , first=Sat Apr 30 21:51:09 CEST 2016, last=Sat Apr 30 21:51:09 CEST 2016
+3 java.version:
+ - 2 test.model.TestConfigAccessor#readProperty(line:43), first=Sat Apr 30 21:51:09 CEST 2016, last=Sat Apr 30 21:51:09 CEST 2016
+ - 1 <unknown/filtered/internal> , first=Sat Apr 30 21:51:09 CEST 2016, last=Sat Apr 30 21:51:09 CEST 2016
+
+-----------------------------------------------------------
+
==== Programmatic API
@@ -243,7 +341,7 @@ single configuration source (e.g. for configuring the machine's IP address and s
-----------------------------------------------------------
public interface ConfigModel {
- ModelType getType();
+ ModelTarget getType();
String getName();
String getProvider();
boolean isRequired();
@@ -253,11 +351,11 @@ public interface ConfigModel {
-----------------------------------------------------------
-Hereby +ModelType+ defines more details on the kind of model:
+Hereby +ModelTarget+ defines more details on the kind of model:
[source,java]
-----------------------------------------------------------
-public enum ModelType {
+public enum ModelTarget {
/**
* A configuration section.
*/
@@ -267,21 +365,9 @@ public enum ModelType {
*/
Parameter,
/**
- * ConfigModel to ensure a certain configuration filter is installed.
- */
- Filter,
- /**
- * ConfigModel to ensure a certain combination policy is active.
- */
- CombinationPolicy,
- /**
* ConfigModel that is a container of other validations.
*/
- Group,
- /**
- * ConfigModel to simply check availability for a class on the current classpath.
- */
- LoadableClass
+ Group
}
-----------------------------------------------------------
@@ -341,6 +427,13 @@ New instances implementing this interface must be registered into the current +S
+ServiceLoader+ is used.
+=== The ConfigUsageStatsSpi
+
+The methods for managing and tracking of configuration changes are delegated to the current
+most sinificant implementation of the +org.apache.tamaya.model.spi.ConfigUsageStatsSpi+ SPI.
+By implementing this SPI and registerting it with the +ServiceContext+ the usage tracking
+logic can be adapted or replaced.
+
=== Other Utility Classes
The module also provides further utility classes that may be useful for implementing models or testing: