You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/12/18 02:45:29 UTC
[01/10] incubator-tamaya git commit: Added AutorConfigure
annotations/support to overall injection API (was previosuly in SE only),
so we have only one injection API overall.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 5fa2934af -> 642796ba3
Added AutorConfigure annotations/support to overall injection API (was previosuly in SE only), so we have only one injection API overall.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/53738369
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/53738369
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/53738369
Branch: refs/heads/master
Commit: 53738369de7aa41046653c8e58743bf33a43eda7
Parents: 5fa2934
Author: anatole <an...@apache.org>
Authored: Wed Dec 16 08:35:41 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 16 08:35:41 2015 +0100
----------------------------------------------------------------------
README.md | 2 +-
.../tamaya/inject/api/ConfigAutoInject.java | 36 ++++++++++++++++++++
.../org/apache/tamaya/inject/api/NoConfig.java | 36 ++++++++++++++++++++
.../apache/tamaya/inject/ConfigAutoInject.java | 36 --------------------
.../java/org/apache/tamaya/inject/NoConfig.java | 36 --------------------
.../inject/internal/ConfiguredTypeImpl.java | 4 +--
.../internal/DefaultConfigurationInjector.java | 2 +-
.../java/annottext/AnnotatedConfigBean.java | 3 +-
src/site/asciidoc/extensions/mod_events.adoc | 22 ++++++++++++
9 files changed, 99 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index f9b4b77..70727a3 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ There are at least two main usage scenarios for Tamaya, which are synergetic:
basic Tamaya core implementation). As a result all applications/modules in your company follow the same configuration
policy, which makes it much more simpler to move people between your teams. Similarly additional tooling functionality
can help you to manage configuration on application as well as on enterprise level, e.g. providing command line or
- REST support to access the supported configuration entries, types and values, configuration validation and more.
+ REST support to access the supported configuration entries, types and values, configuration configModel and more.
- If you are writing an application, application component or library you can support configuration using Tamaya by
adding it as an optional dependency. If done so your users/customers can use Tamaya to connect their current enterprise
configuration infrastructure transparently to your code. As an example you can use Tamaya to read your default
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java
new file mode 100644
index 0000000..1ed659e
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfigAutoInject.java
@@ -0,0 +1,36 @@
+/*
+ * 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.inject.api;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to control injection of a configured bean. The configuration keys
+ * to be resolved are basically determined by the {@link Config}
+ * annotation(s). When this annotation is added the injection systems tries to inject all
+ * fields found, also including fields not annotated with {@code @ConfigProperty}.
+ * Fields not to be injected ccan be annotated with {@code @NoConfig} to exclude them
+ * being eleceted for injection.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.TYPE })
+public @interface ConfigAutoInject {}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java
new file mode 100644
index 0000000..c5234d3
--- /dev/null
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java
@@ -0,0 +1,36 @@
+/*
+ * 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.inject.api;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
+ * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by
+ * using property or method names without annotations. With that annotation none of these will be happen.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.METHOD })
+public @interface NoConfig {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigAutoInject.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigAutoInject.java b/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigAutoInject.java
deleted file mode 100644
index fa08ac4..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/ConfigAutoInject.java
+++ /dev/null
@@ -1,36 +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.inject;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation to control injection of a configured bean. The configuration keys
- * to be resolved are basically determined by the {@link Config}
- * annotation(s). When this annotation is added the injection systems tries to inject all
- * fields found, also including fields not annotated with {@code @ConfigProperty}.
- * Fields not to be injected ccan be annotated with {@code @NoConfig} to exclude them
- * being eleceted for injection.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.TYPE })
-public @interface ConfigAutoInject {}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java b/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
deleted file mode 100644
index 76d2c5e..0000000
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/NoConfig.java
+++ /dev/null
@@ -1,36 +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.inject;
-
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
- * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by
- * using property or method names without annotations. With that annotation none of these will be happen.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(value = { ElementType.FIELD, ElementType.METHOD })
-public @interface NoConfig {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
index 0c22e1c..1e82462 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredTypeImpl.java
@@ -27,8 +27,8 @@ import java.util.logging.Logger;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.inject.ConfigAutoInject;
-import org.apache.tamaya.inject.NoConfig;
+import org.apache.tamaya.inject.api.ConfigAutoInject;
+import org.apache.tamaya.inject.api.NoConfig;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
import org.apache.tamaya.inject.spi.ConfiguredField;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
index db0baa7..2630552 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
@@ -32,7 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
-import org.apache.tamaya.inject.NoConfig;
+import org.apache.tamaya.inject.api.NoConfig;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
import org.apache.tamaya.inject.spi.ConfiguredType;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java b/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
index dc65dad..4cd4baf 100644
--- a/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
+++ b/modules/injection/src/test/java/annottext/AnnotatedConfigBean.java
@@ -19,8 +19,7 @@
package annottext;
import org.apache.tamaya.inject.api.DynamicValue;
-import org.apache.tamaya.inject.api.LoadPolicy;
-import org.apache.tamaya.inject.NoConfig;
+import org.apache.tamaya.inject.api.NoConfig;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefault;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/53738369/src/site/asciidoc/extensions/mod_events.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_events.adoc b/src/site/asciidoc/extensions/mod_events.adoc
index d725fe0..237b47c 100644
--- a/src/site/asciidoc/extensions/mod_events.adoc
+++ b/src/site/asciidoc/extensions/mod_events.adoc
@@ -296,6 +296,28 @@ Configuration frozenConfig = FrozenConfiguration.of(ConfigurationProvider.getCon
PropertySource frozenSource = FrozenPropertySource.of(ConfigurationProvider.getConfiguration());
--------------------------------------------------
+=== Observing and publishing configuration changes
+
+The event module allows to register and publish listeners for acting on configuration changes, e.g. of paramters with a
+private section name. The main entry point for this feature is the +ConfigurationObserver+ singleton:
+
+[source,java]
+.ConfigurationObserver
+--------------------------------------------------
+public class ConfigurationObserver {
+
+ private ConfigurationObserver() {}
+
+ public static <T> void addObservedKeys(Collection<String> keys);
+ public static <T> void addObservedKeys(String... keys);
+ public static <T> void removeObservedKeys(Collection<String> keys);
+ public static <T> void removeObservedKeys(String... keys);
+ public static Set<String> getObservedKeys();
+--------------------------------------------------
+
+This singleton allows to register keys on which listeners may listen to. Hereby, when changes have been identified
+that are observed, a +ConfigurationChange+ event is published on the event bus.
+
=== SPIs
[10/10] incubator-tamaya git commit: - Removed dependecy of formats
module from events module. - Simplified events module.
Posted by an...@apache.org.
- Removed dependecy of formats module from events module.
- Simplified events module.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/642796ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/642796ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/642796ba
Branch: refs/heads/master
Commit: 642796ba37655556d01be20cae92a081268f9dd5
Parents: 1c3035a
Author: anatole <an...@apache.org>
Authored: Fri Dec 18 02:45:14 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Fri Dec 18 02:45:14 2015 +0100
----------------------------------------------------------------------
examples/6-fileobserver-example/pom.xml | 5 ++
.../fileobserver/ObservedConfigExampleTest.java | 3 +-
.../fileobserver/TestObservingProvider.java | 4 +-
modules/events/pom.xml | 10 +--
.../ObservingPropertySourceProvider.java | 78 ++++++--------------
...g.apache.tamaya.events.spi.ConfigObserverSpi | 19 -----
.../tamaya/events/TestObservingProvider.java | 4 +-
.../tamaya/inject/spi/ConfiguredType.java | 2 +-
modules/injection/pom.xml | 2 -
.../tamaya/inject/internal/InjectionHelper.java | 7 +-
.../integration/osgi/HelloServiceImpl.java | 18 +++++
.../integration/osgi/TestConfigIntegration.java | 13 +++-
.../ConfiguredTypeEventsModelPopulator.java | 13 +++-
.../ConfiguredTypeEventsModelProvider.java | 4 +-
14 files changed, 85 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/examples/6-fileobserver-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/pom.xml b/examples/6-fileobserver-example/pom.xml
index 09c0bad..8578f41 100644
--- a/examples/6-fileobserver-example/pom.xml
+++ b/examples/6-fileobserver-example/pom.xml
@@ -44,6 +44,11 @@ under the License.
<version>0.2-incubating-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.tamaya.ext</groupId>
+ <artifactId>tamaya-formats</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java
index b112413..4d62760 100644
--- a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java
+++ b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/ObservedConfigExampleTest.java
@@ -21,6 +21,7 @@ package org.aspache.tamaya.examples.fileobserver;
import org.apache.commons.io.FileUtils;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.events.folderobserver.ObservingPropertySourceProvider;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
@@ -48,7 +49,7 @@ public class ObservedConfigExampleTest {
// create some temporary config
Path tempDir = Files.createTempDirectory("observedFolder");
- TestObservingProvider.propertyLocation = tempDir;
+ Path propertyLocation = tempDir;
FileUtils.copyInputStreamToFile(
getClass().getResourceAsStream("/test.properties"),
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java
index a70d498..4528260 100644
--- a/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java
+++ b/examples/6-fileobserver-example/src/test/java/org/aspache/tamaya/examples/fileobserver/TestObservingProvider.java
@@ -31,6 +31,8 @@ public class TestObservingProvider extends ObservingPropertySourceProvider{
public static Path propertyLocation;
public TestObservingProvider(){
- super(propertyLocation, new PropertiesFormat());
+ super(propertyLocation);
}
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index cf56fa3..918f4ef 100644
--- a/modules/events/pom.xml
+++ b/modules/events/pom.xml
@@ -41,11 +41,11 @@ under the License.
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-formats</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <!--<dependency>-->
+ <!--<groupId>org.apache.tamaya.ext</groupId>-->
+ <!--<artifactId>tamaya-formats</artifactId>-->
+ <!--<version>${project.version}</version>-->
+ <!--</dependency>-->
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 8387504..d8c869f 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -19,12 +19,10 @@
package org.apache.tamaya.events.folderobserver;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.events.ConfigEventManager;
import org.apache.tamaya.events.ConfigurationContextChange;
import org.apache.tamaya.events.ConfigurationContextChangeBuilder;
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.format.FlattenedDefaultPropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
@@ -35,12 +33,7 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
@@ -64,29 +57,16 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
*/
private final List<PropertySource> propertySources = Collections.synchronizedList(new LinkedList<PropertySource>());
/**
- * The supported configuration formats of this provider.
- */
- private Collection<ConfigurationFormat> formats = new ArrayList<>();
- /**
* The thread pool used.
*/
private ExecutorService executor = Executors.newSingleThreadExecutor();
/**
- * Constructor, reading the config file from classpath resource and system property.
- */
- public ObservingPropertySourceProvider(ConfigurationFormat... formats) {
- this(null, formats);
- }
-
- /**
* Constructorm using an explicit directory, ignoring all kind of configuration, if set.
*
* @param directory the target directory. If null, the default configuration and system property are used.
- * @param formats the formats to be used.
*/
- public ObservingPropertySourceProvider(Path directory, ConfigurationFormat... formats) {
- this.formats = Arrays.asList(formats);
+ public ObservingPropertySourceProvider(Path directory) {
if (directory == null) {
directory = getDirectory();
}
@@ -111,10 +91,7 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
try {
synchronized (propertySources) {
for (Path path : Files.newDirectoryStream(directory, "*")) {
- ConfigurationData data = loadFile(path);
- if (data != null) {
- result.addAll(getPropertySources(data));
- }
+ result.addAll(getPropertySources(path));
}
return result;
}
@@ -124,8 +101,14 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
return result;
}
- protected Collection<PropertySource> getPropertySources(ConfigurationData data) {
- return Arrays.asList(new PropertySource[]{new FlattenedDefaultPropertySource(data)});
+ protected Collection<PropertySource> getPropertySources(final Path file) {
+ return Arrays.asList(new PropertySource[]{new BasePropertySource() {
+ private Map<String,String> props = readProperties(file);
+ @Override
+ public Map<String, String> getProperties() {
+ return props;
+ }
+ }});
}
/**
@@ -133,33 +116,20 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
*
* @param file the file, not null.
*/
- protected ConfigurationData loadFile(Path file) {
- InputStream is = null;
- for (ConfigurationFormat format : formats) {
- try {
- URL url = file.toUri().toURL();
- if (format.accepts(url)) {
- is = url.openStream();
- ConfigurationData data = format.readConfiguration(file.toString(), is);
- if (data != null) {
- return data;
- }
- }
- } catch (IOException e) {
- LOG.log(Level.INFO, "Error reading file: " + file.toString() +
- ", using format: " + format, e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException ioe) {
- LOG.log(Level.SEVERE, "Failed to rea data...", ioe);
- }
- }
+ protected static Map<String,String> readProperties(Path file) {
+ try (InputStream is = file.toUri().toURL().openStream()){
+ Properties props = new Properties();
+ props.load(is);
+ Map<String,String> result = new HashMap<>();
+ for(Map.Entry en:props.entrySet()){
+ result.put(en.getKey().toString(), en.getValue().toString());
}
+ return result;
+ } catch (Exception e) {
+ LOG.log(Level.INFO, "Error reading file: " + file.toString() +
+ ", using format: properties", e);
}
- LOG.warning("Error reading file: " + file.toString());
- return null;
+ return Collections.emptyMap();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
----------------------------------------------------------------------
diff --git a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi b/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
deleted file mode 100644
index 99670e3..0000000
--- a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
+++ /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.events.internal.DefaultConfigChangeObserver
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java b/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
index 896fcf7..2685d3e 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.events;
import org.apache.commons.io.FileUtils;
import org.apache.tamaya.events.folderobserver.ObservingPropertySourceProvider;
-import org.apache.tamaya.format.formats.PropertiesFormat;
import java.io.File;
import java.nio.file.Files;
@@ -74,8 +73,7 @@ public class TestObservingProvider extends ObservingPropertySourceProvider{
}
public TestObservingProvider(){
- super(propertyLocation,
- new PropertiesFormat());
+ super(propertyLocation);
Logger.getLogger(getClass().getName()).info("Using test directory: " + getTestPath());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java
index c223004..c0a2367 100644
--- a/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java
+++ b/modules/injection-api/src/main/java/org/apache/tamaya/inject/spi/ConfiguredType.java
@@ -25,7 +25,7 @@ import java.util.Collection;
/**
* Abstract model of an type used to inject configuration. This also includes instances passed programmatically.
*/
-public interface ConfiguredType {
+public interface ConfiguredType{
/**
* Get the type's class.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/injection/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/pom.xml b/modules/injection/pom.xml
index ee532e1..c884e38 100644
--- a/modules/injection/pom.xml
+++ b/modules/injection/pom.xml
@@ -72,8 +72,6 @@ under the License.
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-events</artifactId>
<version>${project.version}</version>
- <scope>provided</scope>
- <optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
index 878263d..db6f1a2 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
@@ -30,13 +30,14 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventManager;
+import org.apache.tamaya.events.spi.BaseConfigEvent;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefault;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
import org.apache.tamaya.inject.api.InjectionUtils;
import org.apache.tamaya.inject.api.WithPropertyConverter;
+import org.apache.tamaya.inject.spi.ConfiguredType;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
@@ -229,9 +230,9 @@ final class InjectionHelper {
* When Tamaya events are not available, the call simply returns.
* @param event the event to be distributed, not null.
*/
- static void sendConfigurationEvent(ConfigEvent<?> event) {
+ static void sendConfigurationEvent(ConfiguredType event) {
if(EVENTS_AVAILABLE){
- ConfigEventManager.fireEvent(event);
+ ConfigEventManager.fireEvent(new BaseConfigEvent<ConfiguredType>(event, ConfiguredType.class) {});
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java
index 630f5fd..5494cb8 100644
--- a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java
+++ b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/HelloServiceImpl.java
@@ -1,3 +1,21 @@
+/*
+ * 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.osgi;
import org.apache.tamaya.inject.api.Config;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java
index 2078f7a..b050980 100644
--- a/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java
+++ b/modules/integration/osgi/src/test/java/org/apache/tamaya/integration/osgi/TestConfigIntegration.java
@@ -34,6 +34,7 @@ import org.jboss.shrinkwrap.api.importer.ZipImporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.*;
@@ -51,6 +52,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(Arquillian.class)
+@Ignore
public class TestConfigIntegration{
private static final String TAMAYA_VERSION = "0.2-incubating-SNAPSHOT";
@@ -185,7 +187,14 @@ public class TestConfigIntegration{
.as(JavaArchive.class);
}
- @Deployment(name="tamaya-injection", order=15)
+ @Deployment(name="tamaya-events", order=14)
+ public static JavaArchive deployTamayaEvents() {
+ return ShrinkWrap.create(ZipImporter.class, "tamaya-events.jar")
+ .importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-events:"+TAMAYA_VERSION))
+ .as(JavaArchive.class);
+ }
+
+ @Deployment(name="tamaya-injection", order=6)
public static JavaArchive deployTamayaInjectionSE() {
return ShrinkWrap.create(ZipImporter.class, "tamaya-injection.jar")
.importFrom(getBundleFile("org.apache.tamaya.ext:tamaya-injection:"+TAMAYA_VERSION))
@@ -193,6 +202,7 @@ public class TestConfigIntegration{
}
+
private static File getBundleFile(String artifactId) {
// Check
return Maven.configureResolver()
@@ -248,7 +258,6 @@ public class TestConfigIntegration{
// assertEquals("Property 'testKey' not loaded from Tamaya.", "success!", config.get("my.testProperty"));
}
- @OperateOnDeployment("default")
@Test
public void testInjection() throws Exception {
Dictionary<String,Object> config = new Hashtable<>();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
index 44960ed..5be5b5c 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.model.internal;
+import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventListener;
import org.apache.tamaya.inject.spi.ConfiguredField;
import org.apache.tamaya.inject.spi.ConfiguredMethod;
@@ -32,7 +33,7 @@ import java.util.logging.Logger;
* Internal facade that registers all kind of injected fields as {@link org.apache.tamaya.model.ConfigModel} entries,
* so all configured injection points are visible as documented configuration hooks.
*/
-public final class ConfiguredTypeEventsModelPopulator implements ConfigEventListener<ConfiguredType> {
+public final class ConfiguredTypeEventsModelPopulator implements ConfigEventListener {
/**
* The logger.
@@ -45,15 +46,19 @@ public final class ConfiguredTypeEventsModelPopulator implements ConfigEventList
private static final String ENABLE_EVENT_DOC = "org.apache.tamaya.model.autoModelEvents";
@Override
- public void onConfigEvent(ConfiguredType confType) {
+ public void onConfigEvent(ConfigEvent event) {
+ if(event.getResourceType()!=ConfiguredType.class){
+ return;
+ }
String value = System.getProperty(ENABLE_EVENT_DOC);
if(value==null?true:Boolean.parseBoolean(value)) {
+ ConfiguredType confType = (ConfiguredType)event.getResource();
for (ConfiguredField field : confType.getConfiguredFields()) {
Collection<String> keys = field.getConfiguredKeys();
for (String key : keys) {
ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
if (val == null) {
- ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+ ConfiguredTypeEventsModelProvider.addConfigModel(new ParameterModel.Builder(key)
.setType(field.getType().getName())
.setDescription("Injected field: " +
field.getAnnotatedField().getDeclaringClass().getName() + '.' + field.toString() +
@@ -67,7 +72,7 @@ public final class ConfiguredTypeEventsModelPopulator implements ConfigEventList
for (String key : keys) {
ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
if (val == null) {
- ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+ ConfiguredTypeEventsModelProvider.addConfigModel(new ParameterModel.Builder(key)
.setType(method.getParameterTypes()[0].getName())
.setDescription("Injected field: " +
method.getAnnotatedMethod().getDeclaringClass().getName() + '.' + method.toString() +
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/642796ba/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
index 6baa975..f54f77a 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
@@ -30,7 +30,7 @@ import java.util.List;
* Model provider that adds model definitions for the items published as
* {@link org.apache.tamaya.inject.spi.ConfiguredType} events.
*/
-class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
+public class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
/** The collected models. */
private static Collection<ConfigModel> configModels = new ArrayList<>();
@@ -38,7 +38,7 @@ class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
* Adds a model, called from the registered listener class.
* @param configModel adds the config model.
*/
- static void addValidation(ConfigModel configModel){
+ static void addConfigModel(ConfigModel configModel){
List<ConfigModel> newList = new ArrayList<>(configModels);
newList.add(configModel);
ConfiguredTypeEventsModelProvider.configModels = newList;
[07/10] incubator-tamaya git commit: Removed unused imports.
Posted by an...@apache.org.
Removed unused imports.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/1f36bf0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/1f36bf0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/1f36bf0c
Branch: refs/heads/master
Commit: 1f36bf0cf861fd5bd0d7ea9827f90088db0a32a4
Parents: 16361be
Author: anatole <an...@apache.org>
Authored: Wed Dec 16 08:45:14 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 16 08:45:14 2015 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/tamaya/events/ConfigEvent.java | 3 ---
.../apache/tamaya/events/folderobserver/FileChangeListener.java | 3 +--
.../events/folderobserver/ObservingPropertySourceProvider.java | 4 +---
.../tamaya/events/internal/DefaultConfigChangeObserver.java | 5 ++++-
.../apache/tamaya/events/internal/LoggingConfigListener.java | 1 -
.../org/apache/tamaya/events/spi/ConfigEventManagerSpi.java | 1 -
6 files changed, 6 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f36bf0c/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
index b56145e..5a713d7 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
@@ -18,9 +18,6 @@
*/
package org.apache.tamaya.events;
-import java.beans.PropertyChangeEvent;
-import java.util.Collection;
-
/**
* Event that contains a set current changes that were applied or could be applied.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f36bf0c/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
index af51063..3427ce8 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.events.folderobserver;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.events.PropertySourceChange;
import java.io.IOException;
import java.nio.file.FileSystem;
@@ -35,7 +34,7 @@ import java.util.logging.Logger;
/**
* Class that has the responsibility to watch the folder and then publish the changes to a
- * {@link PropertySourceChange}.
+ * {@link org.apache.tamaya.events.PropertySourceChange}.
* @see ObservingPropertySourceProvider
* This listener will wait to events and wait to one second to watch again.
* <p>If new file was created or modified will commit from this file.</p>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f36bf0c/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 14692f4..8387504 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -19,9 +19,7 @@
package org.apache.tamaya.events.folderobserver;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.events.ConfigEventManager;
-import org.apache.tamaya.events.PropertySourceChange;
import org.apache.tamaya.events.ConfigurationContextChange;
import org.apache.tamaya.events.ConfigurationContextChangeBuilder;
import org.apache.tamaya.format.ConfigurationData;
@@ -52,7 +50,7 @@ import java.util.logging.Logger;
* This implementation run in a folder taking up all file compatible with the given
* ConfigurationFormats. When a file is added, deleted or modified the PropertySourceProvider
* will adapt the changes automatically and trigger according
- * {@link PropertySourceChange} events.
+ * {@link org.apache.tamaya.events.PropertySourceChange} events.
* The default folder is META-INF/config, but you can change using the absolute path in
* "-Dtamaya.configdir" parameter.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f36bf0c/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
index 8903566..dfb3816 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
@@ -19,7 +19,10 @@
package org.apache.tamaya.events.internal;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.events.*;
+import org.apache.tamaya.events.ConfigEventManager;
+import org.apache.tamaya.events.ConfigurationChange;
+import org.apache.tamaya.events.ConfigurationChangeBuilder;
+import org.apache.tamaya.events.FrozenConfiguration;
import java.util.*;
import java.util.logging.Logger;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f36bf0c/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
index 41d6924..be8c404 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.events.internal;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventListener;
-import org.apache.tamaya.events.ConfigurationChange;
import java.util.logging.Logger;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f36bf0c/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
index 1ac1055..93c813d 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventListener;
import java.util.Collection;
-import java.util.Set;
/**
* SPI interface to implement the {@link org.apache.tamaya.events.ConfigEventManager} singleton.
[02/10] incubator-tamaya git commit: Added default implementation for
getName in base class.
Posted by an...@apache.org.
Added default implementation for getName in base class.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/8b0143a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/8b0143a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/8b0143a7
Branch: refs/heads/master
Commit: 8b0143a7e8cf515501e4236997e62de78b874af0
Parents: 5373836
Author: anatole <an...@apache.org>
Authored: Wed Dec 16 08:36:28 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 16 08:36:28 2015 +0100
----------------------------------------------------------------------
.../apache/tamaya/core/propertysource/BasePropertySource.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8b0143a7/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
index 286897c..e9f53f9 100644
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
+++ b/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
@@ -47,6 +47,11 @@ public abstract class BasePropertySource implements PropertySource{
}
@Override
+ public String getName() {
+ return getClass().getSimpleName();
+ }
+
+ @Override
public int getOrdinal() {
String configuredOrdinal = get(TAMAYA_ORDINAL);
if(configuredOrdinal!=null){
[09/10] incubator-tamaya git commit: Removed Xlint config for javadoc
since it fails when used with Java 7 as JDK for built.
Posted by an...@apache.org.
Removed Xlint config for javadoc since it fails when used with Java 7 as JDK for built.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/1c3035a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/1c3035a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/1c3035a4
Branch: refs/heads/master
Commit: 1c3035a4497340ea0cee6bf265a988a81976391a
Parents: 8213667
Author: anatole <an...@apache.org>
Authored: Wed Dec 16 08:48:43 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 16 08:48:43 2015 +0100
----------------------------------------------------------------------
modules/pom.xml | 8 --------
1 file changed, 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1c3035a4/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
index 0e55f94..3c58796 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -90,14 +90,6 @@ under the License.
</execution>
</executions>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${javadoc.version}</version>
- <configuration>
- <additionalparam>-Xdoclint:none</additionalparam>
- </configuration>
- </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
[06/10] incubator-tamaya git commit: Added licence header and Javadoc.
Posted by an...@apache.org.
Added licence header and Javadoc.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/16361bed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/16361bed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/16361bed
Branch: refs/heads/master
Commit: 16361bed386564ec6133b9027212e278e079c4ed
Parents: 3b5805e
Author: anatole <an...@apache.org>
Authored: Wed Dec 16 08:42:41 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 16 08:42:41 2015 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/events/SimpleEvent.java | 23 ++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/16361bed/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java b/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
index 2245ec0..5017aa1 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
@@ -1,9 +1,28 @@
+/*
+ * 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.events;
import org.apache.tamaya.events.spi.BaseConfigEvent;
-import java.util.UUID;
-
+/**
+ * Simple test event for testing only.
+ */
public class SimpleEvent extends BaseConfigEvent<String> {
public SimpleEvent(String paylod) {
[08/10] incubator-tamaya git commit: Fixed compilation issue and
removed unused import.
Posted by an...@apache.org.
Fixed compilation issue and removed unused import.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/82136670
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/82136670
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/82136670
Branch: refs/heads/master
Commit: 82136670cc6b2058ef1a8f601b7de3c0f96a62a0
Parents: 1f36bf0
Author: anatole <an...@apache.org>
Authored: Wed Dec 16 08:48:12 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 16 08:48:12 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/inject/internal/InjectionHelper.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/82136670/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
index c6e59db..878263d 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionHelper.java
@@ -30,13 +30,13 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventManager;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefault;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
import org.apache.tamaya.inject.api.InjectionUtils;
import org.apache.tamaya.inject.api.WithPropertyConverter;
-import org.apache.tamaya.inject.spi.ConfiguredType;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
@@ -229,7 +229,7 @@ final class InjectionHelper {
* When Tamaya events are not available, the call simply returns.
* @param event the event to be distributed, not null.
*/
- static void sendConfigurationEvent(ConfiguredType event) {
+ static void sendConfigurationEvent(ConfigEvent<?> event) {
if(EVENTS_AVAILABLE){
ConfigEventManager.fireEvent(event);
}
[05/10] incubator-tamaya git commit: Simplified events module,
adapted documentation as well. Removed model dependency from events,
since events is the more general module here.
Posted by an...@apache.org.
Simplified events module, adapted documentation as well.
Removed model dependency from events, since events is the more general module here.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/3b5805ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/3b5805ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/3b5805ed
Branch: refs/heads/master
Commit: 3b5805ed6c38df6460674dad88d63b7230c82cc3
Parents: 8b0143a
Author: anatole <an...@apache.org>
Authored: Wed Dec 16 08:37:17 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Dec 16 08:37:17 2015 +0100
----------------------------------------------------------------------
.../resources/findbugs/findbugs-exclude.xml | 6 +-
.../tamaya/events/ChangeNotification.java | 66 -----
.../org/apache/tamaya/events/ChangeType.java | 28 ++
.../org/apache/tamaya/events/ConfigEvent.java | 58 ++++
.../tamaya/events/ConfigEventListener.java | 5 +-
.../tamaya/events/ConfigEventManager.java | 112 ++++++--
.../apache/tamaya/events/ConfigListener.java | 31 ---
.../tamaya/events/ConfigurationChange.java | 222 +++++++++++++++
.../events/ConfigurationChangeBuilder.java | 272 +++++++++++++++++++
.../events/ConfigurationContextChange.java | 208 ++++++++++++++
.../ConfigurationContextChangeBuilder.java | 173 ++++++++++++
.../tamaya/events/ConfigurationObserver.java | 107 --------
.../tamaya/events/PropertySourceChange.java | 242 +++++++++++++++++
.../events/PropertySourceChangeBuilder.java | 258 ++++++++++++++++++
.../apache/tamaya/events/delta/ChangeType.java | 28 --
.../events/delta/ConfigurationChange.java | 216 ---------------
.../delta/ConfigurationChangeBuilder.java | 262 ------------------
.../delta/ConfigurationContextChange.java | 192 -------------
.../ConfigurationContextChangeBuilder.java | 159 -----------
.../events/delta/PropertySourceChange.java | 236 ----------------
.../delta/PropertySourceChangeBuilder.java | 258 ------------------
.../folderobserver/FileChangeListener.java | 3 +-
.../ObservingPropertySourceProvider.java | 8 +-
.../internal/DefaultConfigChangeObserver.java | 107 ++++++++
.../internal/DefaultConfigEventManagerSpi.java | 162 ++++++++---
.../internal/DefaultConfigObserverSpi.java | 158 -----------
...faultConfigurationContextChangeListener.java | 57 ++--
.../events/internal/LoggingConfigListener.java | 14 +-
.../org/apache/tamaya/events/package-info.java | 3 +-
.../tamaya/events/spi/BaseConfigEvent.java | 69 +++++
.../events/spi/ConfigEventManagerSpi.java | 83 +++++-
.../tamaya/events/spi/ConfigObserverSpi.java | 71 -----
...org.apache.tamaya.events.ConfigEventListener | 2 +-
...g.apache.tamaya.events.spi.ConfigObserverSpi | 2 +-
.../events/ChangeableGlobalPropertySource.java | 62 +++++
.../ChangeableThreadLocalPropertySource.java | 57 ++++
.../tamaya/events/ConfigEventManagerTest.java | 25 +-
.../org/apache/tamaya/events/SimpleEvent.java | 13 +
.../events/delta/ConfigurationChangeTest.java | 4 +-
.../delta/ConfigurationContextChangeTest.java | 9 +-
.../events/delta/PropertySourceChangeTest.java | 5 +-
.../DefaultConfigEventManagerSpiTest.java | 19 +-
.../apache/tamaya/model/ConfigModelManager.java | 6 +-
.../ConfiguredTypeEventsModelPopulator.java | 54 ++--
.../ConfiguredTypeEventsModelProvider.java | 2 +-
45 files changed, 2189 insertions(+), 1945 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
index 17f61bb..14533e9 100644
--- a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
+++ b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml
@@ -107,7 +107,7 @@ under the License.
</Match>
<Match>
- <Class name="org.apache.tamaya.events.internal.DefaultConfigObserverSpi" />
+ <Class name="org.apache.tamaya.events.internal.DefaultConfigChangeObserver" />
<Method name="checkConfigurationUpdate" />
</Match>
@@ -119,11 +119,11 @@ under the License.
</Match>
<Match>
<!-- Imported from APache Felix. -->
- <Class name="org.apache.tamaya.integration.osgi.base.FilePersistenceManager"/>
+ <Class name="org.apache.tamaya.integration.osgi.felix.FilePersistenceManager"/>
</Match>
<Match>
<!-- Imported from APache Felix. -->
- <Class name="org.apache.tamaya.integration.osgi.base.ConfigurationHandler"/>
+ <Class name="org.apache.tamaya.integration.osgi.felix.ConfigurationHandler"/>
</Match>
<Match>
<Class name="org.apache.tamaya.integration.osgi.injection.Activator"/>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ChangeNotification.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ChangeNotification.java b/modules/events/src/main/java/org/apache/tamaya/events/ChangeNotification.java
deleted file mode 100644
index 73a4fa9..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/ChangeNotification.java
+++ /dev/null
@@ -1,66 +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.events;
-
-import java.beans.PropertyChangeEvent;
-import java.util.Collection;
-
-
-/**
- * Event that contains a set current changes that were applied or could be applied.
- * @param <T> the event type
- */
-public interface ChangeNotification<T>{
-
- /**
- * Get the underlying property provider/configuration.
- * @return the underlying property provider/configuration, never null.
- */
- T getResource();
-
- /**
- * Get the version relative to the observed resource. The version is required to be unique for
- * each change emmitted for a resource. There is no further requirement how this uniqueness is
- * modelled, so returning a UUID is cometely valid.
- * @return the base version.
- */
- String getVersion();
-
- /**
- * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
- * identify a changeset.
- * @return the timestamp, when this changeset was created.
- */
- long getTimestamp();
-
- /**
- * Get the changes recorded.
- * @return the recorded changes, never null.
- */
- Collection<PropertyChangeEvent> getChanges();
-
- /**
- * Checks if the given key is added, or updated OR removed.
- * @param key the target key (can also be a regular expression), that matches the requested keys,
- * not null.
- * @return true, if the given key was added, or updated BUT NOT removed.
- */
- boolean isKeyAffected(String key);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ChangeType.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ChangeType.java b/modules/events/src/main/java/org/apache/tamaya/events/ChangeType.java
new file mode 100644
index 0000000..4363579
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ChangeType.java
@@ -0,0 +1,28 @@
+/*
+ * 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.events;
+
+/**
+ * Created by Anatole on 20.02.2015.
+ */
+public enum ChangeType {
+ NEW,
+ DELETED,
+ UPDATED,
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
new file mode 100644
index 0000000..b56145e
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
@@ -0,0 +1,58 @@
+/*
+ * 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.events;
+
+import java.beans.PropertyChangeEvent;
+import java.util.Collection;
+
+
+/**
+ * Event that contains a set current changes that were applied or could be applied.
+ * @param <T> the resource type.
+ */
+public interface ConfigEvent<T>{
+
+ /**
+ * Access the type of resource. This allows to easily determine the resource an event wants to observe.
+ * @return the resource type.
+ */
+ Class<T> getResourceType();
+
+ /**
+ * Get the underlying property provider/configuration.
+ * @return the underlying property provider/configuration, never null.
+ */
+ T getResource();
+
+ /**
+ * Get the version relative to the observed resource. The version is required to be unique for
+ * each change emmitted for a resource. There is no further requirement how this uniqueness is
+ * modelled, so returning a UUID is a completely valid strategy.
+ * @return the base version.
+ */
+ String getVersion();
+
+ /**
+ * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
+ * identify a changeset.
+ * @return the timestamp, when this changeset was created.
+ */
+ long getTimestamp();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
index dde5175..de635f8 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventListener.java
@@ -20,14 +20,13 @@ package org.apache.tamaya.events;
/**
* Interface to be implemented for listening on changes on {@link org.apache.tamaya.Configuration} instances.
- * @param <T> the type listened to.
*/
//@FunctionalInterface
-public interface ConfigEventListener<T> {
+public interface ConfigEventListener {
/**
* Called if an event occurred.
* @param event the event, not null.
*/
- void onConfigEvent(T event);
+ void onConfigEvent(ConfigEvent<?> event);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
index 1095d48..f0bd0fa 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
@@ -42,12 +42,23 @@ public final class ConfigEventManager {
}
/**
- * Add a listener for observing change events on {@link org.apache.tamaya.Configuration}. References of this
- * component to the listeners must be managed as weak references.
- *
+ * Adds a Config listener that listens to all kind of {@link ConfigEvent}.
+ * @param l the listener not null.
+ */
+ public static void addListener(ConfigEventListener l) {
+ if (SPI == null) {
+ throw new ConfigException("No SPI registered for " +
+ ConfigEventManager.class.getName());
+ }
+ SPI.addListener(l);
+ }
+
+ /**
+ * Adds a Config listener that listens to all kind of {@link ConfigEvent}.
* @param l the listener not null.
+ * @param eventType the event type to which this listener listens to.
*/
- public static <T> void addListener(ConfigEventListener<T> l) {
+ public static <T extends ConfigEvent> void addListener(ConfigEventListener l, Class<T> eventType) {
if (SPI == null) {
throw new ConfigException("No SPI registered for " +
ConfigEventManager.class.getName());
@@ -56,12 +67,25 @@ public final class ConfigEventManager {
}
/**
- * Add a listener for observing change events on {@link org.apache.tamaya.spi.PropertySource}. References of this
- * component to the listeners must be managed as weak references.
+ * Removes a listener registered globally.
+ *
+ * @param l the listener not null.
+ */
+ public static void removeListener(ConfigEventListener l) {
+ if (SPI == null) {
+ throw new ConfigException("No SPI registered for " +
+ ConfigEventManager.class.getName());
+ }
+ SPI.removeListener(l);
+ }
+
+ /**
+ * Removes a listener registered for the given event type.
*
* @param l the listener not null.
+ * @param eventType the event type to which this listener listens to.
*/
- public static <T> void removeListener(ConfigEventListener<T> l) {
+ public static <T extends ConfigEvent> void removeListener(ConfigEventListener l, Class<T> eventType) {
if (SPI == null) {
throw new ConfigException("No SPI registered for " +
ConfigEventManager.class.getName());
@@ -70,38 +94,84 @@ public final class ConfigEventManager {
}
/**
- * Access all registered ConfigEventListeners listening to the given event type.
+ * Access all registered ConfigEventListeners listening to a given event type.
* @param type the event type
* @param <T> type param
* @return a list with the listeners found, never null.
*/
- public static <T>
- Collection<? extends ConfigEventListener<T>> getListeneters(Class<T> type) {
+ public static <T extends ConfigEvent>
+ Collection<? extends ConfigEventListener> getListeners(Class<T> type) {
return SPI.getListeners(type);
}
+ /**
+ * Access all registered ConfigEventListeners listening to a all kind of event types globally.
+ * @return a list with the listeners found, never null.
+ */
+ public static <T extends ConfigEvent>
+ Collection<? extends ConfigEventListener> getListeners() {
+ return SPI.getListeners();
+ }
/**
- * Publishes sn event to all interested listeners.
+ * Publishes a {@link ConfigurationChange} synchronously to all interested listeners.
*
* @param event the event, not null.
*/
- public static void fireEvent(Object event) {
- fireEvent(event, (Class)event.getClass());
+ public static <T> void fireEvent(ConfigEvent<?> event) {
+ SPI.fireEvent(event);
}
/**
- * Publishes a {@link org.apache.tamaya.events.delta.ConfigurationChange} to all interested listeners.
+ * Publishes a {@link ConfigurationChange} asynchronously/multithreaded to all interested listeners.
*
* @param event the event, not null.
- * @param eventType the event type, the vent may be a subclass.
*/
- public static <T> void fireEvent(T event, Class<T> eventType) {
- if (SPI == null) {
- throw new ConfigException("No SPI registered for " +
- ConfigEventManager.class.getName());
- }
- SPI.fireEvent(event, eventType);
+ public static <T> void fireEventAsynch(ConfigEvent<?> event) {
+ SPI.fireEventAsynch(event);
+ }
+
+ /**
+ * Start/Stop the change monitoring service, which will observe/reevaluate the current configuration regularly
+ * and triggers ConfigurationChange events is something changed. This is quite handy for publishing
+ * configuration changes to whatever systems are interested in. Hereby the origin of a configuration change
+ * can be on this machine, or also remotedly. FOr handling corresponding {@link ConfigEventListener} have
+ * to be registered, e.g. listening on {@link org.apache.tamaya.events.ConfigurationChange} events.
+ * @see #isChangeMonitoring()
+ * @see #getChangeMonitoringPeriod()
+ */
+ public static void enableChangeMonitoring(boolean enable) {
+ SPI.enableChangeMonitor(enable);
+ }
+
+ /**
+ * Check if the observer is running currently.
+ *
+ * @return true, if the change monitoring service is currently running.
+ * @see #enableChangeMonitoring(boolean)
+ */
+ public static boolean isChangeMonitoring() {
+ return SPI.isChangeMonitorActive();
+ }
+
+ /**
+ * Get the current check period to check for configuration changes.
+ *
+ * @return the check period in ms.
+ */
+ public long getChangeMonitoringPeriod(){
+ return SPI.getChangeMonitoringPeriod();
+ }
+
+ /**
+ * Sets the current monitoring period and restarts the monitor. You still have to enable the monitor if
+ * it is currently not enabled.
+ * @param millis
+ * @see #enableChangeMonitoring(boolean)
+ * @see #isChangeMonitoring()
+ */
+ public void setChangeMonitoringPeriod(long millis){
+ SPI.setChangeMonitoringPeriod(millis);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigListener.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigListener.java
deleted file mode 100644
index 3608921..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigListener.java
+++ /dev/null
@@ -1,31 +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.events;
-
-import org.apache.tamaya.events.delta.ConfigurationChange;
-
-/**
- * Simple observer interface that can be registered using the current {@code ServiceContext}.
- * This class will be called on each configuration change detected in the current environment.
- */
-// @FunctionalInterface
-public interface ConfigListener
- extends ConfigEventListener<ConfigurationChange> {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java
new file mode 100644
index 0000000..a291084
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java
@@ -0,0 +1,222 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.Configuration;
+
+import java.beans.PropertyChangeEvent;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Event that contains a set current changes that were applied or could be applied.
+ * This class is immutable and thread-safe. To create instances use
+ * {@link PropertySourceChangeBuilder}.
+ *
+ * Created by Anatole on 22.10.2014.
+ */
+public final class ConfigurationChange implements ConfigEvent<Configuration>, Serializable{
+
+ private static final long serialVersionUID = 1L;
+ /** The base property provider/configuration. */
+ private FrozenConfiguration configuration;
+ /** The base version, usable for optimistic locking. */
+ private String version = UUID.randomUUID().toString();
+ /** The timestamp of the change set in millis from the epoch. */
+ private long timestamp = System.currentTimeMillis();
+ /** The recorded changes. */
+ private Map<String,PropertyChangeEvent> changes = new HashMap<>();
+
+ /**
+ * Get an empty change set for the given provider.
+ * @param configuration The configuration changed, not null.
+ * @return an empty ConfigurationChangeSet instance.
+ */
+ public static ConfigurationChange emptyChangeSet(Configuration configuration){
+ return ConfigurationChangeBuilder.of(configuration).build();
+ }
+
+ /**
+ * Constructor used by {@link PropertySourceChangeBuilder}.
+ * @param builder The builder used, not null.
+ */
+ ConfigurationChange(ConfigurationChangeBuilder builder) {
+ this.configuration = FrozenConfiguration.of(builder.source);
+ for(PropertyChangeEvent ev:builder.delta.values()){
+ this.changes.put(ev.getPropertyName(), ev);
+ }
+ if(builder.version!=null){
+ this.version = builder.version;
+ }
+ if(builder.timestamp!=null){
+ this.timestamp = builder.timestamp;
+ }
+ }
+
+ @Override
+ public Class<Configuration> getResourceType() {
+ return Configuration.class;
+ }
+
+ /**
+ * Get the underlying property provider/configuration.
+ * @return the underlying property provider/configuration, never null.
+ */
+ @Override
+ public Configuration getResource(){
+ return this.configuration;
+ }
+
+ /**
+ * Get the base version, usable for optimistic locking.
+ * @return the base version.
+ */
+ @Override
+ public String getVersion(){
+ return version;
+ }
+
+ /**
+ * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
+ * identify a changeset.
+ * @return the timestamp, when this changeset was created.
+ */
+ @Override
+ public long getTimestamp(){
+ return timestamp;
+ }
+
+ /**
+ * Get the changes recorded.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertyChangeEvent> getChanges(){
+ return Collections.unmodifiableCollection(this.changes.values());
+ }
+
+ /**
+ * Access the number current removed entries.
+ * @return the number current removed entries.
+ */
+ public int getRemovedSize() {
+ int removedCount = 0;
+ for(PropertyChangeEvent ev:this.changes.values()){
+ if(ev.getNewValue() == null){
+ removedCount++;
+ }
+ }
+ return removedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
+ }
+
+ /**
+ * Access the number current added entries.
+ * @return the number current added entries.
+ */
+ public int getAddedSize() {
+ int addedCount = 0;
+ for(PropertyChangeEvent ev:this.changes.values()){
+ if(ev.getOldValue() == null &&
+ ev.getNewValue() != null){
+ addedCount++;
+ }
+ }
+ return addedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null &&
+// e.getNewValue() != null).count();
+ }
+
+ /**
+ * Access the number current updated entries.
+ * @return the number current updated entries.
+ */
+ public int getUpdatedSize() {
+ int updatedCount = 0;
+ for(PropertyChangeEvent ev:this.changes.values()){
+ if( ev.getOldValue()!=null && ev.getNewValue()!=null){
+ updatedCount++;
+ }
+ }
+ return updatedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
+ }
+
+
+ /**
+ * Checks if the given key was removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was removed.
+ */
+ public boolean isRemoved(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() == null;
+ }
+
+ /**
+ * Checks if the given key was added.
+ * @param key the target key, not null.
+ * @return true, if the given key was added.
+ */
+ public boolean isAdded(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() == null;
+ }
+
+ /**
+ * Checks if the given key was updated.
+ * @param key the target key, not null.
+ * @return true, if the given key was updated.
+ */
+ public boolean isUpdated(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() != null && change.getNewValue() != null;
+ }
+
+ /**
+ * Checks if the given key is added, or updated AND NOT removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was added, or updated BUT NOT removed.
+ */
+ public boolean isKeyAffected(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() != null;
+ }
+
+ /**
+ * CHecks if the current change set does not contain any changes.
+ * @return tru, if the change set is empty.
+ */
+ public boolean isEmpty(){
+ return this.changes.isEmpty();
+ }
+
+
+ @Override
+ public String toString() {
+ return "ConfigurationChange{" +
+ "configuration=" + configuration +
+ ", version='" + version + '\'' +
+ ", timestamp=" + timestamp +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java
new file mode 100644
index 0000000..78f60a9
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java
@@ -0,0 +1,272 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+
+import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
+ * can observing changes to property sources and
+ * <ol>
+ * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
+ * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
+ * change, its only the data of the property source).</li>
+ * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
+ * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
+ * event on configuration level.
+ * </ol>
+ */
+public final class ConfigurationChangeBuilder {
+ /**
+ * The recorded changes.
+ */
+ final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
+ /**
+ * The underlying configuration/provider.
+ */
+ Configuration source;
+ /**
+ * The version configured, or null, for generating a default.
+ */
+ String version;
+ /**
+ * The optional timestamp in millis of this epoch.
+ */
+ Long timestamp;
+
+ /**
+ * Constructor.
+ *
+ * @param configuration the underlying configuration, not null.
+ */
+ private ConfigurationChangeBuilder(Configuration configuration) {
+ this.source = Objects.requireNonNull(configuration);
+ }
+
+ /**
+ * Creates a new instance current this builder using the current COnfiguration as root resource.
+ *
+ * @return the builder for chaining.
+ */
+ public static ConfigurationChangeBuilder of() {
+ return new ConfigurationChangeBuilder(ConfigurationProvider.getConfiguration());
+ }
+
+ /**
+ * Creates a new instance current this builder.
+ *
+ * @param configuration the configuration changed, not null.
+ * @return the builder for chaining.
+ */
+ public static ConfigurationChangeBuilder of(Configuration configuration) {
+ return new ConfigurationChangeBuilder(configuration);
+ }
+
+ /**
+ * Compares the two property config/configurations and creates a collection current all changes
+ * that must be appied to render {@code map1} into {@code map2}.
+ *
+ * @param map1 the source map, not null.
+ * @param map2 the target map, not null.
+ * @return a collection current change events, never null.
+ */
+ public static Collection<PropertyChangeEvent> compare(Configuration map1, Configuration map2) {
+ List<PropertyChangeEvent> changes = new ArrayList<>();
+ for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
+ String val = map2.get(en.getKey());
+ if (val == null) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ } else if (!val.equals(en.getValue())) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
+ }
+ }
+ for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
+ String val = map1.get(en.getKey());
+ if (val == null) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ } else if (!val.equals(en.getValue())) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
+ }
+ }
+ return changes;
+ }
+
+ /*
+ * Apply a version/UUID to the set being built.
+ * @param version the version to apply, or null, to let the system generate a version for you.
+ * @return the builder for chaining.
+ */
+ public ConfigurationChangeBuilder setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ /*
+ * Apply given timestamp to the set being built.
+ * @param version the version to apply, or null, to let the system generate a version for you.
+ * @return the builder for chaining.
+ */
+ public ConfigurationChangeBuilder setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ return this;
+ }
+
+ /**
+ * This method records all changes to be applied to the base property provider/configuration to
+ * achieve the given target state.
+ *
+ * @param newState the new target state, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationChangeBuilder addChanges(Configuration newState) {
+ for (PropertyChangeEvent c : compare(newState, this.source)) {
+ this.delta.put(c.getPropertyName(), c);
+ }
+ return this;
+ }
+
+ /**
+ * Applies a single key/value change.
+ *
+ * @param key the changed key
+ * @param value the new value.
+ * @return this instance for chining.
+ */
+ public ConfigurationChangeBuilder addChange(String key, String value) {
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key), value));
+ return this;
+ }
+
+ /**
+ * Get the current values, also considering any changes recorded within this change set.
+ *
+ * @param key the key current the entry, not null.
+ * @return the keys, or null.
+ */
+ public String get(String key) {
+ PropertyChangeEvent change = this.delta.get(key);
+ if (change != null && !(change.getNewValue() == null)) {
+ return (String) change.getNewValue();
+ }
+ return null;
+ }
+
+ /**
+ * Marks the given key(s) fromMap the configuration/properties to be removed.
+ *
+ * @param key the key current the entry, not null.
+ * @param otherKeys additional keys to be removed (convenience), not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationChangeBuilder removeKey(String key, String... otherKeys) {
+ String oldValue = this.source.get(key);
+ if (oldValue == null) {
+ this.delta.remove(key);
+ }
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
+ for (String addKey : otherKeys) {
+ oldValue = this.source.get(addKey);
+ if (oldValue == null) {
+ this.delta.remove(addKey);
+ }
+ this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null));
+ }
+ return this;
+ }
+
+ /**
+ * Apply all the given values to the base configuration/properties.
+ * Note that all values passed must be convertible to String, either
+ * <ul>
+ * <li>the registered codecs provider provides codecs for the corresponding keys, or </li>
+ * <li>default codecs are present for the given type, or</li>
+ * <li>the value is an instanceof String</li>
+ * </ul>
+ *
+ * @param changes the changes to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationChangeBuilder putAll(Map<String, String> changes) {
+ changes.putAll(changes);
+ return this;
+ }
+
+ /**
+ * This method will create a change set that clears all entries fromMap the given base configuration/properties.
+ *
+ * @return the builder for chaining.
+ */
+ public ConfigurationChangeBuilder removeAllKeys() {
+ this.delta.clear();
+ for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
+ this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null));
+ }
+// this.source.getProperties().forEach((k, v) ->
+// this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
+ return this;
+ }
+
+ /**
+ * Checks if the change set is empty, i.e. does not contain any changes.
+ *
+ * @return true, if the set is empty.
+ */
+ public boolean isEmpty() {
+ return this.delta.isEmpty();
+ }
+
+ /**
+ * Resets this change set instance. This will clear all changes done to this builder, so the
+ * set will be empty.
+ */
+ public void reset() {
+ this.delta.clear();
+ }
+
+ /**
+ * Builds the corresponding change set.
+ *
+ * @return the new change set, never null.
+ */
+ public ConfigurationChange build() {
+ return new ConfigurationChange(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "ConfigurationChangeSetBuilder [config=" + source + ", " +
+ ", delta=" + delta + "]";
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java
new file mode 100644
index 0000000..eda5ab1
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java
@@ -0,0 +1,208 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Event that contains a set current changes that were applied or could be applied.
+ * This class is immutable and thread-safe. To create instances use
+ * {@link PropertySourceChangeBuilder}.
+ *
+ * Created by Anatole on 22.10.2014.
+ */
+public final class ConfigurationContextChange implements ConfigEvent<ConfigurationContext>, Serializable{
+
+ private static final long serialVersionUID = 1L;
+ /** The base property provider/configuration. */
+ private List<PropertySourceChange> changedPropertySources = new ArrayList<>();
+ /** The base version, usable for optimistic locking. */
+ private String version = UUID.randomUUID().toString();
+ /** The timestamp of the change set in millis from the epoch. */
+ private long timestamp = System.currentTimeMillis();
+ /** The configuration context. */
+ private ConfigurationContext configurationContext;
+
+ /**
+ * Get an empty change set for the given provider.
+ * @return an empty ConfigurationContextChange instance.
+ */
+ public static ConfigurationContextChange emptyChangeSet(ConfigurationContext configurationContext){
+ return ConfigurationContextChangeBuilder.of(configurationContext).build();
+ }
+
+ /**
+ * Constructor used by {@link PropertySourceChangeBuilder}.
+ * @param builder The builder used, not null.
+ */
+ ConfigurationContextChange(ConfigurationContextChangeBuilder builder) {
+ this.changedPropertySources.addAll(builder.changedPropertySources);
+ if(builder.version!=null){
+ this.version = builder.version;
+ }
+ if(builder.timestamp!=null){
+ this.timestamp = builder.timestamp;
+ }
+ this.configurationContext = builder.configurationContext;
+ }
+
+ @Override
+ public Class<ConfigurationContext> getResourceType() {
+ return ConfigurationContext.class;
+ }
+
+ @Override
+ public ConfigurationContext getResource() {
+ return configurationContext;
+ }
+
+ /**
+ * Get the base version, usable for optimistic locking.
+ * @return the base version.
+ */
+ @Override
+ public String getVersion(){
+ return version;
+ }
+
+ /**
+ * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
+ * identify a changeset.
+ * @return the timestamp, when this changeset was created.
+ */
+ @Override
+ public long getTimestamp(){
+ return timestamp;
+ }
+
+ /**
+ * Get the changes recorded.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertySourceChange> getPropertySourceChanges(){
+ return Collections.unmodifiableCollection(this.changedPropertySources);
+ }
+
+ /**
+ * Get the property source updates.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertySourceChange> getPropertySourceUpdates(){
+ List<PropertySourceChange> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.UPDATED) {
+ result.add(pc);
+ }
+ }
+ return result;
+// return Collections.unmodifiableCollection(this.changedPropertySources).stream()
+// .filter(pc -> pc.getChangeType()==ChangeType.UPDATED).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the property sources to be removed.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertySource> getRemovedPropertySources(){
+ List<PropertySource> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.DELETED) {
+ result.add(pc.getResource());
+ }
+ }
+ return result;
+// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.DELETED).
+// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the property sources to be added.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertySource> getAddedPropertySources(){
+ List<PropertySource> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.NEW) {
+ result.add(pc.getResource());
+ }
+ }
+ return result;
+// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.NEW).
+// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the property sources to be updated.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertySource> getUpdatedPropertySources(){
+ List<PropertySource> result = new ArrayList<>();
+ for (PropertySourceChange pc : this.changedPropertySources) {
+ if (pc.getChangeType() == ChangeType.UPDATED) {
+ result.add(pc.getResource());
+ }
+ }
+ return result;
+// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.UPDATED).
+// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
+ }
+
+ /**
+ * Checks if the given propertySource is affected (added, changed or removed).
+ * @param propertySource the propertySource, not null.
+ * @return true, if the given propertySource ia affected.
+ */
+ public boolean isAffected(PropertySource propertySource) {
+ for (PropertySourceChange ps : this.changedPropertySources) {
+ if (ps.getResource() == propertySource ||
+ ps.getResource().getName().equals(propertySource.getName())) {
+ return true;
+ }
+ }
+ return false;
+// return this.changedPropertySources.stream().filter(ps -> ps.getPropertySource()==propertySource ||
+// ps.getPropertySource().getName().equals(propertySource.getName())).findAny().isPresent();
+ }
+
+ /**
+ * CHecks if the current change set does not contain any changes.
+ * @return tru, if the change set is empty.
+ */
+ public boolean isEmpty(){
+ return this.changedPropertySources.isEmpty();
+ }
+
+
+ @Override
+ public String toString() {
+ return "ConfigurationContextChange{" +
+ "changedPropertySources=" + changedPropertySources +
+ ", version='" + version + '\'' +
+ ", timestamp=" + timestamp +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java
new file mode 100644
index 0000000..2341f92
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java
@@ -0,0 +1,173 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
+ * can observing changes to property sources and
+ * <ol>
+ * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
+ * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
+ * change, its only the data of the property source).</li>
+ * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
+ * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
+ * event on configuration level.
+ * </ol>
+ */
+public final class ConfigurationContextChangeBuilder {
+ /**
+ * The recorded changes.
+ */
+ final List<PropertySourceChange> changedPropertySources = new ArrayList<>();
+ /**
+ * The version configured, or null, for generating a default.
+ */
+ String version;
+ /**
+ * The optional timestamp in millis of this epoch.
+ */
+ Long timestamp;
+
+ ConfigurationContext configurationContext;
+
+ /**
+ * Constructor.
+ */
+ private ConfigurationContextChangeBuilder(ConfigurationContext configurationContext) {
+ this.configurationContext = Objects.requireNonNull(configurationContext);
+ }
+
+ /**
+ * Just creates a new ConfigurationContextBuilder using the current COnfigurationContext has root resource.
+ * @return a new ConfigurationContextBuilder, never null.
+ */
+ public static ConfigurationContextChangeBuilder of() {
+ return of(ConfigurationProvider.getConfigurationContext());
+ }
+
+ /**
+ * Creates a new instance current this builder.
+ *
+ * @return the builder for chaining.
+ */
+ public static ConfigurationContextChangeBuilder of(ConfigurationContext context) {
+ return new ConfigurationContextChangeBuilder(context);
+ }
+
+ /*
+ * Apply a version/UUID to the set being built.
+ * @param version the version to apply, or null, to let the system generate a version for you.
+ * @return the builder for chaining.
+ */
+ public ConfigurationContextChangeBuilder setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ /*
+ * Apply given timestamp to the set being built.
+ * @param version the version to apply, or null, to let the system generate a version for you.
+ * @return the builder for chaining.
+ */
+ public ConfigurationContextChangeBuilder setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ return this;
+ }
+
+ /**
+ * This method records all changes to be applied to the base property provider/configuration to
+ * achieve the given target state.
+ *
+ * @param propertySource the new target state, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationContextChangeBuilder newPropertySource(PropertySource propertySource) {
+ this.changedPropertySources.add(PropertySourceChange.ofAdded(propertySource));
+ return this;
+ }
+
+ /**
+ * This method records all changes to be applied to the base property provider/configuration to
+ * achieve the given target state.
+ *
+ * @param propertySource the new target state, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationContextChangeBuilder removedPropertySource(PropertySource propertySource) {
+ this.changedPropertySources.add(PropertySourceChange.ofDeleted(propertySource));
+ return this;
+ }
+
+ /**
+ * This method records all changes to be applied to the base property provider/configuration to
+ * achieve the given target state.
+ *
+ * @param propertySourceChange the change state, not null.
+ * @return the builder for chaining.
+ */
+ public ConfigurationContextChangeBuilder changedPropertySource(PropertySourceChange propertySourceChange) {
+ this.changedPropertySources.add(Objects.requireNonNull(propertySourceChange));
+ return this;
+ }
+
+ /**
+ * Checks if the change set is empty, i.e. does not contain any changes.
+ *
+ * @return true, if the set is empty.
+ */
+ public boolean isEmpty() {
+ return this.changedPropertySources.isEmpty();
+ }
+
+ /**
+ * Resets this change set instance. This will clear all changes done to this builder, so the
+ * set will be empty.
+ */
+ public void reset() {
+ this.changedPropertySources.clear();
+ }
+
+ /**
+ * Builds the corresponding change set.
+ *
+ * @return the new change set, never null.
+ */
+ public ConfigurationContextChange build() {
+ return new ConfigurationContextChange(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "ConfigurationContextChangeBuilder [propertySources=" + changedPropertySources + "]";
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationObserver.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationObserver.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationObserver.java
deleted file mode 100644
index 1eafc0c..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationObserver.java
+++ /dev/null
@@ -1,107 +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.events;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.events.spi.ConfigObserverSpi;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * Singleton accessor for managing {@link ConfigListener} instances and mappings.
- */
-public class ConfigurationObserver {
-
- /**
- * Private singleton constructor.
- */
- private ConfigurationObserver() {
- }
-
- /**
- * The backing SPI.
- */
- private static final ConfigObserverSpi SPI = ServiceContextManager.getServiceContext()
- .getService(ConfigObserverSpi.class);
-
-
- /**
- * Add key expressions for generating ConfigurationChange events.
- *
- * @param keys the keys to be observed for changes.
- */
- public static <T> void addObservedKeys(Collection<String> keys) {
- if (SPI == null) {
- throw new ConfigException("No SPI registered for " +
- ConfigurationObserver.class.getName());
- }
- SPI.addObservedKeys(keys);
- }
-
- /**
- * Add key expressions for generating ConfigurationChange events.
- *
- * @param keys the keys to be observed for changes.
- */
- public static <T> void addObservedKeys(String... keys) {
- if (SPI == null) {
- throw new ConfigException("No SPI registered for " +
- ConfigurationObserver.class.getName());
- }
- SPI.addObservedKeys(Arrays.asList(keys));
- }
-
- /**
- * Removes key expressions for generating ConfigurationChange events.
- *
- * @param keys the keys to be observed for changes.
- */
- public static <T> void removeObservedKeys(Collection<String> keys) {
- if (SPI == null) {
- throw new ConfigException("No SPI registered for " +
- ConfigurationObserver.class.getName());
- }
- SPI.removeObservedKeys(keys);
- }
-
- /**
- * Removes key expressions for generating ConfigurationChange events.
- *
- * @param keys the keys to be observed for changes.
- */
- public static <T> void removeObservedKeys(String... keys) {
- if (SPI == null) {
- throw new ConfigException("No SPI registered for " +
- ConfigurationObserver.class.getName());
- }
- SPI.removeObservedKeys(Arrays.asList(keys));
- }
-
- /**
- * Get all registered key expressions for generating ConfigurationChange events.
- *
- * @return set with the keys found, never null.
- */
- public static Set<String> getObservedKeys() {
- return SPI.getObservedKeys();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java
new file mode 100644
index 0000000..a34e949
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java
@@ -0,0 +1,242 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.beans.PropertyChangeEvent;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Event that contains a set current changes that were applied or could be applied.
+ * This class is immutable and thread-safe. To create instances use
+ * {@link PropertySourceChangeBuilder}.
+ *
+ * Created by Anatole on 22.10.2014.
+ */
+public final class PropertySourceChange implements ConfigEvent<PropertySource>, Serializable{
+
+ private static final long serialVersionUID = 1L;
+ /** The base property provider/configuration. */
+ private FrozenPropertySource propertySource;
+ /** The base version, usable for optimistic locking. */
+ private String version = UUID.randomUUID().toString();
+ /** The timestamp of the change set in millis from the epoch. */
+ private long timestamp = System.currentTimeMillis();
+ /** The recorded changes. */
+ private Map<String,PropertyChangeEvent> changes = new HashMap<>();
+ /** The overall type of change. */
+ private ChangeType changeType;
+
+ /**
+ * Constructor used by {@link PropertySourceChangeBuilder}.
+ * @param builder The builder used, not null.
+ */
+ PropertySourceChange(PropertySourceChangeBuilder builder) {
+ this.propertySource = FrozenPropertySource.of(builder.source);
+ for (PropertyChangeEvent c : builder.delta.values()) {
+ this.changes.put(c.getPropertyName(), c);
+ }
+ if(builder.version!=null){
+ this.version = builder.version;
+ }
+ if(builder.timestamp!=null){
+ this.timestamp = builder.timestamp;
+ }
+ this.changeType = builder.changeType;
+ }
+
+ /**
+ * Gets the type of change for this PropertySource.
+ * @return the type of change for this PropertySource, never null.
+ */
+ public ChangeType getChangeType(){
+ return this.changeType;
+ }
+
+ @Override
+ public Class<PropertySource> getResourceType() {
+ return PropertySource.class;
+ }
+
+ /**
+ * Get the underlying property provider/configuration.
+ * @return the underlying property provider/configuration, or null, if the change instance was deserialized.
+ */
+ @Override
+ public PropertySource getResource(){
+ return this.propertySource;
+ }
+
+ /**
+ * Get the base version, usable for optimistic locking.
+ * @return the base version.
+ */
+ @Override
+ public String getVersion(){
+ return version;
+ }
+
+ /**
+ * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
+ * identify a changeset.
+ * @return the timestamp, when this changeset was created.
+ */
+ @Override
+ public long getTimestamp(){
+ return timestamp;
+ }
+
+ /**
+ * Get the changes recorded.
+ * @return the recorded changes, never null.
+ */
+ public Collection<PropertyChangeEvent> getChanges(){
+ return Collections.unmodifiableCollection(this.changes.values());
+ }
+
+ /**
+ * Access the number current removed entries.
+ * @return the number current removed entries.
+ */
+ public int getRemovedSize() {
+ int removedCount = 0;
+ for (PropertyChangeEvent ev : this.changes.values()) {
+ if (ev.getNewValue() == null) {
+ removedCount++;
+ }
+ }
+ return removedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
+ }
+
+ /**
+ * Access the number current added entries.
+ * @return the number current added entries.
+ */
+ public int getAddedSize() {
+ int addedCount = 0;
+ for (PropertyChangeEvent ev : this.changes.values()) {
+ if (ev.getOldValue() == null &&
+ ev.getNewValue() != null) {
+ addedCount++;
+ }
+ }
+ return addedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
+ }
+
+ /**
+ * Access the number current updated entries.
+ * @return the number current updated entries.
+ */
+ public int getUpdatedSize() {
+ int updatedCount = 0;
+ for (PropertyChangeEvent ev : this.changes.values()) {
+ if (ev.getOldValue() != null && ev.getNewValue() != null) {
+ updatedCount++;
+ }
+ }
+ return updatedCount;
+// return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
+ }
+
+
+ /**
+ * Checks if the given key was removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was removed.
+ */
+ public boolean isRemoved(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() == null;
+ }
+
+ /**
+ * Checks if the given key was added.
+ * @param key the target key, not null.
+ * @return true, if the given key was added.
+ */
+ public boolean isAdded(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() == null;
+ }
+
+ /**
+ * Checks if the given key was updated.
+ * @param key the target key, not null.
+ * @return true, if the given key was updated.
+ */
+ public boolean isUpdated(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getOldValue() != null && change.getNewValue() != null;
+ }
+
+ /**
+ * Checks if the given key is added, or updated AND NOT removed.
+ * @param key the target key, not null.
+ * @return true, if the given key was added, or updated BUT NOT removed.
+ */
+ public boolean isKeyAffected(String key) {
+ PropertyChangeEvent change = this.changes.get(key);
+ return change != null && change.getNewValue() != null;
+ }
+
+ /**
+ * CHecks if the current change set does not contain any changes.
+ * @return tru, if the change set is empty.
+ */
+ public boolean isEmpty(){
+ return this.changes.isEmpty();
+ }
+
+
+ /**
+ * Create a change event for a new PropertySource that was added.
+ * @param propertySource the new property source, not null.
+ * @return a new PropertySourceChange, representing a PropertySource that was added.
+ */
+ public static PropertySourceChange ofAdded(PropertySource propertySource) {
+ return PropertySourceChangeBuilder.of(propertySource, ChangeType.NEW).build();
+ }
+
+ /**
+ * Create a change event for a deleted PropertySource.
+ * @param propertySource the deleted property source, not null.
+ * @return a new PropertySourceChange, representing a PropertySource that was deleted.
+ */
+ public static PropertySourceChange ofDeleted(PropertySource propertySource) {
+ return PropertySourceChangeBuilder.of(propertySource, ChangeType.DELETED).build();
+ }
+
+ @Override
+ public String toString() {
+ return "PropertySourceChange{" +
+ "changeType=" + changeType +
+ ", propertySource=" + propertySource +
+ ", version='" + version + '\'' +
+ ", timestamp=" + timestamp +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
new file mode 100644
index 0000000..25f3620
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
@@ -0,0 +1,258 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
+ * can observing changes to property sources and
+ * <ol>
+ * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
+ * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
+ * change, its only the data of the property source).</li>
+ * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
+ * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
+ * event on configuration level.
+ * </ol>
+ */
+public final class PropertySourceChangeBuilder {
+ /**
+ * The recorded changes.
+ */
+ final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
+ /**
+ * The underlying configuration/provider.
+ */
+ PropertySource source;
+ /**
+ * The version configured, or null, for generating a default.
+ */
+ String version;
+ /**
+ * The optional timestamp in millis of this epoch.
+ */
+ Long timestamp;
+
+ /** The type of change. */
+ ChangeType changeType;
+
+ /**
+ * Constructor.
+ *
+ * @param source the underlying configuration/provider, not null.
+ */
+ private PropertySourceChangeBuilder(PropertySource source, ChangeType changeType) {
+ this.source = Objects.requireNonNull(source);
+ this.changeType = Objects.requireNonNull(changeType);
+ }
+
+ /**
+ * Creates a new instance current this builder.
+ *
+ * @param source the underlying property provider/configuration, not null.
+ * @return the builder for chaining.
+ */
+ public static PropertySourceChangeBuilder of(PropertySource source, ChangeType changeType) {
+ return new PropertySourceChangeBuilder(source, changeType);
+ }
+
+ /**
+ * Compares the two property config/configurations and creates a collection current all changes
+ * that must be appied to render {@code map1} into {@code map2}.
+ *
+ * @param map1 the source map, not null.
+ * @param map2 the target map, not null.
+ * @return a collection current change events, never null.
+ */
+ public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
+ List<PropertyChangeEvent> changes = new ArrayList<>();
+ for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
+ String val = map2.get(en.getKey());
+ if (val == null) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ } else if (!val.equals(en.getValue())) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
+ }
+ }
+ for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
+ String val = map1.get(en.getKey());
+ if (val == null) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), null));
+ } else if (!val.equals(en.getValue())) {
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), val));
+ }
+ }
+ return changes;
+ }
+
+ /*
+ * Apply a version/UUID to the set being built.
+ * @param version the version to apply, or null, to let the system generate a version for you.
+ * @return the builder for chaining.
+ */
+ public PropertySourceChangeBuilder setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ /*
+ * Apply given timestamp to the set being built.
+ * @param version the version to apply, or null, to let the system generate a version for you.
+ * @return the builder for chaining.
+ */
+ public PropertySourceChangeBuilder setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ return this;
+ }
+
+ /**
+ * This method records all changes to be applied to the base property provider/configuration to
+ * achieve the given target state.
+ *
+ * @param newState the new target state, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourceChangeBuilder addChanges(PropertySource newState) {
+ Collection<PropertyChangeEvent> events = PropertySourceChangeBuilder.compare(newState, this.source);
+ for (PropertyChangeEvent c : events) {
+ this.delta.put(c.getPropertyName(), c);
+ }
+ return this;
+ }
+
+ /**
+ * Get the current values, also considering any changes recorded within this change set.
+ *
+ * @param key the key current the entry, not null.
+ * @return the keys, or null.
+ */
+ public String get(String key) {
+ PropertyChangeEvent change = this.delta.get(key);
+ if (change != null && !(change.getNewValue() == null)) {
+ return (String) change.getNewValue();
+ }
+ return null;
+ }
+
+ /**
+ * Marks the given key(s) fromMap the configuration/properties to be removed.
+ *
+ * @param key the key current the entry, not null.
+ * @param otherKeys additional keys to be removed (convenience), not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourceChangeBuilder remove(String key, String... otherKeys) {
+ String oldValue = this.source.get(key);
+ if (oldValue == null) {
+ this.delta.remove(key);
+ }
+ this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
+ for (String addKey : otherKeys) {
+ oldValue = this.source.get(addKey);
+ if (oldValue == null) {
+ this.delta.remove(addKey);
+ }
+ this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null));
+ }
+ return this;
+ }
+
+ /**
+ * Apply all the given values to the base configuration/properties.
+ * Note that all values passed must be convertible to String, either
+ * <ul>
+ * <li>the registered codecs provider provides codecs for the corresponding keys, or </li>
+ * <li>default codecs are present for the given type, or</li>
+ * <li>the value is an instanceof String</li>
+ * </ul>
+ *
+ * @param changes the changes to be applied, not null.
+ * @return the builder for chaining.
+ */
+ public PropertySourceChangeBuilder putAll(Map<String, String> changes) {
+ changes.putAll(changes);
+ return this;
+ }
+
+ /**
+ * This method will create a change set that clears all entries fromMap the given base configuration/properties.
+ *
+ * @return the builder for chaining.
+ */
+ public PropertySourceChangeBuilder deleteAll() {
+ this.delta.clear();
+ for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
+ this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null));
+ }
+ return this;
+ }
+
+ /**
+ * Checks if the change set is empty, i.e. does not contain any changes.
+ *
+ * @return true, if the set is empty.
+ */
+ public boolean isEmpty() {
+ return this.delta.isEmpty();
+ }
+
+ /**
+ * Resets this change set instance. This will clear all changes done to this builder, so the
+ * set will be empty.
+ */
+ public void reset() {
+ this.delta.clear();
+ }
+
+ public PropertySourceChangeBuilder setChangeType(ChangeType changeType) {
+ this.changeType = changeType;
+ return this;
+ }
+
+ /**
+ * Builds the corresponding change set.
+ *
+ * @return the new change set, never null.
+ */
+ public PropertySourceChange build() {
+ return new PropertySourceChange(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "PropertiesChangeBuilder [source=" + source + ", " +
+ ", delta=" + delta + "]";
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/delta/ChangeType.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ChangeType.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ChangeType.java
deleted file mode 100644
index ecc0a2d..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ChangeType.java
+++ /dev/null
@@ -1,28 +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.events.delta;
-
-/**
- * Created by Anatole on 20.02.2015.
- */
-public enum ChangeType {
- NEW,
- DELETED,
- UPDATED,
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
deleted file mode 100644
index 41c6ba1..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
+++ /dev/null
@@ -1,216 +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.events.delta;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.events.ChangeNotification;
-import org.apache.tamaya.events.FrozenConfiguration;
-
-import java.beans.PropertyChangeEvent;
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * Event that contains a set current changes that were applied or could be applied.
- * This class is immutable and thread-safe. To create instances use
- * {@link PropertySourceChangeBuilder}.
- *
- * Created by Anatole on 22.10.2014.
- */
-public final class ConfigurationChange implements ChangeNotification<Configuration>, Serializable{
-
- private static final long serialVersionUID = 1L;
- /** The base property provider/configuration. */
- private FrozenConfiguration configuration;
- /** The base version, usable for optimistic locking. */
- private String version = UUID.randomUUID().toString();
- /** The timestamp of the change set in millis from the epoch. */
- private long timestamp = System.currentTimeMillis();
- /** The recorded changes. */
- private Map<String,PropertyChangeEvent> changes = new HashMap<>();
-
- /**
- * Get an empty change set for the given provider.
- * @param configuration The configuration changed, not null.
- * @return an empty ConfigurationChangeSet instance.
- */
- public static ConfigurationChange emptyChangeSet(Configuration configuration){
- return ConfigurationChangeBuilder.of(configuration).build();
- }
-
- /**
- * Constructor used by {@link PropertySourceChangeBuilder}.
- * @param builder The builder used, not null.
- */
- ConfigurationChange(ConfigurationChangeBuilder builder) {
- this.configuration = FrozenConfiguration.of(builder.source);
- for(PropertyChangeEvent ev:builder.delta.values()){
- this.changes.put(ev.getPropertyName(), ev);
- }
- if(builder.version!=null){
- this.version = builder.version;
- }
- if(builder.timestamp!=null){
- this.timestamp = builder.timestamp;
- }
- }
-
- /**
- * Get the underlying property provider/configuration.
- * @return the underlying property provider/configuration, never null.
- */
- public Configuration getResource(){
- return this.configuration;
- }
-
- /**
- * Get the base version, usable for optimistic locking.
- * @return the base version.
- */
- public String getVersion(){
- return version;
- }
-
- /**
- * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
- * identify a changeset.
- * @return the timestamp, when this changeset was created.
- */
- public long getTimestamp(){
- return timestamp;
- }
-
- /**
- * Get the changes recorded.
- * @return the recorded changes, never null.
- */
- public Collection<PropertyChangeEvent> getChanges(){
- return Collections.unmodifiableCollection(this.changes.values());
- }
-
- /**
- * Access the number current removed entries.
- * @return the number current removed entries.
- */
- public int getRemovedSize() {
- int removedCount = 0;
- for(PropertyChangeEvent ev:this.changes.values()){
- if(ev.getNewValue() == null){
- removedCount++;
- }
- }
- return removedCount;
-// return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
- }
-
- /**
- * Access the number current added entries.
- * @return the number current added entries.
- */
- public int getAddedSize() {
- int addedCount = 0;
- for(PropertyChangeEvent ev:this.changes.values()){
- if(ev.getOldValue() == null &&
- ev.getNewValue() != null){
- addedCount++;
- }
- }
- return addedCount;
-// return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null &&
-// e.getNewValue() != null).count();
- }
-
- /**
- * Access the number current updated entries.
- * @return the number current updated entries.
- */
- public int getUpdatedSize() {
- int updatedCount = 0;
- for(PropertyChangeEvent ev:this.changes.values()){
- if( ev.getOldValue()!=null && ev.getNewValue()!=null){
- updatedCount++;
- }
- }
- return updatedCount;
-// return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
- }
-
-
- /**
- * Checks if the given key was removed.
- * @param key the target key, not null.
- * @return true, if the given key was removed.
- */
- public boolean isRemoved(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getNewValue() == null;
- }
-
- /**
- * Checks if the given key was added.
- * @param key the target key, not null.
- * @return true, if the given key was added.
- */
- public boolean isAdded(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getOldValue() == null;
- }
-
- /**
- * Checks if the given key was updated.
- * @param key the target key, not null.
- * @return true, if the given key was updated.
- */
- public boolean isUpdated(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getOldValue() != null && change.getNewValue() != null;
- }
-
- /**
- * Checks if the given key is added, or updated AND NOT removed.
- * @param key the target key, not null.
- * @return true, if the given key was added, or updated BUT NOT removed.
- */
- public boolean isKeyAffected(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getNewValue() != null;
- }
-
- /**
- * CHecks if the current change set does not contain any changes.
- * @return tru, if the change set is empty.
- */
- public boolean isEmpty(){
- return this.changes.isEmpty();
- }
-
-
- @Override
- public String toString() {
- return "ConfigurationChange{" +
- "configuration=" + configuration +
- ", version='" + version + '\'' +
- ", timestamp=" + timestamp +
- '}';
- }
-}
[03/10] incubator-tamaya git commit: Simplified events module,
adapted documentation as well. Removed model dependency from events,
since events is the more general module here.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
new file mode 100644
index 0000000..759d429
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
@@ -0,0 +1,57 @@
+/*
+ * 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.events;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * PropertySource implementation that accesses properties that are stored on ThreadLocal level, e.g. good to use for
+ * testing..
+ */
+public class ChangeableThreadLocalPropertySource extends BasePropertySource{
+
+ private static ThreadLocal<Map<String,String>> STORED_ENTRIES = new ThreadLocal<Map<String,String>>(){
+ protected Map<String,String> initialValue(){
+ return new HashMap<>();
+ }
+ };
+
+ @Override
+ public String getName() {
+ return getClass().getSimpleName();
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return null;
+ }
+
+ public static String put(String key, String value){
+ return STORED_ENTRIES.get().put(key,value);
+ }
+
+ public static void putAll(Map<String,String> properties){
+ STORED_ENTRIES.get().putAll(properties);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java b/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
index 45c15d2..b56407c 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ConfigEventManagerTest.java
@@ -20,6 +20,8 @@ package org.apache.tamaya.events;
import org.junit.Test;
+import java.util.UUID;
+
import static org.junit.Assert.*;
/**
@@ -27,37 +29,38 @@ import static org.junit.Assert.*;
*/
public class ConfigEventManagerTest {
- private String testAddListenerValue;
+ private Object testAddListenerValue;
@Test
public void testAddRemoveListener() throws Exception {
- ConfigEventListener<String> testListener = new ConfigEventListener<String>() {
+ ConfigEventListener testListener = new ConfigEventListener() {
@Override
- public void onConfigEvent(String event) {
- testAddListenerValue = event;
+ public void onConfigEvent(ConfigEvent<?> event) {
+ testAddListenerValue = event.getResource();
}
};
ConfigEventManager.addListener(testListener);
- ConfigEventManager.fireEvent("Event1", String.class);
+ ConfigEventManager.fireEvent(new SimpleEvent("Event1"));
assertEquals(testAddListenerValue, "Event1");
ConfigEventManager.removeListener(testListener);
- ConfigEventManager.fireEvent("Event2", String.class);
+ ConfigEventManager.fireEvent(new SimpleEvent("Event2"));
assertEquals(testAddListenerValue, "Event1");
}
@Test
public void testFireEvent() throws Exception {
- ConfigEventListener<String> testListener = new ConfigEventListener<String>() {
+ ConfigEventListener testListener = new ConfigEventListener() {
@Override
- public void onConfigEvent(String event) {
- testAddListenerValue = event;
+ public void onConfigEvent(ConfigEvent<?> event) {
+ testAddListenerValue = event.getResource();
}
};
ConfigEventManager.addListener(testListener);
- ConfigEventManager.fireEvent("Event1");
+ ConfigEventManager.fireEvent(new SimpleEvent("Event1"));
assertEquals(testAddListenerValue, "Event1");
ConfigEventManager.removeListener(testListener);
- ConfigEventManager.fireEvent("Event2");
+ ConfigEventManager.fireEvent(new SimpleEvent("Event2"));
assertEquals(testAddListenerValue, "Event1");
}
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java b/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
new file mode 100644
index 0000000..2245ec0
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/SimpleEvent.java
@@ -0,0 +1,13 @@
+package org.apache.tamaya.events;
+
+import org.apache.tamaya.events.spi.BaseConfigEvent;
+
+import java.util.UUID;
+
+public class SimpleEvent extends BaseConfigEvent<String> {
+
+ public SimpleEvent(String paylod) {
+ super(paylod, String.class);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
index 0a639ab..95269e2 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java
@@ -20,6 +20,8 @@ package org.apache.tamaya.events.delta;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.events.ConfigurationChange;
+import org.apache.tamaya.events.ConfigurationChangeBuilder;
import org.junit.Test;
import java.util.Map;
@@ -27,7 +29,7 @@ import java.util.Map;
import static org.junit.Assert.*;
/**
- * Test class for {@link org.apache.tamaya.events.delta.ConfigurationChange}.
+ * Test class for {@link ConfigurationChange}.
*/
public class ConfigurationChangeTest {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
index 5640b81..ee631ce 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java
@@ -21,19 +21,24 @@ package org.apache.tamaya.events.delta;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.events.ChangeType;
+import org.apache.tamaya.events.ConfigurationContextChange;
+import org.apache.tamaya.events.ConfigurationContextChangeBuilder;
+import org.apache.tamaya.events.PropertySourceChangeBuilder;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
import static org.junit.Assert.*;
/**
- * Test class for {@link org.apache.tamaya.events.delta.ConfigurationContextChange}.
+ * Test class for {@link ConfigurationContextChange}.
*/
public class ConfigurationContextChangeTest {
@Test
public void testEmptyChangeSet() throws Exception {
- ConfigurationContextChange change = ConfigurationContextChange.emptyChangeSet();
+ ConfigurationContextChange change = ConfigurationContextChange.emptyChangeSet(
+ ConfigurationProvider.getConfigurationContext());
assertNotNull(change);
assertTrue(change.isEmpty());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
index b3be028..0dcdfba 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java
@@ -21,6 +21,9 @@ package org.apache.tamaya.events.delta;
import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
import org.apache.tamaya.core.propertysource.SimplePropertySource;
import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.events.ChangeType;
+import org.apache.tamaya.events.PropertySourceChange;
+import org.apache.tamaya.events.PropertySourceChangeBuilder;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
@@ -30,7 +33,7 @@ import java.util.Map;
import static org.junit.Assert.*;
/**
- * Tests for {@link org.apache.tamaya.events.delta.PropertySourceChange} and its builder.
+ * Tests for {@link PropertySourceChange} and its builder.
*/
public class PropertySourceChangeTest {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
index 7bac25a..55b49dc 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java
@@ -18,7 +18,9 @@
*/
package org.apache.tamaya.events.internal;
+import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventListener;
+import org.apache.tamaya.events.SimpleEvent;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -29,32 +31,31 @@ import static org.junit.Assert.assertEquals;
public class DefaultConfigEventManagerSpiTest {
private DefaultConfigEventManagerSpi spi = new DefaultConfigEventManagerSpi();
- private String testAddListenerValue;
+ private Object testAddListenerValue;
@Test
public void testAddListener() throws Exception {
- ConfigEventListener<String> testListener = new ConfigEventListener<String>() {
-
+ ConfigEventListener testListener = new ConfigEventListener() {
@Override
- public void onConfigEvent(String event) {
- testAddListenerValue = event;
+ public void onConfigEvent(ConfigEvent<?> event) {
+ testAddListenerValue = event.getResource();
}
};
spi.addListener(testListener);
- spi.fireEvent("Event1", String.class);
+ spi.fireEvent(new SimpleEvent("Event1"));
assertEquals(testAddListenerValue, "Event1");
spi.removeListener(testListener);
- spi.fireEvent("Event2", String.class);
+ spi.fireEvent(new SimpleEvent("Event2"));
assertEquals(testAddListenerValue, "Event1");
}
@Test
public void testRemoveListener() throws Exception {
- ConfigEventListener<String> testListener = new ConfigEventListener<String>() {
+ ConfigEventListener testListener = new ConfigEventListener() {
@Override
- public void onConfigEvent(String event) {
+ public void onConfigEvent(ConfigEvent<?> event) {
testAddListenerValue = event;
}
};
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
index 18b6b98..c87369a 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
@@ -89,11 +89,11 @@ public final class ConfigModelManager {
* @param name the name to use, not null.
* @return the sections defined, never null.
*/
- public static <T extends ConfigModel> T getModel(String name, Class<T> validationType) {
+ public static <T extends ConfigModel> T getModel(String name, Class<T> modelType) {
for (ModelProviderSpi model : ServiceContextManager.getServiceContext().getServices(ModelProviderSpi.class)) {
for(ConfigModel configModel : model.getConfigModels()) {
- if(configModel.getName().equals(name) && configModel.getClass().equals(validationType)) {
- return validationType.cast(configModel);
+ if(configModel.getName().equals(name) && configModel.getClass().equals(modelType)) {
+ return modelType.cast(configModel);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
index f1c03cc..44960ed 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelPopulator.java
@@ -39,33 +39,41 @@ public final class ConfiguredTypeEventsModelPopulator implements ConfigEventList
*/
private static final Logger LOG = Logger.getLogger(ConfiguredTypeEventsModelPopulator.class.getName());
+ /** System property to be set to deactivate auto documentation of configured classes published thorugh
+ * ConfiguredType events.
+ */
+ private static final String ENABLE_EVENT_DOC = "org.apache.tamaya.model.autoModelEvents";
+
@Override
public void onConfigEvent(ConfiguredType confType) {
- for (ConfiguredField field : confType.getConfiguredFields()) {
- Collection<String> keys = field.getConfiguredKeys();
- for (String key : keys) {
- ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
- if (val == null) {
- ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
- .setType(field.getType().getName())
- .setDescription("Injected field: " +
- field.getAnnotatedField().getDeclaringClass().getName() + '.' + field.toString() +
- ", \nconfigured with keys: " + keys)
- .build());
+ String value = System.getProperty(ENABLE_EVENT_DOC);
+ if(value==null?true:Boolean.parseBoolean(value)) {
+ for (ConfiguredField field : confType.getConfiguredFields()) {
+ Collection<String> keys = field.getConfiguredKeys();
+ for (String key : keys) {
+ ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
+ if (val == null) {
+ ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+ .setType(field.getType().getName())
+ .setDescription("Injected field: " +
+ field.getAnnotatedField().getDeclaringClass().getName() + '.' + field.toString() +
+ ", \nconfigured with keys: " + keys)
+ .build());
+ }
}
}
- }
- for (ConfiguredMethod method : confType.getConfiguredMethods()) {
- Collection<String> keys = method.getConfiguredKeys();
- for (String key : keys) {
- ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
- if (val == null) {
- ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
- .setType(method.getParameterTypes()[0].getName())
- .setDescription("Injected field: " +
- method.getAnnotatedMethod().getDeclaringClass().getName() + '.' + method.toString() +
- ", \nconfigured with keys: " + keys)
- .build());
+ for (ConfiguredMethod method : confType.getConfiguredMethods()) {
+ Collection<String> keys = method.getConfiguredKeys();
+ for (String key : keys) {
+ ParameterModel val = ConfigModelManager.getModel(key, ParameterModel.class);
+ if (val == null) {
+ ConfiguredTypeEventsModelProvider.addValidation(new ParameterModel.Builder(key)
+ .setType(method.getParameterTypes()[0].getName())
+ .setDescription("Injected field: " +
+ method.getAnnotatedMethod().getDeclaringClass().getName() + '.' + method.toString() +
+ ", \nconfigured with keys: " + keys)
+ .build());
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
index 946d99b..6baa975 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredTypeEventsModelProvider.java
@@ -30,7 +30,7 @@ import java.util.List;
* Model provider that adds model definitions for the items published as
* {@link org.apache.tamaya.inject.spi.ConfiguredType} events.
*/
-public class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
+class ConfiguredTypeEventsModelProvider implements ModelProviderSpi {
/** The collected models. */
private static Collection<ConfigModel> configModels = new ArrayList<>();
[04/10] incubator-tamaya git commit: Simplified events module,
adapted documentation as well. Removed model dependency from events,
since events is the more general module here.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
deleted file mode 100644
index ff5e26b..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChangeBuilder.java
+++ /dev/null
@@ -1,262 +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.events.delta;
-
-import org.apache.tamaya.Configuration;
-
-import java.beans.PropertyChangeEvent;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-/**
- * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
- * can observing changes to property sources and
- * <ol>
- * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
- * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
- * change, its only the data of the property source).</li>
- * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
- * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
- * event on configuration level.
- * </ol>
- */
-public final class ConfigurationChangeBuilder {
- /**
- * The recorded changes.
- */
- final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
- /**
- * The underlying configuration/provider.
- */
- Configuration source;
- /**
- * The version configured, or null, for generating a default.
- */
- String version;
- /**
- * The optional timestamp in millis of this epoch.
- */
- Long timestamp;
-
- /**
- * Constructor.
- *
- * @param configuration the underlying configuration, not null.
- */
- private ConfigurationChangeBuilder(Configuration configuration) {
- this.source = Objects.requireNonNull(configuration);
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param configuration the configuration changed, not null.
- * @return the builder for chaining.
- */
- public static ConfigurationChangeBuilder of(Configuration configuration) {
- return new ConfigurationChangeBuilder(configuration);
- }
-
- /**
- * Compares the two property config/configurations and creates a collection current all changes
- * that must be appied to render {@code map1} into {@code map2}.
- *
- * @param map1 the source map, not null.
- * @param map2 the target map, not null.
- * @return a collection current change events, never null.
- */
- public static Collection<PropertyChangeEvent> compare(Configuration map1, Configuration map2) {
- List<PropertyChangeEvent> changes = new ArrayList<>();
- for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
- String val = map2.get(en.getKey());
- if (val == null) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
- } else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
- }
- }
- for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
- String val = map1.get(en.getKey());
- if (val == null) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
- } else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
- }
- }
- return changes;
- }
-
- /*
- * Apply a version/UUID to the set being built.
- * @param version the version to apply, or null, to let the system generate a version for you.
- * @return the builder for chaining.
- */
- public ConfigurationChangeBuilder setVersion(String version) {
- this.version = version;
- return this;
- }
-
- /*
- * Apply given timestamp to the set being built.
- * @param version the version to apply, or null, to let the system generate a version for you.
- * @return the builder for chaining.
- */
- public ConfigurationChangeBuilder setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- return this;
- }
-
- /**
- * This method records all changes to be applied to the base property provider/configuration to
- * achieve the given target state.
- *
- * @param newState the new target state, not null.
- * @return the builder for chaining.
- */
- public ConfigurationChangeBuilder addChanges(Configuration newState) {
- for (PropertyChangeEvent c : compare(newState, this.source)) {
- this.delta.put(c.getPropertyName(), c);
- }
- return this;
- }
-
- /**
- * Applies a single key/value change.
- *
- * @param key the changed key
- * @param value the new value.
- * @return this instance for chining.
- */
- public ConfigurationChangeBuilder addChange(String key, String value) {
- this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key), value));
- return this;
- }
-
- /**
- * Get the current values, also considering any changes recorded within this change set.
- *
- * @param key the key current the entry, not null.
- * @return the keys, or null.
- */
- public String get(String key) {
- PropertyChangeEvent change = this.delta.get(key);
- if (change != null && !(change.getNewValue() == null)) {
- return (String) change.getNewValue();
- }
- return null;
- }
-
- /**
- * Marks the given key(s) fromMap the configuration/properties to be removed.
- *
- * @param key the key current the entry, not null.
- * @param otherKeys additional keys to be removed (convenience), not null.
- * @return the builder for chaining.
- */
- public ConfigurationChangeBuilder removeKey(String key, String... otherKeys) {
- String oldValue = this.source.get(key);
- if (oldValue == null) {
- this.delta.remove(key);
- }
- this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
- for (String addKey : otherKeys) {
- oldValue = this.source.get(addKey);
- if (oldValue == null) {
- this.delta.remove(addKey);
- }
- this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null));
- }
- return this;
- }
-
- /**
- * Apply all the given values to the base configuration/properties.
- * Note that all values passed must be convertible to String, either
- * <ul>
- * <li>the registered codecs provider provides codecs for the corresponding keys, or </li>
- * <li>default codecs are present for the given type, or</li>
- * <li>the value is an instanceof String</li>
- * </ul>
- *
- * @param changes the changes to be applied, not null.
- * @return the builder for chaining.
- */
- public ConfigurationChangeBuilder putAll(Map<String, String> changes) {
- changes.putAll(changes);
- return this;
- }
-
- /**
- * This method will create a change set that clears all entries fromMap the given base configuration/properties.
- *
- * @return the builder for chaining.
- */
- public ConfigurationChangeBuilder removeAllKeys() {
- this.delta.clear();
- for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
- this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null));
- }
-// this.source.getProperties().forEach((k, v) ->
-// this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
- return this;
- }
-
- /**
- * Checks if the change set is empty, i.e. does not contain any changes.
- *
- * @return true, if the set is empty.
- */
- public boolean isEmpty() {
- return this.delta.isEmpty();
- }
-
- /**
- * Resets this change set instance. This will clear all changes done to this builder, so the
- * set will be empty.
- */
- public void reset() {
- this.delta.clear();
- }
-
- /**
- * Builds the corresponding change set.
- *
- * @return the new change set, never null.
- */
- public ConfigurationChange build() {
- return new ConfigurationChange(this);
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "ConfigurationChangeSetBuilder [config=" + source + ", " +
- ", delta=" + delta + "]";
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
deleted file mode 100644
index 0aef2fd..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
+++ /dev/null
@@ -1,192 +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.events.delta;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-/**
- * Event that contains a set current changes that were applied or could be applied.
- * This class is immutable and thread-safe. To create instances use
- * {@link org.apache.tamaya.events.delta.PropertySourceChangeBuilder}.
- *
- * Created by Anatole on 22.10.2014.
- */
-public final class ConfigurationContextChange implements Serializable{
-
- private static final long serialVersionUID = 1L;
- /** The base property provider/configuration. */
- private List<PropertySourceChange> changedPropertySources = new ArrayList<>();
- /** The base version, usable for optimistic locking. */
- private String version = UUID.randomUUID().toString();
- /** The timestamp of the change set in millis from the epoch. */
- private long timestamp = System.currentTimeMillis();
-
- /**
- * Get an empty change set for the given provider.
- * @return an empty ConfigurationChangeSet instance.
- */
- public static ConfigurationContextChange emptyChangeSet(){
- return ConfigurationContextChangeBuilder.of().build();
- }
-
- /**
- * Constructor used by {@link org.apache.tamaya.events.delta.PropertySourceChangeBuilder}.
- * @param builder The builder used, not null.
- */
- ConfigurationContextChange(ConfigurationContextChangeBuilder builder) {
- this.changedPropertySources.addAll(builder.changedPropertySources);
- if(builder.version!=null){
- this.version = builder.version;
- }
- if(builder.timestamp!=null){
- this.timestamp = builder.timestamp;
- }
- }
-
- /**
- * Get the base version, usable for optimistic locking.
- * @return the base version.
- */
- public String getVersion(){
- return version;
- }
-
- /**
- * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
- * identify a changeset.
- * @return the timestamp, when this changeset was created.
- */
- public long getTimestamp(){
- return timestamp;
- }
-
- /**
- * Get the changes recorded.
- * @return the recorded changes, never null.
- */
- public Collection<PropertySourceChange> getPropertySourceChanges(){
- return Collections.unmodifiableCollection(this.changedPropertySources);
- }
-
- /**
- * Get the property source updates.
- * @return the recorded changes, never null.
- */
- public Collection<PropertySourceChange> getPropertySourceUpdates(){
- List<PropertySourceChange> result = new ArrayList<>();
- for (PropertySourceChange pc : this.changedPropertySources) {
- if (pc.getChangeType() == ChangeType.UPDATED) {
- result.add(pc);
- }
- }
- return result;
-// return Collections.unmodifiableCollection(this.changedPropertySources).stream()
-// .filter(pc -> pc.getChangeType()==ChangeType.UPDATED).collect(Collectors.toList());
- }
-
- /**
- * Get the property sources to be removed.
- * @return the recorded changes, never null.
- */
- public Collection<PropertySource> getRemovedPropertySources(){
- List<PropertySource> result = new ArrayList<>();
- for (PropertySourceChange pc : this.changedPropertySources) {
- if (pc.getChangeType() == ChangeType.DELETED) {
- result.add(pc.getResource());
- }
- }
- return result;
-// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.DELETED).
-// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
- }
-
- /**
- * Get the property sources to be added.
- * @return the recorded changes, never null.
- */
- public Collection<PropertySource> getAddedPropertySources(){
- List<PropertySource> result = new ArrayList<>();
- for (PropertySourceChange pc : this.changedPropertySources) {
- if (pc.getChangeType() == ChangeType.NEW) {
- result.add(pc.getResource());
- }
- }
- return result;
-// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.NEW).
-// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
- }
-
- /**
- * Get the property sources to be updated.
- * @return the recorded changes, never null.
- */
- public Collection<PropertySource> getUpdatedPropertySources(){
- List<PropertySource> result = new ArrayList<>();
- for (PropertySourceChange pc : this.changedPropertySources) {
- if (pc.getChangeType() == ChangeType.UPDATED) {
- result.add(pc.getResource());
- }
- }
- return result;
-// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.UPDATED).
-// map(ps -> ps.getPropertySource()).collect(Collectors.toList());
- }
-
- /**
- * Checks if the given propertySource is affected (added, changed or removed).
- * @param propertySource the propertySource, not null.
- * @return true, if the given propertySource ia affected.
- */
- public boolean isAffected(PropertySource propertySource) {
- for (PropertySourceChange ps : this.changedPropertySources) {
- if (ps.getResource() == propertySource ||
- ps.getResource().getName().equals(propertySource.getName())) {
- return true;
- }
- }
- return false;
-// return this.changedPropertySources.stream().filter(ps -> ps.getPropertySource()==propertySource ||
-// ps.getPropertySource().getName().equals(propertySource.getName())).findAny().isPresent();
- }
-
- /**
- * CHecks if the current change set does not contain any changes.
- * @return tru, if the change set is empty.
- */
- public boolean isEmpty(){
- return this.changedPropertySources.isEmpty();
- }
-
-
- @Override
- public String toString() {
- return "ConfigurationContextChange{" +
- "changedPropertySources=" + changedPropertySources +
- ", version='" + version + '\'' +
- ", timestamp=" + timestamp +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChangeBuilder.java
deleted file mode 100644
index 3e21635..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChangeBuilder.java
+++ /dev/null
@@ -1,159 +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.events.delta;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
- * can observing changes to property sources and
- * <ol>
- * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
- * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
- * change, its only the data of the property source).</li>
- * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
- * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
- * event on configuration level.
- * </ol>
- */
-public final class ConfigurationContextChangeBuilder {
- /**
- * The recorded changes.
- */
- final List<PropertySourceChange> changedPropertySources = new ArrayList<>();
- /**
- * The version configured, or null, for generating a default.
- */
- String version;
- /**
- * The optional timestamp in millis of this epoch.
- */
- Long timestamp;
-
- /**
- * Constructor.
- */
- private ConfigurationContextChangeBuilder() {
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @return the builder for chaining.
- */
- public static ConfigurationContextChangeBuilder of() {
- return new ConfigurationContextChangeBuilder();
- }
-
- /*
- * Apply a version/UUID to the set being built.
- * @param version the version to apply, or null, to let the system generate a version for you.
- * @return the builder for chaining.
- */
- public ConfigurationContextChangeBuilder setVersion(String version) {
- this.version = version;
- return this;
- }
-
- /*
- * Apply given timestamp to the set being built.
- * @param version the version to apply, or null, to let the system generate a version for you.
- * @return the builder for chaining.
- */
- public ConfigurationContextChangeBuilder setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- return this;
- }
-
- /**
- * This method records all changes to be applied to the base property provider/configuration to
- * achieve the given target state.
- *
- * @param propertySource the new target state, not null.
- * @return the builder for chaining.
- */
- public ConfigurationContextChangeBuilder newPropertySource(PropertySource propertySource) {
- this.changedPropertySources.add(PropertySourceChange.ofAdded(propertySource));
- return this;
- }
-
- /**
- * This method records all changes to be applied to the base property provider/configuration to
- * achieve the given target state.
- *
- * @param propertySource the new target state, not null.
- * @return the builder for chaining.
- */
- public ConfigurationContextChangeBuilder removedPropertySource(PropertySource propertySource) {
- this.changedPropertySources.add(PropertySourceChange.ofDeleted(propertySource));
- return this;
- }
-
- /**
- * This method records all changes to be applied to the base property provider/configuration to
- * achieve the given target state.
- *
- * @param propertySourceChange the change state, not null.
- * @return the builder for chaining.
- */
- public ConfigurationContextChangeBuilder changedPropertySource(PropertySourceChange propertySourceChange) {
- this.changedPropertySources.add(Objects.requireNonNull(propertySourceChange));
- return this;
- }
-
- /**
- * Checks if the change set is empty, i.e. does not contain any changes.
- *
- * @return true, if the set is empty.
- */
- public boolean isEmpty() {
- return this.changedPropertySources.isEmpty();
- }
-
- /**
- * Resets this change set instance. This will clear all changes done to this builder, so the
- * set will be empty.
- */
- public void reset() {
- this.changedPropertySources.clear();
- }
-
- /**
- * Builds the corresponding change set.
- *
- * @return the new change set, never null.
- */
- public ConfigurationContextChange build() {
- return new ConfigurationContextChange(this);
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "ConfigurationContextChangeBuilder [propertySources=" + changedPropertySources + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
deleted file mode 100644
index 330f3b0..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
+++ /dev/null
@@ -1,236 +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.events.delta;
-
-import org.apache.tamaya.events.ChangeNotification;
-import org.apache.tamaya.events.FrozenPropertySource;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.beans.PropertyChangeEvent;
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * Event that contains a set current changes that were applied or could be applied.
- * This class is immutable and thread-safe. To create instances use
- * {@link org.apache.tamaya.events.delta.PropertySourceChangeBuilder}.
- *
- * Created by Anatole on 22.10.2014.
- */
-public final class PropertySourceChange implements ChangeNotification<PropertySource>, Serializable{
-
- private static final long serialVersionUID = 1L;
- /** The base property provider/configuration. */
- private FrozenPropertySource propertySource;
- /** The base version, usable for optimistic locking. */
- private String version = UUID.randomUUID().toString();
- /** The timestamp of the change set in millis from the epoch. */
- private long timestamp = System.currentTimeMillis();
- /** The recorded changes. */
- private Map<String,PropertyChangeEvent> changes = new HashMap<>();
- /** The overall type of change. */
- private ChangeType changeType;
-
- /**
- * Constructor used by {@link org.apache.tamaya.events.delta.PropertySourceChangeBuilder}.
- * @param builder The builder used, not null.
- */
- PropertySourceChange(PropertySourceChangeBuilder builder) {
- this.propertySource = FrozenPropertySource.of(builder.source);
- for (PropertyChangeEvent c : builder.delta.values()) {
- this.changes.put(c.getPropertyName(), c);
- }
- if(builder.version!=null){
- this.version = builder.version;
- }
- if(builder.timestamp!=null){
- this.timestamp = builder.timestamp;
- }
- this.changeType = builder.changeType;
- }
-
- /**
- * Gets the type of change for this PropertySource.
- * @return the type of change for this PropertySource, never null.
- */
- public ChangeType getChangeType(){
- return this.changeType;
- }
-
- /**
- * Get the underlying property provider/configuration.
- * @return the underlying property provider/configuration, or null, if the change instance was deserialized.
- */
- public PropertySource getResource(){
- return this.propertySource;
- }
-
- /**
- * Get the base version, usable for optimistic locking.
- * @return the base version.
- */
- public String getVersion(){
- return version;
- }
-
- /**
- * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to
- * identify a changeset.
- * @return the timestamp, when this changeset was created.
- */
- public long getTimestamp(){
- return timestamp;
- }
-
- /**
- * Get the changes recorded.
- * @return the recorded changes, never null.
- */
- public Collection<PropertyChangeEvent> getChanges(){
- return Collections.unmodifiableCollection(this.changes.values());
- }
-
- /**
- * Access the number current removed entries.
- * @return the number current removed entries.
- */
- public int getRemovedSize() {
- int removedCount = 0;
- for (PropertyChangeEvent ev : this.changes.values()) {
- if (ev.getNewValue() == null) {
- removedCount++;
- }
- }
- return removedCount;
-// return (int) this.changes.values().stream().filter((e) -> e.getNewValue() == null).count();
- }
-
- /**
- * Access the number current added entries.
- * @return the number current added entries.
- */
- public int getAddedSize() {
- int addedCount = 0;
- for (PropertyChangeEvent ev : this.changes.values()) {
- if (ev.getOldValue() == null &&
- ev.getNewValue() != null) {
- addedCount++;
- }
- }
- return addedCount;
-// return (int) this.changes.values().stream().filter((e) -> e.getOldValue() == null).count();
- }
-
- /**
- * Access the number current updated entries.
- * @return the number current updated entries.
- */
- public int getUpdatedSize() {
- int updatedCount = 0;
- for (PropertyChangeEvent ev : this.changes.values()) {
- if (ev.getOldValue() != null && ev.getNewValue() != null) {
- updatedCount++;
- }
- }
- return updatedCount;
-// return (int) this.changes.values().stream().filter((e) -> e.getOldValue()!=null && e.getNewValue()!=null).count();
- }
-
-
- /**
- * Checks if the given key was removed.
- * @param key the target key, not null.
- * @return true, if the given key was removed.
- */
- public boolean isRemoved(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getNewValue() == null;
- }
-
- /**
- * Checks if the given key was added.
- * @param key the target key, not null.
- * @return true, if the given key was added.
- */
- public boolean isAdded(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getOldValue() == null;
- }
-
- /**
- * Checks if the given key was updated.
- * @param key the target key, not null.
- * @return true, if the given key was updated.
- */
- public boolean isUpdated(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getOldValue() != null && change.getNewValue() != null;
- }
-
- /**
- * Checks if the given key is added, or updated AND NOT removed.
- * @param key the target key, not null.
- * @return true, if the given key was added, or updated BUT NOT removed.
- */
- public boolean isKeyAffected(String key) {
- PropertyChangeEvent change = this.changes.get(key);
- return change != null && change.getNewValue() != null;
- }
-
- /**
- * CHecks if the current change set does not contain any changes.
- * @return tru, if the change set is empty.
- */
- public boolean isEmpty(){
- return this.changes.isEmpty();
- }
-
-
- /**
- * Create a change event for a new PropertySource that was added.
- * @param propertySource the new property source, not null.
- * @return a new PropertySourceChange, representing a PropertySource that was added.
- */
- public static PropertySourceChange ofAdded(PropertySource propertySource) {
- return PropertySourceChangeBuilder.of(propertySource, ChangeType.NEW).build();
- }
-
- /**
- * Create a change event for a deleted PropertySource.
- * @param propertySource the deleted property source, not null.
- * @return a new PropertySourceChange, representing a PropertySource that was deleted.
- */
- public static PropertySourceChange ofDeleted(PropertySource propertySource) {
- return PropertySourceChangeBuilder.of(propertySource, ChangeType.DELETED).build();
- }
-
- @Override
- public String toString() {
- return "PropertySourceChange{" +
- "changeType=" + changeType +
- ", propertySource=" + propertySource +
- ", version='" + version + '\'' +
- ", timestamp=" + timestamp +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
deleted file mode 100644
index a0c0027..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChangeBuilder.java
+++ /dev/null
@@ -1,258 +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.events.delta;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.beans.PropertyChangeEvent;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-/**
- * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
- * can observing changes to property sources and
- * <ol>
- * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
- * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a
- * change, its only the data of the property source).</li>
- * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on
- * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change
- * event on configuration level.
- * </ol>
- */
-public final class PropertySourceChangeBuilder {
- /**
- * The recorded changes.
- */
- final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
- /**
- * The underlying configuration/provider.
- */
- PropertySource source;
- /**
- * The version configured, or null, for generating a default.
- */
- String version;
- /**
- * The optional timestamp in millis of this epoch.
- */
- Long timestamp;
-
- /** The type of change. */
- ChangeType changeType;
-
- /**
- * Constructor.
- *
- * @param source the underlying configuration/provider, not null.
- */
- private PropertySourceChangeBuilder(PropertySource source, ChangeType changeType) {
- this.source = Objects.requireNonNull(source);
- this.changeType = Objects.requireNonNull(changeType);
- }
-
- /**
- * Creates a new instance current this builder.
- *
- * @param source the underlying property provider/configuration, not null.
- * @return the builder for chaining.
- */
- public static PropertySourceChangeBuilder of(PropertySource source, ChangeType changeType) {
- return new PropertySourceChangeBuilder(source, changeType);
- }
-
- /**
- * Compares the two property config/configurations and creates a collection current all changes
- * that must be appied to render {@code map1} into {@code map2}.
- *
- * @param map1 the source map, not null.
- * @param map2 the target map, not null.
- * @return a collection current change events, never null.
- */
- public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
- List<PropertyChangeEvent> changes = new ArrayList<>();
- for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
- String val = map2.get(en.getKey());
- if (val == null) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
- } else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue()));
- }
- }
- for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
- String val = map1.get(en.getKey());
- if (val == null) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), null));
- } else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), val));
- }
- }
- return changes;
- }
-
- /*
- * Apply a version/UUID to the set being built.
- * @param version the version to apply, or null, to let the system generate a version for you.
- * @return the builder for chaining.
- */
- public PropertySourceChangeBuilder setVersion(String version) {
- this.version = version;
- return this;
- }
-
- /*
- * Apply given timestamp to the set being built.
- * @param version the version to apply, or null, to let the system generate a version for you.
- * @return the builder for chaining.
- */
- public PropertySourceChangeBuilder setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- return this;
- }
-
- /**
- * This method records all changes to be applied to the base property provider/configuration to
- * achieve the given target state.
- *
- * @param newState the new target state, not null.
- * @return the builder for chaining.
- */
- public PropertySourceChangeBuilder addChanges(PropertySource newState) {
- Collection<PropertyChangeEvent> events = PropertySourceChangeBuilder.compare(newState, this.source);
- for (PropertyChangeEvent c : events) {
- this.delta.put(c.getPropertyName(), c);
- }
- return this;
- }
-
- /**
- * Get the current values, also considering any changes recorded within this change set.
- *
- * @param key the key current the entry, not null.
- * @return the keys, or null.
- */
- public String get(String key) {
- PropertyChangeEvent change = this.delta.get(key);
- if (change != null && !(change.getNewValue() == null)) {
- return (String) change.getNewValue();
- }
- return null;
- }
-
- /**
- * Marks the given key(s) fromMap the configuration/properties to be removed.
- *
- * @param key the key current the entry, not null.
- * @param otherKeys additional keys to be removed (convenience), not null.
- * @return the builder for chaining.
- */
- public PropertySourceChangeBuilder remove(String key, String... otherKeys) {
- String oldValue = this.source.get(key);
- if (oldValue == null) {
- this.delta.remove(key);
- }
- this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
- for (String addKey : otherKeys) {
- oldValue = this.source.get(addKey);
- if (oldValue == null) {
- this.delta.remove(addKey);
- }
- this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null));
- }
- return this;
- }
-
- /**
- * Apply all the given values to the base configuration/properties.
- * Note that all values passed must be convertible to String, either
- * <ul>
- * <li>the registered codecs provider provides codecs for the corresponding keys, or </li>
- * <li>default codecs are present for the given type, or</li>
- * <li>the value is an instanceof String</li>
- * </ul>
- *
- * @param changes the changes to be applied, not null.
- * @return the builder for chaining.
- */
- public PropertySourceChangeBuilder putAll(Map<String, String> changes) {
- changes.putAll(changes);
- return this;
- }
-
- /**
- * This method will create a change set that clears all entries fromMap the given base configuration/properties.
- *
- * @return the builder for chaining.
- */
- public PropertySourceChangeBuilder deleteAll() {
- this.delta.clear();
- for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
- this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null));
- }
- return this;
- }
-
- /**
- * Checks if the change set is empty, i.e. does not contain any changes.
- *
- * @return true, if the set is empty.
- */
- public boolean isEmpty() {
- return this.delta.isEmpty();
- }
-
- /**
- * Resets this change set instance. This will clear all changes done to this builder, so the
- * set will be empty.
- */
- public void reset() {
- this.delta.clear();
- }
-
- public PropertySourceChangeBuilder setChangeType(ChangeType changeType) {
- this.changeType = changeType;
- return this;
- }
-
- /**
- * Builds the corresponding change set.
- *
- * @return the new change set, never null.
- */
- public PropertySourceChange build() {
- return new PropertySourceChange(this);
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "PropertiesChangeBuilder [source=" + source + ", " +
- ", delta=" + delta + "]";
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
index dd64145..af51063 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.events.folderobserver;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.events.PropertySourceChange;
import java.io.IOException;
import java.nio.file.FileSystem;
@@ -34,7 +35,7 @@ import java.util.logging.Logger;
/**
* Class that has the responsibility to watch the folder and then publish the changes to a
- * {@link org.apache.tamaya.events.delta.PropertySourceChange}.
+ * {@link PropertySourceChange}.
* @see ObservingPropertySourceProvider
* This listener will wait to events and wait to one second to watch again.
* <p>If new file was created or modified will commit from this file.</p>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 9b88c0a..14692f4 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -19,9 +19,11 @@
package org.apache.tamaya.events.folderobserver;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.events.ConfigEventManager;
-import org.apache.tamaya.events.delta.ConfigurationContextChange;
-import org.apache.tamaya.events.delta.ConfigurationContextChangeBuilder;
+import org.apache.tamaya.events.PropertySourceChange;
+import org.apache.tamaya.events.ConfigurationContextChange;
+import org.apache.tamaya.events.ConfigurationContextChangeBuilder;
import org.apache.tamaya.format.ConfigurationData;
import org.apache.tamaya.format.ConfigurationFormat;
import org.apache.tamaya.format.FlattenedDefaultPropertySource;
@@ -50,7 +52,7 @@ import java.util.logging.Logger;
* This implementation run in a folder taking up all file compatible with the given
* ConfigurationFormats. When a file is added, deleted or modified the PropertySourceProvider
* will adapt the changes automatically and trigger according
- * {@link org.apache.tamaya.events.delta.PropertySourceChange} events.
+ * {@link PropertySourceChange} events.
* The default folder is META-INF/config, but you can change using the absolute path in
* "-Dtamaya.configdir" parameter.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
new file mode 100644
index 0000000..8903566
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
@@ -0,0 +1,107 @@
+/*
+ * 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.events.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.events.*;
+
+import java.util.*;
+import java.util.logging.Logger;
+
+/**
+ * Timer task that regularly checks the configuration for changes.
+ */
+public class DefaultConfigChangeObserver {
+
+ private static final long START_DELAY = 5000L;
+
+ private static final Logger LOG = Logger.getLogger(DefaultConfigChangeObserver.class.getName());
+
+ private Timer timer = new Timer("DefaultConfigChangeObserver", true);
+
+ private long checkPeriod = 2000L;
+
+ private volatile FrozenConfiguration lastConfig;
+
+ private volatile boolean running;
+
+ /**
+ * Constructor. Also loads all registered listeners.
+ */
+ public DefaultConfigChangeObserver() {
+ LOG.info("Registering config change observer, rechecking config changes every " + checkPeriod + " ms.");
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ if(running) {
+ checkConfigurationUpdate();
+ }
+ }
+ }, START_DELAY, checkPeriod);
+ }
+
+
+ public void checkConfigurationUpdate() {
+ LOG.finest("Checking configuration for changes...");
+ FrozenConfiguration newConfig = FrozenConfiguration.of(ConfigurationProvider.getConfiguration());
+ ConfigurationChange changes = null;
+ if(lastConfig==null){
+ changes = ConfigurationChangeBuilder.of(newConfig).putAll(newConfig.getProperties())
+ .build();
+ }else{
+ changes = ConfigurationChangeBuilder.of(lastConfig).addChanges(newConfig)
+ .build();
+ }
+ if(!changes.isEmpty()) {
+ LOG.info("Identified configuration changes, publishing change event...");
+ ConfigEventManager.fireEvent(changes);
+ }
+ }
+
+ public long getCheckPeriod() {
+ return checkPeriod;
+ }
+
+ public boolean isMonitoring(){
+ return running;
+ }
+
+ public void enableMonitoring(boolean enable){
+ this.running = true;
+ }
+
+ /**
+ * Sets the new check period, cancels the currently running timer and schedules a new task with the new checkperiod
+ * and a startup delay of 500ms.
+ * @param checkPeriod
+ */
+ public void setCheckPeriod(long checkPeriod) {
+ LOG.finest("Resetting check period to " + checkPeriod + " ms, reregistering timer.");
+ this.checkPeriod = checkPeriod;
+ timer.cancel();
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ if(running) {
+ checkConfigurationUpdate();
+ }
+ }
+ }, 500L, checkPeriod);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
index 6773c7d..75f2c91 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
@@ -18,18 +18,15 @@
*/
package org.apache.tamaya.events.internal;
-import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventListener;
import org.apache.tamaya.events.spi.ConfigEventManagerSpi;
import org.apache.tamaya.spi.ServiceContextManager;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -41,14 +38,18 @@ public class DefaultConfigEventManagerSpi implements ConfigEventManagerSpi {
private static final Logger LOG = Logger.getLogger(DefaultConfigEventManagerSpi.class.getName());
- private Map<Type, List<ConfigEventListener<?>>> listenerMap = new ConcurrentHashMap<>();
+ private Map<Class,List<ConfigEventListener>> listeners = new ConcurrentHashMap<>();
+
+ private ExecutorService publisher = Executors.newCachedThreadPool();
+
+ private DefaultConfigChangeObserver changeObserver = new DefaultConfigChangeObserver();
/**
* Constructor. Also loads all registered listeners.
*/
public DefaultConfigEventManagerSpi() {
try {
- for (ConfigEventListener<?> l : ServiceContextManager.getServiceContext().getServices(ConfigEventListener.class)) {
+ for (ConfigEventListener l : ServiceContextManager.getServiceContext().getServices(ConfigEventListener.class)) {
try {
addListener(l);
} catch (Exception e) {
@@ -61,37 +62,76 @@ public class DefaultConfigEventManagerSpi implements ConfigEventManagerSpi {
}
@Override
- public <T> void addListener(ConfigEventListener<T> l) {
- Type type = TypeLiteral.getGenericInterfaceTypeParameters(l.getClass(), ConfigEventListener.class)[0];
- List<ConfigEventListener<?>> listeners = listenerMap.get(type);
- if (listeners == null) {
- listeners = Collections.synchronizedList(new ArrayList<ConfigEventListener<?>>());
- listenerMap.put(type, listeners);
+ public void addListener(ConfigEventListener l){
+ addListener(l, ConfigEvent.class);
+ }
+
+ @Override
+ public <T extends ConfigEvent> void addListener(ConfigEventListener l, Class<T> eventType){
+ List<ConfigEventListener> ls = listeners.get(eventType);
+ if(ls==null){
+ ls = Collections.synchronizedList(new ArrayList<ConfigEventListener>());
+ listeners.put(eventType, ls);
}
- synchronized (listeners) {
- if (!listeners.contains(l)) {
- listeners.add(l);
+ synchronized (ls){
+ if(!ls.contains(l)){
+ ls.add(l);
}
}
}
@Override
- public <T> void removeListener(ConfigEventListener<T> l) {
- Type type = TypeLiteral.getGenericInterfaceTypeParameters(l.getClass(), ConfigEventListener.class)[0];
- List<ConfigEventListener<?>> listeners = listenerMap.get(type);
- if (listeners != null) {
- synchronized (listeners) {
- listeners.remove(l);
+ public void removeListener(ConfigEventListener l){
+ removeListener(l, ConfigEvent.class);
+ }
+
+ @Override
+ public <T extends ConfigEvent> void removeListener(ConfigEventListener l, Class<T> eventType) {
+ List<ConfigEventListener> targets = this.listeners.get(eventType);
+ if(targets!=null) {
+ // forward to explicit listeners
+ synchronized (targets) {
+ targets.remove(l);
}
}
}
@Override
- public <T> void fireEvent(T event, Class<T> eventType) {
- List<ConfigEventListener<?>> listeners = listenerMap.get(eventType);
- if (listeners != null) {
- synchronized (listeners) {
- for (ConfigEventListener l : listeners) {
+ public Collection<? extends ConfigEventListener> getListeners(Class<? extends ConfigEvent> eventType) {
+ List<ConfigEventListener> targets = this.listeners.get(eventType);
+ if(targets!=null){
+ synchronized(targets){
+ return new ArrayList<>(targets);
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Collection<? extends ConfigEventListener> getListeners() {
+ Set<ConfigEventListener> targets = new HashSet<>();
+ for(List<ConfigEventListener> l:this.listeners.values()){
+ targets.addAll(l);
+ }
+ return targets;
+ }
+
+ @Override
+ public void fireEvent(ConfigEvent<?> event) {
+ List<ConfigEventListener> targets = this.listeners.get(event.getClass());
+ if(targets!=null) {
+ // forward to explicit listeners
+ synchronized (targets) {
+ for (ConfigEventListener l : targets) {
+ l.onConfigEvent(event);
+ }
+ }
+ }
+ // forward to global listeners
+ targets = this.listeners.get(ConfigEvent.class);
+ if(targets!=null) {
+ synchronized (targets) {
+ for (ConfigEventListener l : targets) {
l.onConfigEvent(event);
}
}
@@ -99,12 +139,64 @@ public class DefaultConfigEventManagerSpi implements ConfigEventManagerSpi {
}
@Override
- public <T> Collection<ConfigEventListener<T>> getListeners(Class<T> eventType) {
- List<ConfigEventListener<?>> listeners =
- listenerMap.get(eventType);
- if (listeners != null) {
- return Collection.class.cast(listeners);
+ public void fireEventAsynch(ConfigEvent<?> event) {
+ List<ConfigEventListener> targets = this.listeners.get(event.getClass());
+ if(targets!=null) {
+ // forward to explicit listeners
+ synchronized (targets) {
+ for (ConfigEventListener l : targets) {
+ publisher.execute(new PublishConfigChangeTask(l, event));
+ }
+ }
+ }
+ // forward to global listeners
+ targets = this.listeners.get(ConfigEvent.class);
+ if(targets!=null) {
+ synchronized (targets) {
+ for (ConfigEventListener l : targets) {
+ publisher.execute(new PublishConfigChangeTask(l, event));
+ }
+ }
+ }
+ }
+
+ @Override
+ public long getChangeMonitoringPeriod() {
+ return changeObserver.getCheckPeriod();
+ }
+
+ @Override
+ public void setChangeMonitoringPeriod(long millis){
+ changeObserver.setCheckPeriod(millis);
+ }
+
+ @Override
+ public boolean isChangeMonitorActive() {
+ return changeObserver.isMonitoring();
+ }
+
+ @Override
+ public void enableChangeMonitor(boolean enable) {
+ changeObserver.enableMonitoring(enable);
+ }
+
+
+ /**
+ * Tasks to inform observers on detected configuration changes.
+ */
+ private static final class PublishConfigChangeTask implements Runnable{
+
+ private ConfigEventListener l;
+ private ConfigEvent<?> changes;
+
+ public PublishConfigChangeTask(ConfigEventListener l, ConfigEvent<?> changes) {
+ this.l = Objects.requireNonNull(l);
+ this.changes = Objects.requireNonNull(changes);
+ }
+
+ @Override
+ public void run() {
+ l.onConfigEvent(changes);
}
- return Collections.emptyList();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigObserverSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigObserverSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigObserverSpi.java
deleted file mode 100644
index 6bcb44c..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigObserverSpi.java
+++ /dev/null
@@ -1,158 +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.events.internal;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.events.ConfigEventManager;
-import org.apache.tamaya.events.ConfigListener;
-import org.apache.tamaya.events.FrozenConfiguration;
-import org.apache.tamaya.events.delta.ConfigurationChange;
-import org.apache.tamaya.events.delta.ConfigurationChangeBuilder;
-import org.apache.tamaya.events.spi.ConfigObserverSpi;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.beans.PropertyChangeEvent;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Default implementation of {@link org.apache.tamaya.events.spi.ConfigObserverSpi} just forwarding all
- * events synchronously to the listeners.
- */
-public class DefaultConfigObserverSpi implements ConfigObserverSpi {
-
- private static final long START_DELAY = 5000L;
-
- private static final Logger LOG = Logger.getLogger(DefaultConfigObserverSpi.class.getName());
-
- private Set<String> keys = new HashSet<>();
-
- private Timer timer = new Timer("ConfigurationObserver", true);
-
- private long checkPeriod = 2000L;
-
- private volatile FrozenConfiguration lastConfig;
-
- private ExecutorService publisher = Executors.newCachedThreadPool();
-
- private volatile boolean running;
-
- /**
- * Constructor. Also loads all registered listeners.
- */
- public DefaultConfigObserverSpi() {
- try {
- // Load and register ConfigListener from the current ServiceContext
- for (ConfigListener l : ServiceContextManager.getServiceContext().getServices(ConfigListener.class)) {
- ConfigEventManager.addListener(l);
- }
- } catch (Exception e) {
- LOG.log(Level.WARNING, "Failed to load configured listeners.", e);
- }
- timer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- if(running) {
- checkConfigurationUpdate();
- }
- }
- }, START_DELAY, checkPeriod);
- }
-
- public void checkConfigurationUpdate() {
- LOG.finest("Checking configuration for changes...");
- FrozenConfiguration newConfig = FrozenConfiguration.of(ConfigurationProvider.getConfiguration());
- ConfigurationChange changes = null;
- if(lastConfig==null){
- changes = ConfigurationChangeBuilder.of(newConfig).putAll(newConfig.getProperties())
- .build();
- }else{
- changes = ConfigurationChangeBuilder.of(lastConfig).addChanges(newConfig)
- .build();
- }
- Set<ConfigListener> affected = new HashSet<>();
- for(PropertyChangeEvent evt: changes.getChanges()) {
- for (String key : keys) {
- if (evt.getPropertyName().matches(key)) {
- ConfigEventManager.fireEvent(changes);
- return;
- }
- }
- }
- }
-
- @Override
- public synchronized <T> void addObservedKeys(Collection<String> keys) {
- this.keys.addAll(keys);
- }
-
- @Override
- public synchronized <T> void removeObservedKeys(Collection<String> keys) {
- this.keys.removeAll(keys);
- }
-
-
- @Override
- public synchronized Set<String> getObservedKeys() {
- return Collections.unmodifiableSet(this.keys);
- }
-
- @Override
- public long getCheckPeriod() {
- return checkPeriod;
- }
-
- @Override
- public boolean isRunning(){
- return running;
- }
-
- @Override
- public void enableObservation(boolean enable){
- this.running = true;
- }
-
- /**
- * Tasks to inform observers on detected configuration changes.
- */
- private static final class PublishConfigChangeTask implements Runnable{
-
- private ConfigListener l;
- private ConfigurationChange changes;
-
- public PublishConfigChangeTask(ConfigListener l, ConfigurationChange changes) {
- this.l = Objects.requireNonNull(l);
- this.changes = Objects.requireNonNull(changes);
- }
-
- @Override
- public void run() {
- l.onConfigEvent(changes);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
index fed5e40..e49856d 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
@@ -19,13 +19,17 @@
package org.apache.tamaya.events.internal;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventListener;
-import org.apache.tamaya.events.delta.ConfigurationContextChange;
+import org.apache.tamaya.events.ConfigurationContextChange;
import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.PropertySource;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -33,35 +37,38 @@ import java.util.logging.Logger;
* Default ConfigEventListener for ConfigurationContextChange events that updates the current context, if resources were
* affected.
*/
-public class DefaultConfigurationContextChangeListener implements ConfigEventListener<ConfigurationContextChange> {
+public class DefaultConfigurationContextChangeListener implements ConfigEventListener {
private static final Logger LOG = Logger.getLogger(DefaultConfigurationContextChangeListener.class.getName());
@Override
- public void onConfigEvent(ConfigurationContextChange event) {
- ConfigurationContext context = ConfigurationProvider.getConfigurationContext();
- List<PropertySource> affectedPropertySources = new ArrayList<>();
- for (PropertySource ps : context.getPropertySources()) {
- if (event.isAffected(ps)) {
- affectedPropertySources.add(ps);
+ public void onConfigEvent(ConfigEvent<?> event) {
+ if(event.getClass() == ConfigurationContextChange.class) {
+ ConfigurationContextChange contextChange = (ConfigurationContextChange) event;
+ ConfigurationContext context = ConfigurationProvider.getConfigurationContext();
+ List<PropertySource> affectedPropertySources = new ArrayList<>();
+ for (PropertySource ps : context.getPropertySources()) {
+ if (contextChange.isAffected(ps)) {
+ affectedPropertySources.add(ps);
+ }
}
- }
- ConfigurationContextBuilder newContextBuilder = ConfigurationProvider.getConfigurationContextBuilder()
- .setContext(context);
- if (!affectedPropertySources.isEmpty()) {
- Set<String> propertySourceNames = new HashSet<>();
- for (PropertySource removed : event.getRemovedPropertySources()) {
- propertySourceNames.add(removed.getName());
+ ConfigurationContextBuilder newContextBuilder = ConfigurationProvider.getConfigurationContextBuilder()
+ .setContext(context);
+ if (!affectedPropertySources.isEmpty()) {
+ Set<String> propertySourceNames = new HashSet<>();
+ for (PropertySource removed : contextChange.getRemovedPropertySources()) {
+ propertySourceNames.add(removed.getName());
+ }
+ newContextBuilder.removePropertySources(propertySourceNames);
+ }
+ newContextBuilder.addPropertySources(contextChange.getAddedPropertySources());
+ newContextBuilder.addPropertySources(contextChange.getUpdatedPropertySources());
+ ConfigurationContext newContext = newContextBuilder.build();
+ try {
+ ConfigurationProvider.setConfigurationContext(newContext);
+ } catch (Exception e) {
+ LOG.log(Level.INFO, "Failed to update the current ConfigurationContext due to config model changes", e);
}
- newContextBuilder.removePropertySources(propertySourceNames);
- }
- newContextBuilder.addPropertySources(event.getAddedPropertySources());
- newContextBuilder.addPropertySources(event.getUpdatedPropertySources());
- ConfigurationContext newContext = newContextBuilder.build();
- try {
- ConfigurationProvider.setConfigurationContext(newContext);
- } catch (Exception e) {
- LOG.log(Level.INFO, "Failed to update the current ConfigurationContext due to config model changes", e);
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
index 43b2700..41d6924 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/LoggingConfigListener.java
@@ -18,20 +18,24 @@
*/
package org.apache.tamaya.events.internal;
-import org.apache.tamaya.events.ConfigListener;
-import org.apache.tamaya.events.delta.ConfigurationChange;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.events.ConfigEvent;
+import org.apache.tamaya.events.ConfigEventListener;
+import org.apache.tamaya.events.ConfigurationChange;
import java.util.logging.Logger;
/**
* Simple ConfigListener that simply logs any detected config changes to INFO level.
*/
-public class LoggingConfigListener implements ConfigListener{
+public class LoggingConfigListener implements ConfigEventListener {
private static final Logger LOG = Logger.getLogger(LoggingConfigListener.class.getName());
@Override
- public void onConfigEvent(ConfigurationChange event) {
- LOG.info("Configuration changed: " + event);
+ public void onConfigEvent(ConfigEvent<?> event) {
+ if(event.getResourceType()== Configuration.class) {
+ LOG.info("Configuration changed: " + event);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/package-info.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/package-info.java b/modules/events/src/main/java/org/apache/tamaya/events/package-info.java
index 33f5f25..e175ceb 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/package-info.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/package-info.java
@@ -18,6 +18,7 @@
*/
/**
* This package provides the main building blocks for handling configuration changes, such as
- * {@link org.apache.tamaya.events.ConfigEventManager}, {@link org.apache.tamaya.events.ConfigEventListener}.
+ * {@link org.apache.tamaya.events.ConfigEventManager}, {@link org.apache.tamaya.events.ConfigEventListener} and
+ * artifacts to describe the changes (delta) of a Configuration or a PropertySource.
*/
package org.apache.tamaya.events;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/spi/BaseConfigEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/spi/BaseConfigEvent.java b/modules/events/src/main/java/org/apache/tamaya/events/spi/BaseConfigEvent.java
new file mode 100644
index 0000000..15f3dfd
--- /dev/null
+++ b/modules/events/src/main/java/org/apache/tamaya/events/spi/BaseConfigEvent.java
@@ -0,0 +1,69 @@
+/*
+ * 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.events.spi;
+
+import org.apache.tamaya.events.ConfigEvent;
+
+import java.util.Objects;
+import java.util.UUID;
+
+/**
+ * Abstract base class for implementing your own configuration events.
+ * @param <T> the vent type
+ */
+public abstract class BaseConfigEvent<T> implements ConfigEvent<T> {
+ private long timestamp = System.currentTimeMillis();
+ protected String version = UUID.randomUUID().toString();
+ protected T paylod;
+ private Class<T> type;
+
+ public BaseConfigEvent(T paylod, Class<T> type){
+ this.paylod = Objects.requireNonNull(paylod);
+ this.type = Objects.requireNonNull(type);
+ }
+
+ @Override
+ public Class<T> getResourceType() {
+ return type;
+ }
+
+ @Override
+ public T getResource() {
+ return paylod;
+ }
+
+ @Override
+ public String getVersion() {
+ return version;
+ }
+
+ @Override
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + '{' +
+ "timestamp=" + timestamp +
+ ", version='" + version + '\'' +
+ ", paylod='" + paylod + '\'' +
+ '}';
+ }
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
index 7cb47a0..1ac1055 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigEventManagerSpi.java
@@ -18,9 +18,11 @@
*/
package org.apache.tamaya.events.spi;
+import org.apache.tamaya.events.ConfigEvent;
import org.apache.tamaya.events.ConfigEventListener;
import java.util.Collection;
+import java.util.Set;
/**
* SPI interface to implement the {@link org.apache.tamaya.events.ConfigEventManager} singleton.
@@ -35,29 +37,88 @@ public interface ConfigEventManagerSpi {
*
* @param l the listener not null.
*/
- <T> void addListener(ConfigEventListener<T> l);
+ <T> void addListener(ConfigEventListener l);
+ /**
+ * Adds a listener for observing events of a given type.
+ *
+ * @param l the listener not null.
+ * @param eventType the type of concrete configuration event this listeners should be informed about. All other
+ * event types will never be delivered toe this listener instance.
+ */
+ <T extends ConfigEvent> void addListener(ConfigEventListener l, Class<T> eventType);
/**
* Removes a listener for observing events.
*
* @param l the listener not null.
*/
- <T> void removeListener(ConfigEventListener<T> l);
+ void removeListener(ConfigEventListener l);
+
+ /**
+ * Removes a listener for observing events of a certain type.
+ *
+ * @param l the listener not null.
+ * @param eventType the type of concrete configuration event this listeners should be informed about. All other
+ * event types will never be delivered toe this listener instance.
+ */
+ <T extends ConfigEvent> void removeListener(ConfigEventListener l, Class<T> eventType);
/**
- * Publishes an event to all interested listeners.
+ * Access all globally registered listeners.
*
- * @param event the event, not null.
- * @param eventType the event type.
+ * @return the listeners found, never null.
+ */
+ Collection<? extends ConfigEventListener> getListeners();
+
+ /**
+ * Access all listeners listening for a certain event type, including any global listeners.
+ * @param eventType the type of concrete configuration event this listeners should be informed about. All other
+ * event types will never be delivered toe this listener instance.
+ * @return the listeners found, never null.
*/
- <T> void fireEvent(T event, Class<T> eventType);
+ Collection<? extends ConfigEventListener> getListeners(Class<? extends ConfigEvent> eventType);
/**
- * Access all known listeners for a given targe type.
- * @param type the type.
- * @param <T> the listener type.
- * @return the items found, never null.
+ * Publishes an event to all interested listeners, hereby executing all registered listeners sequentually and
+ * synchronously.,
+ *
+ * @param event the event, not null.
*/
- <T> Collection<? extends ConfigEventListener<T>> getListeners(Class<T> type);
+ void fireEvent(ConfigEvent<?> event);
+
+ /**
+ * Publishes an event to all interested listeners, hereby publishing the change events asynchrously and in
+ * parallel (multithreaded).
+ *
+ * @param event the event, not null.
+ */
+ void fireEventAsynch(ConfigEvent<?> event);
+
+ /**
+ * Get the current check period to check for configuration changes.
+ *
+ * @return the check period in ms.
+ */
+ long getChangeMonitoringPeriod();
+
+ void setChangeMonitoringPeriod(long millis);
+
+ /**
+ * Check if the observer is running currently.
+ *
+ * @return true, if the change monitoring service is currently running.
+ */
+ boolean isChangeMonitorActive();
+
+ /**
+ * Start/Stop the change monitoring service, which will observe/reevaluate the current configuration regularly
+ * and triggers ConfigurationChange events is something changed. This is quite handy for publishing
+ * configuration changes to whatever systems are interested in. Hereby the origin of a configuration change
+ * can be on this machine, or also remotedly. FOr handling corresponding {@link ConfigEventListener} have
+ * to be registered, e.g. listening on {@link org.apache.tamaya.events.ConfigurationChange} events.
+ */
+ void enableChangeMonitor(boolean enable);
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigObserverSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigObserverSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigObserverSpi.java
deleted file mode 100644
index 95eb6e7..0000000
--- a/modules/events/src/main/java/org/apache/tamaya/events/spi/ConfigObserverSpi.java
+++ /dev/null
@@ -1,71 +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.events.spi;
-
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * SPI interface to implement the {@link org.apache.tamaya.events.ConfigurationObserver} singleton.
- * Implementations of this interface must be registered with the current {@link org.apache.tamaya.spi.ServiceContext},
- * by default this equals to registering it with {@link java.util.ServiceLoader}. Add {@link javax.annotation.Priority}
- * annotations for overriding (higher values overriden lower values).
- */
-public interface ConfigObserverSpi {
- /**
- * Add key expressions for generating ConfigurationChange events.
- *
- * @param keys the keys to be observed for changes.
- */
- <T> void addObservedKeys(Collection<String> keys);
-
- /**
- * Remove key expressions for generating ConfigurationChange events.
- *
- * @param keys the keys to be observed for changes.
- */
- <T> void removeObservedKeys(Collection<String> keys);
-
- /**
- * Get all registered key expressions for generating ConfigurationChange events.
- *
- * @return a set with the keys found, never null.
- */
- Set<String> getObservedKeys();
-
- /**
- * Get the current check period to check for configuration changes.
- *
- * @return the check period in ms.
- */
- long getCheckPeriod();
-
- /**
- * Check if the observer is running currently.
- *
- * @return true, if the observer is running.
- */
- boolean isRunning();
-
- /**
- * Start/Stop the observer container.
- */
- void enableObservation(boolean enable);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener
----------------------------------------------------------------------
diff --git a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener b/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener
index f675fd6..f9942c1 100644
--- a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener
+++ b/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.events.internal.DefaultConfigurationContextChangeListener
\ No newline at end of file
+org.apache.tamaya.events.internal.DefaultConfigurationContextChangeListener
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
----------------------------------------------------------------------
diff --git a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi b/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
index de5ee6f..99670e3 100644
--- a/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
+++ b/modules/events/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.events.internal.DefaultConfigObserverSpi
\ No newline at end of file
+org.apache.tamaya.events.internal.DefaultConfigChangeObserver
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3b5805ed/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
new file mode 100644
index 0000000..c93b2ca
--- /dev/null
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.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.events;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * PropertySource implementation that accesses properties that are statically stored.
+ */
+public class ChangeableGlobalPropertySource extends BasePropertySource{
+
+ private static Map<String,String> STORED_ENTRIES = new ConcurrentHashMap<>();
+
+ @Override
+ public String getName() {
+ return getClass().getSimpleName();
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return null;
+ }
+
+ /**
+ * Put a value (globally) into this property source.
+ * @param key the key, not null
+ * @param value the value, not null
+ * @return the entry replaced, or null.
+ */
+ public static String put(String key, String value){
+ return STORED_ENTRIES.put(key,value);
+ }
+
+ /**
+ * Put all the properties, overriding any existing ones with the same key.
+ * @param properties the properties, not null.
+ */
+ public static void putAll(Map<String,String> properties){
+ STORED_ENTRIES.putAll(properties);
+ }
+
+}