You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2016/09/06 17:18:06 UTC
[10/50] [abbrv] incubator-tamaya-sandbox git commit: TAMAYA-116:
Moved Sabot CDI module to extension section. Added docs.
TAMAYA-116: Moved Sabot CDI module to extension section. Added docs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/5105df0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/5105df0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/5105df0e
Branch: refs/heads/master
Commit: 5105df0ef5ff12450fb687f7036cba2daa8469af
Parents: 7b9d4e6
Author: anatole <an...@apache.org>
Authored: Mon Oct 12 07:14:59 2015 +0200
Committer: anatole <an...@apache.org>
Committed: Mon Oct 12 08:02:09 2015 +0200
----------------------------------------------------------------------
.../ClasspathPropertiesEnvironmentProvider.java | 167 ------------
.../environment/internal/package-info.java | 22 --
.../tamaya/integration/cdi2/ConfigDefault.java | 41 ---
.../integration/cdi2/ConfigDefaultSections.java | 43 ----
.../tamaya/integration/cdi2/ConfigProperty.java | 80 ------
.../cdi2/ConfigurationExtension.java | 257 -------------------
.../integration/cdi2/ConfigurationProducer.java | 115 ---------
.../integration/cdi2/WithConfigOperator.java | 45 ----
.../integration/cdi2/WithPropertyConverter.java | 45 ----
.../cdi2/src/main/resources/META-INF/beans.xml | 1 -
.../javax.enterprise.inject.spi.Extension | 1 -
.../META-INF/javaconfiguration.properties | 14 -
integration/pom.xml | 4 +-
...he.tamaya.store.spi.PropertyStoreProviderSpi | 18 ++
.../HazelcastProprtyStoreProviderSpi.java | 87 +++++++
integration/store/pom.xml | 54 ++++
.../org/apache/tamaya/store/PropertyStore.java | 64 +++++
.../tamaya/store/PropertyStoreProvider.java | 78 ++++++
.../tamaya/store/WritablePropertySource.java | 66 +++++
.../store/spi/DefaultStoredPropertySource.java | 137 ++++++++++
.../store/spi/PropertyStoreProviderSpi.java | 34 +++
.../tamaya/zookeeper/EmbeddedKafkaCluster.java | 138 ----------
.../tamaya/zookeeper/EmbeddedZookeeper.java | 95 -------
metamodels/pom.xml | 1 +
24 files changed, 541 insertions(+), 1066 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java b/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
deleted file mode 100644
index d9767e5..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/ClasspathPropertiesEnvironmentProvider.java
+++ /dev/null
@@ -1,167 +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.environment.internal;
-
-
-import org.apache.tamaya.environment.spi.BaseEnvironmentPropertySourceProvider;
-import org.apache.tamaya.spisupport.SimplePropertiesPropertySource;
-import org.apache.tamaya.resource.ConfigResources;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spisupport.BasePropertySource;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
-
-/**
- * Configuration provider that resolves to a location in the classpath.
- * Hereby the following system properties can be set to configure the provider
- * (all entries are optional):
- * <pre>
- * env.STAGE : ordered list of configs to be loaded, e.g. GLOBAL,TEST,DEV
- * env.ROOT : root context of the environment, by default ENV
- * </pre>
- * Adding {@code System.getenv()} as stage maps the current environment properties using
- * the priority to be aliged with the context ordering, defined by {@code env.STAGE}.
- */
-public class ClasspathPropertiesEnvironmentProvider extends BaseEnvironmentPropertySourceProvider {
-
- private static final String STAGE_PROP = "env.STAGE";
-
- private static final String ROOT_PROP = "env.ROOT";
-
- private static final Logger LOGGER = Logger.getLogger(ClasspathPropertiesEnvironmentProvider.class.getName());
-
- private String rootLocation;
-
- private static final String DEFAULT_ENV = "System.getenv()";
-
-
- public ClasspathPropertiesEnvironmentProvider(){
- super(evaluateRoot(), evaluateStages());
- }
-
- private static String evaluateRoot() {
- String value = System.getProperty(ROOT_PROP);
- if(value==null) {
- value = System.getenv(ROOT_PROP);
- }
- if(value==null){
- value = "ENV";
- }
- return value;
- }
-
- private static String[] evaluateStages() {
- String value = System.getProperty(STAGE_PROP);
- if(value==null) {
- value = System.getenv(STAGE_PROP);
- }
- if(value==null){
- value = "System.getenv(),GLOBAL,DEVELOPMENT";
- }
- return value.split(",");
- }
-
- @Override
- protected Collection<PropertySource> loadEnvProperties(
- String environmentRootContext, String contextId, int priority) {
- List<PropertySource> result = new ArrayList<>();
- if (DEFAULT_ENV.equals(contextId)){
- result.add(new EnvPropertiesPropertySource(environmentRootContext, priority));
- }
- else{
- loadProperties(environmentRootContext, contextId, priority, result);
- }
- return result;
- }
-
- private void loadProperties(String environmentRootContext, String contextId, int priority, List<PropertySource> result) {
- String cpExp = getBaseResourcePath()+'/' +contextId+".properties";
- if(cpExp.startsWith("/")){
- cpExp = cpExp.substring(1);
- }
- for(URL url: ConfigResources.getResourceResolver().getResources(cpExp)){
- result.add(new SimplePropertiesPropertySource(environmentRootContext, url, priority));
- }
- }
-
- /**
- * Get the basic resource path used for lookup of properties files.
- * @return the basic resource path, never null.
- */
- protected String getBaseResourcePath() {
- return "";
- }
-
- private static final class EnvPropertiesPropertySource extends BasePropertySource{
-
- private final int priority;
-
- private Map<String, String> envProps = new HashMap<>();
-
- public EnvPropertiesPropertySource(int priority) {
- this(null, priority);
- }
-
- public EnvPropertiesPropertySource(String environmentRootContext, int priority){
- this.priority = priority;
- if(environmentRootContext==null){
- envProps.putAll(System.getenv());
- }
- else{
- for(Map.Entry<String,String> en: System.getenv().entrySet()){
- String prefix = environmentRootContext;
- if(!prefix.endsWith(".")){
- prefix += ".";
- }
- envProps.put(prefix+en.getKey(), en.getValue());
- }
- }
- this.envProps = Collections.unmodifiableMap(envProps);
- }
-
- @Override
- public String getName() {
- return "System.getenv()";
- }
-
- @Override
- public Map<String, String> getProperties() {
- return this.envProps;
- }
-
- @Override
- public int getOrdinal(){
- return priority;
- }
-
- @Override
- public String toString() {
- return "EnvPropertiesPropertySource{" +
- "priority=" + priority +
- '}';
- }
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
----------------------------------------------------------------------
diff --git a/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java b/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
deleted file mode 100644
index 3f5b53f..0000000
--- a/environment/src/main/java/org/apache/tamaya/environment/internal/package-info.java
+++ /dev/null
@@ -1,22 +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.
- */
-/**
- * Contains the provided implementation classes for the environment module.
- */
-package org.apache.tamaya.environment.internal;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java b/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
deleted file mode 100644
index 420f1fd..0000000
--- a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefault.java
+++ /dev/null
@@ -1,41 +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.cdi2;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define a default keys to be returned, when no configured keys could be
- * determined for a property/template accessor. The keys hereby can also contain a
- * dynamic expression that is evaluated by the configuration system.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
-public @interface ConfigDefault {
-
- /**
- * The default keys to be injected, if no such configuration entry was found. If keys was found and no default
- * is defined, it is handled as a deployment error.
- */
- String value() default "";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java b/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
deleted file mode 100644
index e6b5ba2..0000000
--- a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigDefaultSections.java
+++ /dev/null
@@ -1,43 +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.cdi2;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to control injection and resolution current a configured bean. The configuration keys
- * to be resolved are basically determined by the {@link org.apache.tamaya.inject.ConfigProperty}
- * annotation(s). Nevertheless these annotations can also have relative key names. This annotation allows
- * to define a configuration area that is prefixed to all relative configuration keys within the
- * corresponding class/template interface.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.TYPE })
-public @interface ConfigDefaultSections {
-
- /**
- * Allows to declare an section names that are prepended to resolve relative configuration keys.
- * @return the section names to used for key resolution.
- */
- String[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java b/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
deleted file mode 100644
index 4077fce..0000000
--- a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigProperty.java
+++ /dev/null
@@ -1,80 +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.cdi2;
-
-
-import javax.enterprise.util.Nonbinding;
-import javax.inject.Qualifier;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to enable injection current a configured property or define the returned data for
- * a configuration template method. Hereby this annotation can be used in multiple ways and combined
- * with other annotations such as {@link ConfigDefault}, {@link WithConfigOperator}, {@link WithPropertyConverter}.
- *
- * Below the most simple variant current a configured class is given:
- * {@code
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty
- * private String aValue;
- * }
- * When this class is configured, e.g. by passing it to {@link org.apache.tamaya.Configuration#configure(Object)},
- * the following is happening:
- * <ul>
- * <li>The current valid Configuration is evaluated by calling {@code Configuration cfg = ConfigurationProvider.getConfiguration();}</li>
- * <li>The current possible property keys are evaluated by calling {@code cfg.get("aValue");}</li>
- * <li>if not successful, and a @ConfigDefault annotation is present, the default value is used.
- * <li>If no value could be evaluated a ({@link org.apache.tamaya.ConfigException} is thrown.</li>
- * <li>On success, since no type conversion is involved, the value is injected.</li>
- * </ul>
- *
- * In the next example we explicitly define the property keys:
- * {@code
- * @ConfigDefaultSections("section1")
- * pubic class ConfiguredItem{
- *
- * @ConfiguredProperty({"b", "[a.b.deprecated.keys]", "a"})
- * @ConfigDefault("myDefaultValue")
- * private String aValue;
- * }
- *
- * Within this example we evaluate multiple possible keys (section1.b, a.b.deprecated.keys, section1.a). Evaluation is
- * aborted if a key could be successfully resolved. Hereby the ordering current the annotations define the ordering
- * current resolution, so in the example above
- * resolution equals to {@code "section1.b", "a.b.deprecated.keys", "section1.a"}. If no value has bee found,
- * the configured default {@code myDefaultValue} is returned.
- */
-@Qualifier
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
-public @interface ConfigProperty {
-
- /**
- * Get the property names to be used. Hereby the first non null keys evaluated is injected as property keys.
- *
- * @return the property names, not null. If missing the field or method name being injected is used by default.
- */
- @Nonbinding
- String[] value() default {};
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java b/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
deleted file mode 100644
index ffec5d1..0000000
--- a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationExtension.java
+++ /dev/null
@@ -1,257 +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.cdi2;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.ProcessBean;
-import javax.enterprise.inject.spi.ProcessProducerMethod;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * CDI Extension module that adds injection mechanism for configuration.
- *
- * @see ConfigProperty
- * @see ConfigDefault
- * @see org.apache.tamaya.integration.cdi2.ConfigDefaultSections
- * @see ConfigException
- */
-public class ConfigurationExtension implements Extension {
-
- static final Map<Class, ConfigOperator> CUSTOM_OPERATORS = new ConcurrentHashMap<>();
- static final Map<Class, PropertyConverter> CUSTOM_CONVERTERS = new ConcurrentHashMap<>();
-
- private static class ConverterBean implements Bean<Object> {
-
- private final Bean<Object> delegate;
- private final Set<Type> types;
-
- public ConverterBean(final Bean convBean, final Set<Type> types) {
- this.types = types;
- this.delegate = convBean;
- }
-
- @Override
- public Set<Type> getTypes() {
- return types;
- }
-
- @Override
- public Class<?> getBeanClass() {
- return delegate.getBeanClass();
- }
-
- @Override
- public Set<InjectionPoint> getInjectionPoints() {
- return delegate.getInjectionPoints();
- }
-
- @Override
- public String getName() {
- return delegate.getName();
- }
-
- @Override
- public Set<Annotation> getQualifiers() {
- return delegate.getQualifiers();
- }
-
- @Override
- public Class<? extends Annotation> getScope() {
- return delegate.getScope();
- }
-
- @Override
- public Set<Class<? extends Annotation>> getStereotypes() {
- return delegate.getStereotypes();
- }
-
- @Override
- public boolean isAlternative() {
- return delegate.isAlternative();
- }
-
- @Override
- public boolean isNullable() {
- return delegate.isNullable();
- }
-
- @Override
- public Object create(CreationalContext<Object> creationalContext) {
- return delegate.create(creationalContext);
- }
-
- @Override
- public void destroy(Object instance, CreationalContext<Object> creationalContext) {
- delegate.destroy(instance, creationalContext);
- }
- }
-
- private Set<Type> types = new HashSet<>();
- private Bean<?> convBean;
-
- /**
- * Method that checks the configuration injection points during deployment for available configuration.
- * @param pb the bean to process.
- */
- public void retrieveTypes(@Observes final ProcessBean<?> pb) {
-
- final Set<InjectionPoint> ips = pb.getBean().getInjectionPoints();
-
- for (InjectionPoint injectionPoint : ips) {
- if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
- final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
- final List<String> keys = evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
-
- final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
- if(withOperatorAnnot!=null){
- tryLoadOpererator(withOperatorAnnot.value());
- }
- final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
- if(withConverterAnnot!=null){
- tryLoadConverter(withConverterAnnot.value());
- }
-
- // We don't want to wait until the injection really fails at runtime.
- // If there is a non resolvable configuration, we want to know at startup.
- Configuration config = ConfigurationProvider.getConfiguration();
- String keyFound = null;
- String value = null;
- for(String key:keys) {
- value = config.get(key);
- if(value!=null){
- keyFound = key;
- break;
- }
- }
- if(value==null && defaultAnnot!=null){
- value = defaultAnnot.value();
- }
- if(value==null){
- throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s. Please provide one of the given keys" +
- "with a value in your configuration sources.",
- keys.toString()));
- }
- types.add(injectionPoint.getType());
- }
- }
- }
-
- private void tryLoadOpererator(Class<? extends ConfigOperator> operatorClass) {
- Objects.requireNonNull(operatorClass);
- if(ConfigOperator.class == operatorClass){
- return;
- }
- try{
- if(!CUSTOM_OPERATORS.containsKey(operatorClass)) {
- CUSTOM_OPERATORS.put(operatorClass, operatorClass.newInstance());
- }
- }
- catch(Exception e){
- throw new ConfigException("Custom ConfigOperator could not be loaded: " + operatorClass.getName(), e);
- }
- }
-
- private void tryLoadConverter(Class<? extends PropertyConverter> converterClass) {
- Objects.requireNonNull(converterClass);
- if(PropertyConverter.class == converterClass){
- return;
- }
- try{
- if(!CUSTOM_CONVERTERS.containsKey(converterClass)) {
- CUSTOM_CONVERTERS.put(converterClass, converterClass.newInstance());
- }
- }
- catch(Exception e){
- throw new ConfigException("Custom PropertyConverter could not be loaded: " + converterClass.getName(), e);
- }
- }
-
- /**
- * Evaluates the effective keys to be used. if no {@code keys} are defined, {@code memberName} is used.
- * The effective keys are then combined with the sections given (if any) and only, if the given keys are not
- * absolute keys (surrounded by brackets).
- * @param memberName the default member name, not null.
- * @param keys the keys, may be empty, but not null.
- * @param sections the default sections, may be empty. May also be null.
- * @return the list of keys to be finally used for configuration resolution in order of
- * precedence. The first keys in the list that could be successfully resolved define the final
- * configuration value.
- */
- public static List<String> evaluateKeys(String memberName, String[] keys, String[] sections) {
- List<String> effKeys = new ArrayList<>(Arrays.asList(keys));
- if (effKeys.isEmpty()) {
- effKeys.add(memberName);
- }
- ListIterator<String> iterator = effKeys.listIterator();
- while (iterator.hasNext()) {
- String next = iterator.next();
- if (next.startsWith("[") && next.endsWith("]")) {
- // absolute key, strip away brackets, take key as is
- iterator.set(next.substring(1, next.length() - 1));
- } else {
- if (sections != null && sections.length>0) {
- // Remove original entry, since it will be replaced with prefixed entries
- iterator.remove();
- // Add prefixed entries, including absolute (root) entry for "" area keys.
- for (String area : sections) {
- iterator.add(area.isEmpty() ? next : area + '.' + next);
- }
- }
- }
- }
- return effKeys;
- }
-
-
- public void captureConvertBean(@Observes final ProcessProducerMethod<?, ?> ppm) {
- if (ppm.getAnnotated().isAnnotationPresent(ConfigProperty.class)) {
- convBean = ppm.getBean();
- }
-
- }
-
- public void addConverter(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
- abd.addBean(new ConverterBean(convBean, types));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java b/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
deleted file mode 100644
index 8b4ae9f..0000000
--- a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/ConfigurationProducer.java
+++ /dev/null
@@ -1,115 +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.cdi2;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-@ApplicationScoped
-public class ConfigurationProducer {
-
- private static final Logger LOGGER = Logger.getLogger(ConfigurationProducer.class.getName());
-
- @Produces
- @ConfigProperty
- public Object resolveAndConvert(final InjectionPoint injectionPoint) {
-
- final ConfigProperty annotation = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
- final ConfigDefault defaultAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefault.class);
- final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
- final List<String> keys = ConfigurationExtension.evaluateKeys(injectionPoint.getMember().getName(), annotation.value(), typeAnnot.value());
-
- final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
- ConfigOperator operator = null;
- if(withOperatorAnnot!=null){
- operator = ConfigurationExtension.CUSTOM_OPERATORS.get(withOperatorAnnot.value());
- }
- PropertyConverter customCnverter = null;
- final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
- if(withConverterAnnot!=null){
- customCnverter = ConfigurationExtension.CUSTOM_CONVERTERS.get(withConverterAnnot.value());
- }
-
- // unless the extension is not installed, this should never happen because the extension
- // enforces the resolvability of the config
- Configuration config = ConfigurationProvider.getConfiguration();
- if(operator!=null){
- config = operator.operate(config);
- }
- final Class<?> toType = (Class<?>) injectionPoint.getAnnotated().getBaseType();
- String textValue = null;
- String defaultTextValue = defaultAnnot!=null?defaultAnnot.value():null;
- String keyFound = null;
- for(String key:keys) {
- textValue = config.get(key);
- if(textValue!=null){
- keyFound = key;
- break;
- }
- }
- Object value = null;
- if(keyFound!=null){
- if(customCnverter!=null) {
- value = customCnverter.convert(textValue);
- }
- if(value==null){
- value = config.get(keyFound, toType);
- }
- }
- else if(defaultTextValue!=null){
- if(customCnverter!=null) {
- value = customCnverter.convert(defaultTextValue);
- }
- if(value==null) {
- List<PropertyConverter<Object>> converters = ConfigurationProvider.getConfigurationContext()
- .getPropertyConverters(TypeLiteral.of(toType));
- for (PropertyConverter<Object> converter : converters) {
- try {
- value = converter.convert(defaultTextValue);
- if (value != null) {
- LOGGER.log(Level.FINEST, "Parsed default value from '" + defaultTextValue + "' into " +
- injectionPoint);
- break;
- }
- } catch (Exception e) {
- LOGGER.log(Level.FINEST, "Failed to convert default value '" + defaultTextValue + "' for " +
- injectionPoint, e);
- }
- }
- }
- }
- if(value==null){
- throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s to the required target type: %s",
- keys.toString(), toType.getName()));
- }
- LOGGER.finest(String.format("Injecting %s for key %s in class %s", keyFound, value.toString(), injectionPoint.toString()));
- return value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java b/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
deleted file mode 100644
index 7d6ac66..0000000
--- a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithConfigOperator.java
+++ /dev/null
@@ -1,45 +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.cdi2;
-
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.Configuration;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define an configuration operator to be used before accessing a configured keys.
- * This allows filtering current configuration, e.g. for realizing views or ensuring security
- * constraints.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = {ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER})
-public @interface WithConfigOperator {
-
- /**
- * Define a custom adapter that should be used to adapt the configuration entry injected. This overrides any
- * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is
- * registered, it is handled as a deployment error.
- */
- Class<? extends ConfigOperator> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java b/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
deleted file mode 100644
index f50edcb..0000000
--- a/integration/cdi2/src/main/java/org/apache/tamaya/integration/cdi2/WithPropertyConverter.java
+++ /dev/null
@@ -1,45 +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.cdi2;
-
-
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to define a type adapter to be used before injecting a configured keys, or for applying changes.
- * This will override any other adapter for performing the type conversion before
- * injecting the field keys.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = {ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
-public @interface WithPropertyConverter {
-
- /**
- * Define a custom adapter or codec that should be used to adapt the configuration entry injected. This overrides any
- * general org.apache.tamaya.core.internal registered. If no adapter is defined (default) and no corresponding adapter is
- * registered, it is handled as a deployment error.
- */
- Class<? extends PropertyConverter<?>> value();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/resources/META-INF/beans.xml b/integration/cdi2/src/main/resources/META-INF/beans.xml
deleted file mode 100644
index e71e480..0000000
--- a/integration/cdi2/src/main/resources/META-INF/beans.xml
+++ /dev/null
@@ -1 +0,0 @@
-<beans></beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
deleted file mode 100644
index 78139d5..0000000
--- a/integration/cdi2/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
+++ /dev/null
@@ -1 +0,0 @@
-org.tomitribe.sabot.ConfigurationExtension
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties b/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties
deleted file mode 100644
index 6c8b06c..0000000
--- a/integration/cdi2/src/test/resources/META-INF/javaconfiguration.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-remote.wsdl.location = classpath:/service-wsdl.xml
-remote.port=1443
-remote.address=${remote.host}:${remote.port}
-remote.target.url = https://${remote.address}/remote/service/url
-remote.username = joecool
-# ciphered using built in StaticDESPasswordCipher
-remote.password = NjAq6q2agYVnvSMz+eYUZg==
-cipher=org.apache.openejb.cipher.StaticDESPasswordCipher
-
-string.value = hello
-file.value = ./conf
-duration.value = 10 minutes and 57 seconds
-boolean.value = true
-integer.value = 123
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/pom.xml
----------------------------------------------------------------------
diff --git a/integration/pom.xml b/integration/pom.xml
index dd3dfaa..efecb5e 100644
--- a/integration/pom.xml
+++ b/integration/pom.xml
@@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-sandbox</artifactId>
+ <artifactId>tamaya-extensions</artifactId>
<version>0.2-incubating-SNAPSHOT</version>
</parent>
@@ -32,7 +32,7 @@ under the License.
<artifactId>tamaya-integration-sandbox</artifactId>
<modules>
- <module>cdi2</module>
+ <module>store</module>
<module>commons</module>
</modules>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi
----------------------------------------------------------------------
diff --git a/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi b/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi
new file mode 100644
index 0000000..f3199f2
--- /dev/null
+++ b/integration/store-file/src/main/resources/META-INF/services/org.apache.tamaya.store.spi.PropertyStoreProviderSpi
@@ -0,0 +1,18 @@
+#
+# 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/5105df0e/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java
----------------------------------------------------------------------
diff --git a/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java b/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java
new file mode 100644
index 0000000..db567ac
--- /dev/null
+++ b/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/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.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/5105df0e/integration/store/pom.xml
----------------------------------------------------------------------
diff --git a/integration/store/pom.xml b/integration/store/pom.xml
new file mode 100644
index 0000000..d755551
--- /dev/null
+++ b/integration/store/pom.xml
@@ -0,0 +1,54 @@
+<!--
+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-integration-sandbox</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+ <artifactId>tamaya-store</artifactId>
+ <name>Apache Tamaya Storage/Cache/Datagrid Integration</name>
+ <description>Integration with a Datagrid backend for distributed configuration.</description>
+ <packaging>jar</packaging>
+
+ <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>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-events</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java
----------------------------------------------------------------------
diff --git a/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java b/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java
new file mode 100644
index 0000000..d1d6adf
--- /dev/null
+++ b/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Map;
+
+/**
+ * Simple abstraction of a property synchronization backend. Most methods are similar
+ * to a {@link org.apache.tamaya.spi.PropertySource}, enhanced with methods for
+ * updating the property storage.
+ */
+public interface PropertyStore {
+
+ /**
+ * Get the store's name.
+ * @return the name, never null.
+ */
+ String getName();
+
+ /**
+ * Stores the given PropertySource into the store.
+ * @param propertySource
+ */
+ void store(PropertySource propertySource);
+
+ /**
+ * Read all properties.
+ * @return the properties from the remote store, never null.
+ */
+ Map<String,String> read();
+
+ /**
+ * Reads a single key fromt hthe store.
+ * @param key the key, not null.
+ * @return the value, or null.
+ */
+ String read(String key);
+
+ /**
+ * Determines if {@link #read()} returns all contained properties, or optionally only
+ * a subset of the accessible and defined properties are returned.
+ * @return true, if this store is scannable.
+ */
+ boolean isScannable();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java
----------------------------------------------------------------------
diff --git a/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java b/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java
new file mode 100644
index 0000000..dceb29a
--- /dev/null
+++ b/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.store.spi.PropertyStoreProviderSpi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Simple provider accessor singleton for accessing {@link PropertyStore}
+ * instances.
+ */
+public final class PropertyStoreProvider {
+ /**
+ * The logger used.
+ */
+ private static final Logger LOG = Logger.getLogger(PropertyStoreProvider.class.getName());
+
+
+ /**
+ * Singleton constructor.
+ */
+ private PropertyStoreProvider() {
+ }
+
+
+ /**
+ * Access a {@link PropertyStore} using it's id.
+ *
+ * @param storeId the unique id of the store to use.
+ * @return
+ */
+ public static PropertyStore getPropertyStore(String storeId) {
+ for (PropertyStoreProviderSpi propertyStoreProviderSpi : ServiceContextManager.getServiceContext()
+ .getServices(PropertyStoreProviderSpi.class)) {
+ PropertyStore store = propertyStoreProviderSpi.getPropertyStore(storeId);
+ if (store != null) {
+ LOG.finest("DataGrid '" + storeId + "' used: " + store);
+ return store;
+ }
+ }
+ throw new ConfigException("No such Store: " + storeId);
+ }
+
+ /**
+ * Access a {@link PropertyStore} using it's id, hereby returning the most significant of the configured
+ * {@link PropertyStore} instances.
+ *
+ * @return the default PropertyStore instance.
+ */
+ public static PropertyStore getDefaultPropertyStore() {
+ return getPropertyStore("default");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java
----------------------------------------------------------------------
diff --git a/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java b/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java
new file mode 100644
index 0000000..c19fa45
--- /dev/null
+++ b/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Map;
+
+/**
+ * Simple abstraction of a property synchronization backend. Most methods are similar
+ * to a {@link org.apache.tamaya.spi.PropertySource}, enhanced with methods for
+ * updating the property storage.
+ */
+public interface WritablePropertySource extends PropertySource{
+
+ /**
+ * Loads the property source from its store..
+ */
+ void load();
+
+ /**
+ * Sets the store to the given properties, replacing all previous state.
+ * @param props the new properties.
+ */
+ void setAll(Map<String, String> props);
+
+ /**
+ * Updates/adds all the given entries.
+ * @param props the entries to be added/updated.
+ */
+ void putAll(Map<String, String> props);
+
+ /**
+ * Writes a single entry.
+ * @param key the key, not null.
+ * @param value the new value, not null.
+ */
+ void put(String key, String value);
+
+ /**
+ * Removes all entries.
+ */
+ void clear();
+
+ /**
+ * Synchronize the current state with the remote version.
+ */
+ void synch();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java
----------------------------------------------------------------------
diff --git a/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java b/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java
new file mode 100644
index 0000000..b3fe1ee
--- /dev/null
+++ b/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java
@@ -0,0 +1,137 @@
+/*
+ * 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.spi;
+
+import org.apache.tamaya.events.ConfigEventManager;
+import org.apache.tamaya.events.FrozenPropertySource;
+import org.apache.tamaya.events.delta.ChangeType;
+import org.apache.tamaya.events.delta.PropertySourceChange;
+import org.apache.tamaya.events.delta.PropertySourceChangeBuilder;
+import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.store.PropertyStore;
+import org.apache.tamaya.store.WritablePropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * PropertySource that is connected to a {@link PropertyStore}.
+ */
+public class DefaultStoredPropertySource extends BasePropertySource
+ implements WritablePropertySource {
+
+ /**
+ * The store to be used, not null.
+ */
+ private PropertyStore propertyStore;
+
+ /**
+ * The last version of stoarge data accessed.
+ */
+ private String lastVersion;
+
+ private Map<String, String> properties = new HashMap<>();
+
+
+ private FrozenPropertySource currentConfig;
+
+ /**
+ * Creates a new property source.
+ *
+ * @param propertyStore the backend store.
+ * @param defaultOrdinal the default ordinal to be used.
+ */
+ public DefaultStoredPropertySource(PropertyStore propertyStore, int defaultOrdinal) {
+ super(defaultOrdinal);
+ this.propertyStore = Objects.requireNonNull(propertyStore);
+ this.properties.putAll(this.propertyStore.read());
+ }
+
+ @Override
+ public void load() {
+ this.properties.clear();
+ this.properties.putAll(this.propertyStore.read());
+ synch();
+ }
+
+ @Override
+ public String getName() {
+ return this.propertyStore.getName();
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public String get(String key) {
+ if (!propertyStore.isScannable()) {
+ return propertyStore.read(key);
+ }
+ return properties.get(key);
+ }
+
+ @Override
+ public boolean isScannable() {
+ return propertyStore.isScannable();
+ }
+
+ @Override
+ public String toString() {
+ return "StoredPropertySource{" +
+ "propertyStore=" + propertyStore.getName() +
+ '}';
+ }
+
+ @Override
+ public void setAll(Map<String, String> props) {
+ this.properties.clear();
+ this.properties.putAll(props);
+ synch();
+ }
+
+ @Override
+ public void putAll(Map<String, String> props) {
+ this.properties.putAll(props);
+ synch();
+ }
+
+ @Override
+ public void put(String key, String value) {
+ this.properties.put(key, value);
+ synch();
+ }
+
+ @Override
+ public void clear() {
+ this.properties.clear();
+ synch();
+ }
+
+ @Override
+ public void synch() {
+ FrozenPropertySource newConfig = FrozenPropertySource.of(this);
+ PropertySourceChange change = PropertySourceChangeBuilder.of(currentConfig, ChangeType.UPDATED)
+ .addChanges(newConfig).build();
+ currentConfig = newConfig;
+ ConfigEventManager.fireEvent(change);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java
----------------------------------------------------------------------
diff --git a/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java b/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java
new file mode 100644
index 0000000..1b20fc1
--- /dev/null
+++ b/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java
@@ -0,0 +1,34 @@
+/*
+ * 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.spi;
+
+import org.apache.tamaya.store.PropertyStore;
+
+/**
+ * Class, that provides access to PropertyStores to be used.
+ */
+public interface PropertyStoreProviderSpi {
+
+ /**
+ * Access a {@link PropertyStore} using it's id.
+ * @param storeId the unique id of the store to use.
+ * @return
+ */
+ PropertyStore getPropertyStore(String storeId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java
----------------------------------------------------------------------
diff --git a/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java b/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java
deleted file mode 100644
index e260732..0000000
--- a/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java
+++ /dev/null
@@ -1,138 +0,0 @@
-import kafka.server.KafkaConfig;
-import kafka.server.KafkaServer;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-public class EmbeddedKafkaCluster {
- private final List<Integer> ports;
- private final String zkConnection;
- private final Properties baseProperties;
-
- private final String brokerList;
-
- private final List<KafkaServer> brokers;
- private final List<File> logDirs;
-
- public EmbeddedKafkaCluster(String zkConnection) {
- this(zkConnection, new Properties());
- }
-
- public EmbeddedKafkaCluster(String zkConnection, Properties baseProperties) {
- this(zkConnection, baseProperties, Collections.singletonList(-1));
- }
-
- public EmbeddedKafkaCluster(String zkConnection, Properties baseProperties, List<Integer> ports) {
- this.zkConnection = zkConnection;
- this.ports = resolvePorts(ports);
- this.baseProperties = baseProperties;
-
- this.brokers = new ArrayList<KafkaServer>();
- this.logDirs = new ArrayList<File>();
-
- this.brokerList = constructBrokerList(this.ports);
- }
-
- private List<Integer> resolvePorts(List<Integer> ports) {
- List<Integer> resolvedPorts = new ArrayList<Integer>();
- for (Integer port : ports) {
- resolvedPorts.add(resolvePort(port));
- }
- return resolvedPorts;
- }
-
- private int resolvePort(int port) {
- if (port == -1) {
- return TestUtils.getAvailablePort();
- }
- return port;
- }
-
- private String constructBrokerList(List<Integer> ports) {
- StringBuilder sb = new StringBuilder();
- for (Integer port : ports) {
- if (sb.length() > 0) {
- sb.append(",");
- }
- sb.append("localhost:").append(port);
- }
- return sb.toString();
- }
-
- public void startup() {
- for (int i = 0; i < ports.size(); i++) {
- Integer port = ports.get(i);
- File logDir = TestUtils.constructTempDir("kafka-local");
-
- Properties properties = new Properties();
- properties.putAll(baseProperties);
- properties.setProperty("zookeeper.connect", zkConnection);
- properties.setProperty("broker.id", String.valueOf(i + 1));
- properties.setProperty("host.name", "localhost");
- properties.setProperty("port", Integer.toString(port));
- properties.setProperty("log.dir", logDir.getAbsolutePath());
- properties.setProperty("log.flush.interval.messages", String.valueOf(1));
-
- KafkaServer broker = startBroker(properties);
-
- brokers.add(broker);
- logDirs.add(logDir);
- }
- }
-
-
- private KafkaServer startBroker(Properties props) {
- KafkaServer server = new KafkaServer(new KafkaConfig(props), new SystemTime());
- server.startup();
- return server;
- }
-
- public Properties getProps() {
- Properties props = new Properties();
- props.putAll(baseProperties);
- props.put("metadata.broker.list", brokerList);
- props.put("zookeeper.connect", zkConnection);
- return props;
- }
-
- public String getBrokerList() {
- return brokerList;
- }
-
- public List<Integer> getPorts() {
- return ports;
- }
-
- public String getZkConnection() {
- return zkConnection;
- }
-
- public void shutdown() {
- for (KafkaServer broker : brokers) {
- try {
- broker.shutdown();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- for (File logDir : logDirs) {
- try {
- TestUtils.deleteFile(logDir);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("EmbeddedKafkaCluster{");
- sb.append("brokerList='").append(brokerList).append('\'');
- sb.append('}');
- return sb.toString();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java
----------------------------------------------------------------------
diff --git a/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java b/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java
deleted file mode 100644
index 54068fc..0000000
--- a/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java
+++ /dev/null
@@ -1,95 +0,0 @@
-import org.apache.zookeeper.server.NIOServerCnxnFactory;
-import org.apache.zookeeper.server.ServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
-public class EmbeddedZookeeper {
- private int port = -1;
- private int tickTime = 500;
-
- private ServerCnxnFactory factory;
- private File snapshotDir;
- private File logDir;
-
- public EmbeddedZookeeper() {
- this(-1);
- }
-
- public EmbeddedZookeeper(int port) {
- this(port, 500);
- }
-
- public EmbeddedZookeeper(int port, int tickTime) {
- this.port = resolvePort(port);
- this.tickTime = tickTime;
- }
-
- private int resolvePort(int port) {
- if (port == -1) {
- return TestUtils.getAvailablePort();
- }
- return port;
- }
-
- public void startup() throws IOException{
- if (this.port == -1) {
- this.port = TestUtils.getAvailablePort();
- }
- this.factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
- this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot");
- this.logDir = TestUtils.constructTempDir("embeeded-zk/log");
-
- try {
- factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime));
- } catch (InterruptedException e) {
- throw new IOException(e);
- }
- }
-
-
- public void shutdown() {
- factory.shutdown();
- try {
- TestUtils.deleteFile(snapshotDir);
- } catch (FileNotFoundException e) {
- // ignore
- }
- try {
- TestUtils.deleteFile(logDir);
- } catch (FileNotFoundException e) {
- // ignore
- }
- }
-
- public String getConnection() {
- return "localhost:" + port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public void setTickTime(int tickTime) {
- this.tickTime = tickTime;
- }
-
- public int getPort() {
- return port;
- }
-
- public int getTickTime() {
- return tickTime;
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("EmbeddedZookeeper{");
- sb.append("connection=").append(getConnection());
- sb.append('}');
- return sb.toString();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5105df0e/metamodels/pom.xml
----------------------------------------------------------------------
diff --git a/metamodels/pom.xml b/metamodels/pom.xml
index fcc37ae..4a05846 100644
--- a/metamodels/pom.xml
+++ b/metamodels/pom.xml
@@ -34,6 +34,7 @@ under the License.
<modules>
<module>simple</module>
+ <module>staged</module>
</modules>
</project>