Implemented UI improvements and overall fixes of minor issues.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/ee79c0ef Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/ee79c0ef Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/ee79c0ef Branch: refs/heads/master Commit: ee79c0efa2ec4cf067dd2dfa777435940702afed Parents: 089e951 Author: anatole <anat...@apache.org> Authored: Fri Jun 3 23:17:00 2016 +0200 Committer: anatole <anat...@apache.org> Committed: Tue Aug 16 15:51:30 2016 +0200 ---------------------------------------------------------------------- mutable-config/pom.xml | 1 - .../mutableconfig/ChangePropagationPolicy.java | 7 +- .../mutableconfig/MutableConfiguration.java | 13 ++- .../MutableConfigurationProvider.java | 25 +++-- .../internal/DefaultMutableConfiguration.java | 57 +++++++---- .../AbstractMutablePropertySource.java | 27 +++-- .../propertysources/ConfigChangeContext.java | 31 +++++- .../spi/MutablePropertySource.java | 22 ++-- .../mutableconfig/ui/ConfigEditorWidget.java | 29 ++++-- .../mutableconfig/ui/ConfigUpdaterView.java | 12 ++- .../tamaya/mutableconfig/ui/ProtocolWidget.java | 2 + .../ui/TransactionControlWidget.java | 100 ++++++++++++++++--- .../main/resources/ui/lang/tamaya.properties | 5 +- .../org.apache.tamaya.spi.PropertySource | 2 +- 14 files changed, 246 insertions(+), 87 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/pom.xml ---------------------------------------------------------------------- diff --git a/mutable-config/pom.xml b/mutable-config/pom.xml index cf06546..85dacd5 100644 --- a/mutable-config/pom.xml +++ b/mutable-config/pom.xml @@ -59,7 +59,6 @@ under the License. <version>${project.version}</version> <scope>runtime</scope> </dependency> - <dependency> <groupId>org.hamcrest</groupId> <artifactId>java-hamcrest</artifactId> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java index 0986c08..8e675ab 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ChangePropagationPolicy.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.mutableconfig; +import org.apache.tamaya.mutableconfig.propertysources.ConfigChangeContext; import org.apache.tamaya.spi.PropertySource; import java.util.Collection; @@ -50,7 +51,7 @@ public interface ChangePropagationPolicy { * @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); + void applyChanges(String transactionID, Collection<PropertySource> propertySources, Map<String,String> changes); /** * Method being called when a single key/value pair has been added or updated. @@ -60,7 +61,7 @@ public interface ChangePropagationPolicy { * @param key the key, not null. * @param value the value, not null. */ - void applyChange(Collection<PropertySource> propertySources, UUID transactionID, String key, String value); + void applyChange(String transactionID, Collection<PropertySource> propertySources, String key, String value); /** * Method being called when a multiple keys has been removed from the configuration. @@ -69,6 +70,6 @@ public interface ChangePropagationPolicy { * @param transactionID the transaction ID, not null. * @param keys the keys being removed, not null. */ - void applyRemove(Collection<PropertySource> propertySources, UUID transactionID, String... keys); + void applyRemove(String transactionID, Collection<PropertySource> propertySources, String... keys); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java index a0cb471..4f24701 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfiguration.java @@ -19,6 +19,7 @@ package org.apache.tamaya.mutableconfig; import org.apache.tamaya.Configuration; +import org.apache.tamaya.mutableconfig.propertysources.ConfigChangeContext; import org.apache.tamaya.mutableconfig.spi.MutablePropertySource; import java.util.Collection; @@ -50,7 +51,7 @@ public interface MutableConfiguration extends Configuration { * passed, when writing (committing) any changes applied. * @return the transaction id, not null. */ - UUID startTransaction(); + String startTransaction(); /** * Commits the request. After a commit the change is not editable anymore. All changes applied will be written to @@ -72,7 +73,7 @@ public interface MutableConfiguration extends Configuration { * Get the current transaction id. * @return the current transaction id, or null, if no transaction is active. */ - UUID getTransactionId(); + String getTransactionId(); /** * Get the current autoCommit policy. AutoCommit will commit the transaction after each change applied. @@ -95,6 +96,14 @@ public interface MutableConfiguration extends Configuration { ChangePropagationPolicy getChangePropagationPolicy(); /** + * Access the current configuration change context, built up on all the change context of the participating + * {@link MutablePropertySource} instances. + * @return the colleted changes as one single config change for the current transaction, or null, if no transaction + * is active. + */ + ConfigChangeContext getConfigChangeContext(); + + /** * Set the autoCommit policy to be used for this configuration instance. * @param autoCommit the new autoCommit policy. * @throws IllegalStateException when there are uncommitted changes. http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java index ec936b2..98c918b 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/MutableConfigurationProvider.java @@ -31,7 +31,6 @@ 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; @@ -131,7 +130,7 @@ public final class MutableConfigurationProvider { */ private static final ChangePropagationPolicy ALL_POLICY = new ChangePropagationPolicy() { @Override - public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID, + public void applyChanges(String transactionID, Collection<PropertySource> propertySources, Map<String, String> changes) { for(PropertySource propertySource: propertySources){ if(propertySource instanceof MutablePropertySource){ @@ -146,7 +145,7 @@ public final class MutableConfigurationProvider { } @Override - public void applyChange(Collection<PropertySource> propertySources, UUID transactionID, + public void applyChange(String transactionID, Collection<PropertySource> propertySources, String key, String value) { for(PropertySource propertySource: propertySources){ if(propertySource instanceof MutablePropertySource){ @@ -159,7 +158,7 @@ public final class MutableConfigurationProvider { } @Override - public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID, + public void applyRemove(String transactionID, Collection<PropertySource> propertySources, String... keys) { for(PropertySource propertySource: propertySources){ if(propertySource instanceof MutablePropertySource){ @@ -180,7 +179,7 @@ public final class MutableConfigurationProvider { */ private static final ChangePropagationPolicy MOST_SIGNIFICANT_ONLY_POLICY = new ChangePropagationPolicy() { @Override - public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID, + public void applyChanges(String transactionID, Collection<PropertySource> propertySources, Map<String, String> changes) { changes:for(Map.Entry<String,String> en:changes.entrySet()) { for(PropertySource propertySource: propertySources){ @@ -196,7 +195,7 @@ public final class MutableConfigurationProvider { } @Override - public void applyChange(Collection<PropertySource> propertySources, UUID transactionID, + public void applyChange(String transactionID, Collection<PropertySource> propertySources, String key, String value) { for(PropertySource propertySource: propertySources){ if(propertySource instanceof MutablePropertySource){ @@ -210,7 +209,7 @@ public final class MutableConfigurationProvider { } @Override - public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID, + public void applyRemove(String transactionID, Collection<PropertySource> propertySources, String... keys) { keys:for(String key:keys) { for(PropertySource propertySource: propertySources){ @@ -232,15 +231,15 @@ public final class MutableConfigurationProvider { */ private static final ChangePropagationPolicy NONE_POLICY = new ChangePropagationPolicy() { @Override - public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID, Map<String, String> changes) { + public void applyChanges(String transactionID, Collection<PropertySource> propertySources, Map<String, String> changes) { } @Override - public void applyChange(Collection<PropertySource> propertySources, UUID transactionID, String key, String value) { + public void applyChange(String transactionID, Collection<PropertySource> propertySources, String key, String value) { } @Override - public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID, String... keys) { + public void applyRemove(String transactionID, Collection<PropertySource> propertySources, String... keys) { } }; @@ -256,7 +255,7 @@ public final class MutableConfigurationProvider { } @Override - public void applyChanges(Collection<PropertySource> propertySources, UUID transactionID, + public void applyChanges(String transactionID, Collection<PropertySource> propertySources, Map<String, String> changes) { for(PropertySource propertySource: propertySources){ if(propertySource instanceof MutablePropertySource){ @@ -273,7 +272,7 @@ public final class MutableConfigurationProvider { } @Override - public void applyChange(Collection<PropertySource> propertySources, UUID transactionID, + public void applyChange(String transactionID, Collection<PropertySource> propertySources, String key, String value) { for(PropertySource propertySource: propertySources){ if(propertySource instanceof MutablePropertySource){ @@ -288,7 +287,7 @@ public final class MutableConfigurationProvider { } @Override - public void applyRemove(Collection<PropertySource> propertySources, UUID transactionID, + public void applyRemove(String transactionID, Collection<PropertySource> propertySources, String... keys) { for(PropertySource propertySource: propertySources){ if(propertySource instanceof MutablePropertySource){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java index 02f7193..bf75bae 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/internal/DefaultMutableConfiguration.java @@ -25,6 +25,7 @@ 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.propertysources.ConfigChangeContext; import org.apache.tamaya.mutableconfig.spi.MutablePropertySource; import org.apache.tamaya.spi.ConfigurationContext; import org.apache.tamaya.spi.PropertySource; @@ -46,7 +47,7 @@ public class DefaultMutableConfiguration implements MutableConfiguration { private final Configuration config; private ChangePropagationPolicy changePropagationPolicy = MutableConfigurationProvider.getApplyAllChangePolicy(); - private UUID transactionId; + private String transactionId; private boolean autoCommit = false; public DefaultMutableConfiguration(Configuration config){ @@ -74,11 +75,32 @@ public class DefaultMutableConfiguration implements MutableConfiguration { } @Override - public UUID getTransactionId() { + public String getTransactionId() { return transactionId; } @Override + public ConfigChangeContext getConfigChangeContext(){ + if(this.transactionId==null){ + return null; + } + ConfigChangeContext context = new ConfigChangeContext(this.transactionId); + long startedAt = Long.MAX_VALUE; + for(MutablePropertySource mps:getMutablePropertySources()){ + ConfigChangeContext subContext = mps.getConfigChangeContext(this.transactionId); + if(subContext!=null){ + context.putAll(subContext.getAddedProperties()); + context.removeAll(subContext.getRemovedProperties()); + if(subContext.getStartedAt()<startedAt){ + startedAt = subContext.getStartedAt(); + } + } + } + context.setStartedAt(startedAt); + return context; + } + + @Override public boolean getAutoCommit() { return autoCommit; } @@ -138,12 +160,7 @@ public class DefaultMutableConfiguration implements MutableConfiguration { @Override public boolean isExisting(String keyExpression) { - for(MutablePropertySource target:getMutablePropertySources()) { - if(target.get(keyExpression)!=null) { - return true; - } - } - return false; + return this.config.get(keyExpression)!=null; } @Override @@ -159,8 +176,8 @@ public class DefaultMutableConfiguration implements MutableConfiguration { @Override public MutableConfiguration put(String key, String value) { - UUID taID = startTransaction(); - changePropagationPolicy.applyChange(getPropertySources(), taID, key, value); + String taID = startTransaction(); + changePropagationPolicy.applyChange(taID, getPropertySources(), key, value); if(autoCommit){ commitTransaction(); } @@ -169,8 +186,8 @@ public class DefaultMutableConfiguration implements MutableConfiguration { @Override public MutableConfiguration putAll(Map<String, String> properties) { - UUID taID = startTransaction(); - changePropagationPolicy.applyChanges(getPropertySources(), taID, properties); + String taID = startTransaction(); + changePropagationPolicy.applyChanges(taID, getPropertySources(), properties); if(autoCommit){ commitTransaction(); } @@ -179,8 +196,8 @@ public class DefaultMutableConfiguration implements MutableConfiguration { @Override public MutableConfiguration remove(String... keys) { - UUID taID = startTransaction(); - changePropagationPolicy.applyRemove(getPropertySources(), taID, keys); + String taID = startTransaction(); + changePropagationPolicy.applyRemove(taID, getPropertySources(), keys); for(String key:keys){ for(MutablePropertySource target:getMutablePropertySources()) { if (target.isRemovable(key)) { @@ -195,12 +212,12 @@ public class DefaultMutableConfiguration implements MutableConfiguration { } @Override - public UUID startTransaction() { - UUID taID = transactionId; + public String startTransaction() { + String taID = transactionId; if(taID!=null){ return taID; } - taID = UUID.randomUUID(); + taID = UUID.randomUUID().toString(); transactionId = taID; try { for (MutablePropertySource target : getMutablePropertySources()) { @@ -214,7 +231,7 @@ public class DefaultMutableConfiguration implements MutableConfiguration { @Override public void commitTransaction() { - UUID taID = transactionId; + String taID = transactionId; if(taID==null){ LOG.warning("No active transaction on this thread, ignoring commit."); return; @@ -231,7 +248,7 @@ public class DefaultMutableConfiguration implements MutableConfiguration { @Override public void rollbackTransaction() { - UUID taID = transactionId; + String taID = transactionId; if(taID==null){ LOG.warning("No active transaction on this thread, ignoring rollback."); return; @@ -247,7 +264,7 @@ public class DefaultMutableConfiguration implements MutableConfiguration { @Override public MutableConfiguration remove(Collection<String> keys) { - UUID taID = startTransaction(); + String taID = startTransaction(); for(String key:keys){ for(MutablePropertySource target:getMutablePropertySources()) { if (target.isRemovable(key)) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java index 7931019..8133ab4 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/AbstractMutablePropertySource.java @@ -26,7 +26,6 @@ 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; /** @@ -38,7 +37,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource /** * Map with the curren transactions, identified by transactionId. */ - protected final Map<UUID, ConfigChangeContext> transactions = new ConcurrentHashMap<>(); + protected final Map<String, ConfigChangeContext> transactions = new ConcurrentHashMap<>(); /** * Constructor udsing zero' as default ordinal. @@ -60,7 +59,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource * @param transactionId the transaction id, not null. * @return the removed property keys, never null. */ - protected final Set<String> getRemovedProperties(UUID transactionId) { + protected final Set<String> getRemovedProperties(String transactionId) { ConfigChangeContext ctx = this.transactions.get(transactionId); if(ctx!=null) { return ctx.getRemovedProperties(); @@ -73,7 +72,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource * @param transactionId the transaction id, not null. * @return the added property keys, never null. */ - protected final Map<String,String> getAddedProperties(UUID transactionId) { + protected final Map<String,String> getAddedProperties(String transactionId) { ConfigChangeContext ctx = this.transactions.get(transactionId); if(ctx!=null) { return ctx.getAddedProperties(); @@ -92,7 +91,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource } @Override - public final MutablePropertySource put(UUID transactionId, String key, String value) { + public final MutablePropertySource put(String transactionId, String key, String value) { ConfigChangeContext ctx = this.transactions.get(transactionId); if(ctx==null) { throw new IllegalStateException("No such transaction: " + transactionId); @@ -102,7 +101,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource } @Override - public final MutablePropertySource putAll(UUID transactionId, Map<String, String> properties) { + public final MutablePropertySource putAll(String transactionId, Map<String, String> properties) { ConfigChangeContext ctx = this.transactions.get(transactionId); if(ctx==null) { throw new IllegalStateException("No such transaction: " + transactionId); @@ -112,7 +111,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource } @Override - public final MutablePropertySource remove(UUID transactionId, String... keys) { + public final MutablePropertySource remove(String transactionId, String... keys) { ConfigChangeContext ctx = this.transactions.get(transactionId); if(ctx==null) { throw new IllegalStateException("No such transaction: " + transactionId); @@ -122,7 +121,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource } @Override - public final MutablePropertySource remove(UUID transactionId, Collection<String> keys) { + public final MutablePropertySource remove(String transactionId, Collection<String> keys) { ConfigChangeContext ctx = this.transactions.get(transactionId); if(ctx==null) { throw new IllegalStateException("No such transaction: " + transactionId); @@ -132,7 +131,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource } @Override - public final void startTransaction(UUID transactionId) { + public final void startTransaction(String transactionId) { ConfigChangeContext ctx = this.transactions.get(transactionId); if(ctx==null) { this.transactions.put(transactionId, new ConfigChangeContext(transactionId)); @@ -140,7 +139,7 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource } @Override - public final void commitTransaction(UUID transactionId) { + public final void commitTransaction(String transactionId) { ConfigChangeContext ctx = this.transactions.remove(transactionId); if(ctx==null) { throw new IllegalStateException("No such transaction: " + transactionId); @@ -157,7 +156,13 @@ public abstract class AbstractMutablePropertySource extends BasePropertySource protected abstract void commitInternal(ConfigChangeContext context); @Override - public final void rollbackTransaction(UUID transactionId) { + public final void rollbackTransaction(String transactionId) { this.transactions.remove(transactionId); } + + @Override + public ConfigChangeContext getConfigChangeContext(String transactionID){ + return this.transactions.get(transactionID); + } + } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java index 8551cad..b0f46f1 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/ConfigChangeContext.java @@ -25,7 +25,6 @@ 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}. @@ -34,7 +33,7 @@ public final class ConfigChangeContext { /** * The transaction id. */ - private UUID transactionId; + private String transactionId; /** * The starting point. */ @@ -52,15 +51,24 @@ public final class ConfigChangeContext { * Creates a new instance bound to the given transaction. * @param transactionID the transaction ID, not null. */ - public ConfigChangeContext(UUID transactionID){ + public ConfigChangeContext(String transactionID){ this.transactionId = Objects.requireNonNull(transactionID); } /** + * Sets the started at value. By default {@link #startedAt} is already set on instance creation to + * {@code System.currentTimeMillis()}. + * @param startedAt the new UTC POSIX timestamp in millis. + */ + public void setStartedAt(long startedAt) { + this.startedAt = startedAt; + } + + /** * Get the corresppnding transaction ID of this instance. * @return the transaction ID, never null. */ - public UUID getTransactionID(){ + public String getTransactionID(){ return transactionId; } @@ -95,6 +103,7 @@ public final class ConfigChangeContext { */ public void put(String key, String value) { this.addedProperties.put(key, value); + this.removedProperties.remove(key); } /** @@ -103,6 +112,16 @@ public final class ConfigChangeContext { */ public void putAll(Map<String, String> properties) { this.addedProperties.putAll(properties); + this.removedProperties.removeAll(properties.keySet()); + } + + /** + * Remove all the given keys, ir present. + * @param key the key to be removed, not null. + */ + public void remove(String key) { + this.removedProperties.add(key); + this.addedProperties.remove(key); } /** @@ -111,6 +130,9 @@ public final class ConfigChangeContext { */ public void removeAll(Collection<String> keys) { this.removedProperties.addAll(keys); + for(String k:keys) { + this.addedProperties.remove(k); + } } /** @@ -149,4 +171,5 @@ public final class ConfigChangeContext { '}'; } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java index 0872735..cf4b6ee 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/MutablePropertySource.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.mutableconfig.spi; +import org.apache.tamaya.mutableconfig.propertysources.ConfigChangeContext; import org.apache.tamaya.spi.PropertySource; import java.util.Collection; @@ -59,7 +60,7 @@ public interface MutablePropertySource extends PropertySource { * @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); + MutablePropertySource put(String transactionId, String key, String value); /** @@ -75,7 +76,7 @@ public interface MutablePropertySource extends PropertySource { * @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); + MutablePropertySource putAll(String transactionId, Map<String, String> properties); /** * Removes all given configuration entries. This method should check that all given properties are @@ -90,7 +91,7 @@ public interface MutablePropertySource extends PropertySource { * @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); + MutablePropertySource remove(String transactionId, Collection<String> keys); /** * Removes all given configuration entries. This method should check that all given properties are @@ -105,7 +106,7 @@ public interface MutablePropertySource extends PropertySource { * @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); + MutablePropertySource remove(String transactionId, String... keys); /** * Commits the request. After a commit the change is not editable anymore. All changes applied will be written to @@ -117,17 +118,24 @@ public interface MutablePropertySource extends PropertySource { * @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); + void commitTransaction(String 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); + void rollbackTransaction(String transactionId); /** * Start a new transaction context with the given isolation policy. * @param transactionId the transaction id, not null. */ - void startTransaction(UUID transactionId); + void startTransaction(String transactionId); + + /** + * Get the transactional context for the given transaction ID. + * @param transactionID the transaction ID, not null. + * @return the transactional context, or null, if no such cointext is present. + */ + ConfigChangeContext getConfigChangeContext(String transactionID); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigEditorWidget.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigEditorWidget.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigEditorWidget.java index 7f0100f..b614e2a 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigEditorWidget.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigEditorWidget.java @@ -18,11 +18,7 @@ */ package org.apache.tamaya.mutableconfig.ui; -import com.vaadin.ui.Button; -import com.vaadin.ui.FormLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.TextField; +import com.vaadin.ui.*; import org.apache.tamaya.mutableconfig.MutableConfiguration; import org.apache.tamaya.spi.ServiceContextManager; import org.apache.tamaya.ui.services.MessageProvider; @@ -36,6 +32,7 @@ public class ConfigEditorWidget extends FormLayout { private MutableConfiguration mutableConfig; private ProtocolWidget logWriter; + private TransactionControlWidget taWidget; private TextField configKey = new TextField( ServiceContextManager.getServiceContext().getService(MessageProvider.class) @@ -50,9 +47,10 @@ public class ConfigEditorWidget extends FormLayout { private Button readButton = new Button(ServiceContextManager.getServiceContext().getService(MessageProvider.class) .getMessage("view.edit.button.readKey")); - public ConfigEditorWidget(MutableConfiguration mutableConfig, ProtocolWidget logWriter) { + public ConfigEditorWidget(MutableConfiguration mutableConfig, ProtocolWidget logWriter, TransactionControlWidget taWidget) { this.mutableConfig = Objects.requireNonNull(mutableConfig); this.logWriter = Objects.requireNonNull(logWriter); + this.taWidget = Objects.requireNonNull(taWidget); configKey.setWidth(50, Unit.PERCENTAGE); configValue.setWidth(50, Unit.PERCENTAGE); addComponents(configKey, configValue); @@ -69,10 +67,17 @@ public class ConfigEditorWidget extends FormLayout { public void buttonClick(Button.ClickEvent clickEvent) { if(mutableConfig.isWritable(configKey.getValue())){ mutableConfig.put(configKey.getValue(), configValue.getValue()); + Notification.show("Added " + configKey.getValue() + " = " + configValue.getValue(), + Notification.Type.TRAY_NOTIFICATION); logWriter.println(" - PUT " + configKey.getValue() + " = " + configValue.getValue()); + configKey.setValue(""); + configValue.setValue(""); }else{ + Notification.show("Could not add " + configKey.getValue() + " = " + configValue.getValue(), + Notification.Type.ERROR_MESSAGE); logWriter.println(" - PUT " + configKey.getValue() + " rejected - not writable."); } + taWidget.update(); } }); removeButton.addClickListener(new Button.ClickListener() { @@ -81,9 +86,16 @@ public class ConfigEditorWidget extends FormLayout { if(mutableConfig.isRemovable(configKey.getValue())){ mutableConfig.remove(configKey.getValue()); logWriter.println(" - DEL " + configKey.getValue()); + Notification.show("Removed " + configKey.getValue(), + Notification.Type.TRAY_NOTIFICATION); + configKey.setValue(""); + configValue.setValue(""); }else{ + Notification.show("Could not remove " + configKey.getValue(), + Notification.Type.ERROR_MESSAGE); logWriter.println(" - DEL " + configKey.getValue() + " rejected - not removable."); } + taWidget.update(); } }); readButton.addClickListener(new Button.ClickListener() { @@ -92,12 +104,17 @@ public class ConfigEditorWidget extends FormLayout { if(mutableConfig.isExisting(configKey.getValue())){ String key = configKey.getValue(); configValue.setValue(mutableConfig.get(key)); + Notification.show("Successfully read " + configKey.getValue(), + Notification.Type.TRAY_NOTIFICATION); logWriter.println(" - GET " + key + " = " + configValue.getValue()); logWriter.println(" - removable: " + mutableConfig.isRemovable(key)); logWriter.println(" - writable : " + mutableConfig.isWritable(key)); }else{ + Notification.show("Could not read " + configKey.getValue(), + Notification.Type.ERROR_MESSAGE); logWriter.println(" - GET " + configKey.getValue() + " rejected - not existing."); } + taWidget.update(); } }); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigUpdaterView.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigUpdaterView.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigUpdaterView.java index 2ca3646..d2b7745 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigUpdaterView.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ConfigUpdaterView.java @@ -50,6 +50,11 @@ public class ConfigUpdaterView extends VerticalSpacedLayout implements View { } @Override + public String getName() { + return "view.edit.name"; + } + + @Override public String getUrlPattern() { return "/edit"; } @@ -61,7 +66,7 @@ public class ConfigUpdaterView extends VerticalSpacedLayout implements View { } @Override - public View createView(){ + public View createView(Object... params){ return new ConfigUpdaterView(); } } @@ -73,7 +78,7 @@ public class ConfigUpdaterView extends VerticalSpacedLayout implements View { private TransactionControlWidget taControlWidget = new TransactionControlWidget(mutableConfig, protocolArea); - private ConfigEditorWidget editorWidget = new ConfigEditorWidget(mutableConfig, protocolArea); + private ConfigEditorWidget editorWidget = new ConfigEditorWidget(mutableConfig, protocolArea, taControlWidget); public ConfigUpdaterView() { @@ -90,7 +95,8 @@ public class ConfigUpdaterView extends VerticalSpacedLayout implements View { protocolArea.print(ps.getName(), ", "); } protocolArea.println(); - addComponents(caption, description, editorWidget, protocolArea, taControlWidget); + protocolArea.setHeight(100, Unit.PERCENTAGE); + addComponents(caption, description, editorWidget, taControlWidget, protocolArea); } private String getCaption(String key, String value) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ProtocolWidget.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ProtocolWidget.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ProtocolWidget.java index 5ceaaa6..29bc424 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ProtocolWidget.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/ProtocolWidget.java @@ -42,6 +42,7 @@ public class ProtocolWidget extends VerticalLayout{ public ProtocolWidget(){ textArea.setWidth(100, Unit.PERCENTAGE); + textArea.setHeight(100, Unit.PERCENTAGE); textArea.setReadOnly(true); clearButton.addClickListener(new Button.ClickListener() { @Override @@ -52,6 +53,7 @@ public class ProtocolWidget extends VerticalLayout{ }); textArea.setSizeFull(); addComponents(textArea, clearButton); + setHeight(100, Unit.PERCENTAGE); } public PrintWriter getWriter(){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/TransactionControlWidget.java ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/TransactionControlWidget.java b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/TransactionControlWidget.java index 49222c8..8150c4a 100644 --- a/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/TransactionControlWidget.java +++ b/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ui/TransactionControlWidget.java @@ -22,30 +22,39 @@ import com.vaadin.data.Property; import com.vaadin.ui.Button; import com.vaadin.ui.CheckBox; import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Field; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Notification; +import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; import org.apache.tamaya.mutableconfig.ChangePropagationPolicy; import org.apache.tamaya.mutableconfig.MutableConfiguration; import org.apache.tamaya.mutableconfig.MutableConfigurationProvider; +import org.apache.tamaya.mutableconfig.propertysources.ConfigChangeContext; import org.apache.tamaya.spi.ServiceContextManager; import org.apache.tamaya.ui.components.VerticalSpacedLayout; import org.apache.tamaya.ui.services.MessageProvider; import java.util.Arrays; +import java.util.Map; import java.util.Objects; /** * Tamaya UI view to change configuration. */ -public class TransactionControlWidget extends VerticalSpacedLayout { +public class TransactionControlWidget extends HorizontalLayout { + + private Field taID = new TextField("Transaction ID"); + private Field taContent = new TextArea("Transaction Context"); + private VerticalLayout taLayout = new VerticalLayout(taID, taContent); private CheckBox autoCommit = new CheckBox(ServiceContextManager.getServiceContext() .getService(MessageProvider.class).getMessage("view.edit.box.autoCommit")); private ComboBox changePropagationPolicy = new ComboBox(ServiceContextManager.getServiceContext() .getService(MessageProvider.class).getMessage("view.edit.select.propagationPolicy"), - Arrays.asList(new String[]{"ALL", "MOST_SIGNIFICANT_ONLY", "SELECTIVE", "NONE", "CUSTOM"})); + Arrays.asList(new String[]{"ALL", "MOST_SIGNIFICANT_ONLY", "NONE", "CUSTOM"})); private TextField changePropagationPolicyOther = new TextField( ServiceContextManager.getServiceContext().getService(MessageProvider.class) @@ -60,8 +69,15 @@ public class TransactionControlWidget extends VerticalSpacedLayout { private Button commitTAButton = new Button(ServiceContextManager.getServiceContext().getService(MessageProvider.class) .getMessage("view.edit.button.commitTransaction")); private ProtocolWidget logWriter; + private VerticalSpacedLayout leftLayout = new VerticalSpacedLayout(); public TransactionControlWidget(MutableConfiguration mutableConfig, ProtocolWidget logWriter) { + taContent.setReadOnly(true); + taContent.setWidth(600, Unit.PIXELS); + taContent.setHeight(250, Unit.PIXELS); + taLayout.setWidth(600, Unit.PIXELS); + taID.setReadOnly(true); + taID.setWidth(100, Unit.PERCENTAGE); this.mutableConfig = Objects.requireNonNull(mutableConfig); this.logWriter = Objects.requireNonNull(logWriter); changePropagationPolicy.setWidth(300, Unit.PIXELS); @@ -69,8 +85,10 @@ public class TransactionControlWidget extends VerticalSpacedLayout { setWidth(600, Unit.PIXELS); HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.addComponents(startTAButton, commitTAButton, rollbackTAButton); - addComponents(changePropagationPolicy, changePropagationPolicyOther, buttonLayout); + leftLayout.addComponents(changePropagationPolicy, changePropagationPolicyOther, buttonLayout); + addComponents(leftLayout, taLayout); initActions(); + update(); } private void initActions() { @@ -78,6 +96,13 @@ public class TransactionControlWidget extends VerticalSpacedLayout { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { mutableConfig.setAutoCommit(autoCommit.getValue()); + if(mutableConfig.getAutoCommit()) { + Notification.show("Autocommit is now ON.", + Notification.Type.TRAY_NOTIFICATION); + }else{ + Notification.show("Autocommit is now OFF.", + Notification.Type.TRAY_NOTIFICATION); + } logWriter.println(" - Set Auto-Commit to " + autoCommit.getValue()); } }); @@ -93,7 +118,7 @@ public class TransactionControlWidget extends VerticalSpacedLayout { mutableConfig.setChangePropagationPolicy( (ChangePropagationPolicy) Class.forName(className).newInstance()); logWriter.println(" - Set ChangePropagationPolicy " + className); - Notification.show("Successfully applied change policy: " + className); + Notification.show("ChangePropagationPolicy is now CUSTOM: " + className); } catch (Exception e) { Notification.show("Failed to apply change policy: " + className + ": " + e, Notification.Type.ERROR_MESSAGE); @@ -104,19 +129,16 @@ public class TransactionControlWidget extends VerticalSpacedLayout { case "MOST_SIGNIFICANT_ONLY": mutableConfig.setChangePropagationPolicy( MutableConfigurationProvider.getApplyMostSignificantOnlyChangePolicy()); + Notification.show("ChangePropagationPolicy is now MOST_SIGNIFICANT_ONLY.", + Notification.Type.TRAY_NOTIFICATION); logWriter.println(" - Set ChangePropagationPolicy to MOST_SIGNIFICANT_ONLY."); break; - case "SELECTIVE": -// mutableConfig.setChangePropagationPolicy( -// MutableConfigurationProvider.getApplySelectiveChangePolicy("source1", "source2"); - Notification.show("Selective Backends are not yet supported by the UI.", - Notification.Type.WARNING_MESSAGE); - break; case "NONE": Notification.show("Applying none equals being your config READ-ONLY.", Notification.Type.ASSISTIVE_NOTIFICATION); mutableConfig.setChangePropagationPolicy( MutableConfigurationProvider.getApplyNonePolicy()); + Notification.show("ChangePropagationPolicy is now NONE.", Notification.Type.TRAY_NOTIFICATION); logWriter.println(" - Set ChangePropagationPolicy to NONE."); break; case "CUSTOM": @@ -126,6 +148,7 @@ public class TransactionControlWidget extends VerticalSpacedLayout { default: mutableConfig.setChangePropagationPolicy( MutableConfigurationProvider.getApplyAllChangePolicy()); + Notification.show("ChangePropagationPolicy is now ALL.", Notification.Type.TRAY_NOTIFICATION); logWriter.println(" - Set ChangePropagationPolicy to ALL."); } } @@ -133,26 +156,75 @@ public class TransactionControlWidget extends VerticalSpacedLayout { startTAButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { - mutableConfig.startTransaction(); - logWriter.println("Started Transaction: " + mutableConfig.getTransactionId()); + String taId = mutableConfig.startTransaction(); + update(); + Notification.show("Transaction started: " + taId, Notification.Type.TRAY_NOTIFICATION); + logWriter.println("Started Transaction: " + taId); } }); rollbackTAButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { + String taId = mutableConfig.getTransactionId(); mutableConfig.rollbackTransaction(); - logWriter.println("Rolled back Transaction: " + mutableConfig.getTransactionId()); + update(); + Notification.show("Transaction rolled back: " + taId, Notification.Type.TRAY_NOTIFICATION); + logWriter.println("Rolled back Transaction: " + taId); } }); commitTAButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { + String taId = mutableConfig.getTransactionId(); mutableConfig.commitTransaction(); - logWriter.println("Committed Transaction: " + mutableConfig.getTransactionId()); + update(); + Notification.show("Transaction comitted: " + taId, Notification.Type.TRAY_NOTIFICATION); + logWriter.println("Committed Transaction: " + taId); } }); } + public void update(){ + taID.setReadOnly(false); + taContent.setReadOnly(false); + if(mutableConfig.getTransactionId()==null){ + taID.setValue("N/A"); + }else { + taID.setValue(mutableConfig.getTransactionId()); + } + StringBuilder b = new StringBuilder(); + ConfigChangeContext changes = mutableConfig.getConfigChangeContext(); + if(mutableConfig.getTransactionId()==null){ + startTAButton.setEnabled(true); + rollbackTAButton.setEnabled(false); + commitTAButton.setEnabled(false); + changePropagationPolicy.setEnabled(true); + changePropagationPolicyOther.setEnabled(true); + b.append("No Transaction Context available."); + }else{ + b.append("TA ID : ").append(changes.getTransactionID()).append('\n'); + b.append("Started at : ").append(changes.getStartedAt()).append("\n\n"); + b.append("PUT:\n"); + b.append("====\n"); + for(Map.Entry<String,String> en:changes.getAddedProperties().entrySet()){ + b.append(en.getKey()).append(" = ").append(en.getValue()).append("\n\n"); + } + b.append("DEL:\n"); + b.append("====\n"); + for(String key:changes.getRemovedProperties()){ + b.append(key).append("\n\n"); + } + startTAButton.setEnabled(false); + rollbackTAButton.setEnabled(true); + commitTAButton.setEnabled(true); + changePropagationPolicy.setEnabled(false); + changePropagationPolicyOther.setEnabled(false); + } + taContent.setValue(b.toString()); + taID.setReadOnly(true); + taContent.setReadOnly(true); + } + private String getCaption(String key, String value) { int index = key.lastIndexOf('.'); if (index < 0) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/main/resources/ui/lang/tamaya.properties ---------------------------------------------------------------------- diff --git a/mutable-config/src/main/resources/ui/lang/tamaya.properties b/mutable-config/src/main/resources/ui/lang/tamaya.properties index f1ce00a..3a8be1a 100644 --- a/mutable-config/src/main/resources/ui/lang/tamaya.properties +++ b/mutable-config/src/main/resources/ui/lang/tamaya.properties @@ -17,10 +17,11 @@ # under the License. # view.edit.name=Edit Configuration -view.edit.description=This is a simple Tamaya configuration editor for changing configuration values. +view.edit.description=This is a simple Tamaya configuration editor for changing configuration values. \ + It gives you full control on Tamaya's mutability features and transactions. view.edit.select.propagationPolicy=Change Propagation Policy view.edit.text.propagationPolicyOther=Custom Change Propagation Policy (Class) -view.edit.textArea.general=General Infos +view.edit.textArea.protocol=Action Protocol view.edit.box.autoCommit=Auto-Commit view.edit.button.startTransaction=Start TA http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ee79c0ef/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource ---------------------------------------------------------------------- diff --git a/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource index 7f20084..609b9fe 100644 --- a/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource +++ b/mutable-config/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource @@ -17,4 +17,4 @@ # under the License. # org.apache.tamaya.mutableconfig.internal.WritablePropertiesSource -org.apache.tamaya.mutableconfig.internal.WritableXmlPropertiesSource \ No newline at end of file +org.apache.tamaya.mutableconfig.internal.WritableXmlPropertiesSource