DELTASPIKE-1322 switch ConfigSources over anything which contains state is now getting moved over from ConfigResolver to Config
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/bd638aae Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/bd638aae Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/bd638aae Branch: refs/heads/master Commit: bd638aae11d6723b17c7b533e3e21c2106dd581a Parents: f56845c Author: Mark Struberg <strub...@apache.org> Authored: Mon Mar 5 12:45:27 2018 +0100 Committer: Mark Struberg <strub...@apache.org> Committed: Mon Mar 5 12:45:27 2018 +0100 ---------------------------------------------------------------------- .../core/api/config/ConfigResolver.java | 142 ++----------------- ...ore.api.config.ConfigResolver$ConfigProvider | 20 +++ ...ore.api.config.ConfigResolver.ConfigProvider | 20 --- deltaspike/modules/partial-bean/impl/pom.xml | 5 + deltaspike/modules/proxy/impl-asm/pom.xml | 5 + 5 files changed, 42 insertions(+), 150 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bd638aae/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java ---------------------------------------------------------------------- diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java index 4339cca..fa280ef 100644 --- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java +++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/config/ConfigResolver.java @@ -28,8 +28,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.ServiceLoader; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -39,11 +37,9 @@ import javax.enterprise.inject.Typed; import org.apache.deltaspike.core.api.projectstage.ProjectStage; import org.apache.deltaspike.core.spi.config.ConfigFilter; import org.apache.deltaspike.core.spi.config.ConfigSource; -import org.apache.deltaspike.core.spi.config.ConfigSourceProvider; import org.apache.deltaspike.core.util.ClassUtils; import org.apache.deltaspike.core.util.ExceptionUtils; import org.apache.deltaspike.core.util.ProjectStageProducer; -import org.apache.deltaspike.core.util.ServiceUtils; /** * The main entry point to the DeltaSpike configuration mechanism. @@ -54,7 +50,7 @@ import org.apache.deltaspike.core.util.ServiceUtils; * * <p> * You can provide your own lookup paths by implementing and registering additional {@link PropertyFileConfig} or - * {@link ConfigSource} or {@link ConfigSourceProvider} implementations.</p> + * {@link ConfigSource} or {@link org.apache.deltaspike.core.spi.config.ConfigSourceProvider} implementations.</p> * * <p> * The resolved configuration is also accessible by simple injection using the {@link ConfigProperty} qualifier.</p> @@ -79,21 +75,6 @@ public final class ConfigResolver private static final Logger LOG = Logger.getLogger(ConfigResolver.class.getName()); - /** - * The content of this map will get lazily initiated and will hold the - * sorted List of ConfigSources for each WebApp/EAR, etc (thus the - * ClassLoader). - */ - private static Map<ClassLoader, ConfigSource[]> configSources - = new ConcurrentHashMap<ClassLoader, ConfigSource[]>(); - - /** - * The content of this map will hold the List of ConfigFilters - * for each WebApp/EAR, etc (thus the ClassLoader). - */ - private static Map<ClassLoader, List<ConfigFilter>> configFilters - = new ConcurrentHashMap<ClassLoader, List<ConfigFilter>>(); - private static ConfigProvider configProvider; private ConfigResolver() @@ -120,19 +101,7 @@ public final class ConfigResolver */ public static synchronized void addConfigSources(List<ConfigSource> configSourcesToAdd) { - // we first pickup all pre-configured ConfigSources... - getConfigSources(); - - // and now we can easily add our own - ClassLoader currentClassLoader = ClassUtils.getClassLoader(null); - ConfigSource[] configuredConfigSources = configSources.get(currentClassLoader); - - List<ConfigSource> allConfigSources = new ArrayList<ConfigSource>(); - allConfigSources.addAll(Arrays.asList(configuredConfigSources)); - allConfigSources.addAll(configSourcesToAdd); - - // finally put all the configSources back into the map - configSources.put(currentClassLoader, sortDescending(allConfigSources)); + getConfigProvider().getConfig().addConfigSources(configSourcesToAdd); } /** @@ -141,9 +110,11 @@ public final class ConfigResolver */ public static synchronized void freeConfigSources() { - ClassLoader classLoader = ClassUtils.getClassLoader(null); - configSources.remove(classLoader); - configFilters.remove(classLoader); + if (configProvider != null) + { + ClassLoader cl = ClassUtils.getClassLoader(null); + configProvider.releaseConfig(cl); + } } /** @@ -154,8 +125,7 @@ public final class ConfigResolver */ public static void addConfigFilter(ConfigFilter configFilter) { - List<ConfigFilter> currentConfigFilters = getInternalConfigFilters(); - currentConfigFilters.add(configFilter); + getConfigProvider().getConfig().addConfigFilter(configFilter); } /** @@ -163,24 +133,9 @@ public final class ConfigResolver */ public static List<ConfigFilter> getConfigFilters() { - return Collections.unmodifiableList(getInternalConfigFilters()); + return getConfigProvider().getConfig().getConfigFilters(); } - /** - * @return the {@link ConfigFilter}s for the current application. - */ - private static List<ConfigFilter> getInternalConfigFilters() - { - ClassLoader cl = ClassUtils.getClassLoader(null); - List<ConfigFilter> currentConfigFilters = configFilters.get(cl); - if (currentConfigFilters == null) - { - currentConfigFilters = new CopyOnWriteArrayList<ConfigFilter>(); - configFilters.put(cl, currentConfigFilters); - } - - return currentConfigFilters; - } /** * {@link #getPropertyValue(java.lang.String)} which returns the provided default value if no configured value can @@ -500,64 +455,7 @@ public final class ConfigResolver public static synchronized ConfigSource[] getConfigSources() { - ClassLoader currentClassLoader = ClassUtils.getClassLoader(null); - - ConfigSource[] appConfigSources = configSources.get(currentClassLoader); - - if (appConfigSources == null) - { - appConfigSources = sortDescending(resolveConfigSources()); - - if (LOG.isLoggable(Level.FINE)) - { - for (ConfigSource cs : appConfigSources) - { - LOG.log(Level.FINE, "Adding ordinal {0} ConfigSource {1}", - new Object[]{cs.getOrdinal(), cs.getConfigName()}); - } - } - - configSources.put(currentClassLoader, appConfigSources); - } - - return appConfigSources; - } - - private static List<ConfigSource> resolveConfigSources() - { - List<ConfigSource> appConfigSources = ServiceUtils.loadServiceImplementations(ConfigSource.class); - - List<ConfigSourceProvider> configSourceProviderServiceLoader = - ServiceUtils.loadServiceImplementations(ConfigSourceProvider.class); - - for (ConfigSourceProvider configSourceProvider : configSourceProviderServiceLoader) - { - appConfigSources.addAll(configSourceProvider.getConfigSources()); - } - - List<? extends ConfigFilter> configFilters = ServiceUtils.loadServiceImplementations(ConfigFilter.class); - for (ConfigFilter configFilter : configFilters) - { - addConfigFilter(configFilter); - } - - return appConfigSources; - } - - private static ConfigSource[] sortDescending(List<ConfigSource> configSources) - { - Collections.sort(configSources, new Comparator<ConfigSource>() - { - /** - * {@inheritDoc} - */ - @Override - public int compare(ConfigSource configSource1, ConfigSource configSource2) - { - return (configSource1.getOrdinal() > configSource2.getOrdinal()) ? -1 : 1; - } - }); - return configSources.toArray(new ConfigSource[configSources.size()]); + return getConfigProvider().getConfig().getConfigSources(); } private static List<ConfigSource> sortAscending(List<ConfigSource> configSources) @@ -607,15 +505,7 @@ public final class ConfigResolver */ public static String filterConfigValue(String key, String value) { - List<ConfigFilter> currentConfigFilters = getInternalConfigFilters(); - - String filteredValue = value; - - for (ConfigFilter filter : currentConfigFilters) - { - filteredValue = filter.filterValue(key, filteredValue); - } - return filteredValue; + return getConfigProvider().getConfig().filterConfigValue(key, value, false); } /** @@ -625,15 +515,7 @@ public final class ConfigResolver */ public static String filterConfigValueForLog(String key, String value) { - List<ConfigFilter> currentConfigFilters = getInternalConfigFilters(); - - String logValue = value; - - for (ConfigFilter filter : currentConfigFilters) - { - logValue = filter.filterValueForLog(key, logValue); - } - return logValue; + return getConfigProvider().getConfig().filterConfigValue(key, value, true); } /** http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bd638aae/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver$ConfigProvider ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver$ConfigProvider b/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver$ConfigProvider new file mode 100644 index 0000000..117643b --- /dev/null +++ b/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver$ConfigProvider @@ -0,0 +1,20 @@ +# +# 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. +# + +org.apache.deltaspike.core.impl.config.ConfigProviderImpl \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bd638aae/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver.ConfigProvider ---------------------------------------------------------------------- diff --git a/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver.ConfigProvider b/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver.ConfigProvider deleted file mode 100644 index 117643b..0000000 --- a/deltaspike/core/impl/src/main/resources/META-INF/services/org.apache.deltaspike.core.api.config.ConfigResolver.ConfigProvider +++ /dev/null @@ -1,20 +0,0 @@ -# -# 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. -# - -org.apache.deltaspike.core.impl.config.ConfigProviderImpl \ No newline at end of file http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bd638aae/deltaspike/modules/partial-bean/impl/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/partial-bean/impl/pom.xml b/deltaspike/modules/partial-bean/impl/pom.xml index 94238b7..a8d6a3c 100644 --- a/deltaspike/modules/partial-bean/impl/pom.xml +++ b/deltaspike/modules/partial-bean/impl/pom.xml @@ -54,6 +54,11 @@ <groupId>org.apache.deltaspike.core</groupId> <artifactId>deltaspike-core-api</artifactId> </dependency> + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-impl</artifactId> + <scope>runtime</scope> + </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bd638aae/deltaspike/modules/proxy/impl-asm/pom.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/proxy/impl-asm/pom.xml b/deltaspike/modules/proxy/impl-asm/pom.xml index d196d5b..ad472b3 100644 --- a/deltaspike/modules/proxy/impl-asm/pom.xml +++ b/deltaspike/modules/proxy/impl-asm/pom.xml @@ -90,6 +90,11 @@ <groupId>org.apache.deltaspike.core</groupId> <artifactId>deltaspike-core-api</artifactId> </dependency> + <dependency> + <groupId>org.apache.deltaspike.core</groupId> + <artifactId>deltaspike-core-impl</artifactId> + <scope>runtime</scope> + </dependency> <dependency> <groupId>org.apache.deltaspike.modules</groupId>