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/02/28 01:54:08 UTC

[1/4] incubator-tamaya git commit: Added value policy.

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master c805b1deb -> 5d65e35d9


Added value policy.


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

Branch: refs/heads/master
Commit: c3c2a7692f8bb1754561503eabab20a2ef0ce83d
Parents: 7ad4c36
Author: anatole <an...@apache.org>
Authored: Sun Feb 28 01:35:03 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Feb 28 01:35:03 2016 +0100

----------------------------------------------------------------------
 .../mutableconfig/ValueVisibilityPolicy.java    | 41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/c3c2a769/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
new file mode 100644
index 0000000..f93826c
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
@@ -0,0 +1,41 @@
+/*
+ * 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.mutableconfig;
+
+/**
+ * Policy that can be passed when creating a {@link MutableConfigurationQuery} to define how existing values from
+ * the base configuration should be handled. The corresponding behaviour is immedeately activen, it does not
+ * require a {@code commit()}. Nevertheless cleaning up all changes will reverse any changes and also related
+ * effects.
+ */
+public enum ValueVisibilityPolicy {
+    /**
+     * Entries from the base configuration are hidden by the entries edited. This gives you the best control on your
+     * changes applied, but probably will not match the behaviour of your default configuration, since the effective
+     * ordinals of your PropertySources may determine other overriding behaviour.
+     */
+    CHANGES,
+
+    /**
+     * Entries added are also added to the overall configuration for read access before committed, but any existing
+     * values are never overridden.
+     */
+    CONFIG,
+
+}


[4/4] incubator-tamaya git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-tamaya

Posted by an...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-tamaya


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

Branch: refs/heads/master
Commit: 5d65e35d997e526f3f16324e48b0eb253da76de9
Parents: a383d1f c805b1d
Author: anatole <an...@apache.org>
Authored: Sun Feb 28 01:53:36 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Feb 28 01:53:36 2016 +0100

----------------------------------------------------------------------

----------------------------------------------------------------------



[3/4] incubator-tamaya git commit: Added value policy.

Posted by an...@apache.org.
Added value policy.


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

Branch: refs/heads/master
Commit: a383d1f3afd6991e5cbb481b86253510c567abde
Parents: f4d6d9f
Author: anatole <an...@apache.org>
Authored: Sun Feb 28 01:38:35 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Feb 28 01:38:35 2016 +0100

----------------------------------------------------------------------
 .../MutableConfigurationQuery.java              | 103 ++++++++++++++++---
 .../mutableconfig/ValueVisibilityPolicy.java    |  17 +--
 2 files changed, 100 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a383d1f3/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java
index 2e44a4d..34177c3 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java
@@ -22,10 +22,13 @@ import org.apache.tamaya.ConfigException;
 import org.apache.tamaya.ConfigOperator;
 import org.apache.tamaya.ConfigQuery;
 import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
 import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfiguration;
 import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
 import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
 import org.apache.tamaya.spi.ServiceContextManager;
 
 import java.net.URI;
@@ -34,6 +37,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -49,14 +53,17 @@ public final class MutableConfigurationQuery implements ConfigQuery<MutableConfi
      */
     private final List<MutableConfigurationBackendSpi> targets = new ArrayList<>();
 
+    private ValueVisibilityPolicy valueVisibilityPolicy;
+
     /** Singleton constructor. */
-    private MutableConfigurationQuery(List<MutableConfigurationBackendSpi> targets){
+    private MutableConfigurationQuery(ValueVisibilityPolicy valueVisibilityPolicy, List<MutableConfigurationBackendSpi> targets){
         this.targets.addAll(targets);
+        this.valueVisibilityPolicy = valueVisibilityPolicy;
     }
 
     @Override
     public MutableConfiguration query(Configuration config) {
-        return new DefaultMutableConfiguration(config, targets);
+        return new DefaultMutableConfiguration(valueVisibilityPolicy, config, targets);
     }
 
     /**
@@ -70,12 +77,28 @@ public final class MutableConfigurationQuery implements ConfigQuery<MutableConfi
      * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
      */
     public static MutableConfigurationQuery of(String... configurationTargets){
+        return of(ValueVisibilityPolicy.CONFIG, configurationTargets);
+    }
+
+    /**
+     * Creates a new change request for the given configurationSource
+     *
+     * @param configurationTargets the configuration targets (String to create URIs) to use to write the changes/config. By passing multiple
+     *                             URIs you can write back changes into multiple configuration backends, e.g.
+     *                             one for redistributing changes using multicast mechanism, a local property file
+     *                             for failover as well as the shared etcd server.
+     * @param valueVisibilityPolicy the policy that defines how values edited, added or removed are reflected in the read
+     *                         accesses of the {@link MutableConfiguration} created.
+     * @return a new ChangeRequest
+     * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
+     */
+    public static MutableConfigurationQuery of(ValueVisibilityPolicy valueVisibilityPolicy, String... configurationTargets){
         try {
             URI[] uris = new URI[configurationTargets.length];
             for (int i = 0; i < configurationTargets.length; i++) {
                 uris[i] = new URI(configurationTargets[i]);
             }
-            return of(uris);
+            return of(valueVisibilityPolicy, uris);
         } catch(URISyntaxException e){
             throw new ConfigException("Invalid URIs encountered in " + Arrays.toString(configurationTargets));
         }
@@ -92,6 +115,21 @@ public final class MutableConfigurationQuery implements ConfigQuery<MutableConfi
      * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
      */
     public static MutableConfigurationQuery of(URI... configurationTargets){
+        return of(ValueVisibilityPolicy.CONFIG, configurationTargets);
+    }
+    /**
+     * Creates a new change request for the given configurationSource
+     *
+     * @param configurationTargets the configuration targets to use to write the changes/config. By passing multiple
+     *                             URIs you can write back changes into multiple configuration backends, e.g.
+     *                             one for redistributing changes using multicast mechanism, a local property file
+     *                             for failover as well as the shared etcd server.
+     * @param valueVisibilityPolicy the policy that defines how values edited, added or removed are reflected in the read
+     *                         accesses of the {@link MutableConfiguration} created.
+     * @return a new ChangeRequest
+     * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
+     */
+    public static MutableConfigurationQuery of(ValueVisibilityPolicy valueVisibilityPolicy, URI... configurationTargets){
         if(Objects.requireNonNull(configurationTargets).length==0){
             throw new IllegalArgumentException("At least one target URI is required.");
         }
@@ -109,7 +147,7 @@ public final class MutableConfigurationQuery implements ConfigQuery<MutableConfi
             throw new ConfigException("Not an editable configuration target for: " +
                     Arrays.toString(configurationTargets));
         }
-        return new MutableConfigurationQuery(targets);
+        return new MutableConfigurationQuery(Objects.requireNonNull(valueVisibilityPolicy), targets);
     }
 
 
@@ -121,10 +159,12 @@ public final class MutableConfigurationQuery implements ConfigQuery<MutableConfi
 
         private final List<MutableConfigurationBackendSpi> targets;
         private final Configuration config;
+        private ValueVisibilityPolicy valueVisibilityPolicy;
 
-        DefaultMutableConfiguration(Configuration config, List<MutableConfigurationBackendSpi> targets){
+        DefaultMutableConfiguration(ValueVisibilityPolicy valueVisibilityPolicy, Configuration config, List<MutableConfigurationBackendSpi> targets){
             this.targets = Objects.requireNonNull(targets);
             this.config = Objects.requireNonNull(config);
+            this.valueVisibilityPolicy = valueVisibilityPolicy;
         }
 
         @Override
@@ -221,37 +261,76 @@ public final class MutableConfigurationQuery implements ConfigQuery<MutableConfi
 
         @Override
         public String get(String key) {
-            return config.get(key);
+            String addedOrUpdated = this.addedProperties.get(key);
+            switch(valueVisibilityPolicy){
+                case CHANGES:
+                    boolean removed = this.removedProperties.contains(key);
+                    if(removed){
+                        return null;
+                    }
+                    return addedOrUpdated!=null?addedOrUpdated:this.config.get(key);
+                case CONFIG:
+                default:
+                    String val = this.config.get(key);
+                    return val == null?addedOrUpdated:val;
+            }
         }
 
         @Override
         public String getOrDefault(String key, String defaultValue) {
-            return config.getOrDefault(key, defaultValue);
+            String val = get(key);
+            return val == null? defaultValue: val;
         }
 
         @Override
         public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
-            return config.getOrDefault(key, type, defaultValue);
+            return (T)getOrDefault(key, TypeLiteral.of(type), defaultValue);
         }
 
         @Override
         public <T> T get(String key, Class<T> type) {
-            return config.get(key, type);
+            return getOrDefault(key, type, (T)null);
         }
 
         @Override
         public <T> T get(String key, TypeLiteral<T> type) {
-            return config.get(key, type);
+            return getOrDefault(key, type, (T)null);
         }
 
         @Override
         public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
-            return config.getOrDefault(key, type, defaultValue);
+            String val = get(key);
+            if(val==null) {
+                return config.getOrDefault(key, type, defaultValue);
+            }
+            for(PropertyConverter conv: ConfigurationProvider.getConfigurationContext().getPropertyConverters(type)){
+                Object o = conv.convert(val, new ConversionContext.Builder(key, type).setConfiguration(config).build());
+                if(o!=null){
+                    return (T) o;
+                }
+            }
+            return defaultValue;
         }
 
         @Override
         public Map<String, String> getProperties() {
-            return config.getProperties();
+            Map<String, String> configProps = new HashMap<>(config.getProperties());
+            switch(valueVisibilityPolicy){
+                case CHANGES:
+                    for(String key:removedProperties){
+                        configProps.remove(key);
+                    }
+                    configProps.putAll(addedProperties);
+                    return configProps;
+                case CONFIG:
+                default:
+                    Map<String, String> props = new HashMap<>(addedProperties);
+                    for(String key:removedProperties){
+                        props.remove(key);
+                    }
+                    props.putAll(configProps);
+                    return props;
+            }
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a383d1f3/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
index f93826c..841a65d 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
@@ -20,22 +20,23 @@ package org.apache.tamaya.mutableconfig;
 
 /**
  * Policy that can be passed when creating a {@link MutableConfigurationQuery} to define how existing values from
- * the base configuration should be handled. The corresponding behaviour is immedeately activen, it does not
+ * the base configuration should be handled. The corresponding behaviour is immedeately active, it does not
  * require a {@code commit()}. Nevertheless cleaning up all changes will reverse any changes and also related
  * effects.
  */
 public enum ValueVisibilityPolicy {
+
     /**
-     * Entries from the base configuration are hidden by the entries edited. This gives you the best control on your
-     * changes applied, but probably will not match the behaviour of your default configuration, since the effective
-     * ordinals of your PropertySources may determine other overriding behaviour.
+     * Entries added are also added to the mutable configuration for read access before committed. This is also
+     * the default policy used.
      */
-    CHANGES,
+    CONFIG,
 
     /**
-     * Entries added are also added to the overall configuration for read access before committed, but any existing
-     * values are never overridden.
+     * Entries from the base configuration are hidden or overridden by the entries edited. This gives you the best
+     * control on your changes applied, but probably will not match the behaviour of your default configuration,
+     * since the effective ordinals of your PropertySources may determine other overriding behaviour.
      */
-    CONFIG,
+    CHANGES
 
 }


[2/4] incubator-tamaya git commit: Fixed compile issue.

Posted by an...@apache.org.
Fixed compile issue.


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

Branch: refs/heads/master
Commit: f4d6d9f67ec9c754646d3167a1a9a358ec0b1abc
Parents: c3c2a76
Author: anatole <an...@apache.org>
Authored: Sun Feb 28 01:35:55 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Feb 28 01:35:55 2016 +0100

----------------------------------------------------------------------
 .../api/src/main/java/org/apache/tamaya/spi/ConversionContext.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f4d6d9f6/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
index 436c9f1..5b4835a 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
@@ -174,7 +174,7 @@ public class ConversionContext {
         public Builder(Configuration configuration, ConfigurationContext configurationContext, String key, TypeLiteral<?> targetType){
             this.key = key;
             this.configuration = configuration;
-            this.configurationContext = context;
+            this.configurationContext = configurationContext;
             this.targetType = Objects.requireNonNull(targetType);
         }