You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by st...@apache.org on 2017/12/22 16:18:37 UTC

svn commit: r1819053 - in /geronimo/components/config/branches/ConfigJSR/impl: debug-suite.xml src/main/java/org/apache/geronimo/config/ConfigImpl.java src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java

Author: struberg
Date: Fri Dec 22 16:18:37 2017
New Revision: 1819053

URL: http://svn.apache.org/viewvc?rev=1819053&view=rev
Log:
properly shut down Configs on release

Modified:
    geronimo/components/config/branches/ConfigJSR/impl/debug-suite.xml
    geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
    geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java

Modified: geronimo/components/config/branches/ConfigJSR/impl/debug-suite.xml
URL: http://svn.apache.org/viewvc/geronimo/components/config/branches/ConfigJSR/impl/debug-suite.xml?rev=1819053&r1=1819052&r2=1819053&view=diff
==============================================================================
--- geronimo/components/config/branches/ConfigJSR/impl/debug-suite.xml (original)
+++ geronimo/components/config/branches/ConfigJSR/impl/debug-suite.xml Fri Dec 22 16:18:37 2017
@@ -23,7 +23,7 @@
 
     <classes>
         <!-- Issues in the spec -->
-        <class name="org.eclipse.configjsr.PrivateImplicitConverterTest">
+        <class name="org.eclipse.configjsr.CustomConfigSourceTest">
             <methods>
                 <include name=".*"/>
             </methods>

Modified: geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java?rev=1819053&r1=1819052&r2=1819053&view=diff
==============================================================================
--- geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java (original)
+++ geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/ConfigImpl.java Fri Dec 22 16:18:37 2017
@@ -55,7 +55,7 @@ import javax.enterprise.inject.Vetoed;
  */
 @Typed
 @Vetoed
-public class ConfigImpl implements Config {
+public class ConfigImpl implements Config, AutoCloseable {
     protected Logger logger = Logger.getLogger(ConfigImpl.class.getName());
 
     protected List<ConfigSource> configSources = new ArrayList<>();
@@ -234,6 +234,48 @@ public class ConfigImpl implements Confi
     }
 
 
+    @Override
+    public void close() throws Exception {
+        List<Exception> exceptions = new ArrayList<>();
+
+        converters.values().stream()
+                .filter(c -> c instanceof AutoCloseable)
+                .map(AutoCloseable.class::cast)
+                .forEach(c -> {
+                    try {
+                        c.close();
+                    }
+                    catch (Exception e) {
+                        exceptions.add(e);
+                    }
+                });
+
+        configSources.stream()
+                .filter(c -> c instanceof AutoCloseable)
+                .map(AutoCloseable.class::cast)
+                .forEach(c -> {
+                    try {
+                        c.close();
+                    }
+                    catch (Exception e) {
+                        exceptions.add(e);
+                    }
+                });
+
+        if (!exceptions.isEmpty()) {
+            StringBuilder sb = new StringBuilder(1024);
+            sb.append("The following Exceptions got detected while shutting down the Config:\n");
+            for (Exception exception : exceptions) {
+                sb.append(exception.getClass().getName())
+                        .append(" ")
+                        .append(exception.getMessage())
+                        .append('\n');
+            }
+
+            throw new RuntimeException(sb.toString(), exceptions.get(0));
+        }
+    }
+
     private List<ConfigSource> sortDescending(List<ConfigSource> configSources) {
         configSources.sort(
                 (configSource1, configSource2) -> (configSource1.getOrdinal() > configSource2.getOrdinal()) ? -1 : 1);

Modified: geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java?rev=1819053&r1=1819052&r2=1819053&view=diff
==============================================================================
--- geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java (original)
+++ geronimo/components/config/branches/ConfigJSR/impl/src/main/java/org/apache/geronimo/config/DefaultConfigProvider.java Fri Dec 22 16:18:37 2017
@@ -107,6 +107,15 @@ public class DefaultConfigProvider exten
                         break;
                     }
                 }
+
+                if (config instanceof AutoCloseable) {
+                    try {
+                        ((AutoCloseable) config).close();
+                    }
+                    catch (Exception e) {
+                        throw new RuntimeException("Error while closing Config", e);
+                    }
+                }
             }
         }
     }