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] Renamed the fileobserver example to events example.
Date Fri, 24 Feb 2017 23:29:56 GMT
Repository: incubator-tamaya-extensions
Updated Branches:
  refs/heads/master e8db5e48c -> 767bc1ee5


[TAMAYA-206] Renamed the fileobserver example to events example.


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/767bc1ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/767bc1ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/767bc1ee

Branch: refs/heads/master
Commit: 767bc1ee501e8998ece1f67588d98632e3ed508e
Parents: e8db5e4
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Sat Feb 25 00:29:09 2017 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Sat Feb 25 00:29:09 2017 +0100

----------------------------------------------------------------------
 examples/04-events-example/pom.xml              |  71 ++++++++
 .../events/FilePropertySourceProvider.java      |  72 +++++++++
 .../apache/tamaya/ext/examples/events/Main.java | 157 ++++++++++++++++++
 ...org.apache.tamaya.spi.PropertySourceProvider |  20 +++
 examples/04-fileobserver-example/pom.xml        |  72 ---------
 .../FilePropertySourceProvider.java             |  72 ---------
 .../tamaya/ext/examples/fileobserver/Main.java  | 160 -------------------
 ...org.apache.tamaya.spi.PropertySourceProvider |  20 ---
 examples/pom.xml                                |   2 +-
 9 files changed, 321 insertions(+), 325 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/04-events-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/04-events-example/pom.xml b/examples/04-events-example/pom.xml
new file mode 100644
index 0000000..e736f7b
--- /dev/null
+++ b/examples/04-events-example/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.tamaya.ext.examples</groupId>
+        <artifactId>examples</artifactId>
+        <version>0.3-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>04-events-example</artifactId>
+
+    <name>Apache Tamaya Events Example</name>
+
+    <description>
+        This project contains a simple example demonstrating the usage
+        of the events module to observe changes in a configuration.
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+            <version>2.8.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya</groupId>
+            <artifactId>tamaya-core</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya.ext</groupId>
+            <artifactId>tamaya-events</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.hamcrest</groupId>
+            <artifactId>java-hamcrest</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
new file mode 100644
index 0000000..90c430c
--- /dev/null
+++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
@@ -0,0 +1,72 @@
+/*
+ * 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.ext.examples.events;
+
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.resource.AbstractPathPropertySourceProvider;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.*;
+
+import static org.apache.tamaya.ext.examples.events.Main.getPropertiesFilePath;
+
+public class FilePropertySourceProvider extends AbstractPathPropertySourceProvider {
+    public FilePropertySourceProvider() {
+        super(getPropertiesFilePath().toString());
+    }
+
+    @Override
+    protected Collection<PropertySource> getPropertySources(URL url) {
+        return Arrays.asList(new PropertySource[] { new DumbReloadingPropertySource(url)
});
+    }
+
+    public static class DumbReloadingPropertySource extends BasePropertySource {
+        private final URL propertiesFile;
+
+        public DumbReloadingPropertySource(URL url) {
+            propertiesFile = url;
+        }
+
+        @Override
+        public Map<String, String> getProperties() {
+
+            Map<String, String> properties = new HashMap<>();
+            try (InputStream stream = propertiesFile.openStream()) {
+                Properties props = new Properties();
+                if (stream != null) {
+                    props.load(stream);
+                }
+
+                for (String key : props.stringPropertyNames()) {
+                    properties.put(key, props.getProperty(key));
+                }
+            } catch (IOException e) {
+                throw new ConfigException("Error loading properties from " + propertiesFile,
e);
+            }
+
+            return properties;
+
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/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
new file mode 100644
index 0000000..e1af2c5
--- /dev/null
+++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
@@ -0,0 +1,157 @@
+/*
+ * 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.ext.examples.events;
+
+import org.apache.tamaya.events.ConfigEvent;
+import org.apache.tamaya.events.ConfigEventListener;
+import org.apache.tamaya.events.ConfigEventManager;
+import org.apache.tamaya.events.ConfigurationChange;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+import java.beans.PropertyChangeEvent;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.file.*;
+import java.util.*;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
+import static java.lang.System.out;
+import static java.util.Arrays.asList;
+
+public class Main {
+    private static final Duration EXAMPLE_RUNTIME = Duration.standardSeconds(30L);
+
+    /*
+     * Turns off all logging.
+     */
+    static {
+        LogManager.getLogManager().reset();
+        Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
+        globalLogger.setLevel(java.util.logging.Level.OFF);
+    }
+
+    private Main() {
+    }
+
+    public static void main(String[] args) throws Exception {
+        DateTime end = DateTime.now().plus(EXAMPLE_RUNTIME);
+
+        Timer timer = new Timer();
+        timer.schedule(new PropertiesFileWritingTask(), 0L, 5_000L);
+
+        installCleanupHook(getPropertiesFilePath());
+
+        ConfigEventManager.addListener(new ConfigurationChangeListener());
+        ConfigEventManager.setChangeMonitoringPeriod(1_000L);
+        ConfigEventManager.enableChangeMonitoring(true);
+
+        out.println("****************************************************");
+        out.println("File observer example");
+        out.println("****************************************************");
+        out.println();
+        out.println("Configuration source is: " + getPropertiesFilePath());
+        out.println();
+
+        Thread.sleep(EXAMPLE_RUNTIME.getMillis());
+
+        timer.cancel();
+    }
+
+    private static void installCleanupHook(final Path path) {
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+                try {
+                    Files.delete(path);
+                    out.println("Removed " + path);
+                } catch (IOException e) {
+                    throw new RuntimeException("Failed to delete " + path, e);
+                }
+            }
+        });
+    }
+
+    static Path getPropertiesFilePath() {
+        String tempDir = System.getProperty("java.io.tmpdir");
+
+        return Paths.get(tempDir, "fileobserver.properties");
+    }
+
+    private static class ConfigurationChangeListener implements ConfigEventListener {
+        @Override
+        public void onConfigEvent(ConfigEvent<?> event) {
+
+            ConfigurationChange c = (ConfigurationChange) event;
+
+            if (c.isKeyAffected("a")) {
+                PropertyChangeEvent change = c.getChanges().iterator().next();
+                Object oldValue = change.getOldValue();
+                Object newValue = change.getNewValue();
+
+                if (oldValue != null) {
+                    out.println("Value for key a changed (" + oldValue + " (old) => "
+ newValue + " (new))");
+                } else {
+                    out.println("Value for key a changed (" + newValue + " (new))");
+                }
+
+            }
+
+        }
+    }
+
+    private static class ContentProvider implements Iterable<String> {
+        private long value;
+
+        public void setValue(long val) {
+            this.value = val;
+        }
+
+        public long getValue() {
+            return value;
+        }
+
+        @Override
+        public Iterator<String> iterator() {
+            List<String> list = asList("# Generated file", "a="+ getValue());
+
+            return list.iterator();
+        }
+    }
+
+    private static class PropertiesFileWritingTask extends TimerTask {
+        private static ContentProvider contentProvider = new ContentProvider();
+
+        @Override
+        public void run() {
+
+            try {
+                contentProvider.setValue(System.currentTimeMillis());
+
+                Files.write(getPropertiesFilePath(), contentProvider,
+                            Charset.defaultCharset(), StandardOpenOption.CREATE);
+            }
+            catch (IOException e) {
+                throw new RuntimeException("Failed to write properties file.", e);
+            }
+
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
b/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..69b2a3b
--- /dev/null
+++ b/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy 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.ext.examples.events.FilePropertySourceProvider
+

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/04-fileobserver-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/04-fileobserver-example/pom.xml b/examples/04-fileobserver-example/pom.xml
deleted file mode 100644
index e191eb7..0000000
--- a/examples/04-fileobserver-example/pom.xml
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-   http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied.  See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <parent>
-        <groupId>org.apache.tamaya.ext.examples</groupId>
-        <artifactId>examples</artifactId>
-        <version>0.3-incubating-SNAPSHOT</version>
-    </parent>
-
-    <groupId>org.apache.tamaya.ext.examples</groupId>
-    <artifactId>04-fileobserver-example</artifactId>
-    <version>0.3-incubating-SNAPSHOT</version>
-
-    <name>Apache Tamaya File Observer Example</name>
-
-    <description>This project contains a simple example observing a directory
-        for (config) file changes, that updates the configuration correspondingly.
-    </description>
-
-    <dependencies>
-        <dependency>
-            <groupId>joda-time</groupId>
-            <artifactId>joda-time</artifactId>
-            <version>2.8.2</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tamaya</groupId>
-            <artifactId>tamaya-core</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.tamaya.ext</groupId>
-            <artifactId>tamaya-events</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.hamcrest</groupId>
-            <artifactId>java-hamcrest</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-        </dependency>
-    </dependencies>
-
-</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/FilePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/FilePropertySourceProvider.java
b/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/FilePropertySourceProvider.java
deleted file mode 100644
index 28441e7..0000000
--- a/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/FilePropertySourceProvider.java
+++ /dev/null
@@ -1,72 +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.ext.examples.fileobserver;
-
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.resource.AbstractPathPropertySourceProvider;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.*;
-
-import static org.apache.tamaya.ext.examples.fileobserver.Main.getPropertiesFilePath;
-
-public class FilePropertySourceProvider extends AbstractPathPropertySourceProvider {
-    public FilePropertySourceProvider() {
-        super(getPropertiesFilePath().toString());
-    }
-
-    @Override
-    protected Collection<PropertySource> getPropertySources(URL url) {
-        return Arrays.asList(new PropertySource[] { new DumbReloadingPropertySource(url)
});
-    }
-
-    public static class DumbReloadingPropertySource extends BasePropertySource {
-        private final URL propertiesFile;
-
-        public DumbReloadingPropertySource(URL url) {
-            propertiesFile = url;
-        }
-
-        @Override
-        public Map<String, String> getProperties() {
-
-            Map<String, String> properties = new HashMap<>();
-            try (InputStream stream = propertiesFile.openStream()) {
-                Properties props = new Properties();
-                if (stream != null) {
-                    props.load(stream);
-                }
-
-                for (String key : props.stringPropertyNames()) {
-                    properties.put(key, props.getProperty(key));
-                }
-            } catch (IOException e) {
-                throw new ConfigException("Error loading properties from " + propertiesFile,
e);
-            }
-
-            return properties;
-
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/Main.java
----------------------------------------------------------------------
diff --git a/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/Main.java
b/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/Main.java
deleted file mode 100644
index 3f1ba49..0000000
--- a/examples/04-fileobserver-example/src/main/java/org/apache/tamaya/ext/examples/fileobserver/Main.java
+++ /dev/null
@@ -1,160 +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.ext.examples.fileobserver;
-
-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;
-import org.apache.tamaya.events.ConfigurationChange;
-import org.joda.time.DateTime;
-import org.joda.time.Duration;
-
-import java.beans.PropertyChangeEvent;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.file.*;
-import java.util.*;
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-import static java.lang.System.out;
-import static java.nio.file.StandardOpenOption.CREATE;
-import static java.util.Arrays.asList;
-
-public class Main {
-    private static final Duration EXAMPLE_RUNTIME = Duration.standardSeconds(30L);
-
-    /*
-     * Turns off all logging.
-     */
-    static {
-        LogManager.getLogManager().reset();
-        Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
-        globalLogger.setLevel(java.util.logging.Level.OFF);
-    }
-
-    private Main() {
-    }
-
-    public static void main(String[] args) throws Exception {
-        DateTime end = DateTime.now().plus(EXAMPLE_RUNTIME);
-
-        Timer timer = new Timer();
-        timer.schedule(new PropertiesFileWritingTask(), 0L, 5_000L);
-
-        installCleanupHook(getPropertiesFilePath());
-
-        ConfigEventManager.addListener(new ConfigurationChangeListener());
-        ConfigEventManager.setChangeMonitoringPeriod(1_000L);
-        ConfigEventManager.enableChangeMonitoring(true);
-
-        out.println("****************************************************");
-        out.println("File observer example");
-        out.println("****************************************************");
-        out.println();
-        out.println("Configuration source is: " + getPropertiesFilePath());
-        out.println();
-
-        Thread.sleep(EXAMPLE_RUNTIME.getMillis());
-
-        timer.cancel();
-    }
-
-    private static void installCleanupHook(final Path path) {
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            @Override
-            public void run() {
-                try {
-                    Files.delete(path);
-                    out.println("Removed " + path);
-                } catch (IOException e) {
-                    throw new RuntimeException("Failed to delete " + path, e);
-                }
-            }
-        });
-    }
-
-    static Path getPropertiesFilePath() {
-        String tempDir = System.getProperty("java.io.tmpdir");
-
-        return Paths.get(tempDir, "fileobserver.properties");
-    }
-
-    private static class ConfigurationChangeListener implements ConfigEventListener {
-        @Override
-        public void onConfigEvent(ConfigEvent<?> event) {
-
-            ConfigurationChange c = (ConfigurationChange) event;
-
-            if (c.isKeyAffected("a")) {
-                PropertyChangeEvent change = c.getChanges().iterator().next();
-                Object oldValue = change.getOldValue();
-                Object newValue = change.getNewValue();
-
-                if (oldValue != null) {
-                    out.println("Value for key a changed (" + oldValue + " (old) => "
+ newValue + " (new))");
-                } else {
-                    out.println("Value for key a changed (" + newValue + " (new))");
-                }
-
-            }
-
-        }
-    }
-
-    private static class ContentProvider implements Iterable<String> {
-        private long value;
-
-        public void setValue(long val) {
-            this.value = val;
-        }
-
-        public long getValue() {
-            return value;
-        }
-
-        @Override
-        public Iterator<String> iterator() {
-            List<String> list = asList("# Generated file", "a="+ getValue());
-
-            return list.iterator();
-        }
-    }
-
-    private static class PropertiesFileWritingTask extends TimerTask {
-        private static ContentProvider contentProvider = new ContentProvider();
-
-        @Override
-        public void run() {
-
-            try {
-                contentProvider.setValue(System.currentTimeMillis());
-
-                Files.write(getPropertiesFilePath(), contentProvider,
-                            Charset.defaultCharset(), StandardOpenOption.CREATE);
-            }
-            catch (IOException e) {
-                throw new RuntimeException("Failed to write properties file.", e);
-            }
-
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/04-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/examples/04-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
b/examples/04-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
deleted file mode 100644
index fb21cb9..0000000
--- a/examples/04-fileobserver-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy 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.ext.examples.fileobserver.FilePropertySourceProvider
-

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/767bc1ee/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index b1bc219..c332fbb 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -40,7 +40,7 @@ under the License.
         <module>01-resources-example</module>
         <module>02-resolver-example</module>
         <module>03-injection-example</module>
-        <module>04-fileobserver-example</module>
+        <module>04-events-example</module>
     </modules>
 
 </project>
\ No newline at end of file


Mime
View raw message