Repository: incubator-tamaya-sandbox Updated Branches: refs/heads/configjsr f206ce19c -> 35cc751f2
Adapted to comply with JSR API. Signed-off-by: Anatole Tresch <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/35cc751f Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/35cc751f Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/35cc751f Branch: refs/heads/configjsr Commit: 35cc751f27e84177100292d20d9dd9351b63e6e8 Parents: f206ce1 Author: Anatole Tresch <[email protected]> Authored: Wed Jan 10 01:13:01 2018 +0100 Committer: Anatole Tresch <[email protected]> Committed: Wed Jan 10 01:13:01 2018 +0100 ---------------------------------------------------------------------- .../apache/tamaya/usagetracker/ConfigUsage.java | 9 ++++---- .../apache/tamaya/usagetracker/UsageStat.java | 21 ++++++++++--------- .../internal/DefaultConfigUsage.java | 19 ++++++++--------- .../internal/UsageTrackerFilter.java | 18 +++++++--------- .../tamaya/usagetracker/spi/ConfigUsageSpi.java | 18 ++++++++-------- .../services/org.apache.tamaya.spi.Filter | 19 +++++++++++++++++ .../org.apache.tamaya.spi.PropertyFilter | 19 ----------------- .../tamaya/model/ConfigUsageStatsTest.java | 17 ++++++++------- .../java/test/model/TestConfigAccessor.java | 19 ++++++++--------- .../resources/META-INF/javaconfig.properties | 22 ++++++++++++++++++++ .../META-INF/javaconfiguration.properties | 22 -------------------- 11 files changed, 99 insertions(+), 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java index 5cae8d2..1a70a88 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/ConfigUsage.java @@ -18,7 +18,6 @@ */ package org.apache.tamaya.usagetracker; -import org.apache.tamaya.ConfigException; import org.apache.tamaya.spi.ServiceContextManager; import org.apache.tamaya.usagetracker.spi.ConfigUsageSpi; @@ -41,7 +40,7 @@ public final class ConfigUsage { ConfigUsageSpi spi = ServiceContextManager .getServiceContext().getService(ConfigUsageSpi.class); if(spi==null){ - throw new ConfigException(NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE); + throw new IllegalStateException(NO_USAGE_TRACKER_SPI_COMPONENT_MESSAGE); } return spi; } @@ -102,12 +101,12 @@ public final class ConfigUsage { } /** - * Access the usage statistics for accessing {@link org.apache.tamaya.Configuration#getProperties()}. + * Access the usage statistics for accessing {@link javax.config.Config#getPropertyNames()}. * If usage stats collection is not activated (default), this method returns null. * @return the stats collected, or null. */ - public static UsageStat getAllPropertiesStats(){ - return spi().getAllPropertiesStats(); + public static UsageStat getPropertyNamesStats(){ + return spi().getPropertyNamesStats(); } /** http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java index 8cd0236..e3f847a 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/UsageStat.java @@ -18,7 +18,7 @@ */ package org.apache.tamaya.usagetracker; -import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.spi.ConfigValue; import java.util.ArrayList; import java.util.Arrays; @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Logger; /** * Metrics container containing access statistics for a given configuration key. @@ -169,19 +168,21 @@ public final class UsageStat { * Evaluates the current access point from the current stacktrace and adds an according * usage reference object (or updates any existing one) for the given key. The * stacktrace is shortened to a maximal size of 20 items. + * @param key the key accessed, not null. * @param value the value returned, not null. */ - public void trackUsage(PropertyValue value){ - trackUsage(value, maxTrace); + public void trackUsage(String key, String value){ + trackUsage(key, value, maxTrace); } /** * Evaluates the current access point from the current stacktrace and adds an according * usage reference object (or updates any existing one) for the given key. + * @param key the key accessed, not null. * @param value the value returned, not null. * @param maxTraceLength the maximal length of the stored stacktrace. */ - public void trackUsage(PropertyValue value, int maxTraceLength){ + public void trackUsage(String key, String value, int maxTraceLength){ String accessPoint = null; if(maxTraceLength>0) { Exception e = new Exception(); @@ -207,11 +208,11 @@ public final class UsageStat { accessPoint = "<unknown/filtered/internal>"; } AccessStats details = getAccessDetails(accessPoint, trace.toArray(new String[trace.size()])); - details.trackAccess(value); + details.trackAccess(ConfigValue.of(key, value, null)); }else{ accessPoint = "<disabled>"; AccessStats details = getAccessDetails(accessPoint, EMPTY_TRACE); - details.trackAccess(value); + details.trackAccess(ConfigValue.of(key, value, null)); } } @@ -234,7 +235,7 @@ public final class UsageStat { private long firstAccessTS; private String[] stackTrace; private String accessPoint; - private Map<Long, PropertyValue> trackedValues; + private Map<Long, ConfigValue> trackedValues; public AccessStats(String key, String accessPoint, String[] stackTrace){ this.key = Objects.requireNonNull(key); @@ -248,7 +249,7 @@ public final class UsageStat { accessCount.set(0); } - public long trackAccess(PropertyValue value){ + public long trackAccess(ConfigValue value){ long count = accessCount.incrementAndGet(); lastAccessTS = System.currentTimeMillis(); if(firstAccessTS==0){ @@ -289,7 +290,7 @@ public final class UsageStat { return stackTrace.clone(); } - public Map<Long, PropertyValue> getTrackedValues(){ + public Map<Long, ConfigValue> getTrackedValues(){ synchronized (this) { if (trackedValues == null) { return Collections.emptyMap(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java index 34e1fa4..caaa0ec 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/DefaultConfigUsage.java @@ -18,11 +18,10 @@ */ package org.apache.tamaya.usagetracker.internal; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.usagetracker.UsageStat; import org.apache.tamaya.usagetracker.spi.ConfigUsageSpi; +import javax.config.Config; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -98,7 +97,7 @@ public class DefaultConfigUsage implements ConfigUsageSpi { } @Override - public UsageStat getAllPropertiesStats() { + public UsageStat getPropertyNamesStats() { return this.stats.get("<<all>>"); } @@ -112,22 +111,22 @@ public class DefaultConfigUsage implements ConfigUsageSpi { } @Override - public void recordAllPropertiesAccess(ConfigurationContext context){ - recordSingleKeyAccess(PropertyValue.of("<<all>>","<not stored>","-"), context); + public void recordAllPropertiesAccess(Config config){ + recordSingleKeyAccess("Config.getPropertyNames()",config.getPropertyNames().toString(),config); } @Override - public void recordSingleKeyAccess(PropertyValue value, ConfigurationContext context){ + public void recordSingleKeyAccess(String key, String value, Config config){ // Ignore meta-entries if(!isTrackingEnabled()){ return; } - UsageStat usage = this.stats.get(value.getKey()); + UsageStat usage = this.stats.get(key); if(usage==null){ - usage = new UsageStat(value.getKey()); - this.stats.put(value.getKey(), usage); + usage = new UsageStat(key); + this.stats.put(key, usage); } - usage.trackUsage(value); + usage.trackUsage(key, value); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java index c9839ac..cfb7a1d 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/internal/UsageTrackerFilter.java @@ -18,9 +18,8 @@ */ package org.apache.tamaya.usagetracker.internal; -import org.apache.tamaya.spi.FilterContext; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.base.filter.FilterContext; +import org.apache.tamaya.spi.Filter; import org.apache.tamaya.spi.ServiceContextManager; import org.apache.tamaya.usagetracker.spi.ConfigUsageSpi; @@ -32,16 +31,13 @@ import javax.annotation.Priority; * to track configuration usage. */ @Priority(Integer.MAX_VALUE) -public class UsageTrackerFilter implements PropertyFilter{ +public class UsageTrackerFilter implements Filter{ @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - ConfigUsageSpi tracker = ServiceContextManager.getServiceContext().getService(ConfigUsageSpi.class); - if (context.isSinglePropertyScoped()) { - tracker.recordSingleKeyAccess(value, context.getContext()); - } else { - tracker.recordAllPropertiesAccess(context.getContext()); - } + public String filterProperty(String key, String value) { + ConfigUsageSpi tracker = ServiceContextManager.getServiceContext().getService(ConfigUsageSpi.class); + FilterContext context = FilterContext.getContext(); + tracker.recordSingleKeyAccess(key, value, context==null?null:context.getConfig()); return value; } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java index 46fd767..2b5d279 100644 --- a/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java +++ b/usagetracker/src/main/java/org/apache/tamaya/usagetracker/spi/ConfigUsageSpi.java @@ -18,10 +18,9 @@ */ package org.apache.tamaya.usagetracker.spi; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.usagetracker.UsageStat; +import javax.config.Config; import java.util.Collection; import java.util.Set; @@ -64,11 +63,11 @@ public interface ConfigUsageSpi { UsageStat getSinglePropertyStats(String key); /** - * Access the usage statistics for accessing {@link org.apache.tamaya.Configuration#getProperties()}. + * Access the usage statistics for accessing {@link Config#getPropertyNames()}. * If usage stats collection is not activated (default), this method returns null. * @return the stats collected, or null. */ - UsageStat getAllPropertiesStats(); + UsageStat getPropertyNamesStats(); /** * Get the recorded usage references of configuration. @@ -77,19 +76,20 @@ public interface ConfigUsageSpi { Collection<UsageStat> getUsageStats(); /** - * Track the access of {@code Configuration#getProperties()} for + * Track the access of {@code Config#getPropertyNames()} for * usage statistics. - * @param context the corresponding context. + * @param config the corresponding config. */ - void recordAllPropertiesAccess(ConfigurationContext context); + void recordAllPropertiesAccess(Config config); /** * Track the access of {@code Configuration#get(String)} for * usage statistics. - * @param context the corresponding context. + * @param config the corresponding config. + * @param key key to track for * @param value value to track for */ - void recordSingleKeyAccess(PropertyValue value, ConfigurationContext context); + void recordSingleKeyAccess(String key, String value, Config config); /** * Access the usage statistics for the recorded uses of configuration. http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter b/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter new file mode 100644 index 0000000..dee62d6 --- /dev/null +++ b/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter @@ -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.usagetracker.internal.UsageTrackerFilter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter ---------------------------------------------------------------------- diff --git a/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter deleted file mode 100644 index dee62d6..0000000 --- a/usagetracker/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter +++ /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.usagetracker.internal.UsageTrackerFilter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java b/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java index 1fcdee9..36d77a7 100644 --- a/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java +++ b/usagetracker/src/test/java/org/apache/tamaya/model/ConfigUsageStatsTest.java @@ -18,12 +18,13 @@ */ package org.apache.tamaya.model; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.usagetracker.ConfigUsage; import org.junit.Test; import test.model.TestConfigAccessor; +import javax.config.Config; +import javax.config.ConfigProvider; + import static org.junit.Assert.*; /** @@ -35,16 +36,16 @@ public class ConfigUsageStatsTest { public void testUsageWhenEnabled(){ ConfigUsage.enableUsageTracking(true); TestConfigAccessor.readConfiguration(); - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); String info = ConfigUsage.getInfo(); assertFalse(info.contains("java.version")); assertNotNull(info); config = TestConfigAccessor.readConfiguration(); - config.getProperties(); + config.getPropertyNames(); TestConfigAccessor.readProperty(config, "java.locale"); TestConfigAccessor.readProperty(config, "java.version"); TestConfigAccessor.readProperty(config, "java.version"); - config.get("java.version"); + config.getValue("java.version", String.class); info = ConfigUsage.getInfo(); System.out.println(info); assertTrue(info.contains("java.version")); @@ -57,16 +58,16 @@ public class ConfigUsageStatsTest { ConfigUsage.enableUsageTracking(false); ConfigUsage.clearStats(); TestConfigAccessor.readConfiguration(); - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); String info = ConfigUsage.getInfo(); assertNotNull(info); assertFalse(info.contains("java.version")); config = TestConfigAccessor.readConfiguration(); - config.getProperties(); + config.getPropertyNames(); TestConfigAccessor.readProperty(config, "java.locale"); TestConfigAccessor.readProperty(config, "java.version"); TestConfigAccessor.readProperty(config, "java.version"); - config.get("java.version"); + config.getValue("java.version", String.class); info = ConfigUsage.getInfo(); assertFalse(info.contains("java.version")); assertNotNull(info); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/test/java/test/model/TestConfigAccessor.java ---------------------------------------------------------------------- diff --git a/usagetracker/src/test/java/test/model/TestConfigAccessor.java b/usagetracker/src/test/java/test/model/TestConfigAccessor.java index 498d2b6..f77bb07 100644 --- a/usagetracker/src/test/java/test/model/TestConfigAccessor.java +++ b/usagetracker/src/test/java/test/model/TestConfigAccessor.java @@ -18,10 +18,9 @@ */ package test.model; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import java.util.Map; +import javax.config.Config; +import javax.config.ConfigProvider; /** * Created by atsticks on 30.04.16. @@ -30,16 +29,16 @@ public final class TestConfigAccessor { private TestConfigAccessor(){} - public static Map<String,String> readAllProperties(){ - return ConfigurationProvider.getConfiguration() - .getProperties(); + public static Iterable<String> readAllPropertyNames(){ + return ConfigProvider.getConfig() + .getPropertyNames(); } - public static Configuration readConfiguration(){ - return ConfigurationProvider.getConfiguration(); + public static Config readConfiguration(){ + return ConfigProvider.getConfig(); } - public static String readProperty(Configuration config, String key){ - return config.get(key); + public static String readProperty(Config config, String key){ + return config.getValue(key, String.class); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/test/resources/META-INF/javaconfig.properties ---------------------------------------------------------------------- diff --git a/usagetracker/src/test/resources/META-INF/javaconfig.properties b/usagetracker/src/test/resources/META-INF/javaconfig.properties new file mode 100644 index 0000000..b0b8c22 --- /dev/null +++ b/usagetracker/src/test/resources/META-INF/javaconfig.properties @@ -0,0 +1,22 @@ +# +# 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. +# +a.test.existing.aParam=existingValue +a.test.existing.optionalParam=optionalValue +a.test.existing.aABCParam=ABCparam +a.test.existing.aABCParam2=MMM http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/35cc751f/usagetracker/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/usagetracker/src/test/resources/META-INF/javaconfiguration.properties b/usagetracker/src/test/resources/META-INF/javaconfiguration.properties deleted file mode 100644 index b0b8c22..0000000 --- a/usagetracker/src/test/resources/META-INF/javaconfiguration.properties +++ /dev/null @@ -1,22 +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. -# -a.test.existing.aParam=existingValue -a.test.existing.optionalParam=optionalValue -a.test.existing.aABCParam=ABCparam -a.test.existing.aABCParam2=MMM
