http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel/src/test/resources/TEST.properties ---------------------------------------------------------------------- diff --git a/metamodel/src/test/resources/TEST.properties b/metamodel/src/test/resources/TEST.properties new file mode 100644 index 0000000..2b31cb3 --- /dev/null +++ b/metamodel/src/test/resources/TEST.properties @@ -0,0 +1,19 @@ +# +# 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 current 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. +# +aKey=aValue.TEST
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/metamodel/src/test/resources/tamaya-TEST.yaml ---------------------------------------------------------------------- diff --git a/metamodel/src/test/resources/tamaya-TEST.yaml b/metamodel/src/test/resources/tamaya-TEST.yaml new file mode 100644 index 0000000..3e56656 --- /dev/null +++ b/metamodel/src/test/resources/tamaya-TEST.yaml @@ -0,0 +1,27 @@ +# +# 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 current 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. +# +tamaya-configuration: + includes: + tamaya-DEFAULT.yaml + + property-sources: + - class: org.apache.tamaya.resources.ResourceProvider + resource: classpath:META-INF/config/test/**/*.*" + - class: org.apache.tamaya.resources.ResourceProvider + resource: classpath://META-INF/config/test/**/*.*" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 4d6fc16..64f54d0 100644 --- a/pom.xml +++ b/pom.xml @@ -27,18 +27,80 @@ under the License. <artifactId>tamaya-sandbox</artifactId> <groupId>org.apache.tamaya.ext</groupId> - <name>Apache Tamaya Extension Modules - Expermimental Sandbox Modules</name> + <name>Apache Tamaya Extensions - Sandbox</name> <description>This project contains the several extensions that can be used with Tamaya, but that where not yet ready for production use or still under heavy discussion.</description> <packaging>pom</packaging> + <properties> + <commons-io.version>2.5</commons-io.version> + <findbugs.skip>false</findbugs.skip> + <jdkVersion>1.7</jdkVersion> + <osgi.version>6.0.0</osgi.version> + <maven.compile.targetLevel>${jdkVersion}</maven.compile.targetLevel> + <maven.compile.sourceLevel>${jdkVersion}</maven.compile.sourceLevel> + <maven.compile.optimize>false</maven.compile.optimize> + <maven.compile.deprecation>true</maven.compile.deprecation> + <maven.javadoc.skip>false</maven.javadoc.skip> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <json.spec.version>1.0-alpha-1</json.spec.version> + <junit.version>4.12</junit.version> + + <!-- Dependency and plugin relate version properties go here --> + <johnzon.version>0.9-incubating</johnzon.version> + + <!-- Keep the JRuby version in sync with the one used by Asciidoctor --> + <asciidoctor.version>1.5.2</asciidoctor.version> + <asciidoctor-diagramm.version>1.2.1</asciidoctor-diagramm.version> + <asciidoctorj.version>1.5.2</asciidoctorj.version> + <checkstyle.version>2.15</checkstyle.version> + <enforcer.version>1.4.1</enforcer.version> + <gem.plugin>1.0.7</gem.plugin> + <sources.plugin>3.0.1</sources.plugin> + <hamcrest.version>2.0.0.0</hamcrest.version> + <javadoc.version>2.10.4</javadoc.version> + <!-- Must/should match the JRuby version used by AsciidoctorJ --> + <jruby.version>1.7.20</jruby.version> + <findbugs.version>3.0.4</findbugs.version> + <mockito.version>1.10.19</mockito.version> + <rat.version>0.12</rat.version> + <toolchains.plugin>1.1</toolchains.plugin> + + <!-- Dependencies for site generation --> + <reflow-skin.version>1.1.1</reflow-skin.version> + <released_version>0.2-incubating</released_version> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.johnzon</groupId> + <artifactId>johnzon-core</artifactId> + <version>${johnzon.version}</version> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <version>1.3</version> + </dependency> + </dependencies> + </dependencyManagement> + <modules> <module>apache-commons</module> <module>jodatime</module> - <module>metamodel-simple</module> - <module>metamodel-staged</module> + <module>usagetracker</module> + <module>validation</module> <module>remote</module> - <module>sysprops</module> - <module>ui</module> + <module>configured-sysprops</module> + <module>etcd</module> + <module>consul</module> + <module>camel</module> + <module>propertysources</module> + <!--<module>ui</module>--> + <!--<module>osgi</module>--> + <module>management</module> + <!--<module>metamodel</module>--> </modules> </project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/propertysources/pom.xml ---------------------------------------------------------------------- diff --git a/propertysources/pom.xml b/propertysources/pom.xml new file mode 100644 index 0000000..0398cf6 --- /dev/null +++ b/propertysources/pom.xml @@ -0,0 +1,90 @@ +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-sandbox</artifactId> + <version>0.3-incubating-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + <artifactId>tamaya-propertysources</artifactId> + <name>Apache Tamaya Modules - PropertySources</name> + <description>A collection of simple property sources and property source providers.</description> + <packaging>bundle</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-core</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-resources</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-formats</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Import-Package> + org.apache.tamaya, + org.apache.tamaya.spi, + org.apache.tamaya.format, + javax.annotation, + * + </Import-Package> + <Export-Package> + org.apache.tamaya.metamodel.simple + </Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java new file mode 100644 index 0000000..03183f2 --- /dev/null +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/ConfigDirPropertySourceProvider.java @@ -0,0 +1,81 @@ +/* + * 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.propertysources; + + +import org.apache.tamaya.format.ConfigurationData; +import org.apache.tamaya.format.ConfigurationFormats; +import org.apache.tamaya.format.FlattenedDefaultPropertySource; +import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; +import org.apache.tamaya.spi.PropertySource; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Created by Anatole on 20.03.2015. + */ +public class ConfigDirPropertySourceProvider extends AbstractPathPropertySourceProvider { + + public ConfigDirPropertySourceProvider() { + super(getConfigLocation()); + } + + private static String getConfigLocation() { + String location = System.getProperty("configdir"); + if (location == null) { + location = "./config"; + } + if (!location.endsWith("/")) { + location += "/"; + } + if (!location.startsWith("file:")) { + location = "file:" + location; + } + return location + "**/*.*"; + } + + @Override + protected Collection<PropertySource> getPropertySources(URL url) { + try { + ConfigurationData config = ConfigurationFormats.readConfigurationData(url); + if (config == null) { + Logger.getLogger(getClass().getName()).log(Level.INFO, + "Failed to read configuration from " + url); + return Collections.emptySet(); + } + return asCollection(new FlattenedDefaultPropertySource(config)); + } catch (Exception e) { + Logger.getLogger(getClass().getName()).log(Level.SEVERE, + "Failed to read configuration from " + url, e); + return Collections.emptySet(); + } + } + + private Collection<PropertySource> asCollection(PropertySource propertySource) { + List<PropertySource> result = new ArrayList<>(1); + result.add(propertySource); + return result; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/propertysources/src/main/java/org/apache/tamaya/propertysources/FileProprtyStoreProviderSpi.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/FileProprtyStoreProviderSpi.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/FileProprtyStoreProviderSpi.java new file mode 100644 index 0000000..ea661e5 --- /dev/null +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/FileProprtyStoreProviderSpi.java @@ -0,0 +1,85 @@ +///* +// * 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.propertysources; +// +//import com.hazelcast.config.Config; +//import com.hazelcast.config.GroupConfig; +//import com.hazelcast.core.Hazelcast; +//import com.hazelcast.core.HazelcastInstance; +//import org.apache.tamaya.spi.ServiceContextManager; +//import org.apache.tamaya.store.PropertyStore; +//import org.apache.tamaya.store.spi.PropertyStoreProviderSpi; +// +//import java.util.Map; +//import java.util.ServiceLoader; +//import java.util.concurrent.ConcurrentHashMap; +//import java.util.logging.Level; +//import java.util.logging.Logger; +// +///** +// * SPI implmentation for a providing Hazelcast based PropertyStores. +// */ +//public class FileProprtyStoreProviderSpi implements PropertyStoreProviderSpi { +// private static final String CONFIG_CLASS_SYS_PROP = "tamaya.store.file.configClass"; +// private static final String CONFIG_GROUP_SYS_PROP = "tamaya.store.file.groupName"; +// +// private static final Logger LOG = Logger.getLogger(HazelcastProprtyStoreProviderSpi.class.getName()); +// +// private File file; +// private Map<String,HazelcastProprtyStore> stores = new ConcurrentHashMap<>(); +// +// public HazelcastProprtyStoreProviderSpi() { +// String customConfig = System.getProperty(CONFIG_CLASS_SYS_PROP); +// Config config = null; +// if(customConfig!=null){ +// try { +// config = (Config)Class.forName(customConfig).newInstance(); +// LOG.info("Successfully created custom store config for HazelCast store: " + customConfig); +// } catch (Exception e) { +// LOG.log(Level.SEVERE, "Failed to instantiate custom store config for HazelCast store: " + customConfig, e); +// } +// } +// if(config==null){ +// config = ServiceContextManager.getServiceContext().getService(Config.class); +// } +// if(config==null) { +// config = new Config(); +// GroupConfig gc = new GroupConfig(); +// String groupName = System.getProperty(CONFIG_GROUP_SYS_PROP, "Tamaya"); +// gc.setName(groupName); +// config.setGroupConfig(gc); +// } +// LOG.info("Starting HazelCast storage with config: " + config); +// store = Hazelcast.getOrCreateHazelcastInstance(config); +// } +// +// @Override +// public PropertyStore getPropertyStore(String storeId) { +// HazelcastProprtyStore propertyStore = stores.get(storeId); +// if(propertyStore==null){ +// LOG.info("Creating new distributed configuration map in HazelCast store for " + storeId + "..."); +// propertyStore = new HazelcastProprtyStore(store, storeId); +// this.stores.put(storeId, propertyStore); +// } +// return propertyStore; +// } +// +// +// +//} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/propertysources/src/main/java/org/apache/tamaya/propertysources/HazelcastProprtyStoreProviderSpi.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/HazelcastProprtyStoreProviderSpi.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/HazelcastProprtyStoreProviderSpi.java new file mode 100644 index 0000000..cdfcb77 --- /dev/null +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/HazelcastProprtyStoreProviderSpi.java @@ -0,0 +1,87 @@ +///* +// * 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.propertysources; +// +//import com.hazelcast.config.Config; +//import com.hazelcast.config.GroupConfig; +//import com.hazelcast.core.Hazelcast; +//import com.hazelcast.core.HazelcastInstance; +//import org.apache.tamaya.spi.ServiceContextManager; +//import org.apache.tamaya.store.PropertyStore; +//import org.apache.tamaya.store.spi.PropertyStoreProviderSpi; +// +//import java.util.Map; +//import java.util.ServiceLoader; +//import java.util.concurrent.ConcurrentHashMap; +//import java.util.logging.Level; +//import java.util.logging.Logger; +// +///** +// * SPI implmentation for a providing Hazelcast based PropertyStores. +// */ +//public class HazelcastProprtyStoreProviderSpi implements PropertyStoreProviderSpi { +// private static final String CONFIG_CLASS_SYS_PROP = "tamaya.store.hazelcast.configClass"; +// private static final String CONFIG_GROUP_SYS_PROP = "tamaya.store.hazelcast.groupName"; +// +// +// +// private static final Logger LOG = Logger.getLogger(HazelcastProprtyStoreProviderSpi.class.getName()); +// +// private HazelcastInstance store; +// private Map<String,HazelcastProprtyStore> stores = new ConcurrentHashMap<>(); +// +// public HazelcastProprtyStoreProviderSpi() { +// String customConfig = System.getProperty(CONFIG_CLASS_SYS_PROP); +// Config config = null; +// if(customConfig!=null){ +// try { +// config = (Config)Class.forName(customConfig).newInstance(); +// LOG.info("Successfully created custom store config for HazelCast store: " + customConfig); +// } catch (Exception e) { +// LOG.log(Level.SEVERE, "Failed to instantiate custom store config for HazelCast store: " + customConfig, e); +// } +// } +// if(config==null){ +// config = ServiceContextManager.getServiceContext().getService(Config.class); +// } +// if(config==null) { +// config = new Config(); +// GroupConfig gc = new GroupConfig(); +// String groupName = System.getProperty(CONFIG_GROUP_SYS_PROP, "Tamaya"); +// gc.setName(groupName); +// config.setGroupConfig(gc); +// } +// LOG.info("Starting HazelCast storage with config: " + config); +// store = Hazelcast.getOrCreateHazelcastInstance(config); +// } +// +// @Override +// public PropertyStore getPropertyStore(String storeId) { +// HazelcastProprtyStore propertyStore = stores.get(storeId); +// if(propertyStore==null){ +// LOG.info("Creating new distributed configuration map in HazelCast store for " + storeId + "..."); +// propertyStore = new HazelcastProprtyStore(store, storeId); +// this.stores.put(storeId, propertyStore); +// } +// return propertyStore; +// } +// +// +// +//} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java new file mode 100644 index 0000000..88164fa --- /dev/null +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/MetainfConfigPropertySourceProvider.java @@ -0,0 +1,62 @@ +/* + * 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.propertysources; + + +import org.apache.tamaya.format.ConfigurationData; +import org.apache.tamaya.format.ConfigurationFormats; +import org.apache.tamaya.format.FlattenedDefaultPropertySource; +import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; +import org.apache.tamaya.spi.PropertySource; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Created by Anatole on 20.03.2015. + */ +public class MetainfConfigPropertySourceProvider extends AbstractPathPropertySourceProvider { + + public MetainfConfigPropertySourceProvider() { + super("classpath:META-INF/config/**/*.*"); + } + + @Override + protected Collection<PropertySource> getPropertySources(URL url) { + try { + ConfigurationData config = ConfigurationFormats.readConfigurationData(url); + return asCollection(new FlattenedDefaultPropertySource(config)); + } catch (Exception e) { + Logger.getLogger(getClass().getName()).log(Level.SEVERE, + "Failed to read configuration from " + url, e); + return Collections.emptySet(); + } + } + + private Collection<PropertySource> asCollection(PropertySource propertySource) { + List<PropertySource> result = new ArrayList<>(1); + result.add(propertySource); + return result; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java ---------------------------------------------------------------------- diff --git a/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java b/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java new file mode 100644 index 0000000..ea81cbc --- /dev/null +++ b/propertysources/src/main/java/org/apache/tamaya/propertysources/PropertySourceBuilder.java @@ -0,0 +1,119 @@ +/* + * 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.propertysources; + +import org.apache.tamaya.core.propertysource.SimplePropertySource; +import org.apache.tamaya.spi.PropertySource; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Simple builder for building a {@link org.apache.tamaya.spi.PropertySource}. + */ +public final class PropertySourceBuilder { + /** The ordinal to be used. */ + private int ordinal; + /** The name to be used. */ + private final String name; + /** The properties. */ + private final Map<String,String> properties = new HashMap<>(); + + /** private constructor. */ + private PropertySourceBuilder(String name){ + this.name = Objects.requireNonNull(name); + } + + /** + * Gets a new instance of a builder. + * @param name The name of the property source, not null. + * @return a new instance. + */ + public static PropertySourceBuilder of(String name){ + return new PropertySourceBuilder(name); + } + + /** + * Gets a new instance of a builder. + * @param name The name of the property source, not null. + * @return a new instance. + */ + public static PropertySourceBuilder from(String name){ + return new PropertySourceBuilder(name); + } + + /** + * Sets a new property key/value. + * @param key the property key, not null. + * @param value the property value, not null. + * @return the bulder for chaining. + */ + public PropertySourceBuilder put(String key, String value){ + this.properties.put(key, value); + return this; + } + + /** + * Put all the given key, values. + * @param values the new key/values, not null. + * @return the bulder for chaining. + */ + public PropertySourceBuilder putAll(Map<String, String> values){ + this.properties.putAll(values); + return this; + } + + /** + * Sets the ordinal to be used explicitly (instead evaluating it using {@code tamaya.ordinal}. + * @param ordinal the explicit ordinal to be used. + * @return the bulder for chaining. + */ + public PropertySourceBuilder withOrdinal(int ordinal){ + this.ordinal = ordinal; + return this; + } + + /** + * Puts all values from the given property source. + * @param propertySource the property source, not null. + * @return the bulder for chaining. + */ + public PropertySourceBuilder putAll(PropertySource propertySource){ + this.properties.putAll(propertySource.getProperties()); + return this; + } + + /** + * Creates a new immutable {@link org.apache.tamaya.spi.PropertySource} instance. + * @return a new immutable {@link org.apache.tamaya.spi.PropertySource} instance, never null. + */ + public PropertySource build(){ + return new SimplePropertySource(name, properties); + } + + @Override + public String toString() { + return "PropertySourceBuilder{" + + "ordinal=" + ordinal + + ", name='" + name + '\'' + + ", properties=" + properties + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/remote/pom.xml ---------------------------------------------------------------------- diff --git a/remote/pom.xml b/remote/pom.xml index c8917f4..92f428e 100644 --- a/remote/pom.xml +++ b/remote/pom.xml @@ -22,7 +22,7 @@ under the License. <parent> <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-extensions</artifactId> + <artifactId>tamaya-sandbox</artifactId> <version>0.3-incubating-SNAPSHOT</version> <relativePath>..</relativePath> </parent> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/store-file/src/main/java/org/apache/tamaya/store/internal/FileProprtyStoreProviderSpi.java ---------------------------------------------------------------------- diff --git a/store-file/src/main/java/org/apache/tamaya/store/internal/FileProprtyStoreProviderSpi.java b/store-file/src/main/java/org/apache/tamaya/store/internal/FileProprtyStoreProviderSpi.java deleted file mode 100644 index 3ea768a..0000000 --- a/store-file/src/main/java/org/apache/tamaya/store/internal/FileProprtyStoreProviderSpi.java +++ /dev/null @@ -1,85 +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. - */ -package org.apache.tamaya.store.internal; - -import com.hazelcast.config.Config; -import com.hazelcast.config.GroupConfig; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import org.apache.tamaya.spi.ServiceContextManager; -import org.apache.tamaya.store.PropertyStore; -import org.apache.tamaya.store.spi.PropertyStoreProviderSpi; - -import java.util.Map; -import java.util.ServiceLoader; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * SPI implmentation for a providing Hazelcast based PropertyStores. - */ -public class FileProprtyStoreProviderSpi implements PropertyStoreProviderSpi { - private static final String CONFIG_CLASS_SYS_PROP = "tamaya.store.file.configClass"; - private static final String CONFIG_GROUP_SYS_PROP = "tamaya.store.file.groupName"; - - private static final Logger LOG = Logger.getLogger(HazelcastProprtyStoreProviderSpi.class.getName()); - - private File file; - private Map<String,HazelcastProprtyStore> stores = new ConcurrentHashMap<>(); - - public HazelcastProprtyStoreProviderSpi() { - String customConfig = System.getProperty(CONFIG_CLASS_SYS_PROP); - Config config = null; - if(customConfig!=null){ - try { - config = (Config)Class.forName(customConfig).newInstance(); - LOG.info("Successfully created custom store config for HazelCast store: " + customConfig); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Failed to instantiate custom store config for HazelCast store: " + customConfig, e); - } - } - if(config==null){ - config = ServiceContextManager.getServiceContext().getService(Config.class); - } - if(config==null) { - config = new Config(); - GroupConfig gc = new GroupConfig(); - String groupName = System.getProperty(CONFIG_GROUP_SYS_PROP, "Tamaya"); - gc.setName(groupName); - config.setGroupConfig(gc); - } - LOG.info("Starting HazelCast storage with config: " + config); - store = Hazelcast.getOrCreateHazelcastInstance(config); - } - - @Override - public PropertyStore getPropertyStore(String storeId) { - HazelcastProprtyStore propertyStore = stores.get(storeId); - if(propertyStore==null){ - LOG.info("Creating new distributed configuration map in HazelCast store for " + storeId + "..."); - propertyStore = new HazelcastProprtyStore(store, storeId); - this.stores.put(storeId, propertyStore); - } - return propertyStore; - } - - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi ---------------------------------------------------------------------- diff --git a/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi b/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi deleted file mode 100644 index f3199f2..0000000 --- a/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi +++ /dev/null @@ -1,18 +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 current 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. -# http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java ---------------------------------------------------------------------- diff --git a/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java b/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java deleted file mode 100644 index db567ac..0000000 --- a/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java +++ /dev/null @@ -1,87 +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. - */ -package org.apache.tamaya.store.internal; - -import com.hazelcast.config.Config; -import com.hazelcast.config.GroupConfig; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import org.apache.tamaya.spi.ServiceContextManager; -import org.apache.tamaya.store.PropertyStore; -import org.apache.tamaya.store.spi.PropertyStoreProviderSpi; - -import java.util.Map; -import java.util.ServiceLoader; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * SPI implmentation for a providing Hazelcast based PropertyStores. - */ -public class HazelcastProprtyStoreProviderSpi implements PropertyStoreProviderSpi { - private static final String CONFIG_CLASS_SYS_PROP = "tamaya.store.hazelcast.configClass"; - private static final String CONFIG_GROUP_SYS_PROP = "tamaya.store.hazelcast.groupName"; - - - - private static final Logger LOG = Logger.getLogger(HazelcastProprtyStoreProviderSpi.class.getName()); - - private HazelcastInstance store; - private Map<String,HazelcastProprtyStore> stores = new ConcurrentHashMap<>(); - - public HazelcastProprtyStoreProviderSpi() { - String customConfig = System.getProperty(CONFIG_CLASS_SYS_PROP); - Config config = null; - if(customConfig!=null){ - try { - config = (Config)Class.forName(customConfig).newInstance(); - LOG.info("Successfully created custom store config for HazelCast store: " + customConfig); - } catch (Exception e) { - LOG.log(Level.SEVERE, "Failed to instantiate custom store config for HazelCast store: " + customConfig, e); - } - } - if(config==null){ - config = ServiceContextManager.getServiceContext().getService(Config.class); - } - if(config==null) { - config = new Config(); - GroupConfig gc = new GroupConfig(); - String groupName = System.getProperty(CONFIG_GROUP_SYS_PROP, "Tamaya"); - gc.setName(groupName); - config.setGroupConfig(gc); - } - LOG.info("Starting HazelCast storage with config: " + config); - store = Hazelcast.getOrCreateHazelcastInstance(config); - } - - @Override - public PropertyStore getPropertyStore(String storeId) { - HazelcastProprtyStore propertyStore = stores.get(storeId); - if(propertyStore==null){ - LOG.info("Creating new distributed configuration map in HazelCast store for " + storeId + "..."); - propertyStore = new HazelcastProprtyStore(store, storeId); - this.stores.put(storeId, propertyStore); - } - return propertyStore; - } - - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore ---------------------------------------------------------------------- diff --git a/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore b/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore deleted file mode 100644 index 0833eac..0000000 --- a/store-ignite/src/main/resources/META-INF/services/org.apache.tamaya.store.PropertyStore +++ /dev/null @@ -1,19 +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 current 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.tamaya.store.internal.IgniteProprtyStore \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/sysprops/pom.xml ---------------------------------------------------------------------- diff --git a/sysprops/pom.xml b/sysprops/pom.xml deleted file mode 100644 index c40f4ea..0000000 --- a/sysprops/pom.xml +++ /dev/null @@ -1,89 +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 current 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-sandbox</artifactId> - <version>0.3-incubating-SNAPSHOT</version> - <relativePath>..</relativePath> - </parent> - <artifactId>tamaya-sysprops</artifactId> - <name>Apache Tamaya Modules - Configured Java SE System Properties</name> - <packaging>bundle</packaging> - - <build> - <plugins> - <plugin> - <groupId>org.jacoco</groupId> - <artifactId>jacoco-maven-plugin</artifactId> - <executions> - <execution> - <id>prepare-agent</id> - <goals> - <goal>prepare-agent</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Import-Package> - org.apache.tamaya, - org.apache.tamaya.spi, - org.apache.tamaya.resources, - org.apache.tamaya.spisupport, - org.apache.tamaya.functions, - javax.annotation, - * - </Import-Package> - <Export-Package> - org.apache.tamaya.integration.se - </Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>tamaya-core</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/sysprops/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java ---------------------------------------------------------------------- diff --git a/sysprops/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java b/sysprops/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java deleted file mode 100644 index cdef5be..0000000 --- a/sysprops/src/main/java/org/apache/tamaya/integration/se/ConfiguredSystemProperties.java +++ /dev/null @@ -1,353 +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. - */ -package org.apache.tamaya.integration.se; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.Collection; -import java.util.Enumeration; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.logging.Logger; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.Environment; - -/** - * Properties implementation class that can be applied as current System properties by calling - * {@link ConfiguredSystemProperties#install()}. The system properties will - * then behave contextually depending on the current runtime configuration active. - */ -public class ConfiguredSystemProperties extends Properties { - - private static final long serialVersionUID = 2152870929299226804L; - - private static final Logger LOG = Logger.getLogger(ConfiguredSystemProperties.class.getName()); - private Properties initialProperties; - private static volatile Map<String, Properties> contextualProperties = new ConcurrentHashMap<>(); - private static volatile Supplier<String> contextProvider = () -> - Environment.current().get("context.id").orElse("<system>"); - - - private final Object LOCK = new Object(); - - - private ConfiguredSystemProperties(Properties initialProperties) { - super(initialProperties); - this.initialProperties = initialProperties; - } - - public static void install() { - Properties props = System.getProperties(); - if (props instanceof ConfiguredSystemProperties) { - return; - } - ConfiguredSystemProperties systemProps = new ConfiguredSystemProperties(props); - LOG.finest("Installing enhanced system properties..."); - System.setProperties(systemProps); - LOG.info("Installed enhanced system properties successfully."); - } - - public static void uninstall() { - Properties props = System.getProperties(); - if (props instanceof ConfiguredSystemProperties) { - Properties initialProperties = ((ConfiguredSystemProperties) props).initialProperties; - LOG.finest("Uninstalling enhanced system properties..."); - System.setProperties(initialProperties); - LOG.info("Uninstalled enhanced system properties successfully."); - } - } - - @Override - public String getProperty(String key) { - return getContextualProperties().getProperty(key); - } - - @Override - public String getProperty(String key, String defaultValue) { - return getContextualProperties().getProperty(key, defaultValue); - } - - @Override - public Enumeration<?> propertyNames() { - return getContextualProperties().propertyNames(); - } - - @Override - public Set<String> stringPropertyNames() { - return getContextualProperties().stringPropertyNames(); - } - - @Override - public synchronized int size() { - return getContextualProperties().size(); - } - - @Override - public synchronized Enumeration<Object> keys() { - return getContextualProperties().keys(); - } - - @Override - public synchronized Enumeration<Object> elements() { - return getContextualProperties().elements(); - } - - @Override - public synchronized boolean contains(Object value) { - return getContextualProperties().contains(value); - } - - @Override - public boolean containsValue(Object value) { - return getContextualProperties().containsValue(value); - } - - @Override - public synchronized boolean containsKey(Object key) { - return getContextualProperties().containsKey(key); - } - - @Override - public synchronized Object get(Object key) { - return getContextualProperties().get(key); - } - - @Override - public synchronized Object clone() { - return getContextualProperties().clone(); - } - - @Override - public Set<Object> keySet() { - return getContextualProperties().keySet(); - } - - @Override - public Set<Map.Entry<Object, Object>> entrySet() { - return getContextualProperties().entrySet(); - } - - @Override - public Collection<Object> values() { - return getContextualProperties().values(); - } - - - @Override - public Object getOrDefault(Object key, Object defaultValue) { - return getContextualProperties().getOrDefault(key, defaultValue); - } - - @Override - public void forEach(BiConsumer<? super Object, ? super Object> action) { - getContextualProperties().forEach(action); - } - - - @Override - public Object computeIfAbsent(Object key, Function<? super Object, ?> mappingFunction) { - return getContextualProperties().computeIfAbsent(key, mappingFunction); - } - - @Override - public synchronized Object computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) { - return getContextualProperties().computeIfPresent(key, remappingFunction); - } - - @Override - public synchronized Object compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) { - return getContextualProperties().compute(key, remappingFunction); - } - - @Override - public String toString() { - return getContextualProperties().toString(); - } - - @Override - public synchronized Object setProperty(String key, String value) { - return getContextualProperties().setProperty(key, value); - } - - @Override - public synchronized void load(Reader reader) throws IOException { - getContextualProperties().load(reader); - } - - @Override - public synchronized void load(InputStream inStream) throws IOException { - getContextualProperties().load(inStream); - } - - @SuppressWarnings("deprecation") - @Override - public void save(OutputStream out, String comments) { - super.save(out, comments); - } - - @Override - public void store(Writer writer, String comments) throws IOException { - getContextualProperties().store(writer, comments); - } - - @Override - public void store(OutputStream out, String comments) throws IOException { - getContextualProperties().store(out, comments); - } - - @Override - public void loadFromXML(InputStream in) throws IOException { - getContextualProperties().loadFromXML(in); - } - - @Override - public void storeToXML(OutputStream os, String comment) throws IOException { - getContextualProperties().storeToXML(os, comment); - } - - @Override - public void storeToXML(OutputStream os, String comment, String encoding) throws IOException { - getContextualProperties().storeToXML(os, comment, encoding); - } - - @Override - public void list(PrintStream out) { - getContextualProperties().list(out); - } - - @Override - public void list(PrintWriter out) { - getContextualProperties().list(out); - } - - @Override - public boolean isEmpty() { - return getContextualProperties().isEmpty(); - } - - @Override - public Object put(Object key, Object value) { - return getContextualProperties().put(key, value); - } - - @Override - public Object remove(Object key) { - return getContextualProperties().remove(key); - } - - @Override - public void putAll(Map<?, ?> t) { - getContextualProperties().putAll(t); - } - - @Override - public void clear() { - getContextualProperties().clear(); - } - - @Override - public boolean equals(Object o) { - return getContextualProperties().equals(o); - } - - @Override - public int hashCode() { - return getContextualProperties().hashCode(); - } - - @Override - public void replaceAll(BiFunction<? super Object, ? super Object, ?> function) { - getContextualProperties().replaceAll(function); - } - - @Override - public Object putIfAbsent(Object key, Object value) { - return getContextualProperties().putIfAbsent(key, value); - } - - @Override - public boolean remove(Object key, Object value) { - return getContextualProperties().remove(key, value); - } - - @Override - public boolean replace(Object key, Object oldValue, Object newValue) { - return getContextualProperties().replace(key, oldValue, newValue); - } - - @Override - public Object replace(Object key, Object value) { - return getContextualProperties().replace(key, value); - } - - @Override - public Object merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) { - return getContextualProperties().merge(key, value, remappingFunction); - } - - public Properties getInitialProperties() { - return initialProperties; - } - - /** - * Uninstalls the contextual system properties for the current context, as determined by the current - * context provider active. - */ - public static void resetProperties() { - String contextId = contextProvider == null ? "" : contextProvider.get(); - contextualProperties.remove(contextId); - } - - protected Properties getContextualProperties() { - String contextId = contextProvider == null ? "" : contextProvider.get(); - Properties props = ConfiguredSystemProperties.contextualProperties.get(contextId); - if (props == null) { - synchronized (LOCK) { - props = ConfiguredSystemProperties.contextualProperties.get(contextId); - if (props == null) { - props = createNewProperties(); - contextualProperties.put(contextId, props); - } - } - } - return props; - } - - protected Properties createNewProperties() { - Properties props = new Properties(initialProperties); - Configuration config = Configuration.current(); - Map<String, String> configMap = config.getProperties(); - for (Map.Entry<String, String> en : configMap.entrySet()) { - props.put(en.getKey(), en.getValue()); - } - return props; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/tamaya-classloader-support/pom.xml ---------------------------------------------------------------------- diff --git a/tamaya-classloader-support/pom.xml b/tamaya-classloader-support/pom.xml deleted file mode 100644 index 2add22a..0000000 --- a/tamaya-classloader-support/pom.xml +++ /dev/null @@ -1,73 +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 current 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-extensions</artifactId> - <version>0.3-incubating-SNAPSHOT</version> - </parent> - - <artifactId>tamaya-classloader-support</artifactId> - <name>Apache Tamaya Modules - Classloader Support</name> - <description>Apache Tamaya Classloader Support registers a ConfigurationContext that leverages - classloader hierarchies. Also visibility of features and components is aligned with the - corresponding hierarchy of classloaders.</description> - <packaging>bundle</packaging> - - <properties> - <jdkVersion>1.7</jdkVersion> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-spisupport</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Export-Package> - org.apache.tamaya.clsupport - </Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/AbstractClassloaderAwareItemLoader.java ---------------------------------------------------------------------- diff --git a/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/AbstractClassloaderAwareItemLoader.java b/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/AbstractClassloaderAwareItemLoader.java deleted file mode 100644 index 0145d1f..0000000 --- a/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/AbstractClassloaderAwareItemLoader.java +++ /dev/null @@ -1,268 +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. - */ -package org.apache.tamaya.clsupport; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * <p>This class implements an abstract base class, which basically provides a loading mechanism that supports - * loading and managing resources along the classloader hierarchies individually. It ensures resources are loaded - * and stored related to the each target classloader within the hierarchy individually. Additionally it enables - * mechanisms to ensure an item T is not loaded multiple times, when traversing up the classloader hierarchy.</p> - * - * <p>Finally classloaders are not stored by reference by this class, to ensure they still can be garbage collected. - * Instead this class uses the fully qualified class name of the loader and the corresponsing hashCode as returned - * by {@link Objects#hashCode(Object)}.</p> - * - * @param <T> the managed item type. - */ -public abstract class AbstractClassloaderAwareItemLoader<T> { - /** - * The logger used. - */ - private static final Logger LOG = Logger.getLogger(AbstractClassloaderAwareItemLoader.class.getName()); - /** - * The items managed, related to their classloader. - */ - private final Map<String, T> items = new ConcurrentHashMap<>(); - - /** - * Creates a new instance, using the current Thread context classloader, or - if null - the classloader that - * loaded this class for initially initializing the loader instance. - */ - public AbstractClassloaderAwareItemLoader() { - this(getDefaultClassLoader()); - } - - /** - * Creates a new instance, using the class loader given for initializing the resources loaded. - * - * @param classLoader the target top level classloader, not null. - */ - public AbstractClassloaderAwareItemLoader(ClassLoader classLoader) { - loadItems(classLoader); - } - - /** - * Loads the items for the given classloader and all its parent classloaders. This method will not update - * the items already found for any class loader involved. - * - * @param classLoader the target top level classloader, not null. - */ - public void loadItems(ClassLoader classLoader) { - loadItems(classLoader, false); - } - - /** - * Loads the items for the given classloader and all its parent classloaders. - * - * @param classLoader the target top level classloader, not null. - * @param update if set to true, resources not visible on former runs are added during this load. - */ - public void loadItems(ClassLoader classLoader, boolean update) { - this.items.clear(); - List<ClassLoader> cls = new ArrayList<>(); - cls.add(classLoader); - ClassLoader cl = classLoader.getParent(); - while (cl != null) { - cls.add(cl); - cl = cl.getParent(); - } - // Start with the parent classloader and then go up... - for (int i = cls.size() - 1; i <= 0; i--) { - ClassLoader curCL = cls.get(i); - String clKey = getClassLoaderID(curCL); - T itemFound = items.get(clKey); - try { - if (itemFound != null) { - updateItem(itemFound, curCL); - } else { - items.put(clKey, createItem(curCL)); - } - } catch (Exception e) { - LOG.log(Level.SEVERE, - "Error loading from classloader: " + curCL, e); - } - } - } - - /** - * Creates a new item for being stored linked with the given lassloader. - * - * @param classLoader the classloader, not null. - * @return the new item loaded. - */ - protected abstract T createItem(ClassLoader classLoader); - - /** - * Creates a new item for being stored linked with the given lassloader. - * - * @param currentItemSet the current found ItemContainer instance to be updated. - * @param classLoader the classloader, not null. - */ - protected abstract void updateItem(T currentItemSet, ClassLoader classLoader); - - /** - * Evaluates a String key for identfying a classloader instance, based on the loader class and its hashCode. - * This prevents the storage of classloader references as keys and therefore enables classloaders not used anymore - * to be garbage collected. - * - * @param classLoader {@link ClassLoader} to be identified, must not be {@code null}. - * @return the unique key for the given classloader - */ - public static String getClassLoaderID(ClassLoader classLoader) { - return classLoader.getClass().getName() + Objects.hash(classLoader); - } - - /** - * Evaluates a String key for identfying a classloader instance, based on the loader class and its hashCode. - * This prevents the storage of classloader references as keys and therefore enables classloaders not used anymore - * to be garbage collected. - * - * @return the unique key for the current default classloader as returned by #getDefaultClassLoader. - */ - public static String getClassLoaderID() { - return getClassLoaderID(getDefaultClassLoader()); - } - - /** - * Get all items valid for the current thread context class loader, or - if null - the classloader that loaded - * this class. - * - * @return the items found, never null. - */ - public Set<T> getItems() { - return getItems(getDefaultClassLoader()); - } - - /** - * Get all items found for the given classloader and all its parent classloaders. - * - * @param classLoader the target top level classloader, not null. - * @return the items found, never null. - */ - public Set<T> getItems(ClassLoader classLoader) { - Set<T> result = new HashSet<>(); - ClassLoader cl = classLoader; - while (cl != null) { - T item = getItemNoParent(cl, true); - result.add(item); - cl = cl.getParent(); - } - return result; - } - - /** - * Get all items valid for the parent class loader of the current thread context class loader, or - if null - the - * parent of the classloader that loaded this class. This allows - * to build a delta list of instances only visible on the target classloader given. - * - * @return the items found, never null. - */ - public Set<T> getParentItems() { - return getParentItems(getDefaultClassLoader()); - } - - /** - * Get all items found for the parent of the given classloader and all its parent classloaders. This allows - * to build a delta list of instances only visible on the target classloader given. - * - * @param classLoader the target top level classloader, not null. - * @return the items found, never null. - */ - public Set<T> getParentItems(ClassLoader classLoader) { - Set<T> result = new HashSet<>(); - ClassLoader cl = classLoader.getParent(); - while (cl != null) { - T item = getItemNoParent(cl, true); - result.add(item); - cl = cl.getParent(); - } - return result; - } - - /** - * Return the item assigned to the current thread context class loader or - if null - the class that loaded - * this class. If not yet loaded this method will NOT trigger a load. - * - * @return the item attached, or null. - */ - public T getItemNoParent() { - return getItemNoParent(getDefaultClassLoader(), false); - } - - /** - * Return the item assigned to the current thread context class loader or - if null - the class that loaded - * this class. - * - * @param loadIfMissing Flag that allows to define if this method will trigger an item load, when no item is loaded - * for the current class loader. - * @return the item attached, or null. - */ - public T getItemNoParent(boolean loadIfMissing) { - return getItemNoParent(getDefaultClassLoader(), loadIfMissing); - } - - /** - * Return the item assigned to the current thread context class loader or - if null - the class that loaded - * this class. - * - * @param classLoader the target top level classloader, not null. - * @param loadIfMissing Flag that allows to define if this method will trigger an item load, when no item is loaded - * for the current class loader. - * @return the item attached, or null. If {@code loadIfMissing} is set to true, the result is normally not to be - * expected to be null. - */ - public T getItemNoParent(ClassLoader classLoader, boolean loadIfMissing) { - String clKey = getClassLoaderID(classLoader); - T item = items.get(clKey); - if (item == null) { - if (loadIfMissing) { - item = createItem(classLoader); - this.items.put(clKey, item); - } - } - return item; - } - - - /** - * Utility method that either returns the current thread context classloader or - * - if not available - the classloader that loaded this class. - * @return the default classloader to be used, if no explicit classloader has been passed. - */ - public static ClassLoader getDefaultClassLoader() { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = AbstractClassloaderAwareItemLoader.class.getClassLoader(); - } - return cl; - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java ---------------------------------------------------------------------- diff --git a/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java b/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java deleted file mode 100644 index 94e5fb5..0000000 --- a/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareConfigurationContext.java +++ /dev/null @@ -1,105 +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. - */ -package org.apache.tamaya.clsupport; - -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spisupport.DefaultConfigurationContext; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.ConfigurationContextBuilder; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValueCombinationPolicy; - -import javax.annotation.Priority; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - -/** - * Default Implementation of a simple ConfigurationContext. - */ -@Priority(100) -public class CLAwareConfigurationContext implements ConfigurationContext { - - /** The logger used. */ - private final static Logger LOG = Logger.getLogger(CLAwareConfigurationContext.class.getName()); - - private final ContextManager contextManager = new ContextManager(); - - - @Override - public void addPropertySources(PropertySource... propertySourcesToAdd) { - contextManager.getItemNoParent(true).addPropertySources(propertySourcesToAdd); - } - - @Override - public List<PropertySource> getPropertySources() { - return contextManager.getItemNoParent(true).getPropertySources(); - } - - @Override - public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) { - contextManager.getItemNoParent(true).addPropertyConverter(typeToConvert, propertyConverter); - } - - @Override - public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() { - return contextManager.getItemNoParent(true).getPropertyConverters(); - } - - @Override - public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) { - return contextManager.getItemNoParent(true).getPropertyConverters(targetType); - } - - @Override - public List<PropertyFilter> getPropertyFilters() { - return contextManager.getItemNoParent(true).getPropertyFilters(); - } - - @Override - public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){ - return contextManager.getItemNoParent(true).getPropertyValueCombinationPolicy(); - } - - @Override - public ConfigurationContextBuilder toBuilder() { - return contextManager.getItemNoParent(true).toBuilder(); - } - - - /** - * Subcomponent managing {@link ConfigurationContext} instances, one per classloader. - */ - private static final class ContextManager extends AbstractClassloaderAwareItemLoader<ConfigurationContext>{ - - @Override - protected ConfigurationContext createItem(ClassLoader classLoader) { - // Simply create a complete configuration manager for every classloader. Maybe we will optimize this at a - // later stage in the project but as for now it is the most simple working solution. - return new DefaultConfigurationContext(); - } - - @Override - protected void updateItem(ConfigurationContext currentItemSet, ClassLoader classLoader) { - // ignore, currently not supported. - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/041f5998/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java ---------------------------------------------------------------------- diff --git a/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java b/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java deleted file mode 100644 index a5d1700..0000000 --- a/tamaya-classloader-support/src/main/java/org/apache/tamaya/clsupport/CLAwareServiceContext.java +++ /dev/null @@ -1,248 +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. - */ -package org.apache.tamaya.clsupport; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.spi.ServiceContext; - -import javax.annotation.Priority; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * <p>This class implements a {@link ServiceContext}, which basically provides a similar loading mechanism as used - * by the {@link java.util.ServiceLoader}. Whereas the {@link java.util.ServiceLoader} only loads configurations - * and instances from one classloader, this loader manages configs found and the related instances for each - * classloader along the classloader hierarchies individually. It ensures instances are loaded on the classloader - * level, where they first are visible. Additionally it ensures the same configuration resource (and its - * declared services) are loaded multiple times, when going up the classloader hierarchy.</p> - * - * <p>Finally classloaders are not stored by reference by this class, to ensure they still can be garbage collected. - * Refer also the inherited parent class for further details.</p> - * - * <p>This class uses an ordinal of {@code 10}, so it overrides any default {@link ServiceContext} implementations - * provided with the Tamaya core modules.</p> - */ -@Priority(10) -public class CLAwareServiceContext extends AbstractClassloaderAwareItemLoader<ServiceContainer> - implements ServiceContext{ - - private static final Logger LOG = Logger.getLogger(CLAwareServiceContext.class.getName()); - - /** - * Default location for service loader files. - */ - private static final String PREFIX = "META-INF/services/"; - - /** - * Constructor, using the current default classloader as defined by - * {@link AbstractClassloaderAwareItemLoader#getDefaultClassLoader()}. - */ - public CLAwareServiceContext(){ - super(); - } - - /** - * Constructor, using the given classloader. - * @param classLoader the target classloader for initializing of services, not null. - */ - public CLAwareServiceContext(ClassLoader classLoader) { - super(classLoader); - } - - - /** - * Implementation that creates a {@link ServiceContainer}, which manages all configs and instances loaded - * for a given classloader. - * @param classLoader the classloader, not null. - * @return a new empty, {@link ServiceContainer} instance. - */ - @Override - protected ServiceContainer createItem(ClassLoader classLoader) { - if(LOG.isLoggable(Level.INFO)) { - LOG.info("Loading services for classloader: " + classLoader); - } - return new ServiceContainer(classLoader); - } - - @Override - protected void updateItem(ServiceContainer currentContainer, ClassLoader classLoader) { - // nothing to be done here, since we dont have a specific target type. - } - - @Override - public int ordinal() { - return 10; - } - - /** - * This method tries to evaluate the current singleton from the {@link ServiceContainer} attached to the - * current classloader. If not found the singleton instance is evaluated based on the priorities - * assigned for all known providers. The resulting instance is then cached and always returned as - * singleton instance fomr this loader, when the same current classloader instance is active. - * @param serviceType the service type. - * @param <T> the type - * @return the item found, or null. - */ - @Override - public <T> T getService(Class<T> serviceType) { - return getService(serviceType, getDefaultClassLoader()); - } - - /** - * Evaluates the current singleton instance using the given classloader context. - * @param serviceType the service type. - * @param classLoader the classloader, not null. - * @param <T> the type - * @return the item found, or null. - */ - public <T> T getService(Class<T> serviceType, ClassLoader classLoader) { - if(LOG.isLoggable(Level.INFO)) { - LOG.info("Evaluating services for classloader: " + classLoader); - } - ServiceContainer container = getItemNoParent(classLoader, true); - T singleton = container.getSingleton(serviceType); - if(singleton!=null){ - if(LOG.isLoggable(Level.FINEST)) { - LOG.finest("Evaluated singleton of type " + serviceType.getName() + " to " + singleton); - } - return singleton; - } - Collection<? extends T> services = getServices(serviceType, classLoader); - if (services.isEmpty()) { - singleton = null; - } else { - singleton = getServiceWithHighestPriority(services, serviceType); - } - if(singleton!=null) { - container.setSingleton(serviceType, singleton); - } - if(LOG.isLoggable(Level.FINEST)) { - LOG.finest("Evaluated singleton of type " + serviceType.getName() + " to " + singleton); - } - return singleton; - } - - /** - * Gets the services visible. - * @param serviceType - * the service type. - * @param <T> the type param - * @return the services visible for the current classloader. - */ - @Override - public <T> List<T> getServices(Class<T> serviceType) { - return getServices(serviceType, AbstractClassloaderAwareItemLoader.getDefaultClassLoader()); - } - - /** - * Gets the services visible. - * @param serviceType the service type. - * @param classLoader the classloader - * @param <T> the type param - * @return the services visible for the current classloader. - */ - public <T> List<T> getServices(Class<T> serviceType, ClassLoader classLoader) { - List<T> services = new ArrayList<>(); - ClassLoader cl = classLoader; - List<ServiceContainer> containers = new ArrayList<>(); - while(cl!=null) { - ServiceContainer container = getItemNoParent(cl, true); - containers.add(container); - cl = cl.getParent(); - } - List<ServiceContainer> prevContainers = new ArrayList<>(); - Collections.reverse(containers); - for(ServiceContainer container: containers) { - if (!container.isTypeLoaded(serviceType)) { - container.loadServices(serviceType, prevContainers); - } - services.addAll(container.getServices(serviceType)); - prevContainers.add(container); - } - if(LOG.isLoggable(Level.FINEST)) { - LOG.finest("Evaluated services of type " + serviceType.getName() + " to " + services); - } - return services; - } - - /** - * @param services to scan - * @param <T> type of the service - * - * @return the service with the highest {@link javax.annotation.Priority#value()} - * - * @throws ConfigException if there are multiple service implementations with the maximum priority - */ - private <T> T getServiceWithHighestPriority(Collection<? extends T> services, Class<T> serviceType) { - - // we do not need the priority stuff if the list contains only one element - if (services.size() == 1) { - return services.iterator().next(); - } - - Integer highestPriority = null; - int highestPriorityServiceCount = 0; - T highestService = null; - - for (T service : services) { - int prio = getPriority(service); - if (highestPriority == null || highestPriority < prio) { - highestService = service; - highestPriorityServiceCount = 1; - highestPriority = prio; - } else if (highestPriority == prio) { - highestPriorityServiceCount++; - } - } - if (highestPriorityServiceCount > 1) { - throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}", - highestPriorityServiceCount, - serviceType.getName(), - highestPriority, - services)); - } - return highestService; - } - - /** - * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such - * annotation is present, a default priority is returned (1); - * @param o the instance, not null. - * @return a priority, by default 1. - */ - public static int getPriority(Object o){ - int prio = 0; - Priority priority = o.getClass().getAnnotation(Priority.class); - if (priority != null) { - prio = priority.value(); - } - if(LOG.isLoggable(Level.FINEST)) { - LOG.finest("Evaluated priority for " + o.getClass().getName() + " to " + prio); - } - return prio; - } - -}
