You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by jo...@apache.org on 2016/02/14 17:23:36 UTC
[1/2] incubator-tamaya git commit: TAMAYA-134 Patch from Philipp
Ottlinger to fix a number of javadocs.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 9fd1cee1f -> 5701c27e7
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java b/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
index 8cc5d4f..4868bc1 100644
--- a/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
+++ b/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
@@ -19,12 +19,12 @@
package org.apache.tamaya.optional;
-import org.apache.tamaya.ConfigurationProvider;
-
import java.util.Objects;
+import org.apache.tamaya.ConfigurationProvider;
+
/**
- * Simplified configuration API, that can be used by code that only want Tamaya to optionally enhance its configuration
+ * Simplified configuration API, that can be used by code that only wants Tamaya to optionally enhance its configuration
* mechanism, but by default uses its own configuration by default.
*/
public final class OptionalConfiguration {
@@ -48,7 +48,7 @@ public final class OptionalConfiguration {
try {
Class.forName(TAMAYA_CONFIGURATION);
return true;
- } catch (Exception e) {
+ } catch (final Exception e) {
return false;
}
}
@@ -58,6 +58,7 @@ public final class OptionalConfiguration {
* In all other cases {@code null} is returned.
*/
public static final ValueProvider DEFAULT_PROVIDER = new ValueProvider() {
+ @SuppressWarnings("unchecked")
@Override
public <T> T get(String key, Class<T> type) {
if (String.class == type) {
@@ -93,7 +94,8 @@ public final class OptionalConfiguration {
/**
* Creates a new instance.
- * @param policy the policy how a value should be evaluated depending ig Tamaya is availalbe or not.
+ *
+ * @param policy the policy how a value should be evaluated depending if Tamaya is available or not.
* @param provider the non Tamaya-based provider to be used to evaluate values.
*/
private OptionalConfiguration(EvaluationPolicy policy, ValueProvider provider) {
@@ -104,6 +106,8 @@ public final class OptionalConfiguration {
/**
* Returns an instance of OptionalConfiguration, which uses the given provider and policy for evaluating the values.
*
+ * @param policy the policy how a value should be evaluated depending if Tamaya is available or not.
+ * @param provider the non Tamaya-based provider to be used to evaluate values.
* @return a default OptionalConfiguration instance, never null.
*/
public static OptionalConfiguration of(EvaluationPolicy policy, ValueProvider provider) {
@@ -114,6 +118,7 @@ public final class OptionalConfiguration {
* Returns a default instance, which uses a default provider returning values from system properties and environment
* only.
*
+ * @param policy the policy how a value should be evaluated depending if Tamaya is available or not.
* @return a default OptionalConfiguration instance, never null.
*/
public static OptionalConfiguration of(EvaluationPolicy policy) {
@@ -133,13 +138,13 @@ public final class OptionalConfiguration {
/**
* Access a String value.
*
- * @param key the key, not null.
+ * @param key the key, not null.
* @param defaultValue the default value, returned if no such key is found in the configuration.
* @return the value found, or null.
*/
public String getOrDefault(String key, String defaultValue) {
- String value = get(key, String.class);
- if(value==null){
+ final String value = get(key, String.class);
+ if (value == null) {
return defaultValue;
}
return value;
@@ -155,8 +160,8 @@ public final class OptionalConfiguration {
* @return the value, or null.
*/
public <T> T get(String key, Class<T> type) {
- T value = provider.get(key, type);
- T tamayaValue = getTamaya(key, type);
+ final T value = provider.get(key, type);
+ final T tamayaValue = getTamaya(key, type);
switch (policy) {
case OTHER_OVERRIDES_TAMAYA:
return value != null ? value : tamayaValue;
@@ -178,15 +183,15 @@ public final class OptionalConfiguration {
/**
* Access a String value.
*
- * @param key the key, not null.
- * @param type the target type, not null.
- * @param <T> the type param.
+ * @param key the key, not null.
+ * @param type the target type, not null.
+ * @param <T> the type param.
* @param defaultValue the default value, returned if no such key is found in the configuration.
* @return the value found, or null.
*/
public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
- T value = get(key, type);
- if(value==null){
+ final T value = get(key, type);
+ if (value == null) {
return defaultValue;
}
return value;
@@ -194,13 +199,14 @@ public final class OptionalConfiguration {
/**
* Internal method that evaluates a value from Tamaya, when Tamaya is loaded.
- * @param key the key, not null.
+ *
+ * @param key the key, not null.
* @param type the target type, not null.
- * @param <T> The type param
+ * @param <T> The type param
* @return the corresponding value from Tamaya, or null.
*/
private <T> T getTamaya(String key, Class<T> type) {
- if(TAMAYA_LOADED){
+ if (TAMAYA_LOADED) {
return ConfigurationProvider.getConfiguration().get(key, type);
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/server/pom.xml
----------------------------------------------------------------------
diff --git a/modules/server/pom.xml b/modules/server/pom.xml
index f5b1e70..28e26e5 100644
--- a/modules/server/pom.xml
+++ b/modules/server/pom.xml
@@ -134,7 +134,6 @@ under the License.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <version>2.4</version>
<configuration>
<archive>
<manifest>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java b/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
index a9575fe..f38184e 100644
--- a/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
+++ b/modules/server/src/main/java/org/apache/tamaya/server/ConfigurationResource.java
@@ -18,9 +18,10 @@
*/
package org.apache.tamaya.server;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.functions.ConfigurationFunctions;
+import java.io.StringWriter;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicLong;
import javax.json.Json;
import javax.json.JsonArray;
@@ -38,22 +39,22 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import java.io.StringWriter;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.ConfigurationFunctions;
/**
- * Spring boot based configuration service that behavious compatible with etcd REST API (excluded the blocking API
- * calls).
+ * Spring boot based configuration service that is compatible with etcd REST API
+ * (excluding the blocking API calls).
*/
@Path("/")
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
public class ConfigurationResource {
private final String scope;
- private final AtomicLong readCounter = new AtomicLong();
- private final AtomicLong writeCounter = new AtomicLong();
- private final AtomicLong deleteCounter = new AtomicLong();
+ private final AtomicLong readCounter = new AtomicLong();
+ private final AtomicLong writeCounter = new AtomicLong();
+ private final AtomicLong deleteCounter = new AtomicLong();
public ConfigurationResource(String scope) {
this.scope = scope;
@@ -63,6 +64,7 @@ public class ConfigurationResource {
@Path("/version")
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
public String version() {
+ // TODO TAMAYA-139: make version string dynamically calculated based on mvn settings
String product = VersionProperties.getProduct().replace("\"", "\\\"");
String version = VersionProperties.getVersion().replace("\"", "\\\"");
@@ -76,34 +78,37 @@ public class ConfigurationResource {
}
/**
- *
* This models a etcd2 compliant access point for getting a property value.
- * @return
+ *
+ * @param recursive NOT YET IMPLEMENTED!
+ * @return all configuration property values.
*/
@GET
@Path("/keys")
public String readConfig(@QueryParam("recursive") Boolean recursive) {
readCounter.incrementAndGet();
- Configuration config = ConfigurationProvider.getConfiguration();
- Map<String,String> children = config.getProperties();
- JsonArrayBuilder ab = Json.createArrayBuilder();
- for(Map.Entry<String,String> en: children.entrySet()){
- Node node = new Node(config, en.getKey(), "node");
+ final Configuration config = ConfigurationProvider.getConfiguration();
+ final Map<String, String> children = config.getProperties();
+ final JsonArrayBuilder ab = Json.createArrayBuilder();
+ for (final Map.Entry<String, String> en : children.entrySet()) {
+ final Node node = new Node(config, en.getKey(), "node");
ab.add(node.createJsonObject());
}
- Node node = new Node(config, null, "node", ab.build());
- JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get")
+ final Node node = new Node(config, null, "node", ab.build());
+ final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get")
.add("node", node.createJsonObject());
- StringWriter writer = new StringWriter();
- JsonWriter jwriter = Json.createWriter(writer);
+ final StringWriter writer = new StringWriter();
+ final JsonWriter jwriter = Json.createWriter(writer);
jwriter.writeObject(root.build());
return writer.toString();
}
/**
* This models a etcd2 compliant access point for getting a property value.
- * @param key
- * @return
+ *
+ * @param key name of the key to show
+ * @param recursive NOT YET IMPLEMENTED!
+ * @return specific configuration key derived from the given key name.
*/
@GET
@Path("/v2/keys/{key}")
@@ -113,44 +118,46 @@ public class ConfigurationResource {
/**
* This models a etcd2 compliant access point for getting a property value.
- * @param key
- * @return
+ *
+ * @param key name of the key to show
+ * @param recursive NOT YET IMPLEMENTED!
+ * @return configuration value of the given key.
*/
@GET
@Path("/keys/{key}")
public String readConfig(@PathParam("key") String key, @QueryParam("recursive") Boolean recursive) {
readCounter.incrementAndGet();
- Configuration config = ConfigurationProvider.getConfiguration();
- if(key!=null) {
+ final Configuration config = ConfigurationProvider.getConfiguration();
+ if (key != null) {
if (key.startsWith("/")) {
key = key.substring(1);
}
if (config.get(key) != null && !recursive) {
- Node node = new Node(config, key, "node");
- JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get")
+ final Node node = new Node(config, key, "node");
+ final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get")
.add("node", node.createJsonObject());
- StringWriter writer = new StringWriter();
- JsonGenerator gen = Json.createGenerator(writer);
+ final StringWriter writer = new StringWriter();
+ final JsonGenerator gen = Json.createGenerator(writer);
gen.write(root.build());
return writer.toString();
}
}
- Map<String,String> children = null;
- if(key==null){
+ Map<String, String> children = null;
+ if (key == null) {
children = config.getProperties();
- } else{
+ } else {
children = config.with(ConfigurationFunctions.section(key)).getProperties();
}
- JsonArrayBuilder ab = Json.createArrayBuilder();
- for(Map.Entry<String,String> en: children.entrySet()){
- Node node = new Node(config, en.getKey(), "node");
+ final JsonArrayBuilder ab = Json.createArrayBuilder();
+ for (final Map.Entry<String, String> en : children.entrySet()) {
+ final Node node = new Node(config, en.getKey(), "node");
ab.add(node.createJsonObject());
}
- Node node = new Node(config, key, "node", ab.build());
- JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get")
+ final Node node = new Node(config, key, "node", ab.build());
+ final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "get")
.add("node", node.createJsonObject());
- StringWriter writer = new StringWriter();
- JsonWriter jwriter = Json.createWriter(writer);
+ final StringWriter writer = new StringWriter();
+ final JsonWriter jwriter = Json.createWriter(writer);
jwriter.writeObject(root.build());
return writer.toString();
}
@@ -158,48 +165,52 @@ public class ConfigurationResource {
@PUT
@Path("/v2/keys/{key}")
public String writeEtcdConfig(@PathParam("key") String key, @javax.ws.rs.FormParam("value") String value,
- @FormParam("ttl") Integer ttl) {
+ @FormParam("ttl") Integer ttl) {
return writeConfig(key, value, ttl);
}
+
/**
- * This models a etcd2 compliant access point for getting a property value:
+ * This models a etcd2 compliant access point for setting a property value:
* <pre>
* {
- "action": "set",
- "node": {
- "createdIndex": 3,
- "key": "/message",
- "modifiedIndex": 3,
- "value": "Hello etcd"
- },
- "prevNode": {
- "createdIndex": 2,
- "key": "/message",
- "value": "Hello world",
- "modifiedIndex": 2
- }
- }
+ * "action": "set",
+ * "node": {
+ * "createdIndex": 3,
+ * "key": "/message",
+ * "modifiedIndex": 3,
+ * "value": "Hello etcd"
+ * },
+ * "prevNode": {
+ * "createdIndex": 2,
+ * "key": "/message",
+ * "value": "Hello world",
+ * "modifiedIndex": 2
+ * }
+ * }
* </pre>
- * @param key
- * @return
+ *
+ * @param key name of the key to show
+ * @param value configuration value for the given key
+ * @param ttl time to live
+ * @return written configuration value.
*/
@PUT
@Path("/keys/{key}")
public String writeConfig(@PathParam("key") String key, @javax.ws.rs.FormParam("value") String value,
@FormParam("ttl") Integer ttl) {
writeCounter.incrementAndGet();
- Configuration config = ConfigurationProvider.getConfiguration();
- if(key.startsWith("/")){
+ final Configuration config = ConfigurationProvider.getConfiguration();
+ if (key.startsWith("/")) {
key = key.substring(1);
}
- Node prevNode = new Node(config, key, "prevNode");
+ final Node prevNode = new Node(config, key, "prevNode");
// TODO implement write! value and ttl as input
- Node node = new Node(config, key, "node");
- JsonObjectBuilder root = Json.createObjectBuilder().add("action", "set")
+ final Node node = new Node(config, key, "node");
+ final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "set")
.add("node", node.createJsonObject())
.add("prevNode", prevNode.createJsonObject());
- StringWriter writer = new StringWriter();
- JsonWriter jwriter = Json.createWriter(writer);
+ final StringWriter writer = new StringWriter();
+ final JsonWriter jwriter = Json.createWriter(writer);
jwriter.writeObject(root.build());
return writer.toString();
}
@@ -209,80 +220,60 @@ public class ConfigurationResource {
public String deleteEtcdConfig(@PathParam("key") String key) {
return deleteConfig(key);
}
- /**
- * This models a etcd2 compliant access point for getting a property value:
- * <pre>
- * {
- "action": "set",
- "node": {
- "createdIndex": 3,
- "key": "/message",
- "modifiedIndex": 3,
- "value": "Hello etcd"
- },
- "prevNode": {
- "createdIndex": 2,
- "key": "/message",
- "value": "Hello world",
- "modifiedIndex": 2
- }
- }
- * </pre>
- * @param key
- * @return
- */
+
@DELETE
@Path("/keys/{key}")
public String deleteConfig(@PathParam("key") String key) {
deleteCounter.incrementAndGet();
- Configuration config = ConfigurationProvider.getConfiguration();
- if(key.startsWith("/")){
+ final Configuration config = ConfigurationProvider.getConfiguration();
+ if (key.startsWith("/")) {
key = key.substring(1);
}
- Node prevNode = new Node(config, key, "prevNode");
+ final Node prevNode = new Node(config, key, "prevNode");
// TODO implement write! value and ttl as input
- Node node = new Node(config, key, "node");
- JsonObjectBuilder root = Json.createObjectBuilder().add("action", "delete")
+ final Node node = new Node(config, key, "node");
+ final JsonObjectBuilder root = Json.createObjectBuilder().add("action", "delete")
.add("node", node.createJsonObject())
.add("prevNode", prevNode.createJsonObject());
- StringWriter writer = new StringWriter();
- JsonWriter jwriter = Json.createWriter(writer);
+ final StringWriter writer = new StringWriter();
+ final JsonWriter jwriter = Json.createWriter(writer);
jwriter.writeObject(root.build());
return writer.toString();
}
- public long getDeleteCounter(){
+ public long getDeleteCounter() {
return deleteCounter.get();
}
- public long getReadCounter(){
+ public long getReadCounter() {
return readCounter.get();
}
- public long getWriteCounter(){
+ public long getWriteCounter() {
return writeCounter.get();
}
/**
- * Internal representation of a configuration node as modelled by etc.
+ * Internal representation of a configuration node as modeled by etc.
*/
- private static final class Node{
+ private static final class Node {
private Integer createdIndex;
private Integer modifiedIndex;
- private String key;
+ private final String key;
private String value;
- private String nodeId;
+ private final String nodeId;
private Integer ttl;
private String expiration;
- private JsonArray nodes;
+ private final JsonArray nodes;
- Node(Configuration config, String key, String nodeId){
+ Node(Configuration config, String key, String nodeId) {
this(config, key, nodeId, null);
}
- Node(Configuration config, String key, String nodeId, JsonArray nodes){
+
+ Node(Configuration config, String key, String nodeId, JsonArray nodes) {
this.key = key;
this.nodeId = Objects.requireNonNull(nodeId);
- if(key!=null) {
+ if (key != null) {
value = config.get(key);
createdIndex = config.getOrDefault("_" + key + ".createdIndex", Integer.class, null);
modifiedIndex = config.getOrDefault("_" + key + ".modifiedIndex", Integer.class, null);
@@ -292,29 +283,29 @@ public class ConfigurationResource {
this.nodes = nodes;
}
- JsonObject createJsonObject(){
- JsonObjectBuilder nodeBuilder = Json.createObjectBuilder();
- if(key!=null) {
+ JsonObject createJsonObject() {
+ final JsonObjectBuilder nodeBuilder = Json.createObjectBuilder();
+ if (key != null) {
nodeBuilder.add("key", '/' + key);
- }else{
+ } else {
nodeBuilder.add("dir", true);
}
- if(value!=null){
+ if (value != null) {
nodeBuilder.add("value", value);
}
- if(createdIndex!=null){
+ if (createdIndex != null) {
nodeBuilder.add("createdIndex", createdIndex.intValue());
}
- if(modifiedIndex!=null){
+ if (modifiedIndex != null) {
nodeBuilder.add("modifiedIndex", modifiedIndex.intValue());
}
- if(ttl!=null){
+ if (ttl != null) {
nodeBuilder.add("ttl", ttl.intValue());
}
- if(expiration!=null){
+ if (expiration != null) {
nodeBuilder.add("expiration", value);
}
- if(nodes!=null){
+ if (nodes != null) {
nodeBuilder.add("nodes", nodes);
}
return nodeBuilder.build();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
index 3462e40..3d2757a 100644
--- a/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
+++ b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeManager.java
@@ -18,18 +18,18 @@
*/
package org.apache.tamaya.server.spi;
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.spi.ServiceContextManager;
-
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.ConfigOperator;
+import org.apache.tamaya.spi.ServiceContextManager;
+
/**
- * Singleton manager for scopes, used by the server component to filtering returned config.
+ * Singleton manager for scopes, used by the server component to filtering returned configurations.
*/
public final class ScopeManager {
/** The logger used. */
@@ -41,11 +41,11 @@ public final class ScopeManager {
* Singleton constructor.
*/
private static Map<String, ScopeProvider> initProviders(){
- Map<String, ScopeProvider> result = new ConcurrentHashMap<>();
- for(ScopeProvider prov: ServiceContextManager.getServiceContext().getServices(ScopeProvider.class)){
+ final Map<String, ScopeProvider> result = new ConcurrentHashMap<>();
+ for(final ScopeProvider prov: ServiceContextManager.getServiceContext().getServices(ScopeProvider.class)){
try{
result.put(prov.getScopeType(), prov);
- } catch(Exception e){
+ } catch(final Exception e){
LOG.log(Level.WARNING, "Error loading scopes from " + prov, e);
}
}
@@ -58,19 +58,20 @@ public final class ScopeManager {
private ScopeManager(){}
/**
- * Get the scope given its name.
+ * Get the scope given its id and provider.
*
- * @throws ConfigException if no such scope is defined
* @param scopeId the scope name
+ * @param targetScope name of the targetScope
* @return the scope matching
+ * @throws ConfigException if no such scope is defined
*/
- public static ConfigOperator getScope(String scopeId, String target)
+ public static ConfigOperator getScope(String scopeId, String targetScope)
throws ConfigException {
- ScopeProvider prov = scopeProviders.get(scopeId);
+ final ScopeProvider prov = scopeProviders.get(scopeId);
if(prov==null){
throw new ConfigException("No such scope: " + scopeId);
}
- return prov.getScope(target);
+ return prov.getScope(targetScope);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
index d74317c..5c247d8 100644
--- a/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
+++ b/modules/server/src/main/java/org/apache/tamaya/server/spi/ScopeProvider.java
@@ -21,7 +21,7 @@ package org.apache.tamaya.server.spi;
import org.apache.tamaya.ConfigOperator;
/**
- * Simple registratable provider class to register scopes for the server extension.
+ * Simple registrable provider class to register scopes for the server extension.
*/
public interface ScopeProvider {
@@ -33,6 +33,7 @@ public interface ScopeProvider {
/**
* Return the scope operator that implements the scope for the given scope id.
+ * @param scopeId target scope id.
* @return the scope operator, never null.
*/
ConfigOperator getScope(String scopeId);
[2/2] incubator-tamaya git commit: TAMAYA-134 Patch from Philipp
Ottlinger to fix a number of javadocs.
Posted by jo...@apache.org.
TAMAYA-134 Patch from Philipp Ottlinger to fix a number of javadocs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/5701c27e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/5701c27e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/5701c27e
Branch: refs/heads/master
Commit: 5701c27e7913765bda8d8332dfdf88859145ec0a
Parents: 9fd1cee
Author: John D. Ament <jo...@apache.org>
Authored: Sun Feb 14 11:23:17 2016 -0500
Committer: John D. Ament <jo...@apache.org>
Committed: Sun Feb 14 11:23:17 2016 -0500
----------------------------------------------------------------------
.../org/apache/tamaya/spi/PropertySource.java | 6 +-
.../org/apache/tamaya/spi/PropertyValue.java | 4 +-
.../apache/tamaya/spi/PropertyValueBuilder.java | 4 +-
.../tamaya/format/ConfigurationFormats.java | 52 +--
.../functions/ConfigurationFunctions.java | 12 +-
.../functions/PropertySourceFunctions.java | 31 +-
.../camel/TamayaPropertiesComponent.java | 12 +-
.../cdi/internal/TamayaCDIIntegration.java | 9 +-
.../integration/cdi/ConfigurationExtension.java | 3 +-
.../integration/cdi/ConfigurationProducer.java | 44 +-
.../org/apache/tamaya/etcd/EtcdAccessor.java | 448 ++++++++++---------
.../org/apache/tamaya/model/ConfigModel.java | 8 +-
.../apache/tamaya/model/ConfigModelManager.java | 8 +-
.../apache/tamaya/model/ValidationResult.java | 24 +-
.../ConfiguredResourcesModelProviderSpi.java | 83 ++--
.../model/spi/ConfigDocumentationMBean.java | 1 +
.../test/resources/examples/configmodel.json | 4 +-
.../tamaya/optional/OptionalConfiguration.java | 42 +-
modules/server/pom.xml | 1 -
.../tamaya/server/ConfigurationResource.java | 227 +++++-----
.../apache/tamaya/server/spi/ScopeManager.java | 27 +-
.../apache/tamaya/server/spi/ScopeProvider.java | 3 +-
22 files changed, 566 insertions(+), 487 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index ec2ef48..56d084c 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -27,7 +27,7 @@ import java.util.Map;
* properties may be read fromMap single or several sources (composite).
* PropertySources are the building blocks of the final configuration. </p>
* <h3>Implementation Requirements</h3>
- * <p>Implementations current this interface must be</p>
+ * <p>Implementations of this interface must be</p>
* <ul>
* <li>Thread safe.</li>
* </ul>
@@ -106,7 +106,7 @@ public interface PropertySource {
Map<String,String> getProperties();
/**
- * Determines if this config source could be scanned for its list of properties.
+ * Determines if this config source can be scanned for its list of properties.
*
* <p>
* PropertySources which are not scannable might not be able to find all the
@@ -114,7 +114,7 @@ public interface PropertySource {
* if the underlying storage doesn't support listing.
* </p>
*
- * @return {@code true} if this PropertySource could be scanned for its list of properties,
+ * @return {@code true} if this PropertySource can be scanned for its list of properties,
* {@code false} if it should not be scanned.
*/
boolean isScannable();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
index f56fa5d..30afeab 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
@@ -32,7 +32,7 @@ import java.util.Objects;
public final class PropertyValue {
/** The requested key. */
private String key;
- /** Additional metadata provided by thhe provider. */
+ /** Additional metadata provided by the provider. */
private Map<String,String> configEntries = new HashMap<>();
PropertyValue(PropertyValueBuilder builder){
@@ -64,7 +64,7 @@ public final class PropertyValue {
}
/**
- * THe value.
+ * The value.
* @return the value, in case a value is null it is valid to return {#code null} as result for
* {@link PropertySource#get(String)}.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
index 349ee6c..883e5c5 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
@@ -34,9 +34,11 @@ public class PropertyValueBuilder {
Map<String,String> contextData = new HashMap<>();
/**
- * Create a new builder instance, for a given
+ * Create a new builder instance, for a given set of parameters.
+ * @param key to access a property value.
* @param value the value, not null. If a value is null {@link PropertySource#get(String)} should return
* {@code null}.
+ * @param source property source.
*/
public PropertyValueBuilder(String key, String value, String source) {
this.key = Objects.requireNonNull(key);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
index 201a0f5..df9aa84 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/ConfigurationFormats.java
@@ -18,8 +18,6 @@
*/
package org.apache.tamaya.format;
-import org.apache.tamaya.spi.ServiceContextManager;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -33,6 +31,8 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.tamaya.spi.ServiceContextManager;
+
/**
* Small accessor and management class dealing with {@link org.apache.tamaya.format.ConfigurationFormat}
* instances.
@@ -65,9 +65,9 @@ public final class ConfigurationFormats {
* @return the currently available formats, never null.
*/
public static List<ConfigurationFormat> getFormats(String... formatNames) {
- List<ConfigurationFormat> result = new ArrayList<>();
- Set<String> names = new HashSet<>(Arrays.asList(formatNames));
- for (ConfigurationFormat f : getFormats()) {
+ final List<ConfigurationFormat> result = new ArrayList<>();
+ final Set<String> names = new HashSet<>(Arrays.asList(formatNames));
+ for (final ConfigurationFormat f : getFormats()) {
if (names.contains(f.getName())) {
result.add(f);
}
@@ -94,13 +94,13 @@ public final class ConfigurationFormats {
/**
* Get all currently available formats, ordered by priority.
*
- * @param url source to read configuration from.
+ * @param url source to read configuration from.
* @return the currently available formats, never null.
*/
public static List<ConfigurationFormat> getFormats(final URL url) {
- List<ConfigurationFormat> formats = getFormats();
- List<ConfigurationFormat> result = new ArrayList<>();
- for (ConfigurationFormat f : formats) {
+ final List<ConfigurationFormat> formats = getFormats();
+ final List<ConfigurationFormat> result = new ArrayList<>();
+ for (final ConfigurationFormat f : formats) {
if (f.accepts(url)) {
result.add(f);
}
@@ -117,7 +117,7 @@ public final class ConfigurationFormats {
* @throws IOException if the resource cannot be read.
*/
public static ConfigurationData readConfigurationData(final URL url) throws IOException {
- List<ConfigurationFormat> formats = getFormats(url);
+ final List<ConfigurationFormat> formats = getFormats(url);
return readConfigurationData(url, formats.toArray(new ConfigurationFormat[formats.size()]));
}
@@ -134,21 +134,20 @@ public final class ConfigurationFormats {
}
/**
- *
- * @param urls the urls from where to read, not null.
+ * @param urls the urls from where to read, not null.
* @param formats the formats to try.
* @return the {@link org.apache.tamaya.format.ConfigurationData} of the files successfully decoded by the
* given formats.
*/
public static Collection<ConfigurationData> getPropertySources(Collection<URL> urls, ConfigurationFormat... formats) {
- List<ConfigurationData> dataRead = new ArrayList<>();
- for (URL url : urls) {
+ final List<ConfigurationData> dataRead = new ArrayList<>();
+ for (final URL url : urls) {
try {
- ConfigurationData data = readConfigurationData(url, formats);
+ final ConfigurationData data = readConfigurationData(url, formats);
if (data != null) {
dataRead.add(data);
}
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.log(Level.SEVERE, "Error reading file: " + url.toExternalForm(), e);
}
}
@@ -158,7 +157,7 @@ public final class ConfigurationFormats {
/**
* Tries to read configuration data from a given URL, hereby explicitly trying all given formats in order.
*
- * @param resource a descriptive name for the resource, since an InputStream does not have any)
+ * @param resource a descriptive name for the resource, since an InputStream does not have any
* @param inputStream the inputStream from where to read, not null.
* @param formats the formats to try.
* @return the ConfigurationData read, or null.
@@ -168,16 +167,17 @@ public final class ConfigurationFormats {
ConfigurationFormat... formats) throws IOException {
Objects.requireNonNull(inputStream);
Objects.requireNonNull(resource);
- InputStreamFactory isFactory = new InputStreamFactory(inputStream);
- for (ConfigurationFormat format : formats) {
- try (InputStream is = isFactory.createInputStream()) {
- ConfigurationData data = format.readConfiguration(resource, is);
- if (data != null) {
- return data;
+ try (InputStreamFactory isFactory = new InputStreamFactory(inputStream)) {
+ for (final ConfigurationFormat format : formats) {
+ try (InputStream is = isFactory.createInputStream()) {
+ final ConfigurationData data = format.readConfiguration(resource, is);
+ if (data != null) {
+ return data;
+ }
+ } catch (final Exception e) {
+ LOG.log(Level.INFO,
+ "Format " + format.getClass().getName() + " failed to read resource " + resource, e);
}
- } catch (Exception e) {
- LOG.log(Level.INFO,
- "Format " + format.getClass().getName() + " failed to read resource " + resource, e);
}
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
index 5effaa7..eee3b02 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigurationFunctions.java
@@ -101,7 +101,6 @@ public final class ConfigurationFunctions {
}
};
-
/**
* Private singleton constructor.
*/
@@ -140,7 +139,6 @@ public final class ConfigurationFunctions {
};
}
-
/**
* Creates a ConfigOperator that creates a Configuration containing only keys
* that are contained in the given section (non recursive). Hereby
@@ -311,7 +309,6 @@ public final class ConfigurationFunctions {
};
}
-
/**
* Creates a ConfigOperator that creates a Configuration containing only keys
* that are contained in the given section (recursive).
@@ -340,6 +337,7 @@ public final class ConfigurationFunctions {
* Creates a {@link PropertySource}, based on the given {@link Configuration}. The keys and propertx map
* are dynamically calculated, so the returned PropertySource is a real dynamic wrapper.
* @param name the name of the property source, not null.
+ * @param ordinal ordinal of the property source.
* @param config the config to be mapped, not null.
* @return a property source wrapping the configuration.
*/
@@ -459,7 +457,7 @@ public final class ConfigurationFunctions {
}
/**
- * Creates a ConfigQuery that creates a plain text formatted ouitput of all properties in the given configuration.
+ * Creates a ConfigQuery that creates a plain text formatted output of all properties in the given configuration.
*
* @return the given query.
*/
@@ -468,8 +466,8 @@ public final class ConfigurationFunctions {
}
/**
- * Creates a ConfigQuery that creates a plain text formatted ouitput of all properties in the given configuration.
- *
+ * Creates a ConfigQuery that creates a plain text formatted output of all properties in the given configuration.
+ * @param info configuration values to use for filtering.
* @return the given query.
*/
public static ConfigQuery<String> textInfo(final Map<String, String> info) {
@@ -540,7 +538,7 @@ public final class ConfigurationFunctions {
/**
* Creates a ConfigQuery that creates a html formatted ouitput of all properties in the given configuration.
- *
+ * @param info configuration values to use for filtering.
* @return the given query.
*/
public static ConfigQuery<String> htmlInfo(final Map<String, String> info) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
index 23de455..93ff699 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
@@ -78,7 +78,7 @@ public final class PropertySourceFunctions {
}
/**
- * Calculates the current section key and compares it with the given key.
+ * Calculates the current section key and compares it to the given key.
*
* @param key the fully qualified entry key, not null
* @param sectionKey the section key, not null
@@ -91,7 +91,7 @@ public final class PropertySourceFunctions {
}
/**
- * Calculates the current section key and compares it with the given section keys.
+ * Calculates the current section key and compares it to the given section keys.
*
* @param key the fully qualified entry key, not null
* @param sectionKeys the section keys, not null
@@ -107,11 +107,12 @@ public final class PropertySourceFunctions {
}
/**
- * Return a query to evaluate the set with all fully qualifies section names. This method should return the sections as accurate as possible,
+ * Return a query to evaluate the set with all fully qualified section names. This method should return the sections as accurate as possible,
* but may not provide a complete set of sections that are finally accessible, especially when the underlying storage
* does not support key iteration.
*
- * @return s set with all sections, never {@code null}.
+ * @param properties properties to find sections in.
+ * @return set with all sections, never {@code null}.
*/
public static Set<String> sections(Map<String, String> properties) {
final Set<String> areas = new HashSet<>();
@@ -131,7 +132,8 @@ public final class PropertySourceFunctions {
* subarea names, regardless if properties are accessible or not. This method should return the sections as accurate
* as possible, but may not provide a complete set of sections that are finally accessible, especially when the
* underlying storage does not support key iteration.
- *
+ *
+ * @param properties properties to find transitive sections in.
* @return s set with all transitive sections, never {@code null}.
*/
public static Set<String> transitiveSections(Map<String, String> properties) {
@@ -156,8 +158,9 @@ public final class PropertySourceFunctions {
* sections that match the predicate and have properties attached. This method should return the sections as accurate as possible,
* but may not provide a complete set of sections that are finally accessible, especially when the underlying storage
* does not support key iteration.
- *
- * @param predicate A predicate to deternine, which sections should be returned, not {@code null}.
+ *
+ * @param properties properties to find sections in.
+ * @param predicate A predicate to determine, which sections should be returned, not {@code null}.
* @return s set with all sections, never {@code null}.
*/
public static Set<String> sections(Map<String, String> properties, final Predicate<String> predicate) {
@@ -176,7 +179,8 @@ public final class PropertySourceFunctions {
* but may not provide a complete set of sections that are finally accessible, especially when the underlying storage
* does not support key iteration.
*
- * @param predicate A predicate to deternine, which sections should be returned, not {@code null}.
+ * @param properties properties to find transitive sections in.
+ * @param predicate A predicate to determine, which sections should be returned, not {@code null}.
* @return s set with all transitive sections, never {@code null}.
*/
public static Set<String> transitiveSections(Map<String, String> properties, Predicate<String> predicate) {
@@ -193,8 +197,9 @@ public final class PropertySourceFunctions {
/**
* Creates a ConfigOperator that creates a Configuration containing only keys
* that are contained in the given section (recursive). Hereby
- * the section key is stripped away fromMap the resulting key.
+ * the section key is stripped away from the Map of the resulting keys.
*
+ * @param properties properties to find recursive sections in.
* @param sectionKeys the section keys, not null
* @return the section configuration, with the areaKey stripped away.
*/
@@ -206,6 +211,7 @@ public final class PropertySourceFunctions {
* Creates a ConfigOperator that creates a Configuration containing only keys
* that are contained in the given section (recursive).
*
+ * @param properties properties to find sections in.
* @param sectionKeys the section keys, not null
* @param stripKeys if set to true, the section key is stripped away fromMap the resulting key.
* @return the section configuration, with the areaKey stripped away.
@@ -247,6 +253,7 @@ public final class PropertySourceFunctions {
/**
* Creates a ConfigOperator that adds the given items.
*
+ * @param propertySource source property source that is changed.
* @param items the items to be added/replaced.
* @param override if true, all items existing are overridden by the new ones passed.
* @return the ConfigOperator, never null.
@@ -258,6 +265,7 @@ public final class PropertySourceFunctions {
/**
* Creates an operator that adds items to the instance.
*
+ * @param propertySource source property source that is changed.
* @param items the items, not null.
* @return the operator, never null.
*/
@@ -268,6 +276,7 @@ public final class PropertySourceFunctions {
/**
* Creates an operator that replaces the given items.
*
+ * @param propertySource source property source that is changed.
* @param items the items.
* @return the operator for replacing the items.
*/
@@ -305,6 +314,8 @@ public final class PropertySourceFunctions {
* Get a list of all {@link PropertySource} instances managed by the current
* {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given type.
*
+ * @param <T> the type of the property source instances requested
+ * @param type target type to filter for property sources.
* @return the list of all {@link PropertySource} instances matching, never null.
*/
public static <T> Collection<T> getPropertySources(Class<T> type) {
@@ -321,6 +332,8 @@ public final class PropertySourceFunctions {
* Get a list of all {@link PropertySource} instances managed by the current
* {@link org.apache.tamaya.spi.ConfigurationContext} that are assignable to the given type.
*
+ * @param <T> the type of the property source instances requested
+ * @param type target type to filter for property sources.
* @return the list of all {@link PropertySource} instances matching, never null.
*/
public static <T> T getPropertySource(Class<T> type) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/integration/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java
----------------------------------------------------------------------
diff --git a/modules/integration/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java b/modules/integration/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java
index f7a0a10..8b776a5 100644
--- a/modules/integration/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java
+++ b/modules/integration/camel/src/main/java/org/apache/tamaya/integration/camel/TamayaPropertiesComponent.java
@@ -18,11 +18,11 @@
*/
package org.apache.tamaya.integration.camel;
+import java.util.Properties;
+
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.tamaya.ConfigurationProvider;
-import java.util.Properties;
-
/**
* Default Camel PropertiesComponent that additionally has cfg and tamaya prefixes configured for resolution of
* entries from tamaya.
@@ -40,7 +40,8 @@ public class TamayaPropertiesComponent extends PropertiesComponent{
}
/**
- * Constructor similar to parent.
+ * Constructor similar to parent with additional locations.
+ * @param locations additional locations for Camel.
*/
public TamayaPropertiesComponent(String ... locations){
super(locations);
@@ -50,7 +51,8 @@ public class TamayaPropertiesComponent extends PropertiesComponent{
}
/**
- * Constructor similar to parent.
+ * Constructor similar to parent with only one location.
+ * @param location addition location for Camel.
*/
public TamayaPropertiesComponent(String location){
super(location);
@@ -66,7 +68,7 @@ public class TamayaPropertiesComponent extends PropertiesComponent{
*/
public void setTamayaOverrides(boolean enabled){
if(enabled){
- Properties props = new Properties();
+ final Properties props = new Properties();
props.putAll(ConfigurationProvider.getConfiguration().getProperties());
setOverrideProperties(props);
} else{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java
index 09ca92a..43d0074 100644
--- a/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java
+++ b/modules/integration/cdi-se/src/main/java/org/apache/tamaya/integration/cdi/internal/TamayaCDIIntegration.java
@@ -24,15 +24,15 @@ import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
/**
- * Tamaya main integreation with CDI, storing the BeanManager reference for implementation, where no
+ * Tamaya main integration with CDI, storing the BeanManager reference for implementation, where no
* JNDI is available or {@code java:comp/env/BeanManager} is not set correctly.
*/
-public class TamayaCDIIntegration implements Extension{
+public class TamayaCDIIntegration implements Extension {
/** The BeanManager references stored. */
private static BeanManager beanManager;
/**
- * Initializes the current BeanMaanager with the instance passed.
+ * Initializes the current BeanManager with the instance passed.
* @param validation the event
* @param beanManager the BeanManager instance
*/
@@ -42,7 +42,8 @@ public class TamayaCDIIntegration implements Extension{
}
/**
- * Get the current {@link BeanManager} instance.
+ * Get the current {@link BeanManager} instance.
+ * @return the currently used bean manager.
*/
public static BeanManager getBeanManager(){
return beanManager;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
index b7408bb..a6fee37 100644
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationExtension.java
@@ -65,6 +65,7 @@ public class ConfigurationExtension implements Extension {
/**
* Method that checks the configuration injection points during deployment for available configuration.
* @param pb the bean to process.
+ * @param beanManager the bean manager to notify about new injections.
*/
public void retrieveTypes(@Observes final ProcessBean<?> pb, BeanManager beanManager) {
@@ -104,7 +105,7 @@ public class ConfigurationExtension implements Extension {
}
if(value==null){
throw new ConfigException(String.format(
- "Can't resolve any of the possible config keys: %s. Please provide one of the given keys " +
+ "Cannot resolve any of the possible configuration keys: %s. Please provide one of the given keys " +
"with a value in your configuration sources.",
keys.toString()));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java
index b6d29cb..90bec41 100644
--- a/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java
+++ b/modules/integration/cdi/src/main/java/org/apache/tamaya/integration/cdi/ConfigurationProducer.java
@@ -50,10 +50,10 @@ public class ConfigurationProducer {
private DynamicValue createynamicValue(final InjectionPoint injectionPoint) {
Member member = injectionPoint.getMember();
- if(member instanceof Field) {
- return DefaultDynamicValue.of((Field)member, ConfigurationProvider.getConfiguration());
- } else if(member instanceof Method) {
- return DefaultDynamicValue.of((Method)member, ConfigurationProvider.getConfiguration());
+ if (member instanceof Field) {
+ return DefaultDynamicValue.of((Field) member, ConfigurationProvider.getConfiguration());
+ } else if (member instanceof Method) {
+ return DefaultDynamicValue.of((Method) member, ConfigurationProvider.getConfiguration());
}
return null;
}
@@ -61,61 +61,61 @@ public class ConfigurationProducer {
@Produces
@Config
public Object resolveAndConvert(final InjectionPoint injectionPoint) {
- if(DynamicValue.class.equals(injectionPoint.getAnnotated().getBaseType())){
+ if (DynamicValue.class.equals(injectionPoint.getAnnotated().getBaseType())) {
return createynamicValue(injectionPoint);
}
final Config annotation = injectionPoint.getAnnotated().getAnnotation(Config.class);
final ConfigDefaultSections typeAnnot = injectionPoint.getAnnotated().getAnnotation(ConfigDefaultSections.class);
final List<String> keys = ConfigurationExtension.evaluateKeys(injectionPoint.getMember().getName(),
- annotation!=null?annotation.value():null,
- typeAnnot!=null?typeAnnot.value():null);
+ annotation != null ? annotation.value() : null,
+ typeAnnot != null ? typeAnnot.value() : null);
final WithConfigOperator withOperatorAnnot = injectionPoint.getAnnotated().getAnnotation(WithConfigOperator.class);
ConfigOperator operator = null;
- if(withOperatorAnnot!=null){
+ if (withOperatorAnnot != null) {
operator = ConfigurationExtension.CUSTOM_OPERATORS.get(withOperatorAnnot.value());
}
PropertyConverter customCnverter = null;
final WithPropertyConverter withConverterAnnot = injectionPoint.getAnnotated().getAnnotation(WithPropertyConverter.class);
- if(withConverterAnnot!=null){
+ if (withConverterAnnot != null) {
customCnverter = ConfigurationExtension.CUSTOM_CONVERTERS.get(withConverterAnnot.value());
}
// unless the extension is not installed, this should never happen because the extension
// enforces the resolvability of the config
Configuration config = ConfigurationProvider.getConfiguration();
- if(operator!=null){
+ if (operator != null) {
config = operator.operate(config);
}
final Class<?> toType = (Class<?>) injectionPoint.getAnnotated().getBaseType();
String textValue = null;
- String defaultTextValue = annotation.defaultValue().isEmpty()?null:annotation.defaultValue();
+ String defaultTextValue = annotation.defaultValue().isEmpty() ? null : annotation.defaultValue();
String keyFound = null;
- for(String key:keys) {
+ for (String key : keys) {
textValue = config.get(key);
- if(textValue!=null){
+ if (textValue != null) {
keyFound = key;
break;
}
}
ConversionContext.Builder builder = new ConversionContext.Builder(config, keyFound, TypeLiteral.of(toType));
- if(injectionPoint.getMember() instanceof AnnotatedElement){
- builder.setAnnotatedElement((AnnotatedElement)injectionPoint.getMember());
+ if (injectionPoint.getMember() instanceof AnnotatedElement) {
+ builder.setAnnotatedElement((AnnotatedElement) injectionPoint.getMember());
}
ConversionContext conversionContext = builder.build();
Object value = null;
- if(keyFound!=null){
- if(customCnverter!=null) {
+ if (keyFound != null) {
+ if (customCnverter != null) {
value = customCnverter.convert(textValue, conversionContext);
}
- if(value==null){
+ if (value == null) {
value = config.get(keyFound, toType);
}
- } else if(defaultTextValue!=null){
- if(customCnverter!=null) {
+ } else if (defaultTextValue != null) {
+ if (customCnverter != null) {
value = customCnverter.convert(defaultTextValue, conversionContext);
}
- if(value==null) {
+ if (value == null) {
List<PropertyConverter<Object>> converters = ConfigurationProvider.getConfigurationContext()
.getPropertyConverters(TypeLiteral.of(toType));
for (PropertyConverter<Object> converter : converters) {
@@ -133,7 +133,7 @@ public class ConfigurationProducer {
}
}
}
- if(value==null){
+ if (value == null) {
throw new ConfigException(String.format(
"Can't resolve any of the possible config keys: %s to the required target type: %s, supported formats: %s",
keys.toString(), toType.getName(), conversionContext.getSupportedFormats().toString()));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
----------------------------------------------------------------------
diff --git a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
index 677d369..0452c40 100644
--- a/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
+++ b/modules/integration/etcd/src/main/java/org/apache/tamaya/etcd/EtcdAccessor.java
@@ -18,6 +18,21 @@
*/
package org.apache.tamaya.etcd;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
@@ -32,64 +47,67 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonReaderFactory;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
/**
- * Accessor for reading/writing an etcd endpoint.
+ * Accessor for reading to or writing from an etcd endpoint.
*/
public class EtcdAccessor {
private static final Logger LOG = Logger.getLogger(EtcdAccessor.class.getName());
- /** Timeout in seconds. */
+ /**
+ * Timeout in seconds.
+ */
private int timeout = 2;
- /** Timeout in seconds. */
- private int socketTimeout = 1000;
- /** Timeout in seconds. */
- private int connectTimeout = 1000;
+ /**
+ * Timeout in seconds.
+ */
+ private final int socketTimeout = 1000;
+ /**
+ * Timeout in seconds.
+ */
+ private final int connectTimeout = 1000;
- /** Property that make Johnzon accept commentc. */
+ /**
+ * Property that make Johnzon accept commentc.
+ */
public static final String JOHNZON_SUPPORTS_COMMENTS_PROP = "org.apache.johnzon.supports-comments";
- /** The JSON reader factory used. */
+ /**
+ * The JSON reader factory used.
+ */
private final JsonReaderFactory readerFactory = initReaderFactory();
- /** Initializes the factory to be used for creating readers. */
+ /**
+ * Initializes the factory to be used for creating readers.
+ */
private JsonReaderFactory initReaderFactory() {
- Map<String, Object> config = new HashMap<>();
+ final Map<String, Object> config = new HashMap<>();
config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
return Json.createReaderFactory(config);
}
- /** The base server url. */
+ /**
+ * The base server url.
+ */
private final String serverURL;
- /** The http client. */
- private CloseableHttpClient httpclient = HttpClients.createDefault();
+ /**
+ * The http client.
+ */
+ private final CloseableHttpClient httpclient = HttpClients.createDefault();
/**
* Creates a new instance with the basic access url.
+ *
* @param server server url, e.g. {@code http://127.0.0.1:4001}, not null.
*/
- public EtcdAccessor(String server){
+ public EtcdAccessor(String server) {
this(server, 2);
}
public EtcdAccessor(String server, int timeout) {
this.timeout = timeout;
- if(server.endsWith("/")){
- serverURL = server.substring(0, server.length()-1);
- } else{
+ if (server.endsWith("/")) {
+ serverURL = server.substring(0, server.length() - 1);
+ } else {
serverURL = server;
}
@@ -97,16 +115,17 @@ public class EtcdAccessor {
/**
* Get the etcd server version.
+ *
* @return the etcd server version, never null.
*/
- public String getVersion(){
+ public String getVersion() {
CloseableHttpResponse response = null;
String version = "<ERROR>";
try {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpGet httpGet = new HttpGet(serverURL + "/version");
+ final CloseableHttpClient httpclient = HttpClients.createDefault();
+ final HttpGet httpGet = new HttpGet(serverURL + "/version");
httpGet.setConfig(RequestConfig.copy(RequestConfig.DEFAULT)
- .setSocketTimeout(socketTimeout).setConnectTimeout(timeout).build());
+ .setSocketTimeout(socketTimeout).setConnectTimeout(timeout).build());
response = httpclient.execute(httpGet);
HttpEntity entity;
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
@@ -116,13 +135,13 @@ public class EtcdAccessor {
EntityUtils.consume(entity);
}
return version;
- } catch(Exception e){
+ } catch (final Exception e) {
LOG.log(Level.INFO, "Error getting etcd version from: " + serverURL, e);
} finally {
- if(response!=null){
+ if (response != null) {
try {
response.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
LOG.log(Level.WARNING, "Failed to close http response", e);
}
}
@@ -131,16 +150,16 @@ public class EtcdAccessor {
}
/**
- * Ask etcd for s aingle key, value pair. Hereby the response returned from etcd:
+ * Ask etcd for a single key, value pair. Hereby the response returned from etcd:
* <pre>
* {
- "action": "get",
- "node": {
- "createdIndex": 2,
- "key": "/message",
- "modifiedIndex": 2,
- "value": "Hello world"
- }
+ * "action": "get",
+ * "node": {
+ * "createdIndex": 2,
+ * "key": "/message",
+ * "modifiedIndex": 2,
+ * "value": "Hello world"
+ * }
* }
* </pre>
* is mapped to:
@@ -152,66 +171,60 @@ public class EtcdAccessor {
* _key.ttl=300
* _key.expiration=...
* </pre>
+ *
* @param key the requested key
* @return the mapped result, including meta-entries.
*/
- public Map<String,String> get(String key){
- CloseableHttpResponse response = null;
- Map<String,String> result = new HashMap<>();
+ public Map<String, String> get(String key) {
+ final Map<String, String> result = new HashMap<>();
try {
- HttpGet httpGet = new HttpGet(serverURL + "/v2/keys/"+key);
+ final HttpGet httpGet = new HttpGet(serverURL + "/v2/keys/" + key);
httpGet.setConfig(RequestConfig.copy(RequestConfig.DEFAULT)
- .setSocketTimeout(socketTimeout)
+ .setSocketTimeout(socketTimeout)
.setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
- response = httpclient.execute(httpGet);
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- HttpEntity entity = response.getEntity();
- JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
- JsonObject o = reader.readObject();
- JsonObject node = o.getJsonObject("node");
- if(node.containsKey("value")) {
- result.put(key, node.getString("value"));
- result.put("_" + key +".source", "[etcd]"+serverURL);
- }
- if(node.containsKey("createdIndex")) {
- result.put("_" + key +".createdIndex", String.valueOf(node.getInt("createdIndex")));
- }
- if(node.containsKey("modifiedIndex")) {
- result.put("_" + key +".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
- }
- if(node.containsKey("expiration")) {
- result.put("_" + key +".expiration", String.valueOf(node.getString("expiration")));
- }
- if(node.containsKey("ttl")) {
- result.put("_" + key +".ttl", String.valueOf(node.getInt("ttl")));
- }
- EntityUtils.consume(entity);
- }else{
- result.put("_" + key +".NOT_FOUND.target", "[etcd]"+serverURL);
- }
- } catch(Exception e){
- LOG.log(Level.INFO, "Error reading key '"+key+"' from etcd: " + serverURL, e);
- result.put("_ERROR", "Error reading key '"+key+"' from etcd: " + serverURL + ": " + e.toString());
- } finally {
- if(response!=null){
- try {
- response.close();
- } catch (IOException e) {
- LOG.log(Level.WARNING, "Failed to close http response", e);
+ try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+ final HttpEntity entity = response.getEntity();
+ final JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
+ final JsonObject o = reader.readObject();
+ final JsonObject node = o.getJsonObject("node");
+ if (node.containsKey("value")) {
+ result.put(key, node.getString("value"));
+ result.put("_" + key + ".source", "[etcd]" + serverURL);
+ }
+ if (node.containsKey("createdIndex")) {
+ result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
+ }
+ if (node.containsKey("modifiedIndex")) {
+ result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
+ }
+ if (node.containsKey("expiration")) {
+ result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration")));
+ }
+ if (node.containsKey("ttl")) {
+ result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
+ }
+ EntityUtils.consume(entity);
+ } else {
+ result.put("_" + key + ".NOT_FOUND.target", "[etcd]" + serverURL);
}
}
+ } catch (final Exception e) {
+ LOG.log(Level.INFO, "Error reading key '" + key + "' from etcd: " + serverURL, e);
+ result.put("_ERROR", "Error reading key '" + key + "' from etcd: " + serverURL + ": " + e.toString());
}
return result;
}
/**
* Creates/updates an entry in etcd without any ttl set.
- * @see #set(String, String, Integer)
- * @param key the property key, not null
+ *
+ * @param key the property key, not null
* @param value the value to be set
* @return the result map as described above.
+ * @see #set(String, String, Integer)
*/
- public Map<String,String> set(String key, String value){
+ public Map<String, String> set(String key, String value) {
return set(key, value, null);
}
@@ -219,20 +232,20 @@ public class EtcdAccessor {
* Creates/updates an entry in etcd. The response as follows:
* <pre>
* {
- "action": "set",
- "node": {
- "createdIndex": 3,
- "key": "/message",
- "modifiedIndex": 3,
- "value": "Hello etcd"
- },
- "prevNode": {
- "createdIndex": 2,
- "key": "/message",
- "value": "Hello world",
- "modifiedIndex": 2
- }
- }
+ * "action": "set",
+ * "node": {
+ * "createdIndex": 3,
+ * "key": "/message",
+ * "modifiedIndex": 3,
+ * "value": "Hello etcd"
+ * },
+ * "prevNode": {
+ * "createdIndex": 2,
+ * "key": "/message",
+ * "value": "Hello world",
+ * "modifiedIndex": 2
+ * }
+ * }
* </pre>
* is mapped to:
* <pre>
@@ -248,71 +261,72 @@ public class EtcdAccessor {
* _key.prevNode.ttl=300
* _key.prevNode.expiration=...
* </pre>
- * @param key the property key, not null
- * @param value the value to be set
+ *
+ * @param key the property key, not null
+ * @param value the value to be set
* @param ttlSeconds the ttl in seconds (optional)
* @return the result map as described above.
*/
- public Map<String,String> set(String key, String value, Integer ttlSeconds){
+ public Map<String, String> set(String key, String value, Integer ttlSeconds) {
CloseableHttpResponse response = null;
- Map<String,String> result = new HashMap<>();
- try{
- HttpPut put = new HttpPut(serverURL + "/v2/keys/"+key);
+ final Map<String, String> result = new HashMap<>();
+ try {
+ final HttpPut put = new HttpPut(serverURL + "/v2/keys/" + key);
put.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout)
.setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
- List<NameValuePair> nvps = new ArrayList<>();
+ final List<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("value", value));
- if(ttlSeconds!=null){
+ if (ttlSeconds != null) {
nvps.add(new BasicNameValuePair("ttl", ttlSeconds.toString()));
}
put.setEntity(new UrlEncodedFormEntity(nvps));
response = httpclient.execute(put);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED ||
response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- HttpEntity entity = response.getEntity();
- JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
- JsonObject o = reader.readObject();
- JsonObject node = o.getJsonObject("node");
- if(node.containsKey("createdIndex")) {
- result.put("_" + key +".createdIndex", String.valueOf(node.getInt("createdIndex")));
+ final HttpEntity entity = response.getEntity();
+ final JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
+ final JsonObject o = reader.readObject();
+ final JsonObject node = o.getJsonObject("node");
+ if (node.containsKey("createdIndex")) {
+ result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
}
- if(node.containsKey("modifiedIndex")) {
- result.put("_" + key +".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
+ if (node.containsKey("modifiedIndex")) {
+ result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
}
- if(node.containsKey("expiration")) {
- result.put("_" + key +".expiration", String.valueOf(node.getString("expiration")));
+ if (node.containsKey("expiration")) {
+ result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration")));
}
- if(node.containsKey("ttl")) {
- result.put("_" + key +".ttl", String.valueOf(node.getInt("ttl")));
+ if (node.containsKey("ttl")) {
+ result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
}
result.put(key, node.getString("value"));
- result.put("_" + key +".source", "[etcd]"+serverURL);
- if(node.containsKey("prevNode")){
- JsonObject prevNode = node.getJsonObject("prevNode");
+ result.put("_" + key + ".source", "[etcd]" + serverURL);
+ if (node.containsKey("prevNode")) {
+ final JsonObject prevNode = node.getJsonObject("prevNode");
if (prevNode.containsKey("createdIndex")) {
- result.put("_" + key +".prevNode.createdIndex", String.valueOf(prevNode.getInt("createdIndex")));
+ result.put("_" + key + ".prevNode.createdIndex", String.valueOf(prevNode.getInt("createdIndex")));
}
if (prevNode.containsKey("modifiedIndex")) {
- result.put("_" + key +".prevNode.modifiedIndex", String.valueOf(prevNode.getInt("modifiedIndex")));
+ result.put("_" + key + ".prevNode.modifiedIndex", String.valueOf(prevNode.getInt("modifiedIndex")));
}
- if(prevNode.containsKey("expiration")) {
- result.put("_" + key +".prevNode.expiration", String.valueOf(prevNode.getString("expiration")));
+ if (prevNode.containsKey("expiration")) {
+ result.put("_" + key + ".prevNode.expiration", String.valueOf(prevNode.getString("expiration")));
}
- if(prevNode.containsKey("ttl")) {
- result.put("_" + key +".prevNode.ttl", String.valueOf(prevNode.getInt("ttl")));
+ if (prevNode.containsKey("ttl")) {
+ result.put("_" + key + ".prevNode.ttl", String.valueOf(prevNode.getInt("ttl")));
}
- result.put("_" + key +".prevNode.value", prevNode.getString("value"));
+ result.put("_" + key + ".prevNode.value", prevNode.getString("value"));
}
EntityUtils.consume(entity);
}
- } catch(Exception e){
+ } catch (final Exception e) {
LOG.log(Level.INFO, "Error writing to etcd: " + serverURL, e);
- result.put("_ERROR", "Error writing '"+key+"' to etcd: " + serverURL + ": " + e.toString());
+ result.put("_ERROR", "Error writing '" + key + "' to etcd: " + serverURL + ": " + e.toString());
} finally {
- if(response!=null){
+ if (response != null) {
try {
response.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
LOG.log(Level.WARNING, "Failed to close http response", e);
}
}
@@ -336,60 +350,61 @@ public class EtcdAccessor {
* _key.prevNode.expiration=...
* _key.prevNode.value=...
* </pre>
+ *
* @param key the key to be deleted.
* @return the response mpas as described above.
*/
- public Map<String,String> delete(String key){
+ public Map<String, String> delete(String key) {
CloseableHttpResponse response = null;
- Map<String,String> result = new HashMap<>();
- try{
- HttpDelete delete = new HttpDelete(serverURL + "/v2/keys/"+key);
+ final Map<String, String> result = new HashMap<>();
+ try {
+ final HttpDelete delete = new HttpDelete(serverURL + "/v2/keys/" + key);
delete.setConfig(RequestConfig.copy(RequestConfig.DEFAULT).setSocketTimeout(socketTimeout)
.setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
response = httpclient.execute(delete);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- HttpEntity entity = response.getEntity();
- JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
- JsonObject o = reader.readObject();
- JsonObject node = o.getJsonObject("node");
- if(node.containsKey("createdIndex")) {
- result.put("_" + key +".createdIndex", String.valueOf(node.getInt("createdIndex")));
+ final HttpEntity entity = response.getEntity();
+ final JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
+ final JsonObject o = reader.readObject();
+ final JsonObject node = o.getJsonObject("node");
+ if (node.containsKey("createdIndex")) {
+ result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
}
- if(node.containsKey("modifiedIndex")) {
- result.put("_" + key +".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
+ if (node.containsKey("modifiedIndex")) {
+ result.put("_" + key + ".modifiedIndex", String.valueOf(node.getInt("modifiedIndex")));
}
- if(node.containsKey("expiration")) {
- result.put("_" + key +".expiration", String.valueOf(node.getString("expiration")));
+ if (node.containsKey("expiration")) {
+ result.put("_" + key + ".expiration", String.valueOf(node.getString("expiration")));
}
- if(node.containsKey("ttl")) {
- result.put("_" + key +".ttl", String.valueOf(node.getInt("ttl")));
+ if (node.containsKey("ttl")) {
+ result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
}
- if(o.containsKey("prevNode")){
- JsonObject prevNode = o.getJsonObject("prevNode");
+ if (o.containsKey("prevNode")) {
+ final JsonObject prevNode = o.getJsonObject("prevNode");
if (prevNode.containsKey("createdIndex")) {
- result.put("_" + key +".prevNode.createdIndex", String.valueOf(prevNode.getInt("createdIndex")));
+ result.put("_" + key + ".prevNode.createdIndex", String.valueOf(prevNode.getInt("createdIndex")));
}
if (prevNode.containsKey("modifiedIndex")) {
- result.put("_" + key +".prevNode.modifiedIndex", String.valueOf(prevNode.getInt("modifiedIndex")));
+ result.put("_" + key + ".prevNode.modifiedIndex", String.valueOf(prevNode.getInt("modifiedIndex")));
}
- if(prevNode.containsKey("expiration")) {
- result.put("_" + key +".prevNode.expiration", String.valueOf(prevNode.getString("expiration")));
+ if (prevNode.containsKey("expiration")) {
+ result.put("_" + key + ".prevNode.expiration", String.valueOf(prevNode.getString("expiration")));
}
- if(prevNode.containsKey("ttl")) {
- result.put("_" + key +".prevNode.ttl", String.valueOf(prevNode.getInt("ttl")));
+ if (prevNode.containsKey("ttl")) {
+ result.put("_" + key + ".prevNode.ttl", String.valueOf(prevNode.getInt("ttl")));
}
- result.put("_" + key +".prevNode.value", prevNode.getString("value"));
+ result.put("_" + key + ".prevNode.value", prevNode.getString("value"));
}
EntityUtils.consume(entity);
}
- } catch(Exception e){
- LOG.log(Level.INFO, "Error deleting key '"+key+"' from etcd: " + serverURL, e);
- result.put("_ERROR", "Error deleting '"+key+"' from etcd: " + serverURL + ": " + e.toString());
+ } catch (final Exception e) {
+ LOG.log(Level.INFO, "Error deleting key '" + key + "' from etcd: " + serverURL, e);
+ result.put("_ERROR", "Error deleting '" + key + "' from etcd: " + serverURL + ": " + e.toString());
} finally {
- if(response!=null){
+ if (response != null) {
try {
response.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
LOG.log(Level.WARNING, "Failed to close http response", e);
}
}
@@ -399,11 +414,12 @@ public class EtcdAccessor {
/**
* Get all properties for the given directory key recursively.
- * @see #getProperties(String, boolean)
+ *
* @param directory the directory entry
* @return the properties and its metadata
+ * @see #getProperties(String, boolean)
*/
- public Map<String,String> getProperties(String directory){
+ public Map<String, String> getProperties(String directory) {
return getProperties(directory, true);
}
@@ -411,30 +427,30 @@ public class EtcdAccessor {
* Access all properties.
* The response of:
* <pre>
- {
- "action": "get",
- "node": {
- "key": "/",
- "dir": true,
- "nodes": [
- {
- "key": "/foo_dir",
- "dir": true,
- "modifiedIndex": 2,
- "createdIndex": 2
- },
- {
- "key": "/foo",
- "value": "two",
- "modifiedIndex": 1,
- "createdIndex": 1
- }
- ]
- }
-}
- </pre>
- is mapped to a regular Tamaya properties map as follows:
- <pre>
+ * {
+ * "action": "get",
+ * "node": {
+ * "key": "/",
+ * "dir": true,
+ * "nodes": [
+ * {
+ * "key": "/foo_dir",
+ * "dir": true,
+ * "modifiedIndex": 2,
+ * "createdIndex": 2
+ * },
+ * {
+ * "key": "/foo",
+ * "value": "two",
+ * "modifiedIndex": 1,
+ * "createdIndex": 1
+ * }
+ * ]
+ * }
+ * }
+ * </pre>
+ * is mapped to a regular Tamaya properties map as follows:
+ * <pre>
* key1=myvalue
* _key1.source=[etcd]http://127.0.0.1:4001
* _key1.createdIndex=12
@@ -451,34 +467,38 @@ public class EtcdAccessor {
* _key3.createdIndex=12
* _key3.modifiedIndex=2
* </pre>
+ *
+ * @param directory remote directory to query.
+ * @param recursive allows to set if querying is performed recursively
+ * @return all properties read from the remote server.
*/
- public Map<String,String> getProperties(String directory, boolean recursive){
+ public Map<String, String> getProperties(String directory, boolean recursive) {
CloseableHttpResponse response = null;
- Map<String,String> result = new HashMap<>();
- try{
- HttpGet get = new HttpGet(serverURL + "/v2/keys/"+directory+"?recursive="+recursive);
+ final Map<String, String> result = new HashMap<>();
+ try {
+ final HttpGet get = new HttpGet(serverURL + "/v2/keys/" + directory + "?recursive=" + recursive);
get.setConfig(RequestConfig.copy(RequestConfig.DEFAULT)
.setSocketTimeout(socketTimeout)
.setConnectionRequestTimeout(timeout).setConnectTimeout(connectTimeout).build());
response = httpclient.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
- HttpEntity entity = response.getEntity();
- JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
- JsonObject o = reader.readObject();
- JsonObject node = o.getJsonObject("node");
- if(node!=null){
+ final HttpEntity entity = response.getEntity();
+ final JsonReader reader = readerFactory.createReader(new StringReader(EntityUtils.toString(entity)));
+ final JsonObject o = reader.readObject();
+ final JsonObject node = o.getJsonObject("node");
+ if (node != null) {
addNodes(result, node);
}
EntityUtils.consume(entity);
}
- } catch(Exception e){
- LOG.log(Level.INFO, "Error reading properties for '"+directory+"' from etcd: " + serverURL, e);
- result.put("_ERROR", "Error reading properties for '"+directory+"' from etcd: " + serverURL + ": " + e.toString());
+ } catch (final Exception e) {
+ LOG.log(Level.INFO, "Error reading properties for '" + directory + "' from etcd: " + serverURL, e);
+ result.put("_ERROR", "Error reading properties for '" + directory + "' from etcd: " + serverURL + ": " + e.toString());
} finally {
- if(response!=null){
+ if (response != null) {
try {
response.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
LOG.log(Level.WARNING, "Failed to close http response", e);
}
}
@@ -488,12 +508,13 @@ public class EtcdAccessor {
/**
* Recursively read out all key/values from this etcd JSON array.
+ *
* @param result map with key, values and metadata.
- * @param node the node to parse.
+ * @param node the node to parse.
*/
private void addNodes(Map<String, String> result, JsonObject node) {
- if(!node.containsKey("dir") || "false".equals(node.get("dir").toString())) {
- String key = node.getString("key").substring(1);
+ if (!node.containsKey("dir") || "false".equals(node.get("dir").toString())) {
+ final String key = node.getString("key").substring(1);
result.put(key, node.getString("value"));
if (node.containsKey("createdIndex")) {
result.put("_" + key + ".createdIndex", String.valueOf(node.getInt("createdIndex")));
@@ -507,9 +528,9 @@ public class EtcdAccessor {
if (node.containsKey("ttl")) {
result.put("_" + key + ".ttl", String.valueOf(node.getInt("ttl")));
}
- result.put("_" + key +".source", "[etcd]"+serverURL);
+ result.put("_" + key + ".source", "[etcd]" + serverURL);
} else {
- JsonArray nodes = node.getJsonArray("nodes");
+ final JsonArray nodes = node.getJsonArray("nodes");
if (nodes != null) {
for (int i = 0; i < nodes.size(); i++) {
addNodes(result, nodes.getJsonObject(i));
@@ -520,7 +541,8 @@ public class EtcdAccessor {
/**
* Access the server root URL used by this accessor.
- * @return
+ *
+ * @return the server root URL.
*/
public String getUrl() {
return serverURL;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
index 0c24e1c..d03e691 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModel.java
@@ -23,13 +23,12 @@ import org.apache.tamaya.Configuration;
import java.util.Collection;
/**
- * Basis structure describing a validated item, by default a parameter or a section.
+ * Base structure describing a validated item, by default a parameter or a section.
*/
public interface ConfigModel {
-
/**
- * Get the type of item that is modelled..
+ * Get the type of item that is modelled.
* @return the modelled type, never null.
*/
ModelType getType();
@@ -43,11 +42,12 @@ public interface ConfigModel {
* Dependency: mydepClassname
* CombinationPolicy: a.b.c.MyCombinationPolicyClass
* </pre>
+ * @return the item's name.
*/
String getName();
/**
- * CHeck if this validation is a required one.
+ * Check if this validation is a required one.
* @return true, if this validation is required.
*/
boolean isRequired();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
index c87369a..03e6361 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
@@ -85,8 +85,11 @@ public final class ConfigModelManager {
}
/**
- * Find the validations by checking the validation's name using the given regular expression.
+ * Find the validations by matching the validation's name against the given model type.
+ *
* @param name the name to use, not null.
+ * @param modelType classname of the target model type.
+ * @param <T> type of the model to filter for.
* @return the sections defined, never null.
*/
public static <T extends ConfigModel> T getModel(String name, Class<T> modelType) {
@@ -149,6 +152,7 @@ public final class ConfigModelManager {
* Validates the given configuration.
*
* @param config the configuration to be validated against, not null.
+ * @param showUndefined allows filtering for undefined configuration elements.
* @return the validation results, never null.
*/
public static Collection<ValidationResult> validate(Configuration config, boolean showUndefined) {
@@ -215,6 +219,8 @@ public final class ConfigModelManager {
/**
* Registers the {@link ConfigDocumentationMBean} mbean for accessing config documentation into the local platform
* mbean server.
+ *
+ * @param context allows to specify an additional MBean context, maybe {@code null}.
*/
public static void registerMBean(String context) {
try{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java b/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
index 203a73d..bb6dedb 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/ValidationResult.java
@@ -46,6 +46,7 @@ public final class ValidationResult {
* Creates a new ValidationResult.
*
* @param configModel the configModel item, not null.
+ * @return a new validation result containing valid parts of the given model.
*/
public static ValidationResult ofValid(ConfigModel configModel) {
return new ValidationResult(configModel, ValidationState.VALID, null);
@@ -55,17 +56,18 @@ public final class ValidationResult {
* Creates a new ValidationResult.
*
* @param configModel the configModel item, not null.
+ * @return a new validation result containing missing parts of the given model.
*/
public static ValidationResult ofMissing(ConfigModel configModel) {
return new ValidationResult(configModel, ValidationState.MISSING, null);
}
-
/**
* Creates a new ValidationResult.
*
* @param configModel the configModel item, not null.
- * @param message Additional message to be shown (optional).
+ * @param message Additional message to be shown (optional).
+ * @return a new validation result containing missing parts of the given model with a message.
*/
public static ValidationResult ofMissing(ConfigModel configModel, String message) {
return new ValidationResult(configModel, ValidationState.MISSING, message);
@@ -75,6 +77,8 @@ public final class ValidationResult {
* Creates a new ValidationResult.
*
* @param configModel the configModel item, not null.
+ * @param error error message to add.
+ * @return a new validation result containing erroneous parts of the given model with the given error message.
*/
public static ValidationResult ofError(ConfigModel configModel, String error) {
return new ValidationResult(configModel, ValidationState.ERROR, error);
@@ -84,6 +88,8 @@ public final class ValidationResult {
* Creates a new ValidationResult.
*
* @param configModel the configModel item, not null.
+ * @param warning warning message to add.
+ * @return a new validation result containing warning parts of the given model with the given warning message.
*/
public static ValidationResult ofWarning(ConfigModel configModel, String warning) {
return new ValidationResult(configModel, ValidationState.WARNING, warning);
@@ -93,15 +99,18 @@ public final class ValidationResult {
* Creates a new ValidationResult.
*
* @param configModel the configModel item, not null.
+ * @param alternativeUsage allows setting a message to indicate non-deprecated replacement, maybe null.
+ * @return a new validation result containing deprecated parts of the given model with an optional message.
*/
- public static ValidationResult ofDeprecated(ConfigModel configModel, String alternateUsage) {
- return new ValidationResult(configModel, ValidationState.DEPRECATED, alternateUsage != null ? "Use instead: " + alternateUsage : null);
+ public static ValidationResult ofDeprecated(ConfigModel configModel, String alternativeUsage) {
+ return new ValidationResult(configModel, ValidationState.DEPRECATED, alternativeUsage != null ? "Use instead: " + alternativeUsage : null);
}
/**
* Creates a new ValidationResult.
*
* @param configModel the configModel item, not null.
+ * @return a new validation result containing deprecated parts of the given model.
*/
public static ValidationResult ofDeprecated(ConfigModel configModel) {
return new ValidationResult(configModel, ValidationState.DEPRECATED, null);
@@ -110,10 +119,12 @@ public final class ValidationResult {
/**
* Creates a new ValidationResult.
*
- * @param key the name/key
+ * @param key the name/model key
+ * @param type model type
+ * @param provider model provider name
* @return a corresponding configModel item
*/
- public static ValidationResult ofUndefined(final String key, final ModelType type, String provider) {
+ public static ValidationResult ofUndefined(final String key, final ModelType type, final String provider) {
return new ValidationResult(new AbstractModel(key, false, "Undefined key: " + key, provider) {
@Override
@@ -135,6 +146,7 @@ public final class ValidationResult {
* @param configModel the configModel item, not null.
* @param result the configModel result, not null.
* @param message the detail message.
+ * @return new validation result.
*/
public static ValidationResult of(ConfigModel configModel, ValidationState result, String message) {
return new ValidationResult(configModel, result, message);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
index d16855f..2a136aa 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/internal/ConfiguredResourcesModelProviderSpi.java
@@ -18,14 +18,6 @@
*/
package org.apache.tamaya.model.internal;
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormats;
-import org.apache.tamaya.model.ConfigModel;
-import org.apache.tamaya.model.spi.ConfigModelReader;
-import org.apache.tamaya.model.spi.ModelProviderSpi;
-import org.apache.tamaya.resource.ConfigResources;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -37,46 +29,76 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.format.ConfigurationData;
+import org.apache.tamaya.format.ConfigurationFormats;
+import org.apache.tamaya.model.ConfigModel;
+import org.apache.tamaya.model.spi.ConfigModelReader;
+import org.apache.tamaya.model.spi.ModelProviderSpi;
+import org.apache.tamaya.resource.ConfigResources;
+
/**
* ConfigModel provider that reads model metadata from property files from
* {@code classpath*:META-INF/configmodel.json} in the following format:
* <pre>
+ * Example of a configuration metamodel expressed via YAML.
+ * Structure is shown through indentation (one or more spaces).
+ * Sequence items are denoted by a dash,
+ * key value pairs within a map are separated by a colon.
* </pre>
*/
public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi {
- /** The logger. */
+ /**
+ * The logger.
+ */
private static final Logger LOG = Logger.getLogger(ConfiguredResourcesModelProviderSpi.class.getName());
- /** The parameter that can be used to configure the location of the configuration model resources. */
+ /**
+ * The parameter that can be used to configure the location of the configuration model resources.
+ */
private static final String MODEL_RESOURCE_PARAM = "org.apache.tamaya.model.resources";
- /** The resource class to checked for testing the availability of the resources extension module. */
+ /**
+ * The resource class to checked for testing the availability of the resources extension module.
+ */
private static final String CONFIG_RESOURCE_CLASS = "org.apache.tamaya.resource.ConfigResource";
- /** The resource class to checked for testing the availability of the formats extension module. */
+ /**
+ * The resource class to checked for testing the availability of the formats extension module.
+ */
private static final String CONFIGURATION_FORMATS_CLASS = "org.apache.tamaya.format.ConfigurationFormats";
- /** Initializes the flag showing if the formats module is present (required). */
+ /**
+ * Initializes the flag showing if the formats module is present (required).
+ */
private static final boolean AVAILABLE = checkAvailabilityFormats();
- /** Initializes the flag showing if the resources module is present (optional). */
+ /**
+ * Initializes the flag showing if the resources module is present (optional).
+ */
private static final boolean RESOURCES_EXTENSION_AVAILABLE = checkAvailabilityResources();
- /** The configModels read. */
+ /**
+ * The configModels read.
+ */
private List<ConfigModel> configModels = new ArrayList<>();
- /** Initializes the flag showing if the formats module is present (required). */
+ /**
+ * Initializes the flag showing if the formats module is present (required).
+ */
private static boolean checkAvailabilityFormats() {
try {
Class.forName(CONFIGURATION_FORMATS_CLASS);
return true;
- } catch (Exception e) {
+ } catch (final Exception e) {
return false;
}
}
- /** Initializes the flag showing if the resources module is present (optional). */
+ /**
+ * Initializes the flag showing if the resources module is present (optional).
+ */
private static boolean checkAvailabilityResources() {
try {
Class.forName(CONFIG_RESOURCE_CLASS);
return true;
- } catch (Exception e) {
+ } catch (final Exception e) {
return false;
}
}
@@ -88,39 +110,39 @@ public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi {
if (!AVAILABLE) {
LOG.info("tamaya-format extension is required to read model configuration, No extended model support AVAILABLE.");
} else {
- String resources = ConfigurationProvider.getConfiguration().get(MODEL_RESOURCE_PARAM);
- if(resources==null || resources.trim().isEmpty()){
+ final String resources = ConfigurationProvider.getConfiguration().get(MODEL_RESOURCE_PARAM);
+ if (resources == null || resources.trim().isEmpty()) {
LOG.info("Mo model resources location configured in " + MODEL_RESOURCE_PARAM + ".");
return;
}
Collection<URL> urls;
- if(RESOURCES_EXTENSION_AVAILABLE){
+ if (RESOURCES_EXTENSION_AVAILABLE) {
LOG.info("Using tamaya-resources extension to read model configuration from " + resources);
urls = ConfigResources.getResourceResolver().getResources(resources.split(","));
- } else{
+ } else {
LOG.info("Using default classloader resource location to read model configuration from " + resources);
urls = new ArrayList<>();
- for(String resource:resources.split(",")){
- if(!resource.trim().isEmpty()){
+ for (final String resource : resources.split(",")) {
+ if (!resource.trim().isEmpty()) {
Enumeration<URL> configs;
try {
configs = getClass().getClassLoader().getResources(resource);
while (configs.hasMoreElements()) {
urls.add(configs.nextElement());
}
- } catch (IOException e) {
+ } catch (final IOException e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE,
- "Error evaluating config model locations from "+resource, e);
+ "Error evaluating config model locations from " + resource, e);
}
}
}
}
// Reading configs
- for(URL config:urls){
+ for (final URL config : urls) {
try (InputStream is = config.openStream()) {
- ConfigurationData data = ConfigurationFormats.readConfigurationData(config);
+ final ConfigurationData data = ConfigurationFormats.readConfigurationData(config);
configModels.addAll(ConfigModelReader.loadValidations(data.getCombinedProperties(), config.toString()));
- } catch (Exception e) {
+ } catch (final Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE,
"Error loading config model data from " + config, e);
}
@@ -130,6 +152,7 @@ public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi {
}
+ @Override
public Collection<ConfigModel> getConfigModels() {
return configModels;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
----------------------------------------------------------------------
diff --git a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
index afba691..c24b9f7 100644
--- a/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
+++ b/modules/model/src/main/java/org/apache/tamaya/model/spi/ConfigDocumentationMBean.java
@@ -27,6 +27,7 @@ public interface ConfigDocumentationMBean {
/**
* Validates the configuration for the given context.
*
+ * @param showUndefined allows filtering for undefined configuration elements.
* @return the validation results, never null.
*/
String validate(boolean showUndefined);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5701c27e/modules/model/src/test/resources/examples/configmodel.json
----------------------------------------------------------------------
diff --git a/modules/model/src/test/resources/examples/configmodel.json b/modules/model/src/test/resources/examples/configmodel.json
index 1fd831e..e8da8ef 100644
--- a/modules/model/src/test/resources/examples/configmodel.json
+++ b/modules/model/src/test/resources/examples/configmodel.json
@@ -80,9 +80,9 @@
"class": "Section",
"param0": {
"type": "String",
- "description": "a minmally documented String parameter"
+ "description": "a minimally documented String parameter"
},
- // A minmally defined String parameter
+ // A minimally defined String parameter
"param00": {},
"param1": {
"type": "String",