|
From: <ath...@us...> - 2014-03-26 15:51:27
|
Revision: 1584
http://sourceforge.net/p/webassembletool/code/1584
Author: athaveau
Date: 2014-03-26 15:51:21 +0000 (Wed, 26 Mar 2014)
Log Message:
-----------
#297 : refactoring parameter (Parameter<T>)
Modified Paths:
--------------
trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java
trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java
trunk/esigate-core/src/main/java/org/esigate/Parameters.java
trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java
trunk/esigate-core/src/main/java/org/esigate/cache/CacheConfigHelper.java
trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java
trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java
trunk/esigate-core/src/main/java/org/esigate/cookie/DefaultCookieManager.java
trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java
trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java
trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java
trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java
trunk/esigate-core/src/main/java/org/esigate/extension/parallelesi/Esi.java
trunk/esigate-core/src/main/java/org/esigate/http/ContentTypeHelper.java
trunk/esigate-core/src/main/java/org/esigate/http/HttpClientRequestExecutor.java
trunk/esigate-core/src/main/java/org/esigate/impl/UrlRewriter.java
trunk/esigate-core/src/main/java/org/esigate/util/Parameter.java
trunk/esigate-core/src/main/java/org/esigate/util/PropertiesUtil.java
trunk/esigate-servlet/src/main/java/org/esigate/servlet/ServletExtension.java
Added Paths:
-----------
trunk/esigate-core/src/main/java/org/esigate/util/ParameterArray.java
trunk/esigate-core/src/main/java/org/esigate/util/ParameterBoolean.java
trunk/esigate-core/src/main/java/org/esigate/util/ParameterCollection.java
trunk/esigate-core/src/main/java/org/esigate/util/ParameterFloat.java
trunk/esigate-core/src/main/java/org/esigate/util/ParameterInteger.java
trunk/esigate-core/src/main/java/org/esigate/util/ParameterLong.java
trunk/esigate-core/src/main/java/org/esigate/util/ParameterString.java
trunk/esigate-core/src/test/java/org/esigate/util/ParameterTest.java
Modified: trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/DriverConfiguration.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -49,11 +49,11 @@
public DriverConfiguration(String instanceName, Properties props) {
this.instanceName = instanceName;
this.baseUrlRetrieveStrategy = getBaseUrlRetrieveSession(props);
- this.uriEncoding = Parameters.URI_ENCODING.getValueString(props);
- this.preserveHost = Parameters.PRESERVE_HOST.getValueBoolean(props);
- this.visibleBaseURL = Parameters.VISIBLE_URL_BASE.getValueString(props);
+ this.uriEncoding = Parameters.URI_ENCODING.getValue(props);
+ this.preserveHost = Parameters.PRESERVE_HOST.getValue(props);
+ this.visibleBaseURL = Parameters.VISIBLE_URL_BASE.getValue(props);
this.isVisibleBaseURLEmpty = StringUtils.isEmpty(visibleBaseURL);
- this.stripMappingPath= Parameters.STRIP_MAPPING_PATH.getValueBoolean(props);
+ this.stripMappingPath= Parameters.STRIP_MAPPING_PATH.getValue(props);
this.uriMappings = parseMappings(props);
properties = props;
}
@@ -67,7 +67,7 @@
private static List<UriMapping> parseMappings(Properties props) {
List<UriMapping> mappings = new ArrayList<UriMapping>();
- Collection<String> mappingsParam = Parameters.MAPPINGS.getValueList(props);
+ Collection<String> mappingsParam = Parameters.MAPPINGS.getValue(props);
for (String mappingParam : mappingsParam) {
mappings.add(UriMapping.create(mappingParam));
}
@@ -77,14 +77,14 @@
private BaseUrlRetrieveStrategy getBaseUrlRetrieveSession(Properties props) {
BaseUrlRetrieveStrategy urlStrategy;
- String[] baseURLs = Parameters.REMOTE_URL_BASE.getValueArray(props);
+ String[] baseURLs = Parameters.REMOTE_URL_BASE.getValue(props);
if (baseURLs.length == 0) {
throw new ConfigurationException(Parameters.REMOTE_URL_BASE.getName()
+ " property cannot be empty for instance '" + instanceName + "'");
} else if (baseURLs.length == 1) {
urlStrategy = new SingleBaseUrlRetrieveStrategy(baseURLs[0]);
} else {
- String strategy = Parameters.REMOTE_URL_BASE_STRATEGY.getValueString(props);
+ String strategy = Parameters.REMOTE_URL_BASE_STRATEGY.getValue(props);
if (Parameters.ROUNDROBIN.equalsIgnoreCase(strategy)) {
urlStrategy = new RoundRobinBaseUrlRetrieveStrategy(baseURLs);
} else if (Parameters.IPHASH.equalsIgnoreCase(strategy)) {
Modified: trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/DriverFactory.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -167,7 +167,7 @@
newInstances.put(name, createDriver(name, properties));
}
if (newInstances.get(DEFAULT_INSTANCE_NAME) == null
- && Parameters.REMOTE_URL_BASE.getValueString(defaultProperties) != null) {
+ && Parameters.REMOTE_URL_BASE.getValue(defaultProperties)!=null) {
newInstances.put(DEFAULT_INSTANCE_NAME, createDriver(DEFAULT_INSTANCE_NAME, defaultProperties));
}
Modified: trunk/esigate-core/src/main/java/org/esigate/Parameters.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/Parameters.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -26,12 +26,21 @@
import org.esigate.extension.XPoweredBy;
import org.esigate.extension.surrogate.Surrogate;
import org.esigate.util.Parameter;
+import org.esigate.util.ParameterArray;
+import org.esigate.util.ParameterBoolean;
+import org.esigate.util.ParameterCollection;
+import org.esigate.util.ParameterFloat;
+import org.esigate.util.ParameterInteger;
+import org.esigate.util.ParameterString;
+import java.util.Arrays;
+import java.util.Collection;
+
/**
* Configuration properties names and default values.
- *
+ *
* @author Francois-Xavier Bonnet
- *
+ *
*/
public final class Parameters {
@@ -40,37 +49,36 @@
}
// Core parameters
- public static final Parameter REMOTE_URL_BASE = new Parameter("remoteUrlBase", null);
- public static final Parameter MAPPINGS = new Parameter("mappings", null);
- public static final Parameter STRIP_MAPPING_PATH = new Parameter("stripMappingPath", null);
- public static final Parameter URI_ENCODING = new Parameter("uriEncoding", "ISO-8859-1");
- public static final Parameter PARSABLE_CONTENT_TYPES = new Parameter("parsableContentTypes",
- "text/html, application/xhtml+xml");
+ public static final Parameter<String[]> REMOTE_URL_BASE = new ParameterArray("remoteUrlBase", null);
+ public static final Parameter<Collection<String>> MAPPINGS = new ParameterCollection("mappings",null);
+ public static final Parameter<Boolean> STRIP_MAPPING_PATH = new ParameterBoolean("stripMappingPath", false);
+ public static final Parameter<String> URI_ENCODING = new ParameterString("uriEncoding", "ISO-8859-1");
+ public static final Parameter<Collection<String>> PARSABLE_CONTENT_TYPES = new ParameterCollection("parsableContentTypes", Arrays.asList("text/html", "application/xhtml+xml"));
// Network settings
- public static final Parameter MAX_CONNECTIONS_PER_HOST = new Parameter("maxConnectionsPerHost", "20");
- public static final Parameter CONNECT_TIMEOUT = new Parameter("connectTimeout", "1000");
- public static final Parameter SOCKET_TIMEOUT = new Parameter("socketTimeout", "10000");
+ public static final Parameter<Integer> MAX_CONNECTIONS_PER_HOST = new ParameterInteger("maxConnectionsPerHost", 20);
+ public static final Parameter<Integer> CONNECT_TIMEOUT = new ParameterInteger("connectTimeout", 1000);
+ public static final Parameter<Integer> SOCKET_TIMEOUT = new ParameterInteger("socketTimeout", 10000);
// Proxy settings
- public static final Parameter PROXY_HOST = new Parameter("proxyHost", null);
- public static final Parameter PROXY_PORT = new Parameter("proxyPort", null);
- public static final Parameter PROXY_USER = new Parameter("proxyUser", null);
- public static final Parameter PROXY_PASSWORD = new Parameter("proxyPassword", null);
+ public static final Parameter<String> PROXY_HOST = new ParameterString("proxyHost", null);
+ public static final Parameter<Integer> PROXY_PORT = new ParameterInteger("proxyPort", 0 );
+ public static final Parameter<String> PROXY_USER = new ParameterString("proxyUser", null);
+ public static final Parameter<String> PROXY_PASSWORD = new ParameterString("proxyPassword", null);
// Http headers
- public static final Parameter PRESERVE_HOST = new Parameter("preserveHost", "true");
+ public static final Parameter<Boolean> PRESERVE_HOST = new ParameterBoolean("preserveHost", true);
// Cookies
- public static final Parameter COOKIE_MANAGER = new Parameter("cookieManager", DefaultCookieManager.class.getName());
- public static final Parameter DISCARD_COOKIES = new Parameter("discardCookies", null);
- public static final Parameter STORE_COOKIES_IN_SESSION = new Parameter("storeCookiesInSession", null);
+ public static final Parameter<String> COOKIE_MANAGER = new ParameterString("cookieManager", DefaultCookieManager.class.getName());
+ public static final Parameter<Collection<String>> DISCARD_COOKIES = new ParameterCollection("discardCookies",null);
+ public static final Parameter<Collection<String>> STORE_COOKIES_IN_SESSION = new ParameterCollection("storeCookiesInSession",null);
- public static final Parameter FIX_MODE = new Parameter("fixMode", "relative");
- public static final Parameter VISIBLE_URL_BASE = new Parameter("visibleUrlBase", null);
+ public static final Parameter<String> FIX_MODE = new ParameterString("fixMode", "relative");
+ public static final Parameter<String> VISIBLE_URL_BASE = new ParameterString("visibleUrlBase", null);
// Load-balancing
- public static final Parameter REMOTE_URL_BASE_STRATEGY = new Parameter("remoteUrlBaseStrategy",
+ public static final Parameter<String> REMOTE_URL_BASE_STRATEGY = new ParameterString("remoteUrlBaseStrategy",
Parameters.ROUNDROBIN);
// Possible values for remoteUrlBaseStrategy
public static final String STICKYSESSION = "stickysession";
@@ -78,46 +86,45 @@
public static final String ROUNDROBIN = "roundrobin";
// Extensions
- public static final Parameter EXTENSIONS = new Parameter("extensions", FragmentLogging.class.getName() + ","
- + FetchLogging.class.getName() + "," + RemoteUserAuthenticationHandler.class.getName() + ","
- + Esi.class.getName() + "," + ResourceFixup.class.getName() + "," + XPoweredBy.class.getName() + ","
- + Surrogate.class.getName() + "," + ConfigReloadOnChange.class.getName());
+ public static final Parameter<Collection<String>> EXTENSIONS = new ParameterCollection("extensions", Arrays.asList(FragmentLogging.class.getName(),
+ FetchLogging.class.getName() , RemoteUserAuthenticationHandler.class.getName() ,
+ Esi.class.getName() , ResourceFixup.class.getName() , XPoweredBy.class.getName() ,
+ Surrogate.class.getName() , ConfigReloadOnChange.class.getName()));
// Cache settings
- public static final Parameter USE_CACHE = new Parameter("useCache", "true");
- public static final Parameter MAX_CACHE_ENTRIES = new Parameter("maxCacheEntries", "1000");
- public static final Parameter MAX_OBJECT_SIZE = new Parameter("maxObjectSize", "1000000");
- public static final Parameter CACHE_STORAGE = new Parameter("cacheStorage", BasicCacheStorage.class.getName());
- public static final Parameter X_CACHE_HEADER = new Parameter("xCacheHeader", "false");
- public static final Parameter VIA_HEADER = new Parameter("viaHeader", "true");
+ public static final Parameter<Boolean> USE_CACHE = new ParameterBoolean("useCache", true);
+ public static final Parameter<Integer> MAX_CACHE_ENTRIES = new ParameterInteger("maxCacheEntries", 1000);
+ public static final Parameter<Integer> MAX_OBJECT_SIZE = new ParameterInteger("maxObjectSize", 1000000);
+ public static final Parameter<String> CACHE_STORAGE = new ParameterString("cacheStorage", BasicCacheStorage.class.getName());
+ public static final Parameter<Boolean> X_CACHE_HEADER = new ParameterBoolean("xCacheHeader", false);
+ public static final Parameter<Boolean> VIA_HEADER = new ParameterBoolean("viaHeader", true);
// Forced caching
- public static final Parameter TTL = new Parameter("ttl", "0");
+ public static final Parameter<Integer> TTL = new ParameterInteger("ttl", 0);
// Heuristic caching
- public static final Parameter HEURISTIC_CACHING_ENABLED = new Parameter("heuristicCachingEnabled", "true");
+ public static final Parameter<Boolean> HEURISTIC_CACHING_ENABLED = new ParameterBoolean("heuristicCachingEnabled", true);
// default value defined in
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.2.4
- public static final Parameter HEURISTIC_COEFFICIENT = new Parameter("heuristicCoefficient", "0.1");
+ public static final Parameter<Float> HEURISTIC_COEFFICIENT = new ParameterFloat("heuristicCoefficient", 0.1f);
// when no cache directive at all, nothing is cached by default
- public static final Parameter HEURISTIC_DEFAULT_LIFETIME_SECS = new Parameter("heuristicDefaultLifetimeSecs", "0");
+ public static final Parameter<Integer> HEURISTIC_DEFAULT_LIFETIME_SECS = new ParameterInteger("heuristicDefaultLifetimeSecs", 0);
// Background revalidation
- public static final Parameter STALE_WHILE_REVALIDATE = new Parameter("staleWhileRevalidate", "0");
- public static final Parameter STALE_IF_ERROR = new Parameter("staleIfError", "0");
- public static final Parameter MIN_ASYNCHRONOUS_WORKERS = new Parameter("minAsynchronousWorkers", "0");
- public static final Parameter MAX_ASYNCHRONOUS_WORKERS = new Parameter("maxAsynchronousWorkers", "0");
- public static final Parameter ASYNCHRONOUS_WORKER_IDLE_LIFETIME_SECS = new Parameter(
- "asynchronousWorkerIdleLifetimeSecs", "60");
- public static final Parameter MAX_UPDATE_RETRIES = new Parameter("maxUpdateRetries", "1");
- public static final Parameter REVALIDATION_QUEUE_SIZE = new Parameter("revalidationQueueSize", "100");
+ public static final Parameter<Integer> STALE_WHILE_REVALIDATE = new ParameterInteger("staleWhileRevalidate", 0);
+ public static final Parameter<Integer> STALE_IF_ERROR = new ParameterInteger("staleIfError", 0);
+ public static final Parameter<Integer> MIN_ASYNCHRONOUS_WORKERS = new ParameterInteger("minAsynchronousWorkers", 0);
+ public static final Parameter<Integer> MAX_ASYNCHRONOUS_WORKERS = new ParameterInteger("maxAsynchronousWorkers", 0);
+ public static final Parameter<Integer> ASYNCHRONOUS_WORKER_IDLE_LIFETIME_SECS = new ParameterInteger("asynchronousWorkerIdleLifetimeSecs", 60);
+ public static final Parameter<Integer> MAX_UPDATE_RETRIES = new ParameterInteger("maxUpdateRetries", 1);
+ public static final Parameter<Integer> REVALIDATION_QUEUE_SIZE = new ParameterInteger("revalidationQueueSize", 100);
// EhCache
- public static final Parameter EHCACHE_CACHE_NAME_PROPERTY = new Parameter("ehcache.cacheName", "esigate");
- public static final Parameter EHCACHE_CONFIGURATION_FILE_PROPERTY = new Parameter("ehcache.configurationFile", null);
+ public static final Parameter<String> EHCACHE_CACHE_NAME_PROPERTY = new ParameterString("ehcache.cacheName", "esigate");
+ public static final Parameter<String> EHCACHE_CONFIGURATION_FILE_PROPERTY = new ParameterString("ehcache.configurationFile", null);
// MemCached
- public static final Parameter MEMCACHED_SERVERS_PROPERTY = new Parameter("memcached.servers", null);
+ public static final Parameter<Collection<String>> MEMCACHED_SERVERS_PROPERTY = new ParameterCollection("memcached.servers", null);
// Default size for String or byte buffers used to manipulate html page contents
public static final int DEFAULT_BUFFER_SIZE = 1024;
Modified: trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/cache/CacheAdapter.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -50,17 +50,17 @@
private boolean viaHeader;
public void init(Properties properties) {
- staleIfError = Parameters.STALE_IF_ERROR.getValueInt(properties);
- staleWhileRevalidate = Parameters.STALE_WHILE_REVALIDATE.getValueInt(properties);
- int maxAsynchronousWorkers = Parameters.MAX_ASYNCHRONOUS_WORKERS.getValueInt(properties);
+ staleIfError = Parameters.STALE_IF_ERROR.getValue(properties);
+ staleWhileRevalidate = Parameters.STALE_WHILE_REVALIDATE.getValue(properties);
+ int maxAsynchronousWorkers = Parameters.MAX_ASYNCHRONOUS_WORKERS.getValue(properties);
if (staleWhileRevalidate > 0 && maxAsynchronousWorkers == 0) {
throw new ConfigurationException("You must set a positive value for maxAsynchronousWorkers "
+ "in order to enable background revalidation (staleWhileRevalidate)");
}
- ttl = Parameters.TTL.getValueInt(properties);
- xCacheHeader = Parameters.X_CACHE_HEADER.getValueBoolean(properties);
- viaHeader = Parameters.VIA_HEADER.getValueBoolean(properties);
- LOG.info("Initializing cache for provider " + Parameters.REMOTE_URL_BASE.getValueString(properties)
+ ttl = Parameters.TTL.getValue(properties);
+ xCacheHeader = Parameters.X_CACHE_HEADER.getValue(properties);
+ viaHeader = Parameters.VIA_HEADER.getValue(properties);
+ LOG.info("Initializing cache for provider " + Parameters.REMOTE_URL_BASE.getValue(properties)
+ " staleIfError=" + staleIfError + " staleWhileRevalidate=" + staleWhileRevalidate + " ttl=" + ttl
+ " xCacheHeader=" + xCacheHeader + " viaHeader=" + viaHeader);
}
Modified: trunk/esigate-core/src/main/java/org/esigate/cache/CacheConfigHelper.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/cache/CacheConfigHelper.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/cache/CacheConfigHelper.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -29,19 +29,19 @@
public static CacheConfig createCacheConfig(Properties properties) {
// Heuristic caching
- boolean heuristicCachingEnabled = Parameters.HEURISTIC_CACHING_ENABLED.getValueBoolean(properties);
- float heuristicCoefficient = Parameters.HEURISTIC_COEFFICIENT.getValueFloat(properties);
- long heuristicDefaultLifetimeSecs = Parameters.HEURISTIC_DEFAULT_LIFETIME_SECS.getValueLong(properties);
- int maxCacheEntries = Parameters.MAX_CACHE_ENTRIES.getValueInt(properties);
- long maxObjectSize = Parameters.MAX_OBJECT_SIZE.getValueLong(properties);
+ boolean heuristicCachingEnabled = Parameters.HEURISTIC_CACHING_ENABLED.getValue(properties);
+ float heuristicCoefficient = Parameters.HEURISTIC_COEFFICIENT.getValue(properties);
+ long heuristicDefaultLifetimeSecs = Parameters.HEURISTIC_DEFAULT_LIFETIME_SECS.getValue(properties);
+ int maxCacheEntries = Parameters.MAX_CACHE_ENTRIES.getValue(properties);
+ long maxObjectSize = Parameters.MAX_OBJECT_SIZE.getValue(properties);
// Asynchronous revalidation
- int minAsynchronousWorkers = Parameters.MIN_ASYNCHRONOUS_WORKERS.getValueInt(properties);
- int maxAsynchronousWorkers = Parameters.MAX_ASYNCHRONOUS_WORKERS.getValueInt(properties);
+ int minAsynchronousWorkers = Parameters.MIN_ASYNCHRONOUS_WORKERS.getValue(properties);
+ int maxAsynchronousWorkers = Parameters.MAX_ASYNCHRONOUS_WORKERS.getValue(properties);
int asynchronousWorkerIdleLifetimeSecs = Parameters.ASYNCHRONOUS_WORKER_IDLE_LIFETIME_SECS
- .getValueInt(properties);
- int maxUpdateRetries = Parameters.MAX_UPDATE_RETRIES.getValueInt(properties);
- int revalidationQueueSize = Parameters.REVALIDATION_QUEUE_SIZE.getValueInt(properties);
+ .getValue(properties);
+ int maxUpdateRetries = Parameters.MAX_UPDATE_RETRIES.getValue(properties);
+ int revalidationQueueSize = Parameters.REVALIDATION_QUEUE_SIZE.getValue(properties);
CacheConfig.Builder builder = CacheConfig.custom();
builder.setHeuristicCachingEnabled(heuristicCachingEnabled);
@@ -58,7 +58,7 @@
}
public static CacheStorage createCacheStorage(Properties properties) {
- String cacheStorageClass = Parameters.CACHE_STORAGE.getValueString(properties);
+ String cacheStorageClass = Parameters.CACHE_STORAGE.getValue(properties);
Object cacheStorageObject;
try {
cacheStorageObject = Class.forName(cacheStorageClass).newInstance();
Modified: trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/cache/EhcacheCacheStorage.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -28,8 +28,8 @@
@Override
public void init(Properties properties) {
- String cacheName = Parameters.EHCACHE_CACHE_NAME_PROPERTY.getValueString(properties);
- String configurationFileName = Parameters.EHCACHE_CONFIGURATION_FILE_PROPERTY.getValueString(properties);
+ String cacheName = Parameters.EHCACHE_CACHE_NAME_PROPERTY.getValue(properties);
+ String configurationFileName = Parameters.EHCACHE_CONFIGURATION_FILE_PROPERTY.getValue(properties);
// Loaded from the Classpath, default will use /ehcache.xml or if not found /ehcache-failsafe.xml
CacheManager cacheManager = CacheManager.create(configurationFileName);
Ehcache ehcache = cacheManager.getEhcache(cacheName);
Modified: trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/cache/MemcachedCacheStorage.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -34,7 +34,7 @@
public class MemcachedCacheStorage extends CacheStorage {
@Override
public void init(Properties properties) {
- Collection<String> serverStringList = Parameters.MEMCACHED_SERVERS_PROPERTY.getValueList(properties);
+ Collection<String> serverStringList = Parameters.MEMCACHED_SERVERS_PROPERTY.getValue(properties);
if (serverStringList.isEmpty()) {
throw new ConfigurationException("No memcached server defined. Property '"
+ Parameters.MEMCACHED_SERVERS_PROPERTY + "' must be defined.");
Modified: trunk/esigate-core/src/main/java/org/esigate/cookie/DefaultCookieManager.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/cookie/DefaultCookieManager.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/cookie/DefaultCookieManager.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -62,9 +62,9 @@
@Override
public void init(Driver d, Properties properties) {
// Cookies to store to session
- this.storeCookiesInSession = Parameters.STORE_COOKIES_IN_SESSION.getValueList(properties);
+ this.storeCookiesInSession = Parameters.STORE_COOKIES_IN_SESSION.getValue(properties);
// Cookies to discard
- this.discardCookies = Parameters.DISCARD_COOKIES.getValueList(properties);
+ this.discardCookies = Parameters.DISCARD_COOKIES.getValue(properties);
// Verify configuration
if (this.storeCookiesInSession.contains("*") && this.storeCookiesInSession.size() > 1) {
Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/extension/ConfigReloadOnChange.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -14,17 +14,18 @@
*/
package org.esigate.extension;
-import java.io.File;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Properties;
-
import org.esigate.Driver;
import org.esigate.DriverFactory;
import org.esigate.util.Parameter;
+import org.esigate.util.ParameterLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Properties;
+
/**
* This extension reloads configuration when esigate.properties is updated.
* <p>
@@ -47,8 +48,8 @@
* The wait time (ms) between to check for configuration change.
*
*/
- public static final Parameter CONFIG_RELOAD_DELAY = new Parameter("configReloadDelay",
- String.valueOf(DEFAULT_RELOAD_DELAY));
+ public static final Parameter<Long> CONFIG_RELOAD_DELAY = new ParameterLong("configReloadDelay",
+ DEFAULT_RELOAD_DELAY);
// Do not poll too fast. (ms).
private static final int SPEED_LIMIT = 100;
@@ -101,15 +102,14 @@
// Load configuration
try {
// Try to convert as long
- long configDelay = CONFIG_RELOAD_DELAY.getValueLong(properties);
+ long configDelay = CONFIG_RELOAD_DELAY.getValue(properties);
// Do not watch faster than SPEED_LIMIT
if (configDelay < SPEED_LIMIT) {
delay = SPEED_LIMIT;
}
} catch (NumberFormatException e) {
- LOG.warn("Unable to convert {}={} as number", CONFIG_RELOAD_DELAY.getName(),
- CONFIG_RELOAD_DELAY.getValueString(properties));
+ LOG.warn("Unable to convert {}={} as number", CONFIG_RELOAD_DELAY.getName(),e);
}
LOG.info("Will reload configuration every {}ms if {} is modified", Long.valueOf(delay),
Modified: trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/extension/DefaultCharset.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -1,8 +1,5 @@
package org.esigate.extension;
-import java.util.Collection;
-import java.util.Properties;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.esigate.Driver;
@@ -13,9 +10,13 @@
import org.esigate.events.IEventListener;
import org.esigate.events.impl.FetchEvent;
import org.esigate.util.Parameter;
+import org.esigate.util.ParameterString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Collection;
+import java.util.Properties;
+
/**
* This extension adds a default charset to responses which lack the charset attribute in Content-Type header. Only
* parsable MIME types are modified :
@@ -43,7 +44,7 @@
public class DefaultCharset implements Extension, IEventListener {
private static final Logger LOG = LoggerFactory.getLogger(DefaultCharset.class);
- public static final Parameter PARAM_DEFAULT_CHARSET = new Parameter("defaultCharset", "ISO-8859-1");
+ public static final Parameter<String> PARAM_DEFAULT_CHARSET = new ParameterString("defaultCharset", "ISO-8859-1");
private Collection<String> parsableContentTypes;
private String defaultCharset;
@@ -52,8 +53,8 @@
public void init(Driver driver, Properties properties) {
driver.getEventManager().register(EventManager.EVENT_FETCH_POST, this);
- parsableContentTypes = Parameters.PARSABLE_CONTENT_TYPES.getValueList(properties);
- defaultCharset = PARAM_DEFAULT_CHARSET.getValueString(properties);
+ parsableContentTypes = Parameters.PARSABLE_CONTENT_TYPES.getValue(properties);
+ defaultCharset = PARAM_DEFAULT_CHARSET.getValue(properties);
LOG.info("Will use " + defaultCharset + " as default charset for " + parsableContentTypes.toString());
Modified: trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/extension/ExtensionFactory.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -51,9 +51,9 @@
* class which extends Extension class which extends Extension
* @return instance of {@link Extension} or null.
*/
- public static <T extends Extension> T getExtension(Properties properties, Parameter parameter, Driver d) {
+ public static <T extends Extension> T getExtension(Properties properties, Parameter<String> parameter, Driver d) {
T result = null;
- String className = parameter.getValueString(properties);
+ String className = parameter.getValue(properties);
if (className == null) {
return null;
}
@@ -81,8 +81,8 @@
* @param d
* @return the extension list
*/
- public static <T extends Extension> List<T> getExtensions(Properties properties, Parameter parameter, Driver d) {
- Collection<String> className = parameter.getValueList(properties);
+ public static <T extends Extension> List<T> getExtensions(Properties properties, Parameter<Collection<String>> parameter, Driver d) {
+ Collection<String> className = parameter.getValue(properties);
List<T> finalResult = new ArrayList<T>();
for (String cName : className) {
try {
Modified: trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/extension/monitoring/Metric.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -28,6 +28,7 @@
import org.esigate.events.impl.ProxyEvent;
import org.esigate.extension.Extension;
import org.esigate.util.Parameter;
+import org.esigate.util.ParameterInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,7 +47,7 @@
*/
public class Metric implements Extension, IEventListener {
private static final Logger LOG = LoggerFactory.getLogger(Metric.class);
- private static final Parameter PARAM_METRIC_PERIOD = new Parameter("metricPeriod", "60");
+ private static final Parameter<Integer> PARAM_METRIC_PERIOD = new ParameterInteger("metricPeriod", 60);
private MetricRegistry metric = new MetricRegistry();
private ScheduledReporter reporter;
@@ -54,7 +55,7 @@
@Override
public void init(Driver driver, Properties properties) {
-
+ LOG.debug("Initialize Metric");
driver.getEventManager().register(EventManager.EVENT_PROXY_POST, this);
driver.getEventManager().register(EventManager.EVENT_FETCH_POST, this);
@@ -67,7 +68,7 @@
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
- reporter.start(PARAM_METRIC_PERIOD.getValueInt(properties), TimeUnit.MINUTES);
+ reporter.start(PARAM_METRIC_PERIOD.getValue(properties), TimeUnit.SECONDS);
}
Modified: trunk/esigate-core/src/main/java/org/esigate/extension/parallelesi/Esi.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/extension/parallelesi/Esi.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/extension/parallelesi/Esi.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -14,14 +14,6 @@
*/
package org.esigate.extension.parallelesi;
-import static org.apache.commons.lang3.StringUtils.containsIgnoreCase;
-
-import java.util.Properties;
-import java.util.concurrent.Executor;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
import org.esigate.Driver;
import org.esigate.events.Event;
import org.esigate.events.EventDefinition;
@@ -32,9 +24,18 @@
import org.esigate.extension.surrogate.CapabilitiesEvent;
import org.esigate.extension.surrogate.Surrogate;
import org.esigate.util.Parameter;
+import org.esigate.util.ParameterInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Properties;
+import java.util.concurrent.Executor;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.commons.lang3.StringUtils.containsIgnoreCase;
+
/**
* This extension processes ESI directives, like :
* <p>
@@ -47,8 +48,8 @@
public class Esi implements Extension, IEventListener {
private static final Logger LOG = LoggerFactory.getLogger(Esi.class);
// esi_max_threads = 0 -> linear execution
- private static final Parameter THREADS = new Parameter("esi_max_threads", "0");
- private static final Parameter IDLE = new Parameter("esi_max_idle", "60");
+ private static final Parameter<Integer> THREADS = new ParameterInteger("esi_max_threads", 0);
+ private static final Parameter<Integer> IDLE = new ParameterInteger("esi_max_idle", 60);
private int maxThreads;
private int idle;
private Executor executor;
@@ -102,8 +103,8 @@
});
// Load configuration
- this.maxThreads = THREADS.getValueInt(properties);
- this.idle = IDLE.getValueInt(properties);
+ this.maxThreads = THREADS.getValue(properties);
+ this.idle = IDLE.getValue(properties);
if (this.maxThreads == 0) {
this.executor = null;
Modified: trunk/esigate-core/src/main/java/org/esigate/http/ContentTypeHelper.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/http/ContentTypeHelper.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/http/ContentTypeHelper.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -26,7 +26,7 @@
private Collection<String> parsableContentTypes;
public ContentTypeHelper(Properties properties) {
- parsableContentTypes = Parameters.PARSABLE_CONTENT_TYPES.getValueList(properties);
+ parsableContentTypes = Parameters.PARSABLE_CONTENT_TYPES.getValue(properties);
}
/**
Modified: trunk/esigate-core/src/main/java/org/esigate/http/HttpClientRequestExecutor.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/http/HttpClientRequestExecutor.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/http/HttpClientRequestExecutor.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -109,16 +109,16 @@
}
HttpClientRequestExecutor httpClientHelper = new HttpClientRequestExecutor();
httpClientHelper.eventManager = eventManager;
- httpClientHelper.preserveHost = Parameters.PRESERVE_HOST.getValueBoolean(properties);
+ httpClientHelper.preserveHost = Parameters.PRESERVE_HOST.getValue(properties);
httpClientHelper.headerManager = new HeaderManager();
if (cookieManager == null) {
cookieManager = ExtensionFactory.getExtension(properties, Parameters.COOKIE_MANAGER, driver);
}
httpClientHelper.cookieManager = cookieManager;
- httpClientHelper.connectTimeout = Parameters.CONNECT_TIMEOUT.getValueInt(properties);
- httpClientHelper.socketTimeout = Parameters.SOCKET_TIMEOUT.getValueInt(properties);
+ httpClientHelper.connectTimeout = Parameters.CONNECT_TIMEOUT.getValue(properties);
+ httpClientHelper.socketTimeout = Parameters.SOCKET_TIMEOUT.getValue(properties);
httpClientHelper.httpClient = buildHttpClient(properties, eventManager, connectionManager);
- String firstBaseURL = Parameters.REMOTE_URL_BASE.getValueArray(properties)[0];
+ String firstBaseURL = Parameters.REMOTE_URL_BASE.getValue(properties)[0];
httpClientHelper.firstBaseUrlHost = UriUtils.extractHost(firstBaseURL);
return httpClientHelper;
}
@@ -150,13 +150,13 @@
HttpHost proxyHost = null;
Credentials proxyCredentials = null;
// Proxy settings
- String proxyHostParameter = Parameters.PROXY_HOST.getValueString(properties);
+ String proxyHostParameter = Parameters.PROXY_HOST.getValue(properties);
if (proxyHostParameter != null) {
- int proxyPort = Parameters.PROXY_PORT.getValueInt(properties);
+ int proxyPort = Parameters.PROXY_PORT.getValue(properties);
proxyHost = new HttpHost(proxyHostParameter, proxyPort);
- String proxyUser = Parameters.PROXY_USER.getValueString(properties);
+ String proxyUser = Parameters.PROXY_USER.getValue(properties);
if (proxyUser != null) {
- String proxyPassword = Parameters.PROXY_PASSWORD.getValueString(properties);
+ String proxyPassword = Parameters.PROXY_PASSWORD.getValue(properties);
proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword);
}
}
@@ -165,8 +165,8 @@
httpClientBuilder.setProperties(properties);
- httpClientBuilder.setMaxConnPerRoute(Parameters.MAX_CONNECTIONS_PER_HOST.getValueInt(properties));
- httpClientBuilder.setMaxConnTotal(Parameters.MAX_CONNECTIONS_PER_HOST.getValueInt(properties));
+ httpClientBuilder.setMaxConnPerRoute(Parameters.MAX_CONNECTIONS_PER_HOST.getValue(properties));
+ httpClientBuilder.setMaxConnTotal(Parameters.MAX_CONNECTIONS_PER_HOST.getValue(properties));
httpClientBuilder.setRedirectStrategy(new RedirectStrategy());
// Proxy settings
if (proxyHost != null) {
@@ -179,8 +179,8 @@
}
// Cache settings
- boolean useCache = Parameters.USE_CACHE.getValueBoolean(properties);
- httpClientBuilder.setUseCache(Parameters.USE_CACHE.getValueBoolean(properties));
+ boolean useCache = Parameters.USE_CACHE.getValue(properties);
+ httpClientBuilder.setUseCache(Parameters.USE_CACHE.getValue(properties));
if (useCache) {
httpClientBuilder.setHttpCacheStorage(CacheConfigHelper.createCacheStorage(properties));
httpClientBuilder.setCacheConfig(CacheConfigHelper.createCacheConfig(properties));
Modified: trunk/esigate-core/src/main/java/org/esigate/impl/UrlRewriter.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/impl/UrlRewriter.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/impl/UrlRewriter.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -76,12 +76,12 @@
*
*/
public UrlRewriter(Properties properties) {
- if ("absolute".equalsIgnoreCase(Parameters.FIX_MODE.getValueString(properties))) {
+ if ("absolute".equalsIgnoreCase(Parameters.FIX_MODE.getValue(properties))) {
mode = ABSOLUTE;
} else {
mode = RELATIVE;
}
- visibleBaseUrlParameter = stripEnd(Parameters.VISIBLE_URL_BASE.getValueString(properties), "/");
+ visibleBaseUrlParameter = stripEnd(Parameters.VISIBLE_URL_BASE.getValue(properties), "/");
}
private String concatUrl(String begin, String end) {
Modified: trunk/esigate-core/src/main/java/org/esigate/util/Parameter.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/Parameter.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/util/Parameter.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -15,12 +15,11 @@
package org.esigate.util;
-import java.util.Collection;
import java.util.Properties;
-public final class Parameter {
+public class Parameter<T> {
private final String name;
- private final String defaultValue;
+ private final T defaultValue;
@Override
public boolean equals(Object obj) {
@@ -37,62 +36,28 @@
return this.name.hashCode();
}
- public Parameter(String name, String defaultValue) {
+
+ Parameter(String name, T defaultValue) {
this.name = name;
this.defaultValue = defaultValue;
- }
- public int getValueInt(Properties properties) {
- int defaultValueInt = 0;
- if (defaultValue != null) {
- defaultValueInt = Integer.parseInt(defaultValue);
- }
- return PropertiesUtil.getPropertyValue(properties, name, defaultValueInt);
}
- public boolean getValueBoolean(Properties properties) {
- boolean defaultValueBoolean = false;
- if (defaultValue != null) {
- defaultValueBoolean = Boolean.parseBoolean(defaultValue);
- }
- return PropertiesUtil.getPropertyValue(properties, name, defaultValueBoolean);
+ public String getName() {
+ return name;
}
- public float getValueFloat(Properties properties) {
- float defaultValueFloat = 0;
- if (defaultValue != null) {
- defaultValueFloat = Float.parseFloat(defaultValue);
- }
- return PropertiesUtil.getPropertyValue(properties, name, defaultValueFloat);
+ public T getDefaultValue() {
+ return defaultValue;
}
- public long getValueLong(Properties properties) {
- long defaultValueLong = 0;
- if (defaultValue != null) {
- defaultValueLong = Long.parseLong(defaultValue);
+ public T getValue(Properties properties) {
+ T value = (T) properties.getProperty(this.name);
+
+ if (value == null) {
+ value = defaultValue;
}
- return PropertiesUtil.getPropertyValue(properties, name, defaultValueLong);
+ return value;
}
- public String getValueString(Properties properties) {
- return PropertiesUtil.getPropertyValue(properties, name, defaultValue);
- }
-
- public Collection<String> getValueList(Properties properties) {
- return PropertiesUtil.getPropertyValueAsList(properties, name, defaultValue);
- }
-
- public String[] getValueArray(Properties properties) {
- Collection<String> resultAsCollection = getValueList(properties);
- return resultAsCollection.toArray(new String[resultAsCollection.size()]);
- }
-
- public String getName() {
- return name;
- }
-
- public String getDefaultValue() {
- return defaultValue;
- }
-
}
Added: trunk/esigate-core/src/main/java/org/esigate/util/ParameterArray.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/ParameterArray.java (rev 0)
+++ trunk/esigate-core/src/main/java/org/esigate/util/ParameterArray.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,40 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.esigate.util;
+
+import java.util.*;
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterArray extends Parameter<String[]> {
+
+ public ParameterArray(String name, String[] defaultValue) {
+ super(name, defaultValue);
+
+ }
+
+ @Override
+ public String[] getValue(Properties properties) {
+ String[] value;
+ Collection<String> list = PropertiesUtil.getPropertyValue(properties, getName(), Collections.EMPTY_LIST);
+ if (list == null || list.isEmpty()) {
+ value = getDefaultValue();
+ } else {
+ value = list.toArray(new String[list.size()]);
+ }
+ return value;
+ }
+}
Added: trunk/esigate-core/src/main/java/org/esigate/util/ParameterBoolean.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/ParameterBoolean.java (rev 0)
+++ trunk/esigate-core/src/main/java/org/esigate/util/ParameterBoolean.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,32 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.esigate.util;
+
+import java.util.Properties;
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterBoolean extends Parameter<Boolean> {
+
+ public ParameterBoolean(String name, Boolean defaultValue) {
+ super(name, defaultValue);
+ }
+
+ @Override
+ public Boolean getValue(Properties properties) {
+ return PropertiesUtil.getPropertyValue(properties, getName(), getDefaultValue());
+ }
+}
Added: trunk/esigate-core/src/main/java/org/esigate/util/ParameterCollection.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/ParameterCollection.java (rev 0)
+++ trunk/esigate-core/src/main/java/org/esigate/util/ParameterCollection.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,40 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.esigate.util;
+
+import java.util.*;
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterCollection extends Parameter<Collection<String>> {
+
+ public ParameterCollection(String name, Collection<String> defaultValue) {
+ super(name, defaultValue);
+ }
+
+
+ @Override
+ public Collection<String> getValue(Properties properties) {
+
+ Collection<String> defaultValue = getDefaultValue();
+ if (defaultValue == null) {
+ defaultValue = Collections.EMPTY_LIST;
+ }
+ Collection<String> value = PropertiesUtil.getPropertyValue(properties, getName(), defaultValue);
+ return value;
+
+ }
+}
Added: trunk/esigate-core/src/main/java/org/esigate/util/ParameterFloat.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/ParameterFloat.java (rev 0)
+++ trunk/esigate-core/src/main/java/org/esigate/util/ParameterFloat.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,38 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.esigate.util;
+
+import java.util.Properties;
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterFloat extends Parameter<Float> {
+
+ public ParameterFloat(String name, Float defaultValue) {
+ super(name, defaultValue);
+ }
+
+ @Override
+ public Float getValue(Properties properties) {
+ Float defaultValue = 0f;
+ if (getDefaultValue() != null) {
+ defaultValue = getDefaultValue();
+ }
+ Float value = PropertiesUtil.getPropertyValue(properties, getName(), defaultValue);
+ return value;
+
+ }
+}
Added: trunk/esigate-core/src/main/java/org/esigate/util/ParameterInteger.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/ParameterInteger.java (rev 0)
+++ trunk/esigate-core/src/main/java/org/esigate/util/ParameterInteger.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,39 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.esigate.util;
+
+import java.util.Properties;
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterInteger extends Parameter<Integer> {
+
+ public ParameterInteger(String name, Integer defaultValue) {
+ super(name, defaultValue);
+ }
+
+ @Override
+ public Integer getValue(Properties properties) {
+ Integer defaultValue = 0;
+ if(getDefaultValue()!=null){
+ defaultValue = getDefaultValue();
+ }
+ Integer value = PropertiesUtil.getPropertyValue(properties,getName(),defaultValue);
+ return value;
+
+
+ }
+}
Added: trunk/esigate-core/src/main/java/org/esigate/util/ParameterLong.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/ParameterLong.java (rev 0)
+++ trunk/esigate-core/src/main/java/org/esigate/util/ParameterLong.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,38 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.esigate.util;
+
+import java.util.Properties;
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterLong extends Parameter<Long> {
+
+ public ParameterLong(String name, Long defaultValue) {
+ super(name, defaultValue);
+ }
+
+ @Override
+ public Long getValue(Properties properties) {
+ Long defaultValue = 0l;
+ if(getDefaultValue()!=null){
+ defaultValue = getDefaultValue();
+ }
+ Long value = PropertiesUtil.getPropertyValue(properties, getName(), defaultValue);
+ return value;
+
+ }
+}
Added: trunk/esigate-core/src/main/java/org/esigate/util/ParameterString.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/ParameterString.java (rev 0)
+++ trunk/esigate-core/src/main/java/org/esigate/util/ParameterString.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,11 @@
+package org.esigate.util;
+
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterString extends Parameter<String> {
+ public ParameterString(String name, String defaultValue) {
+ super(name, defaultValue);
+ }
+}
Modified: trunk/esigate-core/src/main/java/org/esigate/util/PropertiesUtil.java
===================================================================
--- trunk/esigate-core/src/main/java/org/esigate/util/PropertiesUtil.java 2014-03-26 13:59:20 UTC (rev 1583)
+++ trunk/esigate-core/src/main/java/org/esigate/util/PropertiesUtil.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -22,10 +22,10 @@
/**
* Utility methods for loading configuration parameters.
- *
+ *
* @author Francois-Xavier Bonnet
* @author Nicolas Richeton
- *
+ *
*/
public final class PropertiesUtil {
@@ -36,28 +36,28 @@
/**
* Retrieves a property containing a comma separated list of values, trim them and return them as a Collection of
* String.
- *
+ *
* @param properties
* @param propertyName
* @param defaultValue
* @return the values
*/
- public static Collection<String> getPropertyValueAsList(Properties properties, String propertyName,
- String defaultValue) {
+ public static Collection<String> getPropertyValue(Properties properties, String propertyName,
+ Collection<String> defaultValue) {
+ Collection<String> result = defaultValue;
String propertyValue = properties.getProperty(propertyName);
- if (propertyValue == null) {
- propertyValue = defaultValue;
+ if (propertyValue != null) {
+ result = toCollection(propertyValue);
+ if (result.contains("*") && result.size() > 1) {
+ throw new ConfigurationException(propertyName + " must be a comma-separated list or *");
+ }
}
- Collection<String> result = toCollection(propertyValue);
- if (result.contains("*") && result.size() > 1) {
- throw new ConfigurationException(propertyName + " must be a comma-separated list or *");
- }
return result;
}
/**
* Return the provided comma-separated String as a collection. Order is maintained.
- *
+ *
* @param list
* @return Ordered collection
*/
Added: trunk/esigate-core/src/test/java/org/esigate/util/ParameterTest.java
===================================================================
--- trunk/esigate-core/src/test/java/org/esigate/util/ParameterTest.java (rev 0)
+++ trunk/esigate-core/src/test/java/org/esigate/util/ParameterTest.java 2014-03-26 15:51:21 UTC (rev 1584)
@@ -0,0 +1,118 @@
+package org.esigate.util;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Properties;
+
+/**
+ * @author Alexis Thaveau
+ */
+public class ParameterTest extends TestCase {
+
+ public void testGetValueString() throws Exception {
+ Parameter<String> parameter1 = new ParameterString("test1", null);
+ Parameter<String> parameter2 = new ParameterString("test2", "2");
+ Properties properties = new Properties();
+ assertNull(parameter1.getValue(properties));
+ assertEquals("2", parameter2.getValue(properties));
+
+ properties.put("test1", "0");
+ properties.put("test2", "2");
+ assertEquals("0", parameter1.getValue(properties));
+ assertEquals("2", parameter2.getValue(properties));
+
+ }
+
+ public void testGetValueInteger() throws Exception {
+ Parameter<Integer> parameter1 = new ParameterInteger("test1", null);
+ Parameter<Integer> parameter2 = new ParameterInteger("test2", 2);
+ Properties properties = new Properties();
+ assertEquals((Integer) 0, parameter1.getValue(properties));
+ assertEquals((Integer) 2, parameter2.getValue(properties));
+
+ properties.put("test1", "0");
+ properties.put("test2", "2");
+ assertEquals((Integer) 0, parameter1.getValue(properties));
+ assertEquals((Integer) 2, parameter2.getValue(properties));
+
+ }
+
+ public void testGetValueFloat() throws Exception {
+ Parameter<Float> parameter1 = new ParameterFloat("test1", null);
+ Parameter<Float> parameter2 = new ParameterFloat("test2", 2f);
+ Properties properties = new Properties();
+ assertEquals(0f, parameter1.getValue(properties));
+ assertEquals(2f, parameter2.getValue(properties));
+
+ properties.put("test1", "0");
+ properties.put("test2", "2");
+ assertEquals(0f, parameter1.getValue(properties));
+ assertEquals(2f, parameter2.getValue(properties));
+
+ }
+
+ public void testGetValueBoolean() throws Exception {
+ Parameter<Boolean> parameter1 = new ParameterBoolean("test1", Boolean.FALSE);
+ Parameter<Boolean> parameter2 = new ParameterBoolean("test2", Boolean.TRUE);
+ Properties properties = new Properties();
+ assertFalse(parameter1.getValue(properties));
+ assertTrue(parameter2.getValue(properties));
+ properties.put("test1", "false");
+ properties.put("test2", "false");
+ assertFalse(parameter1.getValue(properties));
+ assertFalse(parameter2.getValue(properties));
+ properties.put("test1", "true");
+ properties.put("test2", "true");
+ assertTrue(parameter1.getValue(properties));
+ assertTrue(parameter2.getValue(properties));
+
+ }
+
+ public void testGetValueCollection() throws Exception {
+ Parameter<Collection<String>> parameter1 = new ParameterCollection("test1", null);
+ Parameter<Collection<String>> parameter2 = new ParameterCollection("test2", Arrays.asList("v1", "v2"));
+ Properties properties = new Properties();
+ assertNotNull(parameter1.getValue(properties));
+ assertTrue(parameter1.getValue(properties).isEmpty());
+ assertEquals(2, parameter2.getValue(properties).size());
+ assertTrue(parameter2.getValue(properties).contains("v1"));
+ assertTrue(parameter2.getValue(properties).contains("v2"));
+
+ properties.put("test1", "v1");
+ properties.put("test2", "v1,v3");
+
+ assertEquals(1, parameter1.getValue(properties).size());
+ assertTrue(parameter1.getValue(properties).contains("v1"));
+
+ assertEquals(2, parameter2.getValue(properties).size());
+ as...
[truncated message content] |