You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by st...@apache.org on 2015/01/05 14:57:13 UTC

incubator-tamaya git commit: TAMAYA-42 only resolve the ConfigurationContext once

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 909ec1616 -> 3368db2e1


TAMAYA-42 only resolve the ConfigurationContext once

The Configuration and ConfigurationConstance impls belong together 1:1.
We not only don't need to proxy them internally but also shall not do this
otherwise we would trash the performance.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/3368db2e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/3368db2e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/3368db2e

Branch: refs/heads/master
Commit: 3368db2e1a8eb5b54fdc8c5320acbfbdb2cfa245
Parents: 909ec16
Author: Mark Struberg <st...@apache.org>
Authored: Mon Jan 5 14:55:56 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Jan 5 14:55:56 2015 +0100

----------------------------------------------------------------------
 .../tamaya/core/internal/DefaultConfiguration.java  | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3368db2e/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index 3769e27..651398b 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -45,6 +45,9 @@ public class DefaultConfiguration implements Configuration {
 
     private static final Logger LOG = Logger.getLogger(DefaultConfiguration.class.getName());
 
+    private final ConfigurationContext configurationContext = ServiceContext.getInstance().getService(ConfigurationContext.class).get();
+
+
     /**
      * This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances
      * provided by the current {@link org.apache.tamaya.spi.ConfigurationContext}. The first non-null-value returned
@@ -57,7 +60,7 @@ public class DefaultConfiguration implements Configuration {
      */
     @Override
     public Optional<String> get(String key) {
-        List<PropertySource> propertySources = ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertySources();
+        List<PropertySource> propertySources = configurationContext.getPropertySources();
         String unfilteredValue = null;
         for (PropertySource propertySource : propertySources) {
             Optional<String> value = propertySource.get(key);
@@ -67,8 +70,7 @@ public class DefaultConfiguration implements Configuration {
             }
         }
         // Apply filters to values, prevent values filtered to null!
-        for(PropertyFilter filter:
-                ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertyFilters()){
+        for(PropertyFilter filter: configurationContext.getPropertyFilters()){
             unfilteredValue = filter.filterProperty(key, unfilteredValue,
                     (String k) -> key.equals(k)?null:get(k).orElse(null));
         }
@@ -77,8 +79,7 @@ public class DefaultConfiguration implements Configuration {
 
     @Override
     public Map<String, String> getProperties() {
-        List<PropertySource> propertySources = new ArrayList<>(
-                ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertySources());
+        List<PropertySource> propertySources = new ArrayList<>(configurationContext.getPropertySources());
         Collections.reverse(propertySources);
         Map<String, String> result = new HashMap<>();
         for (PropertySource propertySource : propertySources) {
@@ -95,7 +96,7 @@ public class DefaultConfiguration implements Configuration {
         }
         // Apply filters to values, prevent values filtered to null!
         for(PropertyFilter filter:
-                ServiceContext.getInstance().getService(ConfigurationContext.class).get().getPropertyFilters()){
+                configurationContext.getPropertyFilters()){
             result.replaceAll((k,v) -> filter.filterProperty(k, v,
                     (String k2) -> k2.equals(k)?null:get(k2).orElse(null)));
         }
@@ -119,8 +120,7 @@ public class DefaultConfiguration implements Configuration {
     public <T> Optional<T> get(String key, Class<T> type) {
         Optional<String> value = get(key);
         if (value.isPresent()) {
-            List<PropertyConverter<T>> converters = ServiceContext.getInstance().getService(ConfigurationContext.class)
-                    .get().getPropertyConverters(type);
+            List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
             for (PropertyConverter<T> converter : converters) {
                 try {
                     T t = converter.convert(value.get());