Repository: incubator-tamaya-extensions Updated Branches: refs/heads/master 3bb03ed23 -> 15fe93587
TAMAYA-194: - Factored out a LazyRefreshablePropertySource from the existing code in MutableConfig. - Added RefreshablePropertySource interface. 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/15fe9358 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/15fe9358 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/15fe9358 Branch: refs/heads/master Commit: 15fe9358723723192b9a9b9804bf169088941015 Parents: 3bb03ed Author: anatole <[email protected]> Authored: Fri Nov 11 18:29:30 2016 +0100 Committer: anatole <[email protected]> Committed: Fri Nov 11 18:29:30 2016 +0100 ---------------------------------------------------------------------- modules/mutable-config/pom.xml | 12 ++ .../mutableconfig/ChangePropagationPolicy.java | 1 - .../mutableconfig/ConfigChangeRequest.java | 176 +++++++++++++++ .../mutableconfig/MutableConfiguration.java | 1 - .../MutableConfigurationProvider.java | 1 - .../RefreshablePropertySource.java | 27 +++ .../internal/DefaultMutableConfiguration.java | 2 +- .../LazyRefreshablePropertySource.java | 215 +++++++++++++++++++ .../MutablePropertiesPropertySource.java | 27 +-- .../MutableXmlPropertiesPropertySource.java | 25 +-- .../mutableconfig/spi/ConfigChangeRequest.java | 176 --------------- .../spi/MutablePropertySource.java | 1 + 12 files changed, 437 insertions(+), 227 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/modules/mutable-config/pom.xml ---------------------------------------------------------------------- diff --git a/modules/mutable-config/pom.xml b/modules/mutable-config/pom.xml index e9be993..1961860 100644 --- a/modules/mutable-config/pom.xml +++ b/modules/mutable-config/pom.xml @@ -47,6 +47,11 @@ under the License. <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> <version>${project.version}</version> @@ -61,6 +66,13 @@ under the License. <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> + <dependency> + <groupId>org.apache.tamaya.ext</groupId> + <artifactId>tamaya-events</artifactId> + <version>0.3-incubating-SNAPSHOT</version> + <optional>true</optional> + <scope>provided</scope> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/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 index 5378166..44bbbcd 100644 --- 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 @@ -18,7 +18,6 @@ */ package org.apache.tamaya.mutableconfig; -import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest; import org.apache.tamaya.spi.PropertySource; import java.util.Collection; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java ---------------------------------------------------------------------- diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java new file mode 100644 index 0000000..a592d58 --- /dev/null +++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/ConfigChangeRequest.java @@ -0,0 +1,176 @@ +/* + * 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 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; + +/** + * Change context used for managing configuration changes within an + * {@link org.apache.tamaya.mutableconfig.spi.MutablePropertySource}. + */ +public final class ConfigChangeRequest { + /** + * The transaction id. + */ + private String 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 ConfigChangeRequest(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 String 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); + this.removedProperties.remove(key); + } + + /** + * 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); + 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); + } + + /** + * 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); + for(String k:keys) { + this.addedProperties.remove(k); + } + } + + /** + * 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 ConfigChangeRequest)) { + return false; + } + ConfigChangeRequest that = (ConfigChangeRequest) o; + return transactionId.equals(that.transactionId); + + } + + @Override + public int hashCode() { + return transactionId.hashCode(); + } + + @Override + public String toString() { + return "ConfigChangeRequest{" + + "transactionId=" + transactionId + + ", startedAt=" + startedAt + + ", addedProperties=" + addedProperties + + ", removedProperties=" + removedProperties + + '}'; + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/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 451769e..6b0e35e 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,7 +19,6 @@ package org.apache.tamaya.mutableconfig; import org.apache.tamaya.Configuration; -import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest; import java.util.Collection; import java.util.Map; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/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 c2cd20e..2e167a1 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 @@ -21,7 +21,6 @@ package org.apache.tamaya.mutableconfig; import org.apache.tamaya.ConfigException; import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest; import org.apache.tamaya.mutableconfig.spi.MutableConfigurationProviderSpi; import org.apache.tamaya.mutableconfig.spi.MutablePropertySource; import org.apache.tamaya.spi.PropertySource; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/RefreshablePropertySource.java ---------------------------------------------------------------------- diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/RefreshablePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/RefreshablePropertySource.java new file mode 100644 index 0000000..573f6d3 --- /dev/null +++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/RefreshablePropertySource.java @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * Simple implementation of a mutable {@link org.apache.tamaya.spi.PropertySource} for .properties files. + */ +public interface RefreshablePropertySource extends PropertySource, Refreshable{ +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/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 ad272ef..45fc3dc 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 @@ -24,7 +24,7 @@ import org.apache.tamaya.Configuration; import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.mutableconfig.ChangePropagationPolicy; import org.apache.tamaya.mutableconfig.MutableConfiguration; -import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest; +import org.apache.tamaya.mutableconfig.ConfigChangeRequest; import org.apache.tamaya.mutableconfig.spi.MutablePropertySource; import org.apache.tamaya.spi.ConfigurationContext; import org.apache.tamaya.spi.PropertySource; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java ---------------------------------------------------------------------- diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java new file mode 100644 index 0000000..7de7d53 --- /dev/null +++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java @@ -0,0 +1,215 @@ +/* + * 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.events.ConfigEventManager; +import org.apache.tamaya.events.FrozenPropertySource; +import org.apache.tamaya.events.PropertySourceChange; +import org.apache.tamaya.events.PropertySourceChangeBuilder; +import org.apache.tamaya.functions.Supplier; +import org.apache.tamaya.mutableconfig.RefreshablePropertySource; +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.spisupport.BasePropertySource; + +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Simple implementation of a mutable {@link PropertySource} for .properties files. + */ +public class LazyRefreshablePropertySource extends BasePropertySource +implements RefreshablePropertySource { + + /** + * The logger. + */ + private static final Logger LOG = Logger.getLogger(LazyRefreshablePropertySource.class.getName()); + + /** + * Default update interval is 1 minute. + */ + private static final long DEFAULT_UPDATE_INTERVAL = 60000L; + + /** + * The property source name. + */ + private Supplier<PropertySource> propertySourceSupplier; + + /** + * The current propertySource. + */ + private PropertySource propertySource; + + /** + * Timestamp of last read. + */ + private long lastRead; + + /** + * Interval, when the resource should try to update its contents. + */ + private long updateInterval = DEFAULT_UPDATE_INTERVAL; + + private static boolean eventSupportLoaded = checkEventSupport(); + + private static boolean checkEventSupport() { + try{ + Class.forName("org.apache.tamaya.events.ConfigEventManager"); + return true; + }catch(Exception e){ + return false; + } + } + + + /** + * Creates a new Properties based PropertySource based on the given URL. + * + * @param defaultOrdinal the default ordinal to be used. + * @param propertySourceSupplier the property source supplier, not null. + */ + private LazyRefreshablePropertySource(Supplier<PropertySource> propertySourceSupplier, int defaultOrdinal) { + super(defaultOrdinal); + this.propertySourceSupplier = Objects.requireNonNull(propertySourceSupplier); + this.propertySource = Objects.requireNonNull(propertySourceSupplier.get()); + } + + /** + * Creates a new Properties based PropertySource based on the given URL. + * + * @param propertySourceSupplier the property source supplier, not null. + */ + private LazyRefreshablePropertySource(Supplier<PropertySource> propertySourceSupplier) { + this.propertySourceSupplier = Objects.requireNonNull(propertySourceSupplier); + this.propertySource = Objects.requireNonNull(propertySourceSupplier.get()); + } + + /** + * Creates a new Properties based PropertySource based on the given URL. + * + * @param defaultOrdinal the default ordinal to be used. + * @param propertySourceSupplier the property source supplier, not null. + */ + public static LazyRefreshablePropertySource of(Supplier<PropertySource> propertySourceSupplier, int defaultOrdinal) { + return new LazyRefreshablePropertySource(propertySourceSupplier, defaultOrdinal); + } + + /** + * Creates a new Properties based PropertySource based on the given URL. + * + * @param propertySourceSupplier the property source supplier, not null. + */ + public static LazyRefreshablePropertySource of(Supplier<PropertySource> propertySourceSupplier) { + return new LazyRefreshablePropertySource(propertySourceSupplier); + } + + /** + * Sets the current refreh interval. + * @param millis the new refreh interval in millis. + */ + public void setUpdateInterval(long millis){ + this.updateInterval = millis; + } + + /** + * Access the current refresh interval. + * @return the current refresh interval. + */ + public long getDefaultUpdateInterval(){ + return this.updateInterval; + } + + @Override + public PropertyValue get(String key) { + checkLoad(); + return this.propertySource.get(key); + } + + @Override + public String getName() { + return this.propertySource.getName(); + } + + @Override + public Map<String, String> getProperties() { + checkLoad(); + return this.propertySource.getProperties(); + } + + + private void checkLoad() { + if((lastRead+updateInterval)<System.currentTimeMillis()){ + refresh(); + } + } + + /** + * Reloads the property source from its supplier. If Tamaya's event module is loaded corresoinding + * change events are triggered if changes were detected. + */ + @Override + public void refresh() { + try{ + Object previous = null; + if(eventSupportLoaded){ + previous = FrozenPropertySource.of(this.propertySource); + } + this.propertySource = Objects.requireNonNull(propertySourceSupplier.get()); + if(eventSupportLoaded){ + PropertySourceChange changeEvent = PropertySourceChangeBuilder.of( + (PropertySource)previous) + .addChanges(this.propertySource).build(); + if(!changeEvent.isEmpty()) { + ConfigEventManager.fireEvent(changeEvent); + } + } + } catch (Exception e) { + LOG.log(Level.WARNING, "Cannot refresh property source " + propertySource.getName(), e); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof LazyRefreshablePropertySource)) return false; + + LazyRefreshablePropertySource that = (LazyRefreshablePropertySource) o; + + return propertySource.getName().equals(that.propertySource.getName()); + + } + + @Override + public int hashCode() { + return propertySource.getName().hashCode(); + } + + @Override + public String toString() { + return "RefreshablePropertySource{" + + "\n name=" + getName() + + "\n delegate=" + propertySource + + "\n lastRead=" + lastRead + + "\n updateInterval=" + updateInterval + + "\n}"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/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 af9bed4..b38cf7a 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 @@ -19,7 +19,7 @@ package org.apache.tamaya.mutableconfig.propertysources; import org.apache.tamaya.ConfigException; -import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest; +import org.apache.tamaya.mutableconfig.ConfigChangeRequest; import org.apache.tamaya.mutableconfig.spi.MutablePropertySource; import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spi.PropertyValueBuilder; @@ -51,11 +51,6 @@ implements MutablePropertySource{ 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; @@ -66,15 +61,6 @@ implements MutablePropertySource{ 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<>(); @@ -91,7 +77,7 @@ implements MutablePropertySource{ this.name = propertiesLocation.toString(); try { this.file = propertiesLocation; - load(); + refresh(); } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot convert file to URL: " + propertiesLocation, e); } @@ -121,23 +107,17 @@ implements MutablePropertySource{ @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 * * @throws IllegalStateException in case of an error while reading properties-file */ - private void load() { + public void refresh() { try (InputStream stream = new FileInputStream(file)) { Map<String, String> properties = new HashMap<>(); Properties props = new Properties(); @@ -145,7 +125,6 @@ implements MutablePropertySource{ 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) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/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 514ed1d..62ae0c8 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 @@ -19,7 +19,7 @@ package org.apache.tamaya.mutableconfig.propertysources; import org.apache.tamaya.ConfigException; -import org.apache.tamaya.mutableconfig.spi.ConfigChangeRequest; +import org.apache.tamaya.mutableconfig.ConfigChangeRequest; import org.apache.tamaya.mutableconfig.spi.MutablePropertySource; import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spi.PropertyValueBuilder; @@ -49,10 +49,6 @@ implements MutablePropertySource{ * 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. @@ -65,15 +61,6 @@ implements MutablePropertySource{ 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<>(); @@ -122,17 +109,10 @@ implements MutablePropertySource{ @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 * @@ -146,12 +126,11 @@ implements MutablePropertySource{ 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); + LOG.log(Level.FINEST, "Cannot refresh properties from " + file, e); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigChangeRequest.java ---------------------------------------------------------------------- diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigChangeRequest.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigChangeRequest.java deleted file mode 100644 index 2349ad1..0000000 --- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/spi/ConfigChangeRequest.java +++ /dev/null @@ -1,176 +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.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; - -/** - * Change context used for managing configuration changes within an - * {@link org.apache.tamaya.mutableconfig.spi.MutablePropertySource}. - */ -public final class ConfigChangeRequest { - /** - * The transaction id. - */ - private String 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 ConfigChangeRequest(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 String 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); - this.removedProperties.remove(key); - } - - /** - * 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); - 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); - } - - /** - * 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); - for(String k:keys) { - this.addedProperties.remove(k); - } - } - - /** - * 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 ConfigChangeRequest)) { - return false; - } - ConfigChangeRequest that = (ConfigChangeRequest) o; - return transactionId.equals(that.transactionId); - - } - - @Override - public int hashCode() { - return transactionId.hashCode(); - } - - @Override - public String toString() { - return "ConfigChangeRequest{" + - "transactionId=" + transactionId + - ", startedAt=" + startedAt + - ", addedProperties=" + addedProperties + - ", removedProperties=" + removedProperties + - '}'; - } - - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/15fe9358/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 b648341..211869c 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 @@ -18,6 +18,7 @@ */ package org.apache.tamaya.mutableconfig.spi; +import org.apache.tamaya.mutableconfig.ConfigChangeRequest; import org.apache.tamaya.spi.PropertySource;
