tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject incubator-tamaya-extensions git commit: [TAMAYA-206] Fixed a minor bug in the events example. Change for key a is now explizitly searched.
Date Sun, 26 Feb 2017 09:57:52 GMT
Repository: incubator-tamaya-extensions
Updated Branches:
  refs/heads/master 767bc1ee5 -> 7c2728d1b


[TAMAYA-206] Fixed a minor bug in the events example. Change for key a is now explizitly searched.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/7c2728d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/7c2728d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/7c2728d1

Branch: refs/heads/master
Commit: 7c2728d1b81e65ee84929343ef558456521779d7
Parents: 767bc1e
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Sun Feb 26 10:56:46 2017 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Sun Feb 26 10:56:46 2017 +0100

----------------------------------------------------------------------
 .../apache/tamaya/ext/examples/events/Main.java | 26 +++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/7c2728d1/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
----------------------------------------------------------------------
diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
index e1af2c5..67d680c 100644
--- a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
+++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
@@ -18,6 +18,8 @@
  */
 package org.apache.tamaya.ext.examples.events;
 
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
 import org.apache.tamaya.events.ConfigEvent;
 import org.apache.tamaya.events.ConfigEventListener;
 import org.apache.tamaya.events.ConfigEventManager;
@@ -37,7 +39,7 @@ import static java.lang.System.out;
 import static java.util.Arrays.asList;
 
 public class Main {
-    private static final Duration EXAMPLE_RUNTIME = Duration.standardSeconds(30L);
+    private static final Duration EXAMPLE_RUNTIME = Duration.standardSeconds(300L);
 
     /*
      * Turns off all logging.
@@ -62,6 +64,13 @@ public class Main {
         ConfigEventManager.addListener(new ConfigurationChangeListener());
         ConfigEventManager.setChangeMonitoringPeriod(1_000L);
         ConfigEventManager.enableChangeMonitoring(true);
+        Configuration configuration = ConfigurationProvider.getConfiguration();
+
+        for (Map.Entry<String, String> e : configuration.getProperties().entrySet())
{
+            System.out.println(e.getKey() + ": " + e.getValue());
+        }
+
+
 
         out.println("****************************************************");
         out.println("File observer example");
@@ -102,9 +111,18 @@ public class Main {
             ConfigurationChange c = (ConfigurationChange) event;
 
             if (c.isKeyAffected("a")) {
-                PropertyChangeEvent change = c.getChanges().iterator().next();
-                Object oldValue = change.getOldValue();
-                Object newValue = change.getNewValue();
+                // Looking for the change event of property a. Not recomanded
+                // for production.
+                Object newValue = null;
+                Object oldValue = null;
+
+                for (PropertyChangeEvent change : c.getChanges()) {
+                    if ("a".equals(change.getPropertyName())) {
+                        oldValue = change.getOldValue();
+                        newValue = change.getNewValue();
+                        break;
+                    }
+                }
 
                 if (oldValue != null) {
                     out.println("Value for key a changed (" + oldValue + " (old) => "
+ newValue + " (new))");


Mime
View raw message