tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [06/14] incubator-tamaya git commit: Added support for having backend data visible in MutableConfig.
Date Tue, 01 Mar 2016 16:47:52 GMT
Added support for having backend data visible in MutableConfig.


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

Branch: refs/heads/master
Commit: d4bd82fd022636ea5f5061b27a9958821e860848
Parents: 2a98a9d
Author: anatole <anatole@apache.org>
Authored: Tue Mar 1 09:47:32 2016 +0100
Committer: anatole <anatole@apache.org>
Committed: Tue Mar 1 09:47:32 2016 +0100

----------------------------------------------------------------------
 .../asciidoc/extensions/mod_mutable_config.adoc | 56 +++++++++++++++++---
 1 file changed, 48 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d4bd82fd/src/site/asciidoc/extensions/mod_mutable_config.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/extensions/mod_mutable_config.adoc b/src/site/asciidoc/extensions/mod_mutable_config.adoc
index ba888b4..a4c1d60 100644
--- a/src/site/asciidoc/extensions/mod_mutable_config.adoc
+++ b/src/site/asciidoc/extensions/mod_mutable_config.adoc
@@ -74,13 +74,13 @@ The core of the module is the +MutableConfigQuery+ singleton, which is
a +Config
 +Mutableonfiguration+ based on a +Configuration+ and a set of target backend +URIs+. If not
sure you can call
 +getSupportedURIInfo()+ to see, which kind of URI's are  currently supported.
 On top of this API you also must have the correponding implementations installed that provide
the backend logic needed
-to write the changes back. This module by default supports writing back to files only. As
an example how to write
-configuration entries back refer to the following snippet:
+to write the changes back. This module by default supports writing back to properties and
xml-properties files only.
+As an example how to write configuration entries back refer to the following snippets:
 
 [source,java]
-.Accessing a mutable configuration backed by etcd
+.Accessing and updating a mutable configuration backed by etcd
 --------------------------------------------
-MutableConfiguration config = ConfigChangeManager.getConfiguration().query(
+MutableConfiguration config = Configuration.EMPTY.query(
     MutableConfigurationQuery.of("file:/home/etcd/backup-config.properties");
 
 config.set("newKey", "newValue")
@@ -89,8 +89,39 @@ config.set("newKey", "newValue")
       .commit();
 --------------------------------------------
 
-Hereby it is also possible to provide multiple URLS that allows you to write your configuration
chnges back to multiple
-backends in one go. Also be aware that the effective effect of your changes to the overall
configuration changes cannot
+[source,java]
+.Accessing and updating a mutable configuration backed by a properties file
+--------------------------------------------
+MutableConfiguration config = Configuration.EMPTY.query(
+    MutableConfigurationQuery.of("file:/home/user/.backup-config.properties");
+
+config.set("newKey", "newValue")
+      .set("anotherKey", "updatedValue")
+      .remove("valueNotValid")
+      .commit();
+--------------------------------------------
+
+Both snippets above will contain values only
+
+* added or updated (uncommitted)
+* already existing in the configuration bakend, but not removed (uncommitted).
+
+This is the case because we provide an EMPTY configuration as a starting point. We can also
combine this feature with
+the current +Configuration+, which then will make the effevtive configuration values visible
as well:
+
+[source,java]
+.Creating a mutable configuration based on the current config
+--------------------------------------------
+MutableConfiguration config = ConfigurationProvider.getConfiguration().query(
+    MutableConfigurationQuery.of("file:/home/user/.backup-config.properties");
+
+config.set("newKey", "newValue")
+      .set("anotherKey", "updatedValue")
+      .remove("valueNotValid")
+      .commit();
+--------------------------------------------
+
+Please be aware that the effective effect of your changes to the overall configuration, cannot
 be easily predicted, since it depends on several aspects:
 
 . is the corresponding configuration resource configured as part of the current system's
configuration?
@@ -110,7 +141,7 @@ is writable at all or can be removed or updated:
 [source,java]
 .Checking for mutability
 --------------------------------------------
-MutableConfiguration config = ConfigChangeManager.getConfiguration().query(
+MutableConfiguration config = Configuration.EMPTY.query(
     MutableConfigurationQuery.of("file:/home/etcd/backup-config.properties");
 
 if(config,isWritable("mycluster.shared.appKey")){
@@ -122,6 +153,15 @@ if(config,isWritable("mycluster.shared.appKey")){
 }
 --------------------------------------------
 
+Finally since the creation if a +MutableConfiguration+ based on an empty configuration instance
is so common, it is
+possible to directlky create one:
+
+[source,java]
+.Checking for mutability
+--------------------------------------------
+MutableConfiguration config = MutableConfigurationQuery.createMutableConfiguration("file:/home/etcd/backup-config.properties");
+--------------------------------------------
+
 === Configuration Changes
 
 This module does not handle detection of changes to the overall system's +Configuration+.
This can be done in
@@ -164,5 +204,5 @@ Implementations are registered with the current +ServiceContext+, be default
as
 As convenience the following base classes are provided:
 
 * +org.apache.tamaya.mutableconfig.spi.AbstractMutableConfiguration+ simplifying implementation
of +MutableConfiguration+.
-* +org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpi+ simplifying
the implemenation of
+* +org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpi+ simplifying
the implementation of
   +MutableConfigurationBackendSpi+.
\ No newline at end of file


Mime
View raw message