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 2016/03/14 00:59:02 UTC
[01/16] incubator-tamaya git commit: Simplified SPI/API.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 44354af19 -> 343531a49
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java
new file mode 100644
index 0000000..e74e9e8
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java
@@ -0,0 +1,162 @@
+/*
+ * 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.propertysources;
+
+import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
+import org.apache.tamaya.spisupport.BasePropertySource;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Base class for implementing a {@link MutablePropertySource}.
+ */
+public abstract class AbstractMutablePropertySource extends BasePropertySource
+ implements MutablePropertySource {
+
+ /**
+ * Map with the curren transactions, identified by transactionId.
+ */
+ protected final Map<UUID, TransactionContext> transactions = new ConcurrentHashMap<>();
+
+ /**
+ * Constructor udsing zero' as default ordinal.
+ */
+ protected AbstractMutablePropertySource(){
+ super();
+ }
+
+ /**
+ * Constructor allow to pass the default ordinal to be used.
+ * @param defaultOrdinal the default ordinal.
+ */
+ protected AbstractMutablePropertySource(int defaultOrdinal){
+ super(defaultOrdinal);
+ }
+
+ /**
+ * Get a list with property keys removed within the given transaction.
+ * @param transactionId the transaction id, not null.
+ * @return the removed property keys, never null.
+ */
+ protected final Set<String> getRemovedProperties(UUID transactionId) {
+ TransactionContext ctx = this.transactions.get(transactionId);
+ if(ctx!=null) {
+ return ctx.getRemovedProperties();
+ }
+ return Collections.emptySet();
+ }
+
+ /**
+ * Get a list with property keys added within the given transaction.
+ * @param transactionId the transaction id, not null.
+ * @return the added property keys, never null.
+ */
+ protected final Map<String,String> getAddedProperties(UUID transactionId) {
+ TransactionContext ctx = this.transactions.get(transactionId);
+ if(ctx!=null) {
+ return ctx.getAddedProperties();
+ }
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isWritable(String keyExpression) {
+ return true;
+ }
+
+ @Override
+ public boolean isRemovable(String keyExpression) {
+ return true;
+ }
+
+ @Override
+ public final MutablePropertySource put(UUID transactionId, String key, String value) {
+ TransactionContext ctx = this.transactions.get(transactionId);
+ if(ctx==null) {
+ throw new IllegalStateException("No such transaction: " + transactionId);
+ }
+ ctx.put(key, value);
+ return this;
+ }
+
+ @Override
+ public final MutablePropertySource putAll(UUID transactionId, Map<String, String> properties) {
+ TransactionContext ctx = this.transactions.get(transactionId);
+ if(ctx==null) {
+ throw new IllegalStateException("No such transaction: " + transactionId);
+ }
+ ctx.putAll(properties);
+ return this;
+ }
+
+ @Override
+ public final MutablePropertySource remove(UUID transactionId, String... keys) {
+ TransactionContext ctx = this.transactions.get(transactionId);
+ if(ctx==null) {
+ throw new IllegalStateException("No such transaction: " + transactionId);
+ }
+ ctx.removeAll(Arrays.asList(keys));
+ return this;
+ }
+
+ @Override
+ public final MutablePropertySource remove(UUID transactionId, Collection<String> keys) {
+ TransactionContext ctx = this.transactions.get(transactionId);
+ if(ctx==null) {
+ throw new IllegalStateException("No such transaction: " + transactionId);
+ }
+ ctx.removeAll(keys);
+ return this;
+ }
+
+ @Override
+ public final void startTransaction(UUID transactionId) {
+ TransactionContext ctx = this.transactions.get(transactionId);
+ if(ctx==null) {
+ this.transactions.put(transactionId, new TransactionContext(transactionId));
+ }
+ }
+
+ @Override
+ public final void commitTransaction(UUID transactionId) {
+ TransactionContext ctx = this.transactions.remove(transactionId);
+ if(ctx==null) {
+ throw new IllegalStateException("No such transaction: " + transactionId);
+ }
+ commitInternal(ctx);
+ }
+
+
+ /**
+ * Commit of the changes to the current property source. This is the last chance to get changes written back to the
+ * property source. On return the transactional context will be removed.
+ */
+ protected abstract void commitInternal(TransactionContext context);
+
+ @Override
+ public final void rollbackTransaction(UUID transactionId) {
+ this.transactions.remove(transactionId);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
new file mode 100644
index 0000000..d713578
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
@@ -0,0 +1,194 @@
+/*
+ * 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.propertysources;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.PropertyValueBuilder;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple implementation of a mutable {@link org.apache.tamaya.spi.PropertySource} for .properties files.
+ */
+public class MutablePropertiesPropertySource extends AbstractMutablePropertySource {
+
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(MutablePropertiesPropertySource.class.getName());
+ /**
+ * Default update interval is 1 minute.
+ */
+ private static final long DEFAULT_UPDATE_INTERVAL = 60000L;
+
+ /**
+ * The property source name.
+ */
+ private String name;
+
+ /**
+ * The configuration resource's URL.
+ */
+ private File file;
+
+ /**
+ * Timestamp of last read.
+ */
+ private long lastRead;
+
+ /**
+ * Interval, when the resource should try to update its contents.
+ */
+ private long updateInterval = DEFAULT_UPDATE_INTERVAL;
+ /**
+ * The current properties.
+ */
+ private Map<String, String> properties = new HashMap<>();
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ */
+ public MutablePropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
+ super(defaultOrdinal);
+ this.name = propertiesLocation.toString();
+ try {
+ this.file = propertiesLocation;
+ load();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e);
+ }
+ }
+
+
+
+ @Override
+ public PropertyValue get(String key) {
+ Map<String,String> properties = getProperties();
+ String val = properties.get(key);
+ if(val==null){
+ return null;
+ }
+ PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName());
+ String metaKeyStart = "_" + key + ".";
+ for(Map.Entry<String,String> en:properties.entrySet()) {
+ if(en.getKey().startsWith(metaKeyStart)){
+ b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue());
+ }
+ }
+ return b.build();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ checkLoad();
+ return Collections.unmodifiableMap(this.properties);
+ }
+
+
+ private void checkLoad() {
+ if(file!=null && (lastRead+updateInterval)<System.currentTimeMillis()){
+ load();
+ }
+ }
+
+ /**
+ * loads the Properties from the given URL
+ *
+ * @return loaded {@link Properties}
+ * @throws IllegalStateException in case of an error while reading properties-file
+ */
+ private void load() {
+ try (InputStream stream = new FileInputStream(file)) {
+ Map<String, String> properties = new HashMap<>();
+ Properties props = new Properties();
+ if (stream != null) {
+ props.load(stream);
+ }
+ for (String key : props.stringPropertyNames()) {
+ properties.put(key, props.getProperty(key));
+ }
+ this.lastRead = System.currentTimeMillis();
+ LOG.log(Level.FINEST, "Loaded properties from " + file);
+ this.properties = properties;
+ } catch (IOException e) {
+ LOG.log(Level.FINEST, "Cannot load properties from " + file, e);
+ }
+ }
+
+ @Override
+ protected void commitInternal(TransactionContext context) {
+ if(context.isEmpty()){
+ LOG.info("Nothing to commit for transaction: " + context.getTransactionID());
+ return;
+ }
+ if(!file.exists()){
+ try {
+ if(!file.createNewFile()){
+ throw new ConfigException("Failed to create config file " + file);
+ }
+ } catch (IOException e) {
+ throw new ConfigException("Failed to create config file " + file, e);
+ }
+ }
+ for(Map.Entry<String,String> en:context.getAddedProperties().entrySet()){
+ int index = en.getKey().indexOf('?');
+ if(index>0){
+ this.properties.put(en.getKey().substring(0, index), en.getValue());
+ }else{
+ this.properties.put(en.getKey(), en.getValue());
+ }
+ }
+ for(String rmKey:context.getRemovedProperties()){
+ this.properties.remove(rmKey);
+ }
+ try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
+ Properties props = new Properties();
+ for (Map.Entry<String,String> en : this.properties.entrySet()) {
+ props.setProperty(en.getKey(), en.getValue());
+ }
+ props.store(bos, "Properties written from Tamaya on " + new Date());
+ bos.flush();
+ }
+ catch(Exception e){
+ throw new ConfigException("Failed to write config to " + file, e);
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
new file mode 100644
index 0000000..1e0d6da
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
@@ -0,0 +1,195 @@
+/*
+ * 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.propertysources;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.PropertyValueBuilder;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple implementation of a mutable {@link org.apache.tamaya.spi.PropertySource} for .xml properties files.
+ */
+public class MutableXmlPropertiesPropertySource extends AbstractMutablePropertySource {
+
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(MutableXmlPropertiesPropertySource.class.getName());
+ /**
+ * Default update interval is 1 minute.
+ */
+ private static final long DEFAULT_UPDATE_INTERVAL = 60000L;
+
+ /**
+ * The property source name.
+ */
+ private String name;
+
+ /**
+ * The configuration resource's URL.
+ */
+ private File file;
+
+ /**
+ * Timestamp of last read.
+ */
+ private long lastRead;
+
+ /**
+ * Interval, when the resource should try to update its contents.
+ */
+ private long updateInterval = DEFAULT_UPDATE_INTERVAL;
+ /**
+ * The current properties.
+ */
+ private Map<String, String> properties = new HashMap<>();
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ *
+ * @param propertiesLocation the URL encoded location, not null.
+ */
+ public MutableXmlPropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
+ super(defaultOrdinal);
+ this.name = propertiesLocation.toString();
+ try {
+ this.file = propertiesLocation;
+ load();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e);
+ }
+ }
+
+
+
+ @Override
+ public PropertyValue get(String key) {
+ Map<String,String> properties = getProperties();
+ String val = properties.get(key);
+ if(val==null){
+ return null;
+ }
+ PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName());
+ String metaKeyStart = "_" + key + ".";
+ for(Map.Entry<String,String> en:properties.entrySet()) {
+ if(en.getKey().startsWith(metaKeyStart)){
+ b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue());
+ }
+ }
+ return b.build();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ checkLoad();
+ return Collections.unmodifiableMap(this.properties);
+ }
+
+
+ private void checkLoad() {
+ if(file!=null && (lastRead+updateInterval)<System.currentTimeMillis()){
+ load();
+ }
+ }
+
+ /**
+ * loads the Properties from the given URL
+ *
+ * @return loaded {@link Properties}
+ * @throws IllegalStateException in case of an error while reading properties-file
+ */
+ private void load() {
+ try (InputStream stream = new FileInputStream(file)) {
+ Map<String, String> properties = new HashMap<>();
+ Properties props = new Properties();
+ if (stream != null) {
+ props.loadFromXML(stream);
+ }
+ for (String key : props.stringPropertyNames()) {
+ properties.put(key, props.getProperty(key));
+ }
+ this.lastRead = System.currentTimeMillis();
+ this.properties = properties;
+ LOG.log(Level.FINEST, "Loaded properties from " + file);
+ this.properties = properties;
+ } catch (IOException e) {
+ LOG.log(Level.FINEST, "Cannot load properties from " + file, e);
+ }
+ }
+
+ @Override
+ protected void commitInternal(TransactionContext context) {
+ if(context.isEmpty()){
+ LOG.info("Nothing to commit for transaction: " + context.getTransactionID());
+ return;
+ }
+ if(!file.exists()){
+ try {
+ if(!file.createNewFile()){
+ throw new ConfigException("Failed to create config file " + file);
+ }
+ } catch (IOException e) {
+ throw new ConfigException("Failed to create config file " + file, e);
+ }
+ }
+ for(Map.Entry<String,String> en:context.getAddedProperties().entrySet()){
+ int index = en.getKey().indexOf('?');
+ if(index>0){
+ this.properties.put(en.getKey().substring(0, index), en.getValue());
+ }else{
+ this.properties.put(en.getKey(), en.getValue());
+ }
+ }
+ for(String rmKey:context.getRemovedProperties()){
+ this.properties.remove(rmKey);
+ }
+ try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
+ Properties props = new Properties();
+ for (Map.Entry<String,String> en : this.properties.entrySet()) {
+ props.setProperty(en.getKey(), en.getValue());
+ }
+ props.storeToXML(bos, "Properties written from Tamaya on " + new Date());
+ bos.flush();
+ }
+ catch(Exception e){
+ throw new ConfigException("Failed to write config to " + file, e);
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfiguration.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfiguration.java
deleted file mode 100644
index d1afaf6..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfiguration.java
+++ /dev/null
@@ -1,106 +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.mutableconfig.spi;
-
-import org.apache.tamaya.mutableconfig.MutableConfiguration;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Base class for implementing a ConfigChangeRequest.
- */
-public abstract class AbstractMutableConfiguration implements MutableConfiguration {
-
- /**
- * The Properties.
- */
- protected final Map<String,String> addedProperties = new HashMap<>();
- /**
- * The Removed.
- */
- protected final Set<String> removedProperties = new HashSet<>();
-
- protected Set<String> getRemovedProperties() {
- return removedProperties;
- }
-
- protected Map<String,String> getAddedProperties() {
- return addedProperties;
- }
-
- @Override
- public boolean isWritable(String keyExpression) {
- return true;
- }
-
- @Override
- public boolean isRemovable(String keyExpression) {
- return true;
- }
-
- @Override
- public abstract boolean isExisting(String keyExpression);
-
- @Override
- public MutableConfiguration put(String key, String value) {
- this.addedProperties.put(key, value);
- return this;
- }
-
- @Override
- public MutableConfiguration putAll(Map<String, String> properties) {
- this.addedProperties.putAll(properties);
- return this;
- }
-
- @Override
- public MutableConfiguration remove(String... keys) {
- Collections.addAll(this.removedProperties, keys);
- return this;
- }
-
- @Override
- public MutableConfiguration remove(Collection<String> keys) {
- this.removedProperties.addAll(keys);
- return this;
- }
-
- @Override
- public final void commit() {
- commitInternal();
- this.removedProperties.clear();
- this.addedProperties.clear();
- }
-
- /**
- * Commit internal.
- */
- protected abstract void commitInternal();
-
- @Override
- public final void rollback() {
- this.removedProperties.clear();
- this.addedProperties.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfigurationBackendSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfigurationBackendSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfigurationBackendSpi.java
deleted file mode 100644
index d529847..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/AbstractMutableConfigurationBackendSpi.java
+++ /dev/null
@@ -1,134 +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.mutableconfig.spi;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.net.URI;
-import java.util.*;
-
-/**
- * Base class for implementing a MutableConfigurationBackend.
- */
-public abstract class AbstractMutableConfigurationBackendSpi implements MutableConfigurationBackendSpi {
-
- /** The URI identifying the current backend. */
- private final URI backendURI;
-
- /**
- * The property source containing the current backend property data.
- */
- private PropertySource backendPropertySource;
-
- /**
- * The added or changed properties (uncommitted)..
- */
- protected final Map<String,String> addedProperties = new HashMap<>();
- /**
- * The removed properties (uncommitted).
- */
- protected final Set<String> removedProperties = new HashSet<>();
-
- /**
- * Get the uncommitted removed properties.
- * @return the uncommitted removed properties, never null.
- */
- protected Set<String> getRemovedProperties() {
- return removedProperties;
- }
-
- /**
- * Get the uncommitted properties added or updated so far.
- * @return the uncommitted properties added or updated, never null.
- */
- protected Map<String,String> getAddedProperties() {
- return addedProperties;
- }
-
- /**
- * Creates a new instance.
- * @param backendURI the backend URI, not null.
- * @param backendPropertySource the backend property source, not null.
- */
- protected AbstractMutableConfigurationBackendSpi(URI backendURI, PropertySource backendPropertySource){
- this.backendURI = Objects.requireNonNull(backendURI);
- this.backendPropertySource = Objects.requireNonNull(backendPropertySource);
- }
-
- @Override
- public URI getBackendURI() {
- return backendURI;
- }
-
- @Override
- public PropertySource getBackendPropertySource(){
- return backendPropertySource;
- }
-
- @Override
- public boolean isWritable(String keyExpression) {
- return true;
- }
-
- @Override
- public boolean isRemovable(String keyExpression) {
- return true;
- }
-
- @Override
- public abstract boolean isExisting(String keyExpression);
-
- @Override
- public void put(String key, String value) {
- this.addedProperties.put(key, value);
- }
-
- @Override
- public void putAll(Map<String, String> properties) {
- this.addedProperties.putAll(properties);
- }
-
- @Override
- public void remove(String... keys) {
- Collections.addAll(this.removedProperties, keys);
- }
-
- @Override
- public void remove(Collection<String> keys) {
- this.removedProperties.addAll(keys);
- }
-
- @Override
- public final void commit() {
- commitInternal();
- this.removedProperties.clear();
- this.addedProperties.clear();
- }
-
- /**
- * Commit internal.
- */
- protected abstract void commitInternal();
-
- @Override
- public final void rollback() {
- this.removedProperties.clear();
- this.addedProperties.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendProviderSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendProviderSpi.java
deleted file mode 100644
index 5e8300b..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendProviderSpi.java
+++ /dev/null
@@ -1,37 +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.mutableconfig.spi;
-
-import java.net.URI;
-
-/**
- * Provider SPI used by {@link org.apache.tamaya.mutableconfig.MutableConfigurationQuery}. Providers may override
- * other providers registering with a higher {@link javax.annotation.Priority} value annotated.
- */
-public interface MutableConfigurationBackendProviderSpi {
-
- /**
- * Creates a new configuration backend for applying changes to.
- *
- * @param backendURI the backend uri
- * @return the requested backend, or null if the given backend URI is not supported by the given SPI.
- */
- MutableConfigurationBackendSpi getBackend(URI backendURI);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendSpi.java
deleted file mode 100644
index ebe2f83..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationBackendSpi.java
+++ /dev/null
@@ -1,147 +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.mutableconfig.spi;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.net.URI;
-import java.util.Collection;
-import java.util.Map;
-
-
-/**
- * This interface models a writable backend for configuration data.
- *
- * As a consequence clients should first check, using the corresponding methods, if entries are to edited or removedProperties
- * actually are eligible for change/creation or removal.
- */
-public interface MutableConfigurationBackendSpi {
-
- /**
- * Identifies the configuration backend that is targeted by this instance and which is
- * also responsible for writing back the changes applied.
- *
- * @return the backend URI, never null.
- */
- URI getBackendURI();
-
- /**
- * Checks if a configuration key is writable (or it can be added).
- *
- * @param keyExpression the key to be checked for write access (including creation), not null. Here this could also
- * be a regular expression, such "as a.b.c.*".
- * @return the boolean
- */
- 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 removedProperties.
- *
- * @param keyExpression the keyExpression the key to be checked for write access (including creation), not null.
- * Here this could also
- * be a regular expression, such "as a.b.c.*".
- * @return the boolean
- */
- boolean isRemovable(String keyExpression);
-
- /**
- * Checks if any keys of the given type already exist in the write backend. <b>NOTE:</b> there may be backends that
- * are not able to support lookups with regular expressions. In most such cases you should pass the keys to
- * lookup explicitly.
- *
- * @param keyExpression the key to be checked for write access (including creation), not null. Here this could
- * also be a regular expression, such "as a.b.c.*".
- * @return true, if there is any key found matching the expression.
- */
- boolean isExisting(String keyExpression);
-
- /**
- * Sets a property.
- *
- * @param key the property's key, not null.
- * @param value the property's value, not null.
- * @throws org.apache.tamaya.ConfigException if the key/value cannot be added, or the request is read-only.
- */
- void put(String key, String value);
-
-
- /**
- * Access a {@link org.apache.tamaya.spi.PropertySource} for reading any properties from the write target.
- * @return the {@link org.apache.tamaya.spi.PropertySource} never {@code null}. In case of a write only
- * data sink, simply return PropertySource.EMPTY.
- */
- PropertySource getBackendPropertySource();
-
- /**
- * 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 org.apache.tamaya.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 org.apache.tamaya.ConfigException if any of the given properties could not be written, or the request is read-only.
- */
- void putAll(Map<String, String> properties);
-
- /**
- * 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 org.apache.tamaya.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 removedProperties, not null.
- * @throws org.apache.tamaya.ConfigException if any of the given keys could not be removedProperties, or the request is read-only.
- */
- void remove(Collection<String> keys);
-
- /**
- * 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 org.apache.tamaya.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 removedProperties, not null.
- * @throws org.apache.tamaya.ConfigException if any of the given keys could not be removedProperties, or the request is read-only.
- */
- void remove(String... keys);
-
- /**
- * Commits the request. After a commit the change is not editable anymore. All changes applied will be written to
- * the corresponding configuration backend.
- *
- * NOTE that changes applied must not necessarily be visible in the current {@link org.apache.tamaya.Configuration} instance,
- * since visibility of changes also depends on the ordinals set on the {@link org.apache.tamaya.spi.PropertySource}s
- * configured.
- * @throws org.apache.tamaya.ConfigException if the request already has been committed or cancelled, or the commit fails.
- */
- void commit();
-
- /**
- * Rollback any changes leaving everything unchanged. This will rollback all changes applied since the last commit.
- */
- void rollback();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java
new file mode 100644
index 0000000..15ba655
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutableConfigurationProviderSpi.java
@@ -0,0 +1,38 @@
+/*
+ * 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.MutableConfiguration;
+
+
+/**
+ * Provider SPI used by {@link org.apache.tamaya.mutableconfig.MutableConfigurationProvider}. Providers may override
+ * other providers registering with a higher {@link javax.annotation.Priority} value annotated.
+ */
+public interface MutableConfigurationProviderSpi {
+
+ /**
+ * Creates a new {@link MutableConfiguration} with {@code autoCommit = false} as default.
+ *
+ * @param configuration the configuration, not null.
+ * @return a new mutable configuration instance.
+ */
+ MutableConfiguration createMutableConfiguration(Configuration configuration);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java
new file mode 100644
index 0000000..2888638
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java
@@ -0,0 +1,125 @@
+/*
+ * 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.spi.PropertySource;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
+
+
+/**
+ * This interface models a writable backend for configuration data.
+ *
+ * As a consequence clients should first check, using the corresponding methods, if entries are to edited or removedProperties
+ * actually are eligible for change/creation or removal.
+ */
+public interface MutablePropertySource extends PropertySource {
+
+ /**
+ * Checks if a configuration key is writable (or it can be added).
+ *
+ * @param key the key to be checked for write access (including creation), not null.
+ * @return true if the key can be added or updated.
+ */
+ boolean isWritable(String key);
+
+ /**
+ * Checks if a configuration key is removable. This also implies that it is writable, but there might be writable
+ * keys that cannot be removedProperties.
+ *
+ * @param key the key to be checked for removal, not null.
+ * @return true, if the key can be removed.
+ */
+ boolean isRemovable(String key);
+
+ /**
+ * Sets a property.
+ *
+ * @param key the property's key, not null.
+ * @param value the property's value, not null.
+ * @throws org.apache.tamaya.ConfigException if the key/value cannot be added, or the request is read-only.
+ */
+ MutablePropertySource put(UUID transactionId, 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 org.apache.tamaya.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 org.apache.tamaya.ConfigException if any of the given properties could not be written, or the request is read-only.
+ */
+ MutablePropertySource putAll(UUID transactionId, Map<String, String> properties);
+
+ /**
+ * 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 org.apache.tamaya.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 removedProperties, not null.
+ * @throws org.apache.tamaya.ConfigException if any of the given keys could not be removedProperties, or the request is read-only.
+ */
+ MutablePropertySource remove(UUID transactionId, Collection<String> keys);
+
+ /**
+ * 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 org.apache.tamaya.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 removedProperties, not null.
+ * @throws org.apache.tamaya.ConfigException if any of the given keys could not be removedProperties, or the request is read-only.
+ */
+ MutablePropertySource remove(UUID transactionId, String... keys);
+
+ /**
+ * Commits the request. After a commit the change is not editable anymore. All changes applied will be written to
+ * the corresponding configuration backend.
+ *
+ * NOTE that changes applied must not necessarily be visible in the current {@link org.apache.tamaya.Configuration} instance,
+ * since visibility of changes also depends on the ordinals set on the {@link org.apache.tamaya.spi.PropertySource}s
+ * configured.
+ * @throws org.apache.tamaya.ConfigException if the request already has been committed or cancelled, or the commit fails.
+ * @param transactionId the transaction id, not null.
+ */
+ void commitTransaction(UUID transactionId);
+
+ /**
+ * Rollback any changes leaving everything unchanged. This will rollback all changes applied since the last commit.
+ * @param transactionId the transaction id, not null.
+ */
+ void rollbackTransaction(UUID transactionId);
+
+ /**
+ * Start a new transaction context with the given isolation policy.
+ * @param transactionId the transaction id, not null.
+ */
+ void startTransaction(UUID transactionId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi b/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
deleted file mode 100644
index 59b0c51..0000000
--- a/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
+++ /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.mutableconfig.internal.DefaultConfigurationBackendSpi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi b/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi
new file mode 100644
index 0000000..eb366fc
--- /dev/null
+++ b/modules/mutable-config/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi
@@ -0,0 +1,19 @@
+#
+# 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.mutableconfig.internal.DefaultMutableConfigurationSpi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationQueryTest.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationQueryTest.java
deleted file mode 100644
index f50a85e..0000000
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationQueryTest.java
+++ /dev/null
@@ -1,84 +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.mutableconfig;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigurationProvider;
-import org.junit.Test;
-
-import java.io.File;
-import java.net.URI;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for {@link MutableConfigurationQuery}.
- */
-public class MutableConfigurationQueryTest {
-
- /**
- * Test create change request.
- *
- * @throws Exception the exception
- */
- @Test
- public void testCreateChangeRequest() throws Exception {
- File f = File.createTempFile("ConfigChangeRequest",".properties");
- MutableConfiguration req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(f.toURI()));
- assertNotNull(req);
- f = File.createTempFile("ConfigChangeRequest",".xml");
- req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(f.toURI()));
- assertNotNull(req);
- }
-
- /**
- * Test invalid create change request.
- *
- * @throws Exception the exception
- */
- @Test(expected=ConfigException.class)
- public void testInvalidCreateChangeRequest() throws Exception {
- MutableConfiguration req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(new URI("foo:bar")));
- }
-
- /**
- * Test null create change request.
- *
- * @throws Exception the exception
- */
- @Test(expected=NullPointerException.class)
- public void testNullCreateChangeRequest1() throws Exception {
- MutableConfiguration req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of((URI)null));
- }
-
- /**
- * Test null create change request.
- *
- * @throws Exception the exception
- */
- @Test(expected=NullPointerException.class)
- public void testNullCreateChangeRequest2() throws Exception {
- MutableConfiguration req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of((String)null));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java
new file mode 100644
index 0000000..e873471
--- /dev/null
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/MutableConfigurationTest.java
@@ -0,0 +1,177 @@
+/*
+ * 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.ConfigurationProvider;
+import org.apache.tamaya.mutableconfig.internal.WritablePropertiesSource;
+import org.apache.tamaya.mutableconfig.internal.WritableXmlPropertiesSource;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link MutableConfiguration}.
+ */
+public class MutableConfigurationTest {
+
+ /**
+ * Test create change request.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testCreateMutableConfiguration() throws Exception {
+ File f = File.createTempFile("ConfigChangeRequest",".properties");
+ MutableConfiguration cfg1 = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration());
+ assertNotNull(cfg1);
+ assertNull(cfg1.getTransactionId());
+ assertFalse(cfg1.getAutoCommit());
+ assertEquals(2, cfg1.getMutablePropertySources().size());
+ MutableConfiguration cfg2 = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration());
+ assertNotNull(cfg2);
+ assert(cfg1!=cfg2);
+ }
+
+ /**
+ * Test null create change request.
+ *
+ * @throws Exception the exception
+ */
+ @Test(expected=NullPointerException.class)
+ public void testNullCreateMutableConfiguration() throws Exception {
+ MutableConfiguration cfg = MutableConfigurationProvider.getMutableConfiguration(
+ null);
+ }
+
+ /**
+ * Test read write properties with rollback.
+ *
+ * @throws IOException the io exception
+ */
+ @Test
+ public void testReadWriteProperties_WithCancel() throws IOException {
+ WritablePropertiesSource.target.delete();
+ MutableConfiguration mutConfig = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration()
+ );
+ mutConfig.put("key1", "value1");
+ Map<String,String> cm = new HashMap<>();
+ cm.put("key2", "value2");
+ cm.put("key3", "value3");
+ mutConfig.rollbackTransaction();
+ assertFalse(WritablePropertiesSource.target.exists());
+ }
+
+ /**
+ * Test read write properties with commit.
+ *
+ * @throws IOException the io exception
+ */
+ @Test
+ public void testReadWriteProperties_WithCommit() throws IOException {
+ WritablePropertiesSource.target.delete();
+ MutableConfiguration mutConfig = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration()
+ );
+ mutConfig.put("key1", "value1");
+ Map<String,String> cm = new HashMap<>();
+ cm.put("key2", "value2");
+ cm.put("key3", "value3");
+ mutConfig.putAll(cm);
+ mutConfig.commitTransaction();
+ assertTrue(WritablePropertiesSource.target.exists());
+ MutableConfiguration mmutConfig2 = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration()
+ );
+ mmutConfig2.remove("foo");
+ mmutConfig2.remove("key3");
+ mmutConfig2.put("key1", "value1.2");
+ mmutConfig2.put("key4", "value4");
+ mmutConfig2.commitTransaction();
+ Properties props = new Properties();
+ props.load(WritablePropertiesSource.target.toURL().openStream());
+ assertEquals(3, props.size());
+ assertEquals("value1.2", props.getProperty("key1"));
+ assertEquals("value2", props.getProperty("key2"));
+ assertEquals("value4", props.getProperty("key4"));
+ }
+
+ /**
+ * Test read write xml properties with commit.
+ *
+ * @throws IOException the io exception
+ */
+ @Test
+ public void testReadWriteXmlProperties_WithCommit() throws IOException {
+ WritableXmlPropertiesSource.target.delete();
+ MutableConfiguration cfg = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration());
+ cfg.put("key1", "value1");
+ Map<String,String> cm = new HashMap<>();
+ cm.put("key2", "value2");
+ cm.put("key3", "value3");
+ cfg.putAll(cm);
+ cfg.commitTransaction();
+ assertTrue(WritableXmlPropertiesSource.target.exists());
+ MutableConfiguration cfg2 = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration());
+ assertTrue(cfg != cfg2);
+ cfg2.remove("foo");
+ cfg2.remove("key3");
+ cfg2.put("key1", "value1.2");
+ cfg2.put("key4", "value4");
+ cfg2.commitTransaction();
+ Properties props = new Properties();
+ props.loadFromXML( WritableXmlPropertiesSource.target.toURL().openStream());
+ assertEquals(3, props.size());
+ assertEquals("value1.2", props.getProperty("key1"));
+ assertEquals("value2", props.getProperty("key2"));
+ assertEquals("value4", props.getProperty("key4"));
+ }
+
+ /**
+ * Test read write xml properties with commit.
+ *
+ * @throws IOException the io exception
+ */
+ @Test
+ public void testWriteWithNoChangePolicy() throws IOException {
+ WritableXmlPropertiesSource.target.delete();
+ MutableConfiguration cfg = MutableConfigurationProvider.getMutableConfiguration(
+ ConfigurationProvider.getConfiguration());
+ cfg.setChangePropagationPolicy(MutableConfigurationProvider.getApplyNonePolicy());
+ cfg.put("key1", "value1");
+ Map<String,String> cm = new HashMap<>();
+ cm.put("key2", "value2");
+ cm.put("key3", "value3");
+ cfg.putAll(cm);
+ cfg.commitTransaction();
+ assertFalse(WritableXmlPropertiesSource.target.exists());
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
index 9a3e130..e2c0dee 100644
--- a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendTest.java
@@ -19,11 +19,11 @@
package org.apache.tamaya.mutableconfig.internal;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.mutableconfig.MutableConfigurationQuery;
import org.apache.tamaya.mutableconfig.MutableConfiguration;
+import org.apache.tamaya.mutableconfig.MutableConfigurationProvider;
+import org.apache.tamaya.mutableconfig.propertysources.MutablePropertiesPropertySource;
import org.junit.Test;
-import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -32,94 +32,8 @@ import java.util.Properties;
import static org.junit.Assert.*;
/**
- * Tests for {@link PropertiesFileConfigBackendSpi}.
+ * Tests for {@link MutablePropertiesPropertySource}.
*/
public class PropertiesFileConfigBackendTest {
- /**
- * Test read write properties with rollback.
- *
- * @throws IOException the io exception
- */
- @Test
- public void testReadWriteProperties_WithCancel() throws IOException {
- File f = File.createTempFile("testReadWriteProperties_WithCancel",".properties");
- f.delete();
- MutableConfiguration req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(f.toURI()));
- req.put("key1", "value1");
- Map<String,String> cm = new HashMap<>();
- cm.put("key2", "value2");
- cm.put("key3", "value3");
- req.rollback();
- assertFalse(f.exists());
- }
-
- /**
- * Test read write properties with commit.
- *
- * @throws IOException the io exception
- */
- @Test
- public void testReadWriteProperties_WithCommit() throws IOException {
- File f = File.createTempFile("testReadWriteProperties_WithCommit",".properties");
- f.delete();
- MutableConfiguration req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(f.toURI()));
- req.put("key1", "value1");
- Map<String,String> cm = new HashMap<>();
- cm.put("key2", "value2");
- cm.put("key3", "value3");
- req.putAll(cm);
- req.commit();
- assertTrue(f.exists());
- MutableConfiguration req2 = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(f.toURI()));
- assertTrue(req != req2);
- req2.remove("foo");
- req2.remove("key3");
- req2.put("key1", "value1.2");
- req2.put("key4", "value4");
- req2.commit();
- Properties props = new Properties();
- props.load(f.toURL().openStream());
- assertEquals(3, props.size());
- assertEquals("value1.2", props.getProperty("key1"));
- assertEquals("value2", props.getProperty("key2"));
- assertEquals("value4", props.getProperty("key4"));
- }
-
- /**
- * Test read write xml properties with commit.
- *
- * @throws IOException the io exception
- */
- @Test
- public void testReadWriteXmlProperties_WithCommit() throws IOException {
- File f = File.createTempFile("testReadWriteProperties_WithCommit",".xml");
- f.delete();
- MutableConfiguration req = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(f.toURI()));
- req.put("key1", "value1");
- Map<String,String> cm = new HashMap<>();
- cm.put("key2", "value2");
- cm.put("key3", "value3");
- req.putAll(cm);
- req.commit();
- assertTrue(f.exists());
- MutableConfiguration req2 = ConfigurationProvider.getConfiguration().query(
- MutableConfigurationQuery.of(f.toURI()));
- assertTrue(req != req2);
- req2.remove("foo");
- req2.remove("key3");
- req2.put("key1", "value1.2");
- req2.put("key4", "value4");
- req2.commit();
- Properties props = new Properties();
- props.loadFromXML(f.toURL().openStream());
- assertEquals(3, props.size());
- assertEquals("value1.2", props.getProperty("key1"));
- assertEquals("value2", props.getProperty("key2"));
- assertEquals("value4", props.getProperty("key4"));
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java
new file mode 100644
index 0000000..5257c8b
--- /dev/null
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritablePropertiesSource.java
@@ -0,0 +1,49 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.mutableconfig.propertysources.MutablePropertiesPropertySource;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Writable test property source based on the {@link MutablePropertiesPropertySource}.
+ */
+public class WritablePropertiesSource extends MutablePropertiesPropertySource {
+
+ public static File target = createFile();
+
+ private static File createFile() {
+ try {
+ return File.createTempFile("writableProps",".properties");
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new IllegalStateException("Cannot init test.", e);
+ }
+ }
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ */
+ public WritablePropertiesSource() throws IOException {
+ super(target, 100);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java
new file mode 100644
index 0000000..d6aa7ec
--- /dev/null
+++ b/modules/mutable-config/src/test/java/org/apache/tamaya/mutableconfig/internal/WritableXmlPropertiesSource.java
@@ -0,0 +1,49 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.mutableconfig.propertysources.MutableXmlPropertiesPropertySource;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Writable test property source based on the {@link MutableXmlPropertiesPropertySource}.
+ */
+public class WritableXmlPropertiesSource extends MutableXmlPropertiesPropertySource {
+
+ public static File target = createFile();
+
+ private static File createFile() {
+ try {
+ return File.createTempFile("writableProps",".xml");
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new IllegalStateException("Cannot init test.", e);
+ }
+ }
+
+ /**
+ * Creates a new Properties based PropertySource based on the given URL.
+ */
+ public WritableXmlPropertiesSource() throws IOException {
+ super(target, 200);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..7f20084
--- /dev/null
+++ b/modules/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -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.mutableconfig.internal.WritablePropertiesSource
+org.apache.tamaya.mutableconfig.internal.WritableXmlPropertiesSource
\ No newline at end of file
[11/16] incubator-tamaya git commit: Added
Configuration.getConfiguratinContext()
Posted by an...@apache.org.
Added Configuration.getConfiguratinContext()
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7b6148c5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7b6148c5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7b6148c5
Branch: refs/heads/master
Commit: 7b6148c5ad94f30570f1311c3da44f6d53011850
Parents: 18fcd12
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:35:54 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:35:54 2016 +0100
----------------------------------------------------------------------
.../apache/tamaya/core/internal/DefaultConfiguration.java | 5 +++++
.../tamaya/core/internal/DefaultConfigurationProvider.java | 8 --------
2 files changed, 5 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7b6148c5/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index ee8abcd..1c76d8c 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -204,6 +204,11 @@ public class DefaultConfiguration implements Configuration {
return query.query(this);
}
+ @Override
+ public ConfigurationContext getContext() {
+ return this.configurationContext;
+ }
+
/**
* Access the configuration's context.
* @return the configurastion context-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7b6148c5/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
index 34c3c53..4330b7e 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -45,14 +45,6 @@ public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
}
@Override
- public ConfigurationContext getConfigurationContext(Configuration config) {
- if(config instanceof DefaultConfiguration){
- return ((DefaultConfiguration)config).getConfigurationContext();
- }
- return null;
- }
-
- @Override
public ConfigurationContextBuilder getConfigurationContextBuilder() {
return ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class);
}
[04/16] incubator-tamaya git commit: Added method to access
ConfigurationContext from Configuration.
Posted by an...@apache.org.
Added method to access ConfigurationContext from Configuration.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/2abd033b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/2abd033b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/2abd033b
Branch: refs/heads/master
Commit: 2abd033bb2ee429b49cc80418a85e9f9301508e5
Parents: dc252f9
Author: anatole <an...@apache.org>
Authored: Sun Mar 13 22:26:18 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 13 22:26:18 2016 +0100
----------------------------------------------------------------------
.../apache/tamaya/core/internal/DefaultConfiguration.java | 8 ++++++++
.../tamaya/core/internal/DefaultConfigurationProvider.java | 8 ++++++++
2 files changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2abd033b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index 9e50c87..ee8abcd 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -203,4 +203,12 @@ public class DefaultConfiguration implements Configuration {
public <T> T query(ConfigQuery<T> query) {
return query.query(this);
}
+
+ /**
+ * Access the configuration's context.
+ * @return the configurastion context-
+ */
+ public ConfigurationContext getConfigurationContext() {
+ return configurationContext;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/2abd033b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
index 4330b7e..34c3c53 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -45,6 +45,14 @@ public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
}
@Override
+ public ConfigurationContext getConfigurationContext(Configuration config) {
+ if(config instanceof DefaultConfiguration){
+ return ((DefaultConfiguration)config).getConfigurationContext();
+ }
+ return null;
+ }
+
+ @Override
public ConfigurationContextBuilder getConfigurationContextBuilder() {
return ServiceContextManager.getServiceContext().getService(ConfigurationContextBuilder.class);
}
[15/16] incubator-tamaya git commit: Resolved style issues.
Posted by an...@apache.org.
Resolved style issues.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ef995ac1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ef995ac1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ef995ac1
Branch: refs/heads/master
Commit: ef995ac1cd2bf8295ee1813afa5b48a8234c3edd
Parents: 7d6ee43
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:56:15 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:56:15 2016 +0100
----------------------------------------------------------------------
.../functions/ConfigurationFunctions.java | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ef995ac1/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
index 624d10f..3b63d8d 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -22,10 +22,22 @@ import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.*;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
import java.net.Inet4Address;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -640,6 +652,8 @@ public final class ConfigurationFunctions {
* Accesses an empty {@link ConfigurationContext}.
* @return an empty {@link ConfigurationContext}, never null.
*/
- public static ConfigurationContext emptyConfigurationContext(){ return EMPTY_CONFIGURATION_CONTEXT; }
+ public static ConfigurationContext emptyConfigurationContext(){
+ return EMPTY_CONFIGURATION_CONTEXT;
+ }
}
[12/16] incubator-tamaya git commit: Added
Configuration.getConfigurationContext(), added EMPTY for config and context.
Posted by an...@apache.org.
Added Configuration.getConfigurationContext(), added EMPTY for config and context.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d59dd828
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d59dd828
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d59dd828
Branch: refs/heads/master
Commit: d59dd8282cf14128da912974ee56ba37befbdb03
Parents: 7b6148c
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:37:43 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:37:43 2016 +0100
----------------------------------------------------------------------
.../tamaya/functions/CombinedConfiguration.java | 7 ++
.../functions/ConfigurationFunctions.java | 72 +++++++++++++++++---
.../tamaya/functions/EnrichedConfiguration.java | 6 ++
.../tamaya/functions/FilteredConfiguration.java | 6 ++
.../tamaya/functions/MappedConfiguration.java | 6 ++
5 files changed, 87 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d59dd828/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java b/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java
index 543bd1b..8a479e9 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/CombinedConfiguration.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
import java.util.Arrays;
import java.util.HashMap;
@@ -130,6 +131,12 @@ class CombinedConfiguration implements Configuration{
}
@Override
+ public ConfigurationContext getContext() {
+ // TODO thjink on combining the participating contexts...
+ return configurations[0].getContext();
+ }
+
+ @Override
public String toString() {
return "CombinedConfiguration{" +
"name='" + name + '\'' +
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d59dd828/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
index eee3b02..624d10f 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -22,16 +22,10 @@ import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.*;
import java.net.Inet4Address;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
+import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -96,11 +90,63 @@ public final class ConfigurationFunctions {
}
@Override
+ public ConfigurationContext getContext() {
+ return EMPTY_CONFIGURATION_CONTEXT;
+ }
+
+ @Override
public String toString(){
return "Configuration<empty>";
}
};
+ private static final ConfigurationContext EMPTY_CONFIGURATION_CONTEXT = new ConfigurationContext() {
+ @Override
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ // ignore
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ // ignore
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() {
+ return PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ throw new UnsupportedOperationException("Cannot build from ConfigurationContext.EMPTY.");
+ }
+
+ @Override
+ public String toString(){
+ return "ConfigurationContext.EMPTY";
+ }
+ };
+
/**
* Private singleton constructor.
*/
@@ -583,11 +629,17 @@ public final class ConfigurationFunctions {
}
/**
- * Accesses an empty PropertySource.
- * @return an empty PropertySource, never null.
+ * Accesses an empty {@link Configuration}.
+ * @return an empty {@link Configuration}, never null.
*/
public static Configuration emptyConfiguration(){
return EMPTY_CONFIGURATION;
}
+ /**
+ * Accesses an empty {@link ConfigurationContext}.
+ * @return an empty {@link ConfigurationContext}, never null.
+ */
+ public static ConfigurationContext emptyConfigurationContext(){ return EMPTY_CONFIGURATION_CONTEXT; }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d59dd828/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedConfiguration.java b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedConfiguration.java
index 93eae3a..7969563 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedConfiguration.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedConfiguration.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
import java.util.HashMap;
import java.util.Map;
@@ -150,4 +151,9 @@ class EnrichedConfiguration implements Configuration {
return query.query(this);
}
+ @Override
+ public ConfigurationContext getContext() {
+ return baseConfiguration.getContext();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d59dd828/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
index 2d23450..e8acaaa 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredConfiguration.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
import java.util.HashMap;
import java.util.Map;
@@ -110,6 +111,11 @@ class FilteredConfiguration implements Configuration {
}
@Override
+ public ConfigurationContext getContext() {
+ return baseConfiguration.getContext();
+ }
+
+ @Override
public String toString() {
return "FilteredConfiguration{" +
"baseConfiguration=" + baseConfiguration +
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d59dd828/modules/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java b/modules/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
index 1170023..b93b9ca 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/MappedConfiguration.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
import java.util.HashMap;
import java.util.Map;
@@ -116,6 +117,11 @@ class MappedConfiguration implements Configuration {
}
@Override
+ public ConfigurationContext getContext() {
+ return baseConfiguration.getContext();
+ }
+
+ @Override
public String toString() {
return "FilteredConfiguration{" +
"baseConfiguration=" + baseConfiguration +
[14/16] incubator-tamaya git commit: Added dep to functions module
for EMPTY instances.
Posted by an...@apache.org.
Added dep to functions module for EMPTY instances.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/7d6ee43c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/7d6ee43c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/7d6ee43c
Branch: refs/heads/master
Commit: 7d6ee43c61122981328caa00be3170c3141198be
Parents: 1f0420f
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:41:46 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:41:46 2016 +0100
----------------------------------------------------------------------
modules/events/pom.xml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/7d6ee43c/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index 33d8659..21269ed 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-functions</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
[05/16] incubator-tamaya git commit: Fixed consul for new mutable
config API/SPI.
Posted by an...@apache.org.
Fixed consul for new mutable config API/SPI.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/4a0e7994
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/4a0e7994
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/4a0e7994
Branch: refs/heads/master
Commit: 4a0e79949cf609afa1f3db9a99490f632943ff48
Parents: 2abd033
Author: anatole <an...@apache.org>
Authored: Sun Mar 13 23:19:52 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 13 23:19:52 2016 +0100
----------------------------------------------------------------------
.../tamaya/consul/ConsulPropertySource.java | 4 +--
.../tamaya/etcd/ConsulPropertySourceTest.java | 4 +--
.../org/apache/tamaya/etcd/ConsulWriteTest.java | 33 +++++++++-----------
3 files changed, 19 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4a0e7994/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
index cdf3c81..b4227a8 100644
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
@@ -61,10 +61,10 @@ public class ConsulPropertySource extends AbstractMutablePropertySource {
/**
* Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
- * @return the default ordinal used, by default 0.
+ * @return the default ordinal used, by default 1000.
*/
public int getDefaultOrdinal(){
- return 100;
+ return 1000;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4a0e7994/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
index 8946a3c..415fb38 100644
--- a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
+++ b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulPropertySourceTest.java
@@ -41,12 +41,12 @@ public class ConsulPropertySourceTest {
@Test
public void testGetOrdinal() throws Exception {
- assertEquals(propertySource.getOrdinal(), 100);
+ assertEquals(propertySource.getOrdinal(), 1000);
}
@Test
public void testGetDefaultOrdinal() throws Exception {
- assertEquals(propertySource.getDefaultOrdinal(), 100);
+ assertEquals(propertySource.getDefaultOrdinal(), 1000);
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/4a0e7994/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
index c728641..466c738 100644
--- a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
+++ b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
@@ -20,12 +20,9 @@ package org.apache.tamaya.etcd;
import com.google.common.net.HostAndPort;
import org.apache.tamaya.consul.ConsulPropertySource;
-import org.apache.tamaya.consul.internal.MutableConfigSupport;
-import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
import org.junit.BeforeClass;
import java.net.MalformedURLException;
-import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.UUID;
@@ -33,47 +30,47 @@ import java.util.UUID;
import static org.junit.Assert.*;
/**
- * Tests for th etcd backend integration. You must have set a system property so, theses tests are executed, e.g.
- * {@code -Detcd.url=http://127.0.0.1:4001}.
+ * Tests for th consul backend integration for writing to the consul backend.
*/
public class ConsulWriteTest {
private static HostAndPort accessor;
static boolean execute = false;
- private static ConsulPropertySource readingSource;
- private static MutablePropertySource writer;
+ private static ConsulPropertySource propertySource;
@BeforeClass
public static void setup() throws MalformedURLException, URISyntaxException {
System.setProperty("consul.urls", "http://127.0.0.1:8300");
accessor = HostAndPort.fromString("127.0.0.1:8500");
- readingSource = new ConsulPropertySource();
- writer = new MutableConfigSupport().getBackend(new URI("config:consul"));
+ propertySource = new ConsulPropertySource();
}
@org.junit.Test
public void testSetNormal() throws Exception {
if (!execute) return;
- String value = UUID.randomUUID().toString();
- writer.put("testSetNormal", value);
+ UUID taID = UUID.randomUUID();
+ propertySource.put(taID, "testSetNormal", taID.toString());
+ propertySource.commitTransaction(taID);
}
@org.junit.Test
public void testDelete() throws Exception {
if(!execute)return;
- String value = UUID.randomUUID().toString();
- writer.put("testDelete", value);
- assertEquals(readingSource.get("testDelete").get("testDelete"), value);
- assertNotNull(readingSource.get("_testDelete.createdIndex"));
- writer.remove("testDelete");
- assertNull(readingSource.get("testDelete").get("testDelete"));
+ UUID taID = UUID.randomUUID();
+ propertySource.put(taID, "testDelete", taID.toString());
+ propertySource.commitTransaction(taID);
+ assertEquals(propertySource.get("testDelete").getValue(), taID.toString());
+ assertNotNull(propertySource.get("_testDelete.createdIndex"));
+ propertySource.remove(taID, "testDelete");
+ propertySource.commitTransaction(taID);
+ assertNull(propertySource.get("testDelete"));
}
@org.junit.Test
public void testGetProperties() throws Exception {
if(!execute)return;
- Map<String,String> result = readingSource.getProperties();
+ Map<String,String> result = propertySource.getProperties();
assertTrue(result.isEmpty());
}
}
\ No newline at end of file
[03/16] incubator-tamaya git commit: Adapted to new simplified API
for mutable configurations.
Posted by an...@apache.org.
Adapted to new simplified API for mutable configurations.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/dc252f96
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/dc252f96
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/dc252f96
Branch: refs/heads/master
Commit: dc252f96144b666f08bb7f1f2da386b587c290a3
Parents: 8e9a3cc
Author: anatole <an...@apache.org>
Authored: Sun Mar 13 22:23:56 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 13 22:23:56 2016 +0100
----------------------------------------------------------------------
.../tamaya/consul/ConsulPropertySource.java | 35 ++++++-
.../ConsulMutableConfigurationBackend.java | 89 ------------------
.../consul/internal/MutableConfigSupport.java | 44 ---------
...g.spi.MutableConfigurationBackendProviderSpi | 19 ----
.../org/apache/tamaya/etcd/ConsulWriteTest.java | 4 +-
.../apache/tamaya/etcd/EtcdPropertySource.java | 43 ++++++++-
.../EtcdMutableConfigurationBackend.java | 98 --------------------
.../etcd/internal/MutableConfigSupport.java | 44 ---------
...g.spi.MutableConfigurationBackendProviderSpi | 19 ----
9 files changed, 76 insertions(+), 319 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
index 65ba6cd..cdf3c81 100644
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
+++ b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/ConsulPropertySource.java
@@ -23,7 +23,8 @@ import com.google.common.net.HostAndPort;
import com.orbitz.consul.Consul;
import com.orbitz.consul.KeyValueClient;
import com.orbitz.consul.model.kv.Value;
-import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.mutableconfig.propertysources.AbstractMutablePropertySource;
+import org.apache.tamaya.mutableconfig.propertysources.TransactionContext;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.PropertyValueBuilder;
@@ -38,7 +39,7 @@ import java.util.logging.Logger;
* {@code consul.prefix} as system property maps the consul based onfiguration
* to this prefix namespace. Consul servers are configured as {@code consul.urls} system or environment property.
*/
-public class ConsulPropertySource implements PropertySource{
+public class ConsulPropertySource extends AbstractMutablePropertySource {
private static final Logger LOG = Logger.getLogger(ConsulPropertySource.class.getName());
private String prefix = System.getProperty("tamaya.consul.prefix", "");
@@ -162,4 +163,34 @@ public class ConsulPropertySource implements PropertySource{
public boolean isScannable() {
return false;
}
+
+ @Override
+ protected void commitInternal(TransactionContext context) {
+ for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
+ try{
+ Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
+ KeyValueClient kvClient = consul.keyValueClient();
+
+ for(String k: context.getRemovedProperties()){
+ try{
+ kvClient.deleteKey(k);
+ } catch(Exception e){
+ LOG.info("Failed to remove key from consul: " + k);
+ }
+ }
+ for(Map.Entry<String,String> en:context.getAddedProperties().entrySet()){
+ String key = en.getKey();
+ try{
+ kvClient.putValue(key,en.getValue());
+ }catch(Exception e) {
+ LOG.info("Failed to add key to consul: " + en.getKey() + "=" + en.getValue());
+ }
+ }
+ // success: stop here
+ break;
+ } catch(Exception e){
+ LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
deleted file mode 100644
index cf6cf9d..0000000
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/ConsulMutableConfigurationBackend.java
+++ /dev/null
@@ -1,89 +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.consul.internal;
-
-import com.google.common.net.HostAndPort;
-import com.orbitz.consul.Consul;
-import com.orbitz.consul.KeyValueClient;
-import org.apache.tamaya.consul.ConsulBackends;
-import org.apache.tamaya.consul.ConsulPropertySource;
-import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpi;
-
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Change Request implementation based on consul services.
- */
-class ConsulMutableConfigurationBackend extends AbstractMutableConfigurationBackendSpi {
-
- private static final Logger LOG = Logger.getLogger(ConsulMutableConfigurationBackend.class.getName());
-
- ConsulMutableConfigurationBackend(URI uri){
- super(uri, new ConsulPropertySource());
- }
-
- @Override
- public boolean isExisting(String keyExpression) {
- for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
- try{
- Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
- KeyValueClient kvClient = consul.keyValueClient();
- List<String> keys = kvClient.getKeys(keyExpression);
- return !keys.isEmpty();
- } catch(Exception e){
- LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
- }
- }
- return false;
- }
-
-
- @Override
- protected void commitInternal() {
- for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
- try{
- Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
- KeyValueClient kvClient = consul.keyValueClient();
-
- for(String k: getRemovedProperties()){
- try{
- kvClient.deleteKey(k);
- } catch(Exception e){
- LOG.info("Failed to remove key from consul: " + k);
- }
- }
- for(Map.Entry<String,String> en:getAddedProperties().entrySet()){
- String key = en.getKey();
- try{
- kvClient.putValue(key,en.getValue());
- }catch(Exception e) {
- LOG.info("Failed to add key to consul: " + en.getKey() + "=" + en.getValue());
- }
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "consul access failed on " + hostAndPort + ", trying next...", e);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java b/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
deleted file mode 100644
index bc0fbf4..0000000
--- a/modules/integration/consul/src/main/java/org/apache/tamaya/consul/internal/MutableConfigSupport.java
+++ /dev/null
@@ -1,44 +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.consul.internal;
-
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi;
-
-import java.net.URI;
-
-/**
- * Created by atsticks on 15.01.16.
- */
-public class MutableConfigSupport implements MutableConfigurationBackendProviderSpi {
-
- private URI backendURI;
-
- public MutableConfigSupport(){
- backendURI = URI.create("config:consul");
- }
-
- @Override
- public MutableConfigurationBackendSpi getBackend(URI uri) {
- if(backendURI.equals(uri)) {
- return new ConsulMutableConfigurationBackend(backendURI);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi b/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
deleted file mode 100644
index 9174018..0000000
--- a/modules/integration/consul/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
+++ /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.consul.internal.MutableConfigSupport
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
index 8901461..c728641 100644
--- a/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
+++ b/modules/integration/consul/src/test/java/org/apache/tamaya/etcd/ConsulWriteTest.java
@@ -21,7 +21,7 @@ package org.apache.tamaya.etcd;
import com.google.common.net.HostAndPort;
import org.apache.tamaya.consul.ConsulPropertySource;
import org.apache.tamaya.consul.internal.MutableConfigSupport;
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
+import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
import org.junit.BeforeClass;
import java.net.MalformedURLException;
@@ -41,7 +41,7 @@ public class ConsulWriteTest {
private static HostAndPort accessor;
static boolean execute = false;
private static ConsulPropertySource readingSource;
- private static MutableConfigurationBackendSpi writer;
+ private static MutablePropertySource writer;
@BeforeClass
public static void setup() throws MalformedURLException, URISyntaxException {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
index 704c79c..9434f65 100644
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
+++ b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdPropertySource.java
@@ -18,7 +18,8 @@
*/
package org.apache.tamaya.etcd;
-import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.mutableconfig.propertysources.AbstractMutablePropertySource;
+import org.apache.tamaya.mutableconfig.propertysources.TransactionContext;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.PropertyValueBuilder;
@@ -34,7 +35,7 @@ import java.util.logging.Logger;
* to this prefix namespace. Etcd servers are configured as {@code etcd.server.urls} system or environment property.
* ETcd can be disabled by setting {@code tamaya.etcdprops.disable} either as env or system property.
*/
-public class EtcdPropertySource implements PropertySource{
+public class EtcdPropertySource extends AbstractMutablePropertySource{
private static final Logger LOG = Logger.getLogger(EtcdPropertySource.class.getName());
private String prefix = System.getProperty("tamaya.etcd.prefix", "");
@@ -164,4 +165,42 @@ public class EtcdPropertySource implements PropertySource{
public boolean isScannable() {
return true;
}
+
+ @Override
+ protected void commitInternal(TransactionContext context) {
+ for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
+ try{
+ for(String k: context.getRemovedProperties()){
+ Map<String,String> res = accessor.delete(k);
+ if(res.get("_ERROR")!=null){
+ LOG.info("Failed to remove key from etcd: " + k);
+ }
+ }
+ for(Map.Entry<String,String> en:context.getAddedProperties().entrySet()){
+ String key = en.getKey();
+ Integer ttl = null;
+ int index = en.getKey().indexOf('?');
+ if(index>0){
+ key = en.getKey().substring(0, index);
+ String rawQuery = en.getKey().substring(index+1);
+ String[] queries = rawQuery.split("&");
+ for(String query:queries){
+ if(query.contains("ttl")){
+ int qIdx = query.indexOf('=');
+ ttl = qIdx>0?Integer.parseInt(query.substring(qIdx+1).trim()):null;
+ }
+ }
+ }
+ Map<String,String> res = accessor.set(key, en.getValue(), ttl);
+ if(res.get("_ERROR")!=null){
+ LOG.info("Failed to add key to etcd: " + en.getKey() + "=" + en.getValue());
+ }
+ }
+ // success, stop here
+ break;
+ } catch(Exception e){
+ LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
deleted file mode 100644
index b662d86..0000000
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/EtcdMutableConfigurationBackend.java
+++ /dev/null
@@ -1,98 +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.etcd.internal;
-
-import org.apache.tamaya.etcd.EtcdAccessor;
-import org.apache.tamaya.etcd.EtcdBackends;
-import org.apache.tamaya.etcd.EtcdPropertySource;
-import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpi;
-
-import java.net.URI;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Change Request implementation based on etcd services. Etcd also supports a ttl to set values only for a defined
- * number of seconds {@code ttl}. This is also supported by this component by adding ttl as a key parameter, e.g.
- * {@code changeRequest.set("myTimedKey?ttl=30", "myValue");} will set a key {@code myTimedKey} valid only for
- * 30 seconds.
- */
-class EtcdMutableConfigurationBackend extends AbstractMutableConfigurationBackendSpi {
-
- private static final Logger LOG = Logger.getLogger(EtcdMutableConfigurationBackend.class.getName());
-
- EtcdMutableConfigurationBackend(URI uri){
- super(uri, new EtcdPropertySource());
- }
-
- @Override
- public boolean isExisting(String keyExpression) {
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
- try{
- Map<String,String> props = accessor.get(keyExpression);
- if(!props.containsKey("_ERROR")) {
- // No repfix mapping necessary here, since we only access/return the value...
- return props.get(keyExpression)!=null;
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
- }
- }
- return false;
- }
-
-
- @Override
- protected void commitInternal() {
- for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
- try{
- for(String k: getRemovedProperties()){
- Map<String,String> res = accessor.delete(k);
- if(res.get("_ERROR")!=null){
- LOG.info("Failed to remove key from etcd: " + k);
- }
- }
- for(Map.Entry<String,String> en:getAddedProperties().entrySet()){
- String key = en.getKey();
- Integer ttl = null;
- int index = en.getKey().indexOf('?');
- if(index>0){
- key = en.getKey().substring(0, index);
- String rawQuery = en.getKey().substring(index+1);
- String[] queries = rawQuery.split("&");
- for(String query:queries){
- if(query.contains("ttl")){
- int qIdx = query.indexOf('=');
- ttl = qIdx>0?Integer.parseInt(query.substring(qIdx+1).trim()):null;
- }
- }
- }
- Map<String,String> res = accessor.set(key, en.getValue(), ttl);
- if(res.get("_ERROR")!=null){
- LOG.info("Failed to add key to etcd: " + en.getKey() + "=" + en.getValue());
- }
- }
- } catch(Exception e){
- LOG.log(Level.FINE, "etcd access failed on " + accessor.getUrl() + ", trying next...", e);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java
deleted file mode 100644
index ba734cd..0000000
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/internal/MutableConfigSupport.java
+++ /dev/null
@@ -1,44 +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.etcd.internal;
-
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi;
-
-import java.net.URI;
-
-/**
- * Created by atsticks on 15.01.16.
- */
-public class MutableConfigSupport implements MutableConfigurationBackendProviderSpi {
-
- private URI backendURI;
-
- public MutableConfigSupport(){
- backendURI = URI.create("config:etcd");
- }
-
- @Override
- public MutableConfigurationBackendSpi getBackend(URI uri) {
- if(backendURI.equals(uri)) {
- return new EtcdMutableConfigurationBackend(backendURI);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/dc252f96/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi b/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
deleted file mode 100644
index 2189807..0000000
--- a/modules/integration/etcd/src/main/resources/META-INF/services/org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi
+++ /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.etcd.internal.MutableConfigSupport
\ No newline at end of file
[16/16] incubator-tamaya git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-tamaya
Posted by an...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-tamaya
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/343531a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/343531a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/343531a4
Branch: refs/heads/master
Commit: 343531a498cca261467da9e576bdd0096e942a84
Parents: ef995ac 44354af
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:58:26 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:58:26 2016 +0100
----------------------------------------------------------------------
.../apache/tamaya/jodatime/PeriodConverter.java | 15 +++---
.../org.apache.tamaya.spi.PropertyConverter | 3 +-
.../org/apache/tamaya/jodatime/FullStackIT.java | 24 ++++++++-
.../tamaya/jodatime/PeriodConverterIT.java | 51 ++++++++++++++++++++
.../tamaya/jodatime/PeriodConverterTest.java | 40 ++++++++++++---
.../META-INF/javaconfiguration.properties | 1 +
6 files changed, 117 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
[10/16] incubator-tamaya git commit: Added
Configuration.getConfiguratinContext()
Posted by an...@apache.org.
Added Configuration.getConfiguratinContext()
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/18fcd12d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/18fcd12d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/18fcd12d
Branch: refs/heads/master
Commit: 18fcd12d7becf00d4420bb21ea4034d2f0febbb1
Parents: 0e3e51d
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:34:54 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:34:54 2016 +0100
----------------------------------------------------------------------
.../main/java/org/apache/tamaya/spi/ConfigurationContext.java | 2 ++
.../java/org/apache/tamaya/spi/ConfigurationProviderSpi.java | 2 ++
.../src/test/java/org/apache/tamaya/TestConfiguration.java | 7 +++++++
3 files changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/18fcd12d/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index a8416a9..d61bde7 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.spi;
import org.apache.tamaya.TypeLiteral;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -155,4 +156,5 @@ public interface ConfigurationContext {
* @return a new builder instance, never null.
*/
ConfigurationContextBuilder toBuilder();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/18fcd12d/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
index bb87372..d179d1e 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
@@ -39,7 +39,9 @@ public interface ConfigurationProviderSpi {
* Get access to the current {@link ConfigurationContext}.
*
* @return the current {@link ConfigurationContext}, never null.
+ * @deprecated Will be removed in favour of {@link Configuration#getContext()}.
*/
+ @Deprecated
ConfigurationContext getConfigurationContext();
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/18fcd12d/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index 3078714..3efdaea 100644
--- a/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -19,6 +19,8 @@
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationContext;
+
import java.util.HashMap;
import java.util.Map;
@@ -123,6 +125,11 @@ public class TestConfiguration implements Configuration{
}
@Override
+ public ConfigurationContext getContext() {
+ return null;
+ }
+
+ @Override
public Map<String, String> getProperties() {
throw new RuntimeException("Method not implemented yet.");
}
[07/16] incubator-tamaya git commit: Fixed invalid tests.
Posted by an...@apache.org.
Fixed invalid tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/3154011f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/3154011f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/3154011f
Branch: refs/heads/master
Commit: 3154011f6873a9dae5e31f43ec48cf4e12427bda
Parents: 154eb26
Author: anatole <an...@apache.org>
Authored: Sun Mar 13 23:26:29 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 13 23:26:29 2016 +0100
----------------------------------------------------------------------
.../test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3154011f/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java b/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java
index 137f832..898a963 100644
--- a/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java
+++ b/modules/integration/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java
@@ -40,12 +40,12 @@ public class EtcdPropertySourceTest {
@Test
public void testGetOrdinal() throws Exception {
- assertEquals(propertySource.getOrdinal(), 100);
+ assertEquals(propertySource.getOrdinal(), 1000);
}
@Test
public void testGetDefaultOrdinal() throws Exception {
- assertEquals(propertySource.getDefaultOrdinal(), 100);
+ assertEquals(propertySource.getDefaultOrdinal(), 1000);
}
@Test
[13/16] incubator-tamaya git commit: Added
Configuration.getConfigurationContext().
Posted by an...@apache.org.
Added Configuration.getConfigurationContext().
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/1f0420f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/1f0420f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/1f0420f5
Branch: refs/heads/master
Commit: 1f0420f5f29cc37d42c49a467359f3aa7c9d1a4d
Parents: d59dd82
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:39:53 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:39:53 2016 +0100
----------------------------------------------------------------------
.../apache/tamaya/events/FrozenConfiguration.java | 7 +++++++
.../org/apache/tamaya/events/TestConfigView.java | 6 ++++++
.../internal/DefaultMutableConfiguration.java | 17 ++++++++++-------
.../tamaya/spisupport/DefaultConfiguration.java | 5 +++++
4 files changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f0420f5/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
index b874987..304ddba 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
@@ -24,6 +24,8 @@ import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.functions.ConfigurationFunctions;
+import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
@@ -162,6 +164,11 @@ public final class FrozenConfiguration implements Configuration, Serializable {
}
@Override
+ public ConfigurationContext getContext() {
+ return ConfigurationFunctions.emptyConfigurationContext();
+ }
+
+ @Override
public boolean equals(Object o) {
if (this == o) {
return true;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f0420f5/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
index 4f2227a..8e5b397 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
@@ -24,6 +24,7 @@ import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
@@ -73,6 +74,11 @@ public class TestConfigView implements ConfigOperator{
}
@Override
+ public ConfigurationContext getContext() {
+ return config.getContext();
+ }
+
+ @Override
public String get(String key) {
return getProperties().get(key);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f0420f5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
index 83a983d..02f7193 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.mutableconfig.internal;
import org.apache.tamaya.ConfigOperator;
import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.mutableconfig.ChangePropagationPolicy;
import org.apache.tamaya.mutableconfig.MutableConfiguration;
@@ -87,8 +86,7 @@ public class DefaultMutableConfiguration implements MutableConfiguration {
@Override
public List<MutablePropertySource> getMutablePropertySources() {
List<MutablePropertySource> result = new ArrayList<>();
- ConfigurationContext context = ConfigurationProvider.getConfigurationContext(this.config);
- for(PropertySource propertySource:context.getPropertySources()) {
+ for(PropertySource propertySource:this.config.getContext().getPropertySources()) {
if(propertySource instanceof MutablePropertySource){
result.add((MutablePropertySource)propertySource);
}
@@ -309,6 +307,15 @@ public class DefaultMutableConfiguration implements MutableConfiguration {
}
@Override
+ public ConfigurationContext getContext() {
+ return config.getContext();
+ }
+
+ private Collection<PropertySource> getPropertySources() {
+ return this.config.getContext().getPropertySources();
+ }
+
+ @Override
public String toString() {
return "DefaultMutableConfiguration{" +
"config=" + config +
@@ -316,8 +323,4 @@ public class DefaultMutableConfiguration implements MutableConfiguration {
'}';
}
- private Collection<PropertySource> getPropertySources() {
- ConfigurationContext context = ConfigurationProvider.getConfigurationContext(this.config);
- return context.getPropertySources();
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f0420f5/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
index 4dbdb77..52a0d11 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
@@ -220,4 +220,9 @@ public class DefaultConfiguration implements Configuration {
public <T> T query(ConfigQuery<T> query) {
return query.query(this);
}
+
+ @Override
+ public ConfigurationContext getContext() {
+ return configurationContext;
+ }
}
[08/16] incubator-tamaya git commit: Added release plugin param and
version.
Posted by an...@apache.org.
Added release plugin param and version.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ee8be4c5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ee8be4c5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ee8be4c5
Branch: refs/heads/master
Commit: ee8be4c59307ddbdb91933d55f350d12cc3e21fb
Parents: 3154011
Author: anatole <an...@apache.org>
Authored: Sun Mar 13 23:27:09 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 13 23:27:09 2016 +0100
----------------------------------------------------------------------
pom.xml | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ee8be4c5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5dae50b..5326eac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -554,6 +554,11 @@ under the License.
</dependency>
</dependencies>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.5.3</version>
+ </plugin>
</plugins>
</pluginManagement>
[06/16] incubator-tamaya git commit: Moved TransactionContext along
the property source impls.
Posted by an...@apache.org.
Moved TransactionContext along the property source impls.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/154eb267
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/154eb267
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/154eb267
Branch: refs/heads/master
Commit: 154eb26742c54a3e79d7c6de99413747b74106ea
Parents: 4a0e799
Author: anatole <an...@apache.org>
Authored: Sun Mar 13 23:25:20 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 13 23:25:20 2016 +0100
----------------------------------------------------------------------
.../propertysources/TransactionContext.java | 150 +++++++++++++++++++
1 file changed, 150 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/154eb267/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/TransactionContext.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/TransactionContext.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/TransactionContext.java
new file mode 100644
index 0000000..2b417d9
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/TransactionContext.java
@@ -0,0 +1,150 @@
+/*
+ * 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.propertysources;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+
+/**
+ * Transactional context used for managing configuration changes within an {@link AbstractMutablePropertySource}.
+ */
+public final class TransactionContext{
+ /**
+ * The transaction id.
+ */
+ private UUID transactionId;
+ /**
+ * The starting point.
+ */
+ private long startedAt = System.currentTimeMillis();
+ /**
+ * The Properties.
+ */
+ private final Map<String,String> addedProperties = new HashMap<>();
+ /**
+ * The Removed.
+ */
+ private final Set<String> removedProperties = new HashSet<>();
+
+ /**
+ * Creates a new instance bound to the given transaction.
+ * @param transactionID the transaction ID, not null.
+ */
+ public TransactionContext(UUID transactionID){
+ this.transactionId = Objects.requireNonNull(transactionID);
+ }
+
+ /**
+ * Get the corresppnding transaction ID of this instance.
+ * @return the transaction ID, never null.
+ */
+ public UUID getTransactionID(){
+ return transactionId;
+ }
+
+ /**
+ * Timestamp in UTC millis, when this transaction (context) was created.
+ * @return the timestamp in millis.
+ */
+ public long getStartedAt(){
+ return startedAt;
+ }
+
+ /**
+ * Get an unmodifiable key/value map of properties added or updated.
+ * @return an unmodifiable key/value map of properties added or updated, never null.
+ */
+ public Map<String,String> getAddedProperties(){
+ return Collections.unmodifiableMap(addedProperties);
+ }
+
+ /**
+ * Get an unmodifiable key set of properties removed.
+ * @return an unmodifiable key set of properties removed, never null.
+ */
+ public Set<String> getRemovedProperties(){
+ return Collections.unmodifiableSet(removedProperties);
+ }
+
+ /**
+ * Adds/updates a new key/value pair.
+ * @param key the key, not null.
+ * @param value the value, not null.
+ */
+ public void put(String key, String value) {
+ this.addedProperties.put(key, value);
+ }
+
+ /**
+ * Add/updated multiple key/values.
+ * @param properties the keys and values to be added/updated, not null.
+ */
+ public void putAll(Map<String, String> properties) {
+ this.addedProperties.putAll(properties);
+ }
+
+ /**
+ * Remove all the given keys, ir present.
+ * @param keys the keys to be removed, not null.
+ */
+ public void removeAll(Collection<String> keys) {
+ this.removedProperties.addAll(keys);
+ }
+
+ /**
+ * Allows easily to check if no additions/changes an no removals are present in the current transaction.
+ * @return true, if not actions have to be committed.
+ */
+ public boolean isEmpty() {
+ return this.addedProperties.isEmpty() && this.removedProperties.isEmpty();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof TransactionContext)) return false;
+
+ TransactionContext that = (TransactionContext) o;
+
+ return transactionId.equals(that.transactionId);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return transactionId.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "TransactionContext{" +
+ "addedProperties=" + addedProperties +
+ ", transactionId=" + transactionId +
+ ", startedAt=" + startedAt +
+ ", removedProperties=" + removedProperties +
+ '}';
+ }
+
+}
\ No newline at end of file
[09/16] incubator-tamaya git commit: Added
Configuration.getConfiguratinContext()
Posted by an...@apache.org.
Added Configuration.getConfiguratinContext()
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/0e3e51d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/0e3e51d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/0e3e51d8
Branch: refs/heads/master
Commit: 0e3e51d8e665614e1299d2c61abbd42b71ae0f7b
Parents: ee8be4c
Author: anatole <an...@apache.org>
Authored: Mon Mar 14 00:34:09 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 14 00:34:09 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 63 +++-----------------
.../apache/tamaya/ConfigurationProvider.java | 2 +
2 files changed, 10 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0e3e51d8/code/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index d5abfc5..0af0cf4 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -18,6 +18,8 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationContext;
+
import java.util.Collections;
import java.util.Map;
@@ -47,61 +49,6 @@ import java.util.Map;
public interface Configuration {
/**
- * Empty instance usable, where a configuration is required but no one is avilable.
- */
- Configuration EMPTY = new Configuration(){
- @Override
- public String get(String key) {
- return null;
- }
-
- @Override
- public String getOrDefault(String key, String defaultValue) {
- return defaultValue;
- }
-
- @Override
- public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
- return defaultValue;
- }
-
- @Override
- public <T> T get(String key, Class<T> type) {
- return null;
- }
-
- @Override
- public <T> T get(String key, TypeLiteral<T> type) {
- return null;
- }
-
- @Override
- public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
- return defaultValue;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public Configuration with(ConfigOperator operator) {
- return operator.operate(this);
- }
-
- @Override
- public <T> T query(ConfigQuery<T> query) {
- return query.query(this);
- }
-
- @Override
- public String toString(){
- return "Configuration.EMPTY";
- }
- };
-
- /**
* Access a property.
*
* @param key the property's key, not null.
@@ -203,4 +150,10 @@ public interface Configuration {
*/
<T> T query(ConfigQuery<T> query);
+ /**
+ * Access a configurationŝ context.
+ * @return the configuration context, never null.
+ */
+ ConfigurationContext getContext();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/0e3e51d8/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
index fabe0a8..5b9c3f1 100644
--- a/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
+++ b/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -87,7 +87,9 @@ public final class ConfigurationProvider {
* Get access to the current ConfigurationContext.
*
* @return the current ConfigurationContext, never null.
+ * @deprecated Use {@link Configuration#getContext()} instead of.
*/
+ @Deprecated
public static ConfigurationContext getConfigurationContext() {
return PROVIDER_SPI.getConfigurationContext();
}
[02/16] incubator-tamaya git commit: Simplified SPI/API.
Posted by an...@apache.org.
Simplified SPI/API.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/8e9a3cc5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/8e9a3cc5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/8e9a3cc5
Branch: refs/heads/master
Commit: 8e9a3cc5c9cd0503f30574c8bb2b85c547145d27
Parents: c46ce36
Author: anatole <an...@apache.org>
Authored: Sun Mar 13 22:22:54 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 13 22:22:54 2016 +0100
----------------------------------------------------------------------
modules/mutable-config/pom.xml | 7 +-
.../mutableconfig/ChangePropagationPolicy.java | 74 ++++
.../mutableconfig/MutableConfiguration.java | 119 ++++--
.../MutableConfigurationProvider.java | 291 +++++++++++++
.../MutableConfigurationQuery.java | 403 -------------------
.../mutableconfig/ValueVisibilityPolicy.java | 42 --
.../internal/BasePropertySource.java | 101 -----
.../DefaultConfigurationBackendSpi.java | 52 ---
.../internal/DefaultMutableConfiguration.java | 323 +++++++++++++++
.../DefaultMutableConfigurationSpi.java | 36 ++
.../PropertiesFileConfigBackendSpi.java | 114 ------
.../internal/SimplePropertySource.java | 163 --------
.../XmlPropertiesFileConfigBackendSpi.java | 114 ------
.../AbstractMutablePropertySource.java | 162 ++++++++
.../MutablePropertiesPropertySource.java | 194 +++++++++
.../MutableXmlPropertiesPropertySource.java | 195 +++++++++
.../spi/AbstractMutableConfiguration.java | 106 -----
.../AbstractMutableConfigurationBackendSpi.java | 134 ------
.../MutableConfigurationBackendProviderSpi.java | 37 --
.../spi/MutableConfigurationBackendSpi.java | 147 -------
.../spi/MutableConfigurationProviderSpi.java | 38 ++
.../spi/MutablePropertySource.java | 125 ++++++
...g.spi.MutableConfigurationBackendProviderSpi | 19 -
...leconfig.spi.MutableConfigurationProviderSpi | 19 +
.../MutableConfigurationQueryTest.java | 84 ----
.../mutableconfig/MutableConfigurationTest.java | 177 ++++++++
.../PropertiesFileConfigBackendTest.java | 92 +----
.../internal/WritablePropertiesSource.java | 49 +++
.../internal/WritableXmlPropertiesSource.java | 49 +++
.../org.apache.tamaya.spi.PropertySource | 20 +
30 files changed, 1857 insertions(+), 1629 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/pom.xml
----------------------------------------------------------------------
diff --git a/modules/mutable-config/pom.xml b/modules/mutable-config/pom.xml
index 8223a3a..38cabbc 100644
--- a/modules/mutable-config/pom.xml
+++ b/modules/mutable-config/pom.xml
@@ -46,9 +46,14 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
- <artifactId>tamaya-events</artifactId>
+ <artifactId>tamaya-spisupport</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</groupId>
<artifactId>tamaya-core</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java
new file mode 100644
index 0000000..0986c08
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java
@@ -0,0 +1,74 @@
+/*
+ * 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.spi.PropertySource;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Policy that defines how changes are applied to the available
+ * {@link org.apache.tamaya.mutableconfig.spi.MutablePropertySource} instances, e.g.
+ * <ul>
+ * <li><b>ALL: </b>Changes are propagated to all {@link org.apache.tamaya.mutableconfig.spi.MutablePropertySource}
+ * instances in order of significance. This means that a key added, updated or removed in each instance, if the key
+ * is writable/removable.</li>
+ * <li><b>SIGNIFICANT_ONLY: </b>A change (creation, update) is only applied, if
+ * <ol>
+ * <li>the value is not provided by a more significant read-only property source.</li>
+ * <li>there is no more significant writable property source, which supports writing a g iven key.</li>
+ * </ol>
+ * In other words a added or updated value is written exactly once to the most significant
+ * writable property source, which accepts a given key. Otherwise the change is discarded.</li>
+ * <li><b>NONE: </b>Do not apply any changes.</li>
+ * </ul>
+ */
+public interface ChangePropagationPolicy {
+
+ /**
+ * Method being called when a multiple key/value pairs are added or updated.
+ * @param propertySources the property sources, including readable property sources of the current configuration,
+ * never null.
+ * @param transactionID the transaction ID, not null.
+ * @param changes the key/values being added or updated, not null.
+ */
+ void applyChanges(Collection<PropertySource> propertySources, UUID transactionID, Map<String,String> changes);
+
+ /**
+ * Method being called when a single key/value pair has been added or updated.
+ * @param propertySources the property sources, including readable property sources of the current configuration,
+ * never null.
+ * @param transactionID the transaction ID, not null.
+ * @param key the key, not null.
+ * @param value the value, not null.
+ */
+ void applyChange(Collection<PropertySource> propertySources, UUID transactionID, String key, String value);
+
+ /**
+ * Method being called when a multiple keys has been removed from the configuration.
+ * @param propertySources the property sources, including readable property sources of the current configuration,
+ * never null.
+ * @param transactionID the transaction ID, not null.
+ * @param keys the keys being removed, not null.
+ */
+ void applyRemove(Collection<PropertySource> propertySources, UUID transactionID, String... keys);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
index 4ad3d70..4108928 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java
@@ -19,32 +19,96 @@
package org.apache.tamaya.mutableconfig;
import org.apache.tamaya.Configuration;
+import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
-import java.net.URI;
import java.util.Collection;
+import java.util.List;
import java.util.Map;
+import java.util.UUID;
/**
* 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.
+ * property sources to persist/control any changes applied. The exact management and storage persistence algorithm
+ * should be transparent.
*
- * As a consequence clients should first check, using the corresponding methods, if entries are to edited or
- * removedProperties
- * actually are eligible for change/creation or removal.
+ * As a consequence clients should first check, using the corresponding methods, if entries can be added/updated or
+ * removed.
+ *
+ * This class should only used in a single threaded context, though all methods inherited from {@link Configuration}
+ * must be thread-safe. Methods handling configuration changes are expected to be used in a single threaded environment
+ * only. For multi-threaded us create a new instance of {@link MutableConfiguration} for each thread.
*/
public interface MutableConfiguration extends Configuration {
/**
+ * Starts a new transaction, if necessary, and returns the transaction id. New transaction are, similar to Java EE,
+ * bound to the current thread. As a consequences all properties added , updated or removed must be managed by
+ * a corresponding context, isolated by thread. The {@link MutablePropertySource} get the right transaction id
+ * passed, when writing (committing) any changes applied.
+ * @return the transaction id, not null.
+ */
+ UUID startTransaction();
+
+ /**
+ * Commits the request. After a commit the change is not editable anymore. All changes applied will be written to
+ * the corresponding configuration backend.
+ *
+ * NOTE that changes applied must not necessarily be visible in the current {@link Configuration} instance,
+ * since visibility of changes also depends on the ordinals set on the {@link org.apache.tamaya.spi.PropertySource}s
+ * configured.
+ * @throws org.apache.tamaya.ConfigException if the request already has been committed or cancelled, or the commit fails.
+ */
+ void commitTransaction();
+
+ /**
+ * Rollback any changes leaving everything unchanged. This will rollback all changes applied since the last commit.
+ */
+ void rollbackTransaction();
+
+ /**
+ * Get the current transaction id.
+ * @return the current transaction id, or null, if no transaction is active.
+ */
+ UUID getTransactionId();
+
+ /**
+ * Get the current autoCommit policy. AutoCommit will commit the transaction after each change applied.
+ * @return the current autoCommit policy, by default false.
+ */
+ boolean getAutoCommit();
+
+ /**
+ * Set the {@link ChangePropagationPolicy}.
+ * @see #getChangePropagationPolicy()
+ * @param changePropagationPolicy the policy, not null.
+ */
+ void setChangePropagationPolicy(ChangePropagationPolicy changePropagationPolicy);
+
+ /**
+ * Access the active {@link ChangePropagationPolicy}.This policy controls how configuration changes are written/published
+ * to the known {@link MutablePropertySource} instances of a {@link Configuration}.
+ * @return he active {@link ChangePropagationPolicy}, never null.
+ */
+ ChangePropagationPolicy getChangePropagationPolicy();
+
+ /**
+ * Set the autoCommit policy to be used for this configuration instance.
+ * @param autoCommit the new autoCommit policy.
+ * @throws IllegalStateException when there are uncommitted changes.
+ */
+ void setAutoCommit(boolean autoCommit);
+
+
+ /**
* Identifies the configuration backend that are targeted by this instance and which are
* also responsible for writing back the changes applied.
*
- * @return the backend URI, never null.
+ * @return the property sources identified, in order of their occurrence/priority (most significant first).
*/
- URI getBackendURI();
+ List<MutablePropertySource> getMutablePropertySources();
/**
* Checks if a configuration key is writable (or it can be added).
@@ -56,6 +120,14 @@ public interface MutableConfiguration extends Configuration {
boolean isWritable(String keyExpression);
/**
+ * Identifies the configuration backends that supports writing the given key(s).
+ * @param keyExpression the key to be checked for write access (including creation), not null. Here this could also
+ * be a regular expression, such "as a.b.c.*".
+ * @return @return the property sources identified, in order of their occurrence/priority (most significant first).
+ */
+ List<MutablePropertySource> getPropertySourcesThatCanWrite(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 removedProperties.
*
@@ -67,6 +139,14 @@ public interface MutableConfiguration extends Configuration {
boolean isRemovable(String keyExpression);
/**
+ * Identifies the configuration backend that know the given key(s) and support removing it/them.
+ * @param keyExpression the key to be checked for write access (including creation), not null. Here this could also
+ * be a regular expression, such "as a.b.c.*".
+ * @return @return the property sources identified, in order of their occurrence/priority (most significant first).
+ */
+ List<MutablePropertySource> getPropertySourcesThatCanRemove(String keyExpression);
+
+ /**
* Checks if any keys of the given type already exist in the write backend. <b>NOTE:</b> there may be backends that
* are not able to support lookups with regular expressions. In most such cases you should pass the keys to
* lookup explicitly.
@@ -78,6 +158,14 @@ public interface MutableConfiguration extends Configuration {
boolean isExisting(String keyExpression);
/**
+ * Identifies the configuration backend that know the given key(s).
+ * @param keyExpression the key to be checked for write access (including creation), not null. Here this could also
+ * be a regular expression, such "as a.b.c.*".
+ * @return @return the property sources identified, in order of their occurrence/priority (most significant first).
+ */
+ List<MutablePropertySource> getPropertySourcesThatKnow(String keyExpression);
+
+ /**
* Sets a property.
*
* @param key the property's key, not null.
@@ -133,20 +221,5 @@ public interface MutableConfiguration extends Configuration {
*/
MutableConfiguration remove(String... keys);
- /**
- * Commits the request. After a commit the change is not editable anymore. All changes applied will be written to
- * the corresponding configuration backend.
- *
- * NOTE that changes applied must not necessarily be visible in the current {@link Configuration} instance,
- * since visibility of changes also depends on the ordinals set on the {@link org.apache.tamaya.spi.PropertySource}s
- * configured.
- * @throws org.apache.tamaya.ConfigException if the request already has been committed or cancelled, or the commit fails.
- */
- void commit();
-
- /**
- * Rollback any changes leaving everything unchanged. This will rollback all changes applied since the last commit.
- */
- void rollback();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java
new file mode 100644
index 0000000..56c0e2a
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java
@@ -0,0 +1,291 @@
+/*
+ * 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 org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi;
+import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContextManager;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.logging.Logger;
+
+
+/**
+ * Accessor for creating {@link MutableConfiguration} instances to change configuration and commit changes.
+ */
+public final class MutableConfigurationProvider {
+
+ private static final Logger LOG = Logger.getLogger(MutableConfigurationProvider.class.getName());
+ /**
+ * URIs used by this query instance to identify the backends to use for write operations.
+ */
+ private static final MutableConfigurationProviderSpi mutableConfigurationProviderSpi = loadSpi();
+
+ /**
+ * SPI loader method.
+ * @throws ConfigException if loading fails.
+ * @return the SPI, never null.
+ */
+ private static MutableConfigurationProviderSpi loadSpi() {
+ try{
+ return ServiceContextManager.getServiceContext().getService(
+ MutableConfigurationProviderSpi.class) ; }
+ catch(Exception e){
+ throw new ConfigException("Failed to initialize MutableConfigurationProviderSpi - " +
+ "mutable configuration support.");
+ }
+ }
+
+
+ /** Singleton constructor. */
+ private MutableConfigurationProvider(){}
+
+ /**
+ * Creates a new {@link MutableConfiguration} for the given configuration, using all
+ * {@link MutablePropertySource} instances found in its context and {@code autoCommit = true}.
+ *
+ * @param configuration the configuration to use to write the changes/config.
+ * @return a new MutableConfiguration instance
+ */
+ public static MutableConfiguration getMutableConfiguration(Configuration configuration){
+ return mutableConfigurationProviderSpi.createMutableConfiguration(configuration);
+ }
+
+ /**
+ * This propagation policy writes through all changes to all mutable property sources, where applicable.
+ * This is also the default policy.
+ */
+ public static ChangePropagationPolicy getApplyAllChangePolicy(){
+ return ALL_POLICY;
+ }
+
+ /**
+ * This propagation policy writes changes only once to the most significant property source, where a change is
+ * applicable.
+ */
+ public static ChangePropagationPolicy getApplyMostSignificantOnlyChangePolicy(){
+ return MOST_SIGNIFICANT_ONLY_POLICY;
+ }
+
+ /**
+ * This propagation policy writes changes only once to the most significant property source, where a change is
+ * applicable.
+ * @param propertySourceNames the names of the mutable property sources to be considered for writing any changes to.
+ */
+ public static ChangePropagationPolicy getApplySelectiveChangePolicy(String... propertySourceNames){
+ return new SelectiveChangeApplyPolicy(propertySourceNames);
+ }
+
+ /**
+ * This propagation policy writes changes only once to the most significant property source, where a change is
+ * applicable.
+ */
+ public static ChangePropagationPolicy getApplyNonePolicy(){
+ return NONE_POLICY;
+ }
+
+ /**
+ * This propagation policy writes through all changes to all mutable property sources, where applicable.
+ */
+ private static final ChangePropagationPolicy ALL_POLICY = new ChangePropagationPolicy() {
+ @Override
+ public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID,
+ Map<String, String> changes) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ MutablePropertySource target = (MutablePropertySource)propertySource;
+ for(Map.Entry<String,String> en:changes.entrySet()) {
+ if (target.isWritable(en.getKey())) {
+ target.put(transactionID, en.getKey(), en.getValue());
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void applyChange(Collection<PropertySource> propertySources, UUID transactionID,
+ String key, String value) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ MutablePropertySource target = (MutablePropertySource)propertySource;
+ if (target.isWritable(key)) {
+ target.put(transactionID, key, value);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID,
+ String... keys) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ MutablePropertySource target = (MutablePropertySource)propertySource;
+ for(String key:keys) {
+ if (target.isRemovable(key)) {
+ target.remove(transactionID, key);
+ }
+ }
+ }
+ }
+ }
+ };
+
+ /**
+ * This propagation policy writes changes only once to the most significant property source, where a change is
+ * applicable.
+ */
+ private static final ChangePropagationPolicy MOST_SIGNIFICANT_ONLY_POLICY = new ChangePropagationPolicy() {
+ @Override
+ public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID,
+ Map<String, String> changes) {
+ changes:for(Map.Entry<String,String> en:changes.entrySet()) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ MutablePropertySource target = (MutablePropertySource)propertySource;
+ if (target.isWritable(en.getKey())) {
+ target.put(transactionID, en.getKey(), en.getValue());
+ continue changes;
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void applyChange(Collection<PropertySource> propertySources, UUID transactionID,
+ String key, String value) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ MutablePropertySource target = (MutablePropertySource)propertySource;
+ if (target.isWritable(key)) {
+ target.put(transactionID, key, value);
+ return;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID,
+ String... keys) {
+ keys:for(String key:keys) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ MutablePropertySource target = (MutablePropertySource)propertySource;
+ if (target.isRemovable(key)) {
+ target.remove(transactionID, key);
+ continue keys;
+ }
+ }
+ }
+ }
+ }
+ };
+
+ /**
+ * This propagation policy writes changes only once to the most significant property source, where a change is
+ * applicable.
+ */
+ private static final ChangePropagationPolicy NONE_POLICY = new ChangePropagationPolicy() {
+ @Override
+ public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID, Map<String, String> changes) {
+ }
+
+ @Override
+ public void applyChange(Collection<PropertySource> propertySources, UUID transactionID, String key, String value) {
+ }
+
+ @Override
+ public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID, String... keys) {
+ }
+ };
+
+ /**
+ * This propagation policy writes through all changes to all mutable property sources, where applicable.
+ */
+ private static final class SelectiveChangeApplyPolicy implements ChangePropagationPolicy {
+
+ private Set<String> propertySourceNames = new HashSet<>();
+
+ SelectiveChangeApplyPolicy(String... propertySourceNames){
+ this.propertySourceNames.addAll(Arrays.asList(propertySourceNames));
+ }
+
+ @Override
+ public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID,
+ Map<String, String> changes) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ if(this.propertySourceNames.contains(propertySource.getName())) {
+ MutablePropertySource target = (MutablePropertySource) propertySource;
+ for (Map.Entry<String, String> en : changes.entrySet()) {
+ if (target.isWritable(en.getKey())) {
+ target.put(transactionID, en.getKey(), en.getValue());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void applyChange(Collection<PropertySource> propertySources, UUID transactionID,
+ String key, String value) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ if(this.propertySourceNames.contains(propertySource.getName())) {
+ MutablePropertySource target = (MutablePropertySource) propertySource;
+ if (target.isWritable(key)) {
+ target.put(transactionID, key, value);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID,
+ String... keys) {
+ for(PropertySource propertySource: propertySources){
+ if(propertySource instanceof MutablePropertySource){
+ if(this.propertySourceNames.contains(propertySource.getName())) {
+ MutablePropertySource target = (MutablePropertySource) propertySource;
+ for (String key : keys) {
+ if (target.isRemovable(key)) {
+ target.remove(transactionID, key);
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java
deleted file mode 100644
index fc7f6cc..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationQuery.java
+++ /dev/null
@@ -1,403 +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.mutableconfig;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.ConfigQuery;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfiguration;
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-
-/**
- * Accessor for creating {@link MutableConfiguration} instances to change configuration and commit changes.
- */
-public final class MutableConfigurationQuery implements ConfigQuery<MutableConfiguration> {
-
- /**
- * URIs used by this query instance to identify the backends to use for write operations.
- */
- private final MutableConfigurationBackendSpi target;
-
- private ValueVisibilityPolicy valueVisibilityPolicy;
-
- /** Singleton constructor. */
- private MutableConfigurationQuery(MutableConfigurationBackendSpi target, ValueVisibilityPolicy valueVisibilityPolicy){
- this.target = Objects.requireNonNull(target);
- this.valueVisibilityPolicy = valueVisibilityPolicy;
- }
-
- @Override
- public MutableConfiguration query(Configuration config) {
- return new DefaultMutableConfiguration(target, valueVisibilityPolicy, config);
- }
-
- /**
- * Creates a new {@link MutableConfigurationQuery} for the given configuration target.
- *
- * @param configurationTarget the configuration targets (String to create URIs) to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfigurationQuery of(String configurationTarget){
- return of(configurationTarget, ValueVisibilityPolicy.CONFIG);
- }
-
- /**
- * Creates a new {@link MutableConfigurationQuery} for the given configuration target and visibility policy.
- *
- * @param configurationTarget the configuration targets (String to create URIs) to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @param valueVisibilityPolicy the policy that defines how values edited, added or removed are reflected in the read
- * accesses of the {@link MutableConfiguration} created.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfigurationQuery of(String configurationTarget, ValueVisibilityPolicy valueVisibilityPolicy){
- try {
- URI uri = new URI(configurationTarget);
- return of(uri, valueVisibilityPolicy);
- } catch(URISyntaxException e){
- throw new ConfigException("Invalid URI " + configurationTarget);
- }
- }
-
- /**
- * Creates a new {@link MutableConfigurationQuery} for the given configuration target.
- *
- * @param configurationTarget the configuration targets to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfigurationQuery of(URI configurationTarget){
- return of(configurationTarget, ValueVisibilityPolicy.CONFIG);
- }
- /**
- * Creates a new {@link MutableConfigurationQuery} for the given configuration target and visibility policy.
- *
- * @param configurationTarget the configuration targets to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @param valueVisibilityPolicy the policy that defines how values edited, added or removed are reflected in the read
- * accesses of the {@link MutableConfiguration} created.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfigurationQuery of(URI configurationTarget, ValueVisibilityPolicy valueVisibilityPolicy){
- MutableConfigurationBackendSpi target = null;
- for(MutableConfigurationBackendProviderSpi spi:ServiceContextManager.getServiceContext()
- .getServices(MutableConfigurationBackendProviderSpi.class)){
- MutableConfigurationBackendSpi req = spi.getBackend(Objects.requireNonNull(configurationTarget));
- if (req != null) {
- target = req;
- break;
- }
- }
- if(target==null) {
- throw new ConfigException("Not an editable configuration target: " +
- configurationTarget);
- }
- return new MutableConfigurationQuery(target, Objects.requireNonNull(valueVisibilityPolicy));
- }
-
-
-
- /**
- * Creates a new {@link MutableConfiguration} for the given configuration target.
- *
- * @param configurationTarget the configuration targets (String to create URIs) to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfiguration createMutableConfiguration(String configurationTarget){
- return createMutableConfiguration(configurationTarget, ValueVisibilityPolicy.CONFIG);
- }
-
- /**
- * Creates a new {@link MutableConfiguration} for the given configuration target and visibility policy.
- *
- * @param configurationTarget the configuration targets (String to create URIs) to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @param valueVisibilityPolicy the policy that defines how values edited, added or removed are reflected in the read
- * accesses of the {@link MutableConfiguration} created.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfiguration createMutableConfiguration(String configurationTarget,
- ValueVisibilityPolicy valueVisibilityPolicy){
- try {
- URI uri = new URI(configurationTarget);
- return createMutableConfiguration(uri, valueVisibilityPolicy);
- } catch(URISyntaxException e){
- throw new ConfigException("Invalid URI " + configurationTarget);
- }
- }
-
- /**
- * Creates a new {@link MutableConfiguration} for the given configuration target.
- *
- * @param configurationTarget the configuration targets to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfiguration createMutableConfiguration(URI configurationTarget){
- return createMutableConfiguration(configurationTarget, ValueVisibilityPolicy.CONFIG);
- }
- /**
- * Creates a new {@link MutableConfiguration} for the given configuration target and visibility policy.
- *
- * @param configurationTarget the configuration targets to use to write the changes/config. By passing multiple
- * URIs you can write back changes into multiple configuration backends, e.g.
- * one for redistributing changes using multicast mechanism, a local property file
- * for failover as well as the shared etcd server.
- * @param valueVisibilityPolicy the policy that defines how values edited, added or removed are reflected in the read
- * accesses of the {@link MutableConfiguration} created.
- * @return a new ChangeRequest
- * @throws org.apache.tamaya.ConfigException if the given configurationSource cannot be edited.
- */
- public static MutableConfiguration createMutableConfiguration(URI configurationTarget,
- ValueVisibilityPolicy valueVisibilityPolicy){
- return Configuration.EMPTY.query(of(configurationTarget, valueVisibilityPolicy));
- }
-
-
- /**
- * Compound request that contains internally multiple change requests. Changes are committed to all members.
- */
- private static final class DefaultMutableConfiguration extends AbstractMutableConfiguration
- implements MutableConfiguration {
-
- private final MutableConfigurationBackendSpi target;
- private final Configuration config;
- private ValueVisibilityPolicy valueVisibilityPolicy;
-
- DefaultMutableConfiguration(MutableConfigurationBackendSpi target, ValueVisibilityPolicy valueVisibilityPolicy, Configuration config){
- this.target = Objects.requireNonNull(target);
- this.config = Objects.requireNonNull(config);
- this.valueVisibilityPolicy = valueVisibilityPolicy;
- }
-
- @Override
- public URI getBackendURI() {
- return target.getBackendURI();
- }
-
- @Override
- public boolean isWritable(String keyExpression) {
- return target.isWritable(keyExpression);
- }
-
- @Override
- public boolean isRemovable(String keyExpression) {
- return target.isRemovable(keyExpression);
- }
-
- @Override
- public boolean isExisting(String keyExpression) {
- return target.isExisting(keyExpression);
- }
-
- @Override
- public MutableConfiguration put(String key, String value) {
- if(target.isWritable(key)){
- target.put(key, value);
- }
- return this;
- }
-
- @Override
- public MutableConfiguration putAll(Map<String, String> properties) {
- for(Map.Entry<String,String> en:properties.entrySet()) {
- if (target.isWritable(en.getKey())) {
- target.put(en.getKey(), en.getValue());
- }
- }
- return super.putAll(properties);
- }
-
- @Override
- public MutableConfiguration remove(String... keys) {
- for(String key:keys){
- if (target.isRemovable(key)) {
- target.remove(key);
- }
- }
- return super.remove(keys);
- }
-
- @Override
- public MutableConfiguration remove(Collection<String> keys) {
- for(String key:keys){
- if (target.isRemovable(key)) {
- target.remove(key);
- }
- }
- return super.remove(keys);
- }
-
- @Override
- protected void commitInternal() {
- target.commit();
- }
-
- @Override
- public String get(String key) {
- String addedOrUpdated = this.addedProperties.get(key);
- switch(valueVisibilityPolicy){
- case CHANGES:
- boolean removed = this.removedProperties.contains(key);
- if(removed){
- return null;
- }
- return addedOrUpdated!=null?addedOrUpdated:getInternal(key);
- case CONFIG:
- default:
- String val = getInternal(key);
- return val == null?addedOrUpdated:val;
- }
- }
-
- private String getInternal(String key) {
- Map<String,String> props = this.config.getProperties();
- if(props.isEmpty()){
- PropertyValue val = this.target.getBackendPropertySource().get(key);
- if(val!=null){
- return val.getValue();
- }
- }
- return this.config.get(key);
- }
-
- @Override
- public String getOrDefault(String key, String defaultValue) {
- String val = get(key);
- return val == null? defaultValue: val;
- }
-
- @Override
- public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
- return (T)getOrDefault(key, TypeLiteral.of(type), defaultValue);
- }
-
- @Override
- public <T> T get(String key, Class<T> type) {
- return getOrDefault(key, type, (T)null);
- }
-
- @Override
- public <T> T get(String key, TypeLiteral<T> type) {
- return getOrDefault(key, type, (T)null);
- }
-
- @Override
- public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
- String val = get(key);
- if(val==null) {
- return defaultValue;
- }
- for(PropertyConverter conv: ConfigurationProvider.getConfigurationContext().getPropertyConverters(type)){
- Object o = conv.convert(val, new ConversionContext.Builder(key, type).setConfiguration(config).build());
- if(o!=null){
- return (T) o;
- }
- }
- return defaultValue;
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> configProps = new HashMap<>();
- if(config.getProperties().isEmpty()) {
- configProps.putAll(target.getBackendPropertySource().getProperties());
- }else{
- configProps.putAll(config.getProperties());
- }
- switch(valueVisibilityPolicy){
- case CHANGES:
- for(String key:removedProperties){
- configProps.remove(key);
- }
- configProps.putAll(addedProperties);
- return configProps;
- case CONFIG:
- default:
- Map<String, String> props = new HashMap<>(addedProperties);
- for(String key:removedProperties){
- props.remove(key);
- }
- props.putAll(configProps);
- return props;
- }
- }
-
- @Override
- public Configuration with(ConfigOperator operator) {
- return operator.operate(this);
- }
-
- @Override
- public <T> T query(ConfigQuery<T> query) {
- if(query instanceof MutableConfigurationQuery){
- throw new ConfigException("Cannot query a mutable configuration, already is one!");
- }
- return query.query(this);
- }
-
- @Override
- public String toString() {
- return "DefaultMutableConfiguration{" +
- "config=" + config +
- ", target=" + target +
- '}';
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
deleted file mode 100644
index 841a65d..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ValueVisibilityPolicy.java
+++ /dev/null
@@ -1,42 +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.mutableconfig;
-
-/**
- * Policy that can be passed when creating a {@link MutableConfigurationQuery} to define how existing values from
- * the base configuration should be handled. The corresponding behaviour is immedeately active, it does not
- * require a {@code commit()}. Nevertheless cleaning up all changes will reverse any changes and also related
- * effects.
- */
-public enum ValueVisibilityPolicy {
-
- /**
- * Entries added are also added to the mutable configuration for read access before committed. This is also
- * the default policy used.
- */
- CONFIG,
-
- /**
- * Entries from the base configuration are hidden or overridden by the entries edited. This gives you the best
- * control on your changes applied, but probably will not match the behaviour of your default configuration,
- * since the effective ordinals of your PropertySources may determine other overriding behaviour.
- */
- CHANGES
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/BasePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/BasePropertySource.java
deleted file mode 100644
index 2fe87df..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/BasePropertySource.java
+++ /dev/null
@@ -1,101 +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.mutableconfig.internal;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
-
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Abstract {@link PropertySource} that allows to set a default ordinal that will be used, if no
- * ordinal is provided with the config.
- */
-abstract class BasePropertySource implements PropertySource{
- /** default ordinal that will be used, if no ordinal is provided with the config. */
- private final int defaultOrdinal;
-
- /**
- * Constructor.
- * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config.
- */
- protected BasePropertySource(int defaultOrdinal){
- this.defaultOrdinal = defaultOrdinal;
- }
-
- /**
- * Constructor, using a default ordinal of 0.
- */
- protected BasePropertySource(){
- this(0);
- }
-
- @Override
- public String getName() {
- return getClass().getSimpleName();
- }
-
- @Override
- public int getOrdinal() {
- PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
-
- if(configuredOrdinal!=null){
- try {
- return Integer.parseInt(configuredOrdinal.getValue());
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING,
- "Configured Ordinal is not an int number: " + configuredOrdinal.getValue(), e);
- }
- }
- return getDefaultOrdinal();
- }
-
- /**
- * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
- * @return the default ordinal used, by default 0.
- */
- public int getDefaultOrdinal(){
- return defaultOrdinal;
- }
-
- @Override
- public PropertyValue get(String key) {
- Map<String,String> properties = getProperties();
- String val = properties.get(key);
- if(val==null){
- return null;
- }
- PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName());
- String metaKeyStart = "_" + key + ".";
- for(Map.Entry<String,String> en:properties.entrySet()) {
- if(en.getKey().startsWith(metaKeyStart)){
- b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue());
- }
- }
- return b.build();
- }
-
- @Override
- public boolean isScannable(){
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultConfigurationBackendSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultConfigurationBackendSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultConfigurationBackendSpi.java
deleted file mode 100644
index cfdfe29..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultConfigurationBackendSpi.java
+++ /dev/null
@@ -1,52 +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.mutableconfig.internal;
-
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendSpi;
-import org.apache.tamaya.mutableconfig.spi.MutableConfigurationBackendProviderSpi;
-
-import java.io.File;
-import java.net.URI;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Mutable Config Request factory that tries to convert given URIs to file references, if successful, it returns
- * ConfigChangeRequests fir .properties and .xml files.
- */
-public class DefaultConfigurationBackendSpi implements MutableConfigurationBackendProviderSpi {
-
- private static final Logger LOG = Logger.getLogger(DefaultConfigurationBackendSpi.class.getName());
-
- @Override
- public MutableConfigurationBackendSpi getBackend(URI uri) {
- try{
- File f = new File(uri);
- if(f.getName().endsWith(".properties")){
- return new PropertiesFileConfigBackendSpi(f);
- }else if(f.getName().endsWith(".xml")){
- return new XmlPropertiesFileConfigBackendSpi(f);
- }
- } catch(Exception e){
- LOG.log(Level.FINEST, "URI not convertible to file, ignoring " + uri, e);
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
new file mode 100644
index 0000000..83a983d
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java
@@ -0,0 +1,323 @@
+/*
+ * 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.internal;
+
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.ConfigQuery;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.mutableconfig.ChangePropagationPolicy;
+import org.apache.tamaya.mutableconfig.MutableConfiguration;
+import org.apache.tamaya.mutableconfig.MutableConfigurationProvider;
+import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.UUID;
+import java.util.logging.Logger;
+
+
+/**
+ * Default implementation of a {@link MutableConfiguration}.
+ */
+public class DefaultMutableConfiguration implements MutableConfiguration {
+ private static final Logger LOG = Logger.getLogger(DefaultMutableConfiguration.class.getName());
+ private final Configuration config;
+ private ChangePropagationPolicy changePropagationPolicy =
+ MutableConfigurationProvider.getApplyAllChangePolicy();
+ private UUID transactionId;
+ private boolean autoCommit = false;
+
+ public DefaultMutableConfiguration(Configuration config){
+ this.config = Objects.requireNonNull(config);
+ this.autoCommit = false;
+ }
+
+ @Override
+ public void setChangePropagationPolicy(ChangePropagationPolicy changePropagationPolicy){
+ this.changePropagationPolicy = Objects.requireNonNull(changePropagationPolicy);
+ }
+
+ @Override
+ public ChangePropagationPolicy getChangePropagationPolicy(){
+ return changePropagationPolicy;
+ }
+
+ @Override
+ public void setAutoCommit(boolean autoCommit) {
+ if(transactionId!=null){
+ throw new IllegalStateException("Cannot change autoCommit within a transaction, perform a " +
+ "commit or rollback first.");
+ }
+ this.autoCommit = autoCommit;
+ }
+
+ @Override
+ public UUID getTransactionId() {
+ return transactionId;
+ }
+
+ @Override
+ public boolean getAutoCommit() {
+ return autoCommit;
+ }
+
+ @Override
+ public List<MutablePropertySource> getMutablePropertySources() {
+ List<MutablePropertySource> result = new ArrayList<>();
+ ConfigurationContext context = ConfigurationProvider.getConfigurationContext(this.config);
+ for(PropertySource propertySource:context.getPropertySources()) {
+ if(propertySource instanceof MutablePropertySource){
+ result.add((MutablePropertySource)propertySource);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isWritable(String keyExpression) {
+ for(MutablePropertySource target:getMutablePropertySources()) {
+ if( target.isWritable(keyExpression)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public List<MutablePropertySource> getPropertySourcesThatCanWrite(String keyExpression) {
+ List<MutablePropertySource> result = new ArrayList<>();
+ for(MutablePropertySource propertySource:getMutablePropertySources()) {
+ if(propertySource.isWritable(keyExpression)){
+ result.add(propertySource);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isRemovable(String keyExpression) {
+ for(MutablePropertySource target:getMutablePropertySources()) {
+ if( target.isRemovable(keyExpression)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public List<MutablePropertySource> getPropertySourcesThatCanRemove(String keyExpression) {
+ List<MutablePropertySource> result = new ArrayList<>();
+ for(MutablePropertySource propertySource:getMutablePropertySources()) {
+ if(propertySource.isRemovable(keyExpression)){
+ result.add(propertySource);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isExisting(String keyExpression) {
+ for(MutablePropertySource target:getMutablePropertySources()) {
+ if(target.get(keyExpression)!=null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public List<MutablePropertySource> getPropertySourcesThatKnow(String keyExpression) {
+ List<MutablePropertySource> result = new ArrayList<>();
+ for(MutablePropertySource propertySource:getMutablePropertySources()) {
+ if(propertySource.get(keyExpression)!=null){
+ result.add(propertySource);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public MutableConfiguration put(String key, String value) {
+ UUID taID = startTransaction();
+ changePropagationPolicy.applyChange(getPropertySources(), taID, key, value);
+ if(autoCommit){
+ commitTransaction();
+ }
+ return this;
+ }
+
+ @Override
+ public MutableConfiguration putAll(Map<String, String> properties) {
+ UUID taID = startTransaction();
+ changePropagationPolicy.applyChanges(getPropertySources(), taID, properties);
+ if(autoCommit){
+ commitTransaction();
+ }
+ return this;
+ }
+
+ @Override
+ public MutableConfiguration remove(String... keys) {
+ UUID taID = startTransaction();
+ changePropagationPolicy.applyRemove(getPropertySources(), taID, keys);
+ for(String key:keys){
+ for(MutablePropertySource target:getMutablePropertySources()) {
+ if (target.isRemovable(key)) {
+ target.remove(taID, key);
+ }
+ }
+ }
+ if(autoCommit){
+ commitTransaction();
+ }
+ return this;
+ }
+
+ @Override
+ public UUID startTransaction() {
+ UUID taID = transactionId;
+ if(taID!=null){
+ return taID;
+ }
+ taID = UUID.randomUUID();
+ transactionId = taID;
+ try {
+ for (MutablePropertySource target : getMutablePropertySources()) {
+ target.startTransaction(taID);
+ }
+ }catch(Exception e){
+ rollbackTransaction();
+ }
+ return taID;
+ }
+
+ @Override
+ public void commitTransaction() {
+ UUID taID = transactionId;
+ if(taID==null){
+ LOG.warning("No active transaction on this thread, ignoring commit.");
+ return;
+ }
+ try {
+ for (MutablePropertySource target : getMutablePropertySources()) {
+ target.commitTransaction(taID);
+ }
+ this.transactionId = null;
+ }catch(Exception e){
+ rollbackTransaction();
+ }
+ }
+
+ @Override
+ public void rollbackTransaction() {
+ UUID taID = transactionId;
+ if(taID==null){
+ LOG.warning("No active transaction on this thread, ignoring rollback.");
+ return;
+ }
+ try {
+ for (MutablePropertySource target : getMutablePropertySources()) {
+ target.rollbackTransaction(taID);
+ }
+ }finally{
+ this.transactionId = null;
+ }
+ }
+
+ @Override
+ public MutableConfiguration remove(Collection<String> keys) {
+ UUID taID = startTransaction();
+ for(String key:keys){
+ for(MutablePropertySource target:getMutablePropertySources()) {
+ if (target.isRemovable(key)) {
+ target.remove(taID, key);
+ }
+ }
+ }
+ if(autoCommit){
+ commitTransaction();
+ }
+ return this;
+ }
+
+ @Override
+ public String get(String key) {
+ return this.config.get(key);
+ }
+
+ @Override
+ public String getOrDefault(String key, String defaultValue) {
+ return this.config.getOrDefault(key, defaultValue);
+ }
+
+ @Override
+ public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
+ return this.config.getOrDefault(key, type, defaultValue);
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> type) {
+ return this.config.get(key, type);
+ }
+
+ @Override
+ public <T> T get(String key, TypeLiteral<T> type) {
+ return this.config.get(key, type);
+ }
+
+ @Override
+ public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
+ return this.config.getOrDefault(key, type, defaultValue);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return this.config.getProperties();
+ }
+
+ @Override
+ public Configuration with(ConfigOperator operator) {
+ return operator.operate(this);
+ }
+
+ @Override
+ public <T> T query(ConfigQuery<T> query) {
+ return query.query(this);
+ }
+
+ @Override
+ public String toString() {
+ return "DefaultMutableConfiguration{" +
+ "config=" + config +
+ ", autoCommit=" + autoCommit +
+ '}';
+ }
+
+ private Collection<PropertySource> getPropertySources() {
+ ConfigurationContext context = ConfigurationProvider.getConfigurationContext(this.config);
+ return context.getPropertySources();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.java
new file mode 100644
index 0000000..178e21f
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfigurationSpi.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.mutableconfig.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.mutableconfig.MutableConfiguration;
+import org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi;
+
+
+/**
+ * SPI implementation that creates instances of {@link DefaultMutableConfiguration}, hereby for
+ * each instance of {@link Configuration} a new instance has to be returned.
+ */
+public class DefaultMutableConfigurationSpi implements MutableConfigurationProviderSpi{
+
+ @Override
+ public MutableConfiguration createMutableConfiguration(Configuration configuration) {
+ return new DefaultMutableConfiguration(configuration);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendSpi.java
deleted file mode 100644
index 39bd0cf..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/PropertiesFileConfigBackendSpi.java
+++ /dev/null
@@ -1,114 +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.mutableconfig.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpi;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Change Request implementation based on .properties file.
- */
-class PropertiesFileConfigBackendSpi extends AbstractMutableConfigurationBackendSpi {
-
- private static final Logger LOG = Logger.getLogger(PropertiesFileConfigBackendSpi.class.getName());
-
- private final File file;
-
- private final Properties properties = new Properties();
-
- /**
- * Instantiates a new Properties file config change request.
- *
- * @param file the file
- */
- PropertiesFileConfigBackendSpi(File file){
- super(file.toURI(), new SimplePropertySource(file));
- this.file = file;
- if(file.exists()) {
- try (InputStream is = getBackendURI().toURL().openStream()) {
- properties.load(is);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to load properties from " + file, e);
- }
- }
- }
-
- @Override
- public boolean isExisting(String keyExpression) {
- if(properties.containsKey(keyExpression)){
- return true;
- }
- for(Object key:properties.keySet()){
- if(key.toString().matches(keyExpression)){
- return true;
- }
- }
- return false;
- }
-
-
- @Override
- protected void commitInternal() {
- if(!file.exists()){
- try {
- if(!file.createNewFile()){
- throw new ConfigException("Failed to create config file " + file);
- }
- } catch (IOException e) {
- throw new ConfigException("Failed to create config file " + file, e);
- }
- }
- for(Map.Entry<String,String> en:super.addedProperties.entrySet()){
- int index = en.getKey().indexOf('?');
- if(index>0){
- this.properties.put(en.getKey().substring(0, index), en.getValue());
- }else{
- this.properties.put(en.getKey(), en.getValue());
- }
- }
- for(String rmKey:super.removedProperties){
- this.properties.remove(rmKey);
- }
- try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
- properties.store(bos, "Properties written from Tamaya on : " + new Date());
- bos.flush();
- }
- catch(Exception e){
- throw new ConfigException("Failed to write config to " + file, e);
- }
- }
-
- @Override
- public String toString() {
- return "PropertiesFileConfigBackend{" +
- "file=" + file +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/SimplePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/SimplePropertySource.java
deleted file mode 100644
index 68b6745..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/SimplePropertySource.java
+++ /dev/null
@@ -1,163 +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.mutableconfig.internal;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for properties-files.
- */
-class SimplePropertySource extends BasePropertySource {
-
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(SimplePropertySource.class.getName());
- /**
- * Default update interval is 1 minute.
- */
- private static final long DEFAULT_UPDATE_INTERVAL = 60000L;
-
- /**
- * The property source name.
- */
- private String name;
-
- /**
- * The configuration resource's URL.
- */
- private URL resource;
-
- /**
- * Timestamp of last read.
- */
- private long lastRead;
-
- /**
- * Interval, when the resource should try to update its contents.
- */
- private long updateInterval = DEFAULT_UPDATE_INTERVAL;
- /**
- * The current properties.
- */
- private Map<String, String> properties;
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(File propertiesLocation) {
- super(0);
- this.name = propertiesLocation.toString();
- try {
- this.resource = propertiesLocation.toURI().toURL();
- load();
- } catch (MalformedURLException e) {
- LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e);
- }
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(URL propertiesLocation) {
- super(0);
- this.name = propertiesLocation.toString();
- this.resource = propertiesLocation;
- load();
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given properties map.
- *
- * @param name the name, not null.
- * @param properties the properties, not null.
- */
- public SimplePropertySource(String name, Map<String, String> properties) {
- super(0);
- this.name = Objects.requireNonNull(name);
- this.properties = new HashMap<>(properties);
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param name The property source name
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(String name, URL propertiesLocation) {
- super(0);
- this.name = Objects.requireNonNull(name);
- this.resource = propertiesLocation;
- load();
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Map<String, String> getProperties() {
- checkLoad();
- return this.properties;
- }
-
- private void checkLoad() {
- if(resource!=null && (lastRead+updateInterval)<System.currentTimeMillis()){
- load();
- }
- }
-
- /**
- * loads the Properties from the given URL
- *
- * @return loaded {@link Properties}
- * @throws IllegalStateException in case of an error while reading properties-file
- */
- private void load() {
- Map<String, String> properties = new HashMap<>();
- try (InputStream stream = resource.openStream()) {
- Properties props = new Properties();
- if (stream != null) {
- props.load(stream);
- }
- for (String key : props.stringPropertyNames()) {
- properties.put(key, props.getProperty(key));
- }
- this.lastRead = System.currentTimeMillis();
- this.properties = properties;
- LOG.log(Level.FINEST, "Loaded properties from " + resource);
- } catch (IOException e) {
- LOG.log(Level.FINEST, "Cannot load properties from " + resource, e);
- this.properties = Collections.emptyMap();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/8e9a3cc5/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/XmlPropertiesFileConfigBackendSpi.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/XmlPropertiesFileConfigBackendSpi.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/XmlPropertiesFileConfigBackendSpi.java
deleted file mode 100644
index 68f7e8f..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/XmlPropertiesFileConfigBackendSpi.java
+++ /dev/null
@@ -1,114 +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.mutableconfig.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.mutableconfig.spi.AbstractMutableConfigurationBackendSpi;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Change Request implementation based on .xml properties file.
- */
-class XmlPropertiesFileConfigBackendSpi extends AbstractMutableConfigurationBackendSpi {
-
- private static final Logger LOG = Logger.getLogger(XmlPropertiesFileConfigBackendSpi.class.getName());
-
- private final File file;
-
- private final Properties properties = new Properties();
-
- /**
- * Instantiates a new Xml properties file config change request.
- *
- * @param file the file
- */
- XmlPropertiesFileConfigBackendSpi(File file){
- super(file.toURI(), new SimplePropertySource(file));
- this.file = file;
- if(file.exists()) {
- try (InputStream is = getBackendURI().toURL().openStream()) {
- properties.loadFromXML(is);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to load properties from " + file, e);
- }
- }
- }
-
- @Override
- public boolean isExisting(String keyExpression) {
- if(properties.containsKey(keyExpression)){
- return true;
- }
- for(Object key:properties.keySet()){
- if(key.toString().matches(keyExpression)){
- return true;
- }
- }
- return false;
- }
-
-
- @Override
- protected void commitInternal() {
- if(!file.exists()){
- try {
- if(!file.createNewFile()){
- throw new ConfigException("Failed to create config file " + file);
- }
- } catch (IOException e) {
- throw new ConfigException("Failed to create config file " + file, e);
- }
- }
- for(Map.Entry<String,String> en:super.addedProperties.entrySet()){
- int index = en.getKey().indexOf('?');
- if(index>0){
- this.properties.put(en.getKey().substring(0, index), en.getValue());
- }else{
- this.properties.put(en.getKey(), en.getValue());
- }
- }
- for(String rmKey:super.removedProperties){
- this.properties.remove(rmKey);
- }
- try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))){
- properties.storeToXML(bos, "Properties written from Tamaya on " + new Date());
- bos.flush();
- }
- catch(Exception e){
- throw new ConfigException("Failed to write config to " + file, e);
- }
- }
-
- @Override
- public String toString() {
- return "XmlPropertiesFileConfigBackend{" +
- "file=" + file +
- '}';
- }
-}