geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject 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
Date Fri, 22 Dec 2017 16:18:37 GMT
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);
+                    }
+                }
             }
         }
     }



Mime
View raw message