tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [14/50] [abbrv] incubator-tamaya-sandbox git commit: Moved mutable config module to sandbox.
Date Tue, 06 Sep 2016 17:18:10 GMT
Moved mutable config module to sandbox.


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

Branch: refs/heads/master
Commit: a4799717e6146dc0022dbae61c0bc05977a80f4f
Parents: 90f544d
Author: Anatole Tresch <anatole@apache.org>
Authored: Wed Oct 28 02:12:13 2015 +0100
Committer: Anatole Tresch <anatole@apache.org>
Committed: Wed Oct 28 02:12:13 2015 +0100

----------------------------------------------------------------------
 mutable-config/pom.xml                          |  81 +++++++++++
 .../tamaya/mutableconfig/ChangeSummary.java     | 105 ++++++++++++++
 .../mutableconfig/ConfigChangeProvider.java     |  50 +++++++
 .../mutableconfig/ConfigChangeRequest.java      | 136 +++++++++++++++++++
 .../spi/ConfigurationChangeProviderSpi.java     |  37 +++++
 pom.xml                                         |   1 +
 6 files changed, 410 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a4799717/mutable-config/pom.xml
----------------------------------------------------------------------
diff --git a/mutable-config/pom.xml b/mutable-config/pom.xml
new file mode 100644
index 0000000..c20a60a
--- /dev/null
+++ b/mutable-config/pom.xml
@@ -0,0 +1,81 @@
+<!-- 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy current the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.tamaya.ext</groupId>
+        <artifactId>tamaya-extensions</artifactId>
+        <version>0.2-incubating-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+
+    <artifactId>tamaya-mutable-config</artifactId>
+    <name>Apache Tamaya Mutable Configuration Support</name>
+    <description>This module provides abstraction, if your scenario needs to actively
change configuration entries
+        and write changes back to some property sources, files etc.</description>
+    <packaging>bundle</packaging>
+
+    <properties>
+        <jdkVersion>1.7</jdkVersion>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tamaya</groupId>
+            <artifactId>tamaya-api</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya.ext</groupId>
+            <artifactId>tamaya-events</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya</groupId>
+            <artifactId>tamaya-core</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>
+                            org.apache.tamaya.mutableconfig
+                        </Export-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a4799717/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangeSummary.java
----------------------------------------------------------------------
diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangeSummary.java
b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangeSummary.java
new file mode 100644
index 0000000..63d084c
--- /dev/null
+++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangeSummary.java
@@ -0,0 +1,105 @@
+/*
+ * 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.mutableconfig;
+
+import org.apache.tamaya.events.delta.ConfigurationChange;
+import org.apache.tamaya.events.delta.PropertySourceChange;
+
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * Summaray class of a configuration change operation.
+ * This class is immutable, read-only and thread-safe.
+ */
+public final class ChangeSummary implements Serializable{
+
+    private static final long serialVersionUID = 1L;
+
+    private String changeId;
+    private ConfigurationChange configChange;
+    private List<PropertySourceChange> sourceChanges = new ArrayList<>();
+    private long commitTS;
+
+    private ChangeSummary(Builder builder){
+        this.changeId = builder.changeId;
+        this.commitTS = builder.commitTS;
+        this.configChange = Objects.requireNonNull(builder.configChange);
+        this.sourceChanges.addAll(builder.sourceChanges);
+    }
+
+    public String getChangeId(){
+        return changeId;
+    }
+
+    public long getTimestampMillis(){
+        return commitTS;
+    }
+
+    public ConfigurationChange getConfigurationChange(){
+        return configChange;
+    }
+
+    public Collection<PropertySourceChange> getPropertySourceChanges(){
+        return Collections.unmodifiableList(this.sourceChanges);
+    }
+
+
+
+
+
+    public static final class Builder {
+
+        private String changeId;
+        private ConfigurationChange configChange;
+        private List<PropertySourceChange> sourceChanges = new ArrayList<>();
+        private long commitTS = System.currentTimeMillis();
+
+        public Builder(){
+            this(UUID.randomUUID().toString());
+        }
+
+        public Builder(String changeId){
+            this.changeId = Objects.requireNonNull(changeId);
+        }
+
+        public Builder setConfigChange(ConfigurationChange configChange){
+            this.configChange = configChange;
+            return this;
+        }
+
+        public Builder addPropertySourceChange(PropertySourceChange propertyChange){
+            this.sourceChanges.add(propertyChange);
+            return this;
+        }
+
+        public Builder setTimestamp(long timestamp){
+            this.commitTS = timestamp;
+            return this;
+        }
+
+        public ChangeSummary build(){
+            return new ChangeSummary(this);
+        }
+
+
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a4799717/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeProvider.java
----------------------------------------------------------------------
diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeProvider.java
b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeProvider.java
new file mode 100644
index 0000000..f8842ea
--- /dev/null
+++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeProvider.java
@@ -0,0 +1,50 @@
+/*
+ * 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.mutableconfig;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.mutableconfig.spi.ConfigurationChangeProviderSpi;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Accessor for creating {@link ConfigChangeRequest} instances to change and commite configuration.
+ */
+public final class ConfigChangeProvider {
+
+    /**
+     * Creates a new change request for the given Configuration.
+     * @param config the configuration.
+     * @return a new ChangeRequest
+     * @throws UnsupportedOperationException if no change providers are registered.
+     */
+    public static ConfigChangeRequest createChangeRequest(Configuration config){
+        return ServiceContextManager.getServiceContext().getService(ConfigurationChangeProviderSpi.class)
+                .createChangeRequest(config);
+    }
+
+    /**
+     * Creates a new change request for the current Configuration.
+     * @return a new ChangeRequest
+     */
+    public static ConfigChangeRequest createChangeRequest(){
+        return createChangeRequest(ConfigurationProvider.getConfiguration());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a4799717/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java
----------------------------------------------------------------------
diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java
b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java
new file mode 100644
index 0000000..6d393cf
--- /dev/null
+++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java
@@ -0,0 +1,136 @@
+/*
+ * 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.mutableconfig;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+
+import java.util.Collection;
+import java.util.Map;
+
+
+/**
+ * This interface extends the Configuration interface hereby adding methods to change configuration
entries.
+ * Hereby not all configuration entries are necessarily mutable, since some entries may be
read from non
+ * mutable areas of configuration. Of course, it is always possible to add a mutable shadow
layer on top of all
+ * configuration to enable whatever changes applied. The exact management and storage persistence
algorithm should be
+ * transparent.<br/>
+ * As a consequence clients should first check, using the corresponding methods, if entries
are to edited or removed
+ * actually are eligible for change/creation or removal.
+ */
+public interface ConfigChangeRequest{
+
+    /**
+     * Returns the configuration onto which the change should be applied.
+     * @return the corresponding configuration, not null.
+     */
+    Configuration getConfiguration();
+
+    /**
+     * Checks if a configuration key is writable (or it can be added).
+     *
+     * @param keyExpression the key to be cheched for write access (including creation),
not null. Here this could also
+     *                      be a regulat expression, such "as a.b.c.*".
+     */
+    boolean isWritable(String keyExpression);
+
+    /**
+     * Checks if a configuration key is removable. This also implies that it is writable,
but there might be writable
+     * keys that cannot be removed.
+     *
+     * @param keyExpression the keyExpression the key to be cheched for write access (including
creation), not null. Here this could also
+     *                      be a regulat expression, such "as a.b.c.*".
+     */
+    boolean isRemovable(String keyExpression);
+
+    /**
+     * Sets a property.
+     *
+     * @param key the property's key, not null.
+     * @param value the property's value, not null.
+     * @return the former property value, or null.
+     * @throws ConfigException if the key/value cannot be added.
+     */
+    String put(String key, String value);
+
+    /**
+     * Puts all given configuration entries. This method should check that all given properties
are
+     * basically removable, as defined by #isWritable. If any of the passed keys is not writable
during this initial
+     * check, the operation should not perform any configuration changes and throw a {@link
ConfigException}. If errors
+     * occur afterwards, when the properties are effectively written back to the backends,
the errors should be
+     * collected and returned as part of the ConfigException payload. Nevertheless the operation
should in that case
+     * remove all entries as far as possible and abort the writing operation.
+     *
+     * @param properties the properties tobe written, not null.
+     * @throws ConfigException if any of the given properties could not be written.
+     */
+    void putAll(Map<String, String> properties);
+
+    /**
+     * Removes a configuration entry.
+     *
+     * @param key the property's key, not null.
+     * @throws ConfigException if the given cannot be removed.
+     * @return the property's keys.
+     */
+    void remove(String key);
+
+    /**
+     * Removes all given configuration entries. This method should check that all given properties
are
+     * basically removable, as defined by #isRemovable. If any of the passed keys is not
removable during this initial
+     * check, the operation should not perform any configuration changes and throw a {@link
ConfigException}. If errors
+     * occur afterwards, when the properties are effectively written back to the backends,
the errors should be
+     * collected and returned as part of the ConfigException payload. Nevertheless the operation
should in that case
+     * remove all entries as far as possible and abort the writing operation.
+     *
+     * @param keys the property's keys to be removed, not null.
+     * @throws ConfigException if any of the given keys could not be removed.
+     */
+    void removeAll(Collection<String> keys);
+
+    /**
+     * Resets all changes, leaving the request still open for further operations.
+     */
+    void reset();
+
+    /**
+     * Closes the request, sby default any uncommitted changes are committed.
+     */
+    void commit();
+
+    /**
+     * Closes the request,
+     * @param saveChanges flag to control if  any uncommitted changes ahould be written (default:
yes).
+     */
+    void commit(boolean saveChanges);
+
+    /**
+     * Operation to check, if the current request is closed. Closed requests are read-only
and can not be used
+     * for preparing/submitting any configuration changes.
+     * @return true, if this instance is closed.
+     */
+    boolean isCommitted();
+
+    /**
+     * Access the summary of the changes applied
+     * @return
+     */
+    ChangeSummary getChangeSummary();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a4799717/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigurationChangeProviderSpi.java
----------------------------------------------------------------------
diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigurationChangeProviderSpi.java
b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigurationChangeProviderSpi.java
new file mode 100644
index 0000000..e378c0d
--- /dev/null
+++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigurationChangeProviderSpi.java
@@ -0,0 +1,37 @@
+/*
+ * 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.mutableconfig.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
+
+/**
+ * Provider SPI for the {@link org.apache.tamaya.mutableconfig.ConfigChangeProvider}.
+ */
+public interface ConfigurationChangeProviderSpi {
+
+   /**
+    * Creates a new change request for the given Configuration.
+    * @param config the configuration.
+    * @return a new ChangeRequest
+    * @throws UnsupportedOperationException if no change providers are registered.
+    */
+    ConfigChangeRequest createChangeRequest(Configuration config);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/a4799717/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 4f8c9c8..8168c47 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,6 +41,7 @@ under the License.
         <module>sysprops</module>
         <module>environment</module>
         <module>collections</module>
+        <module>mutable-config</module>
         <module>ui</module>
     </modules>
 


Mime
View raw message