tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject incubator-tamaya git commit: TAMAYA-362 Implement missing release method.
Date Wed, 21 Nov 2018 06:49:18 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 21391fe59 -> e7e02c4b3


TAMAYA-362 Implement missing release method.


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

Branch: refs/heads/master
Commit: e7e02c4b37f0aef84bf158778faa64b00e410b51
Parents: 21391fe
Author: Anatole Tresch <atsticks@gmail.com>
Authored: Wed Nov 21 07:49:03 2018 +0100
Committer: Anatole Tresch <atsticks@gmail.com>
Committed: Wed Nov 21 07:49:03 2018 +0100

----------------------------------------------------------------------
 .../java/org/apache/tamaya/Configuration.java   | 22 ++++++++++++++------
 .../tamaya/spi/ConfigurationProviderSpi.java    | 11 ++++++++++
 .../org/apache/tamaya/spi/PropertySource.java   | 16 +++++++++++++-
 .../tamaya/TestConfigurationProvider.java       |  5 +++++
 .../internal/CoreConfigurationProvider.java     |  6 ++++++
 .../propertysource/BasePropertySource.java      | 16 ++++++++++++++
 .../spisupport/TestConfigurationProvider.java   |  5 +++++
 7 files changed, 74 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e7e02c4b/code/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index 6b15a05..5f91027 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -390,7 +390,7 @@ public interface Configuration {
      * @return a new builder, never null.
      */
     default ConfigurationBuilder toBuilder() {
-        return getContext().getServiceContext()
+        return ServiceContextManager.getServiceContext(Configuration.class.getClassLoader())
                 .getService(ConfigurationProviderSpi.class).getConfigurationBuilder().setConfiguration(this);
     }
 
@@ -406,7 +406,7 @@ public interface Configuration {
      *                                                 applying a new Configuration.
      */
     static void setCurrent(Configuration config) {
-        ServiceContextManager.getServiceContext()
+        ServiceContextManager.getServiceContext(Configuration.class.getClassLoader())
                 .getService(ConfigurationProviderSpi.class).setConfiguration(config, Thread.currentThread().getContextClassLoader());
     }
 
@@ -423,7 +423,7 @@ public interface Configuration {
      *                                                 applying a new Configuration.
      */
     static void setCurrent(Configuration config, ClassLoader classLoader) {
-        ServiceContextManager.getServiceContext(classLoader)
+        ServiceContextManager.getServiceContext(Configuration.class.getClassLoader())
                 .getService(ConfigurationProviderSpi.class).setConfiguration(config, classLoader);
     }
 
@@ -432,7 +432,7 @@ public interface Configuration {
      * @return the configuration instance, never null.
      */
     static Configuration current(){
-        return ServiceContextManager.getServiceContext()
+        return ServiceContextManager.getServiceContext(Configuration.class.getClassLoader())
                 .getService(ConfigurationProviderSpi.class).getConfiguration(Thread.currentThread().getContextClassLoader());
     }
 
@@ -442,16 +442,26 @@ public interface Configuration {
      * @return the configuration instance, never null.
      */
     static Configuration current(ClassLoader classloader){
-        return ServiceContextManager.getServiceContext(classloader)
+        return ServiceContextManager.getServiceContext(Configuration.class.getClassLoader())
                 .getService(ConfigurationProviderSpi.class).getConfiguration(classloader);
     }
 
     /**
+     * Releases the configuration associated with the given classloader.
+     * @param classloader the classloader, not null.
+     * @return the released configuration, or null.
+     */
+    static Configuration releaseConfiguration(ClassLoader classloader) {
+        return ServiceContextManager.getServiceContext(Configuration.class.getClassLoader())
+                .getService(ConfigurationProviderSpi.class).releaseConfiguration(classloader);
+    }
+
+    /**
      * Access a new configuration builder initialized with the current thread's context classloader.
      * @return the builder, never null.
      */
     static ConfigurationBuilder createConfigurationBuilder(){
-        return ServiceContextManager.getServiceContext()
+        return ServiceContextManager.getServiceContext(Configuration.class.getClassLoader())
                 .getService(ConfigurationProviderSpi.class).getConfigurationBuilder();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e7e02c4b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
index 337e397..97ae1a2 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
@@ -74,6 +74,17 @@ public interface ConfigurationProviderSpi {
     void setConfiguration(Configuration config, ClassLoader classloader);
 
     /**
+     * This method allows to release a {@link org.apache.tamaya.Configuration} for a classloader.
+     * This can be used to refresh the configuration with a new one, e.g. because some of
the
+     * data has changed and must be updated.
+     *
+     * @param classloader the classloader to be used.
+     * @return the configuration instance released, or {@code null}.
+     * @throws java.lang.UnsupportedOperationException if the current provider is read-only.
+     */
+    Configuration releaseConfiguration(ClassLoader classloader);
+
+    /**
      * Method that allows to determine if a new {@link org.apache.tamaya.Configuration} can
be applied
      * programmatically.
      *

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e7e02c4b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index b25bbb4..cc42d66 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -25,6 +25,8 @@ import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 import java.util.function.BiConsumer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 
 /**
@@ -129,7 +131,19 @@ public interface PropertySource{
      * </ul>
      * @return the 'importance' aka ordinal of the configured values. The higher, the more
important.
      */
-    int getOrdinal();
+    default int getOrdinal(){
+        PropertyValue ordinalValue = get(TAMAYA_ORDINAL);
+        if(ordinalValue!=null){
+            try{
+                return Integer.parseInt(ordinalValue.getValue());
+            }catch (Exception e){
+                Logger.getLogger(getClass().getName()).log(Level.WARNING,
+                        "Failed to parse ordinal in property source: " + getName(),
+                        e);
+            }
+        }
+        return 0;
+    }
 
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e7e02c4b/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
index e83045f..e5622e4 100644
--- a/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
+++ b/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
@@ -54,4 +54,9 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi
{
     public void setConfiguration(Configuration config, ClassLoader classLoader) {
         this.config = config;
     }
+
+    @Override
+    public Configuration releaseConfiguration(ClassLoader classloader) {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e7e02c4b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
index 8a0bb55..bbfecf6 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
@@ -87,6 +87,12 @@ public class CoreConfigurationProvider implements ConfigurationProviderSpi
{
     }
 
     @Override
+    public Configuration releaseConfiguration(ClassLoader classloader) {
+        LOG.info("Releasing config for classloader: " + classloader);
+        return this.configurations.remove(classloader);
+    }
+
+    @Override
     public boolean isConfigurationSettable(ClassLoader classLoader) {
         return true;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e7e02c4b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
index cca4d96..d918082 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
@@ -24,6 +24,7 @@ import java.util.Objects;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.tamaya.spi.ChangeSupport;
 import org.apache.tamaya.spi.PropertySource;
 import org.apache.tamaya.spi.PropertyValue;
 
@@ -46,6 +47,7 @@ public abstract class BasePropertySource implements PropertySource{
      * {@code tamaya.envprops.disable} system/environment property to {@code true}.
      */
     private boolean disabled = false;
+    private ChangeSupport changeSupport = ChangeSupport.UNSUPPORTED;
 
     /**
      * Constructor.
@@ -220,4 +222,18 @@ public abstract class BasePropertySource implements PropertySource{
         return result;
     }
 
+    @Override
+    public ChangeSupport getChangeSupport() {
+        return changeSupport;
+    }
+
+    /**
+     * Sets the change support.
+     * @param changeSupport the changeSupport, not null.
+     * @return this instance, for chaining.
+     */
+    public PropertySource setChangeSupport(ChangeSupport changeSupport) {
+        this.changeSupport = Objects.requireNonNull(changeSupport);
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e7e02c4b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
index cf60849..a633519 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
@@ -61,6 +61,11 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi
{
     }
 
     @Override
+    public Configuration releaseConfiguration(ClassLoader classloader) {
+        return null;
+    }
+
+    @Override
     public boolean isConfigurationSettable(ClassLoader classLoader) {
         return true;
     }


Mime
View raw message