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/15 01:43:10 UTC
[2/2] incubator-tamaya git commit: Fixed javadocs issues.
Fixed javadocs 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/38b4a967
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/38b4a967
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/38b4a967
Branch: refs/heads/master
Commit: 38b4a967b6bcae9f00e1b58663b7b61b1dd348a4
Parents: 9b7fed4
Author: anatole <an...@apache.org>
Authored: Tue Mar 15 00:52:20 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Tue Mar 15 01:42:50 2016 +0100
----------------------------------------------------------------------
.../tamaya/consul/ConsulPropertySource.java | 4 +-
.../apache/tamaya/etcd/EtcdPropertySource.java | 4 +-
.../mutableconfig/MutableConfiguration.java | 6 +-
.../MutableConfigurationProvider.java | 3 +
.../AbstractMutablePropertySource.java | 23 +--
.../propertysources/ConfigChangeContext.java | 152 +++++++++++++++++++
.../MutablePropertiesPropertySource.java | 9 +-
.../MutableXmlPropertiesPropertySource.java | 9 +-
.../propertysources/TransactionContext.java | 152 -------------------
.../spi/MutablePropertySource.java | 8 +
.../PropertiesFileConfigBackendTest.java | 10 --
11 files changed, 190 insertions(+), 190 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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 b4227a8..9b61840 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
@@ -24,7 +24,7 @@ import com.orbitz.consul.Consul;
import com.orbitz.consul.KeyValueClient;
import com.orbitz.consul.model.kv.Value;
import org.apache.tamaya.mutableconfig.propertysources.AbstractMutablePropertySource;
-import org.apache.tamaya.mutableconfig.propertysources.TransactionContext;
+import org.apache.tamaya.mutableconfig.propertysources.ConfigChangeContext;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.PropertyValueBuilder;
@@ -165,7 +165,7 @@ public class ConsulPropertySource extends AbstractMutablePropertySource {
}
@Override
- protected void commitInternal(TransactionContext context) {
+ protected void commitInternal(ConfigChangeContext context) {
for(HostAndPort hostAndPort: ConsulBackends.getConsulBackends()){
try{
Consul consul = Consul.builder().withHostAndPort(hostAndPort).build();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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 9434f65..f84fd0d 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
@@ -19,7 +19,7 @@
package org.apache.tamaya.etcd;
import org.apache.tamaya.mutableconfig.propertysources.AbstractMutablePropertySource;
-import org.apache.tamaya.mutableconfig.propertysources.TransactionContext;
+import org.apache.tamaya.mutableconfig.propertysources.ConfigChangeContext;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.PropertyValueBuilder;
@@ -167,7 +167,7 @@ public class EtcdPropertySource extends AbstractMutablePropertySource{
}
@Override
- protected void commitInternal(TransactionContext context) {
+ protected void commitInternal(ConfigChangeContext context) {
for(EtcdAccessor accessor: EtcdBackends.getEtcdBackends()){
try{
for(String k: context.getRemovedProperties()){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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 4108928..ac0b10d 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
@@ -123,7 +123,7 @@ public interface MutableConfiguration extends Configuration {
* 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).
+ * @return the property sources identified, in order of their occurrence/priority (most significant first).
*/
List<MutablePropertySource> getPropertySourcesThatCanWrite(String keyExpression);
@@ -142,7 +142,7 @@ public interface MutableConfiguration extends Configuration {
* 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).
+ * @return the property sources identified, in order of their occurrence/priority (most significant first).
*/
List<MutablePropertySource> getPropertySourcesThatCanRemove(String keyExpression);
@@ -161,7 +161,7 @@ public interface MutableConfiguration extends Configuration {
* 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).
+ * @return the property sources identified, in order of their occurrence/priority (most significant first).
*/
List<MutablePropertySource> getPropertySourcesThatKnow(String keyExpression);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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
index 67e971f..4afa9cb 100644
--- 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
@@ -86,6 +86,7 @@ public final class MutableConfigurationProvider {
/**
* This propagation policy writes changes only once to the most significant property source, where a change is
* applicable.
+ * @return a corresponding {@link ChangePropagationPolicy} implementation, never null.
*/
public static ChangePropagationPolicy getApplyMostSignificantOnlyChangePolicy(){
return MOST_SIGNIFICANT_ONLY_POLICY;
@@ -95,6 +96,7 @@ public final class MutableConfigurationProvider {
* 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.
+ * @return a corresponding {@link ChangePropagationPolicy} implementation, never null.
*/
public static ChangePropagationPolicy getApplySelectiveChangePolicy(String... propertySourceNames){
return new SelectiveChangeApplyPolicy(propertySourceNames);
@@ -103,6 +105,7 @@ public final class MutableConfigurationProvider {
/**
* This propagation policy writes changes only once to the most significant property source, where a change is
* applicable.
+ * @return a corresponding {@link ChangePropagationPolicy} implementation, never null.
*/
public static ChangePropagationPolicy getApplyNonePolicy(){
return NONE_POLICY;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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
index e74e9e8..7931019 100644
--- 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
@@ -38,7 +38,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
/**
* Map with the curren transactions, identified by transactionId.
*/
- protected final Map<UUID, TransactionContext> transactions = new ConcurrentHashMap<>();
+ protected final Map<UUID, ConfigChangeContext> transactions = new ConcurrentHashMap<>();
/**
* Constructor udsing zero' as default ordinal.
@@ -61,7 +61,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
* @return the removed property keys, never null.
*/
protected final Set<String> getRemovedProperties(UUID transactionId) {
- TransactionContext ctx = this.transactions.get(transactionId);
+ ConfigChangeContext ctx = this.transactions.get(transactionId);
if(ctx!=null) {
return ctx.getRemovedProperties();
}
@@ -74,7 +74,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
* @return the added property keys, never null.
*/
protected final Map<String,String> getAddedProperties(UUID transactionId) {
- TransactionContext ctx = this.transactions.get(transactionId);
+ ConfigChangeContext ctx = this.transactions.get(transactionId);
if(ctx!=null) {
return ctx.getAddedProperties();
}
@@ -93,7 +93,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
@Override
public final MutablePropertySource put(UUID transactionId, String key, String value) {
- TransactionContext ctx = this.transactions.get(transactionId);
+ ConfigChangeContext ctx = this.transactions.get(transactionId);
if(ctx==null) {
throw new IllegalStateException("No such transaction: " + transactionId);
}
@@ -103,7 +103,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
@Override
public final MutablePropertySource putAll(UUID transactionId, Map<String, String> properties) {
- TransactionContext ctx = this.transactions.get(transactionId);
+ ConfigChangeContext ctx = this.transactions.get(transactionId);
if(ctx==null) {
throw new IllegalStateException("No such transaction: " + transactionId);
}
@@ -113,7 +113,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
@Override
public final MutablePropertySource remove(UUID transactionId, String... keys) {
- TransactionContext ctx = this.transactions.get(transactionId);
+ ConfigChangeContext ctx = this.transactions.get(transactionId);
if(ctx==null) {
throw new IllegalStateException("No such transaction: " + transactionId);
}
@@ -123,7 +123,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
@Override
public final MutablePropertySource remove(UUID transactionId, Collection<String> keys) {
- TransactionContext ctx = this.transactions.get(transactionId);
+ ConfigChangeContext ctx = this.transactions.get(transactionId);
if(ctx==null) {
throw new IllegalStateException("No such transaction: " + transactionId);
}
@@ -133,15 +133,15 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
@Override
public final void startTransaction(UUID transactionId) {
- TransactionContext ctx = this.transactions.get(transactionId);
+ ConfigChangeContext ctx = this.transactions.get(transactionId);
if(ctx==null) {
- this.transactions.put(transactionId, new TransactionContext(transactionId));
+ this.transactions.put(transactionId, new ConfigChangeContext(transactionId));
}
}
@Override
public final void commitTransaction(UUID transactionId) {
- TransactionContext ctx = this.transactions.remove(transactionId);
+ ConfigChangeContext ctx = this.transactions.remove(transactionId);
if(ctx==null) {
throw new IllegalStateException("No such transaction: " + transactionId);
}
@@ -152,8 +152,9 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource
/**
* 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.
+ * @param context The configuration change to be committed/applied.
*/
- protected abstract void commitInternal(TransactionContext context);
+ protected abstract void commitInternal(ConfigChangeContext context);
@Override
public final void rollbackTransaction(UUID transactionId) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java
new file mode 100644
index 0000000..8551cad
--- /dev/null
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java
@@ -0,0 +1,152 @@
+/*
+ * 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 ConfigChangeContext {
+ /**
+ * 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 ConfigChangeContext(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 ConfigChangeContext)) {
+ return false;
+ }
+ ConfigChangeContext that = (ConfigChangeContext) 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
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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
index d713578..a4105c7 100644
--- 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
@@ -78,6 +78,8 @@ public class MutablePropertiesPropertySource extends AbstractMutablePropertySour
* Creates a new Properties based PropertySource based on the given URL.
*
* @param propertiesLocation the URL encoded location, not null.
+ * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property
+ * source's properties.
*/
public MutablePropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
super(defaultOrdinal);
@@ -130,16 +132,13 @@ public class MutablePropertiesPropertySource extends AbstractMutablePropertySour
/**
* 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);
- }
+ props.load(stream);
for (String key : props.stringPropertyNames()) {
properties.put(key, props.getProperty(key));
}
@@ -152,7 +151,7 @@ public class MutablePropertiesPropertySource extends AbstractMutablePropertySour
}
@Override
- protected void commitInternal(TransactionContext context) {
+ protected void commitInternal(ConfigChangeContext context) {
if(context.isEmpty()){
LOG.info("Nothing to commit for transaction: " + context.getTransactionID());
return;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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
index 1e0d6da..9049340 100644
--- 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
@@ -78,6 +78,8 @@ public class MutableXmlPropertiesPropertySource extends AbstractMutablePropertyS
* Creates a new Properties based PropertySource based on the given URL.
*
* @param propertiesLocation the URL encoded location, not null.
+ * @param defaultOrdinal the default ordinal to be used, when no ordinal is provided with the property
+ * source's properties.
*/
public MutableXmlPropertiesPropertySource(File propertiesLocation, int defaultOrdinal) {
super(defaultOrdinal);
@@ -130,16 +132,13 @@ public class MutableXmlPropertiesPropertySource extends AbstractMutablePropertyS
/**
* 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);
- }
+ props.loadFromXML(stream);
for (String key : props.stringPropertyNames()) {
properties.put(key, props.getProperty(key));
}
@@ -153,7 +152,7 @@ public class MutableXmlPropertiesPropertySource extends AbstractMutablePropertyS
}
@Override
- protected void commitInternal(TransactionContext context) {
+ protected void commitInternal(ConfigChangeContext context) {
if(context.isEmpty()){
LOG.info("Nothing to commit for transaction: " + context.getTransactionID());
return;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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
deleted file mode 100644
index b8604f6..0000000
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/TransactionContext.java
+++ /dev/null
@@ -1,152 +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.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
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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
index 2888638..0872735 100644
--- 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
@@ -55,6 +55,8 @@ public interface MutablePropertySource extends PropertySource {
*
* @param key the property's key, not null.
* @param value the property's value, not null.
+ * @param transactionId the transactionId used to isolate the change, not null.
+ * @return this instance for optional chaining of operations, nrvrt 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);
@@ -68,7 +70,9 @@ public interface MutablePropertySource extends PropertySource {
* 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 transactionId the transactionId used to isolate the change, not null.
* @param properties the properties tobe written, not null.
+ * @return this instance for optional chaining of operations, nrvrt 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);
@@ -81,7 +85,9 @@ public interface MutablePropertySource extends PropertySource {
* 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 transactionId the transactionId used to isolate the change, not null.
* @param keys the property's keys to be removedProperties, not null.
+ * @return this instance for optional chaining of operations, nrvrt 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);
@@ -94,7 +100,9 @@ public interface MutablePropertySource extends PropertySource {
* 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 transactionId the transactionId used to isolate the change, not null.
* @param keys the property's keys to be removedProperties, not null.
+ * @return this instance for optional chaining of operations, nrvrt 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);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/38b4a967/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 e2c0dee..e6c79f5 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
@@ -18,18 +18,8 @@
*/
package org.apache.tamaya.mutableconfig.internal;
-import org.apache.tamaya.ConfigurationProvider;
-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.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.junit.Assert.*;
/**
* Tests for {@link MutablePropertiesPropertySource}.