Updated Branches: refs/heads/develop f282e64b4 -> ae682e957
make LDClient providers configurable Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/ae682e95 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/ae682e95 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/ae682e95 Branch: refs/heads/develop Commit: ae682e957f3645a25bbc38301ef2825a85e7c138 Parents: f282e64 Author: Sebastian Schaffert <[email protected]> Authored: Mon Jan 13 12:30:41 2014 +0100 Committer: Sebastian Schaffert <[email protected]> Committed: Mon Jan 13 12:30:41 2014 +0100 ---------------------------------------------------------------------- .../ldclient/model/ClientConfiguration.java | 103 +++++++++++++++++-- .../ldclient/services/ldclient/LDClient.java | 21 ++-- 2 files changed, 112 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/ae682e95/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java ---------------------------------------------------------------------- diff --git a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java index ae6e143..feccff0 100644 --- a/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java +++ b/libraries/ldclient/ldclient-api/src/main/java/org/apache/marmotta/ldclient/model/ClientConfiguration.java @@ -19,6 +19,7 @@ package org.apache.marmotta.ldclient.model; import org.apache.http.client.HttpClient; import org.apache.marmotta.ldclient.api.endpoint.Endpoint; +import org.apache.marmotta.ldclient.api.provider.DataProvider; import java.util.HashSet; import java.util.Set; @@ -42,7 +43,7 @@ public class ClientConfiguration { private int connectionTimeout = 10000; /** - * Maximum number of HTTP requests to run in parallel + * Maximum number of HTTP requests to run in parallel. Default: 10. */ private int maxParallelRequests = 10; @@ -64,70 +65,123 @@ public class ClientConfiguration { private Set<String> excludeUris; /** - * A collection of endpoint definitions to use by this Linked Data Client. + * A collection of endpoint definitions to use by this Linked Data Client. Can be used to define custom + * endpoint access strategies or in case the ServiceLoader is not working (e.g. in OSGi environments). */ private Set<Endpoint> endpoints; - + + /** + * A collection of provider definitions to use by this Linked Data Client. Can be used in case the + * ServiceLoader is not working (e.g. in OSGi environments) + */ + private Set<DataProvider> providers; + + /** * A HttpClient used for retrieving the resource data. */ private HttpClient httpClient; public ClientConfiguration() { - excludeUris = new HashSet<String>(); - endpoints = new HashSet<Endpoint>(); + excludeUris = new HashSet<>(); + endpoints = new HashSet<>(); + providers = new HashSet<>(); httpClient = null; } + /** + * HTTP connection timeout in milliseconds; default 10 seconds, because we don't want slow servers to slow down + * batch retrievals + */ public int getConnectionTimeout() { return connectionTimeout; } + /** + * HTTP connection timeout in milliseconds; default 10 seconds, because we don't want slow servers to slow down + * batch retrievals + */ public void setConnectionTimeout(int connectionTimeout) { this.connectionTimeout = connectionTimeout; } + /** + * Socket timeout in milliseconds; maximum time a socket may be idle; default 60 seconds + */ public int getSocketTimeout() { return socketTimeout; } + /** + * Socket timeout in milliseconds; maximum time a socket may be idle; default 60 seconds + */ public void setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout; } + /** + * Maximum number of HTTP requests to run in parallel. Default: 10. + */ public int getMaxParallelRequests() { return maxParallelRequests; } + /** + * Maximum number of HTTP requests to run in parallel. Default: 10. + */ public void setMaxParallelRequests(int maxParallelRequests) { this.maxParallelRequests = maxParallelRequests; } + /** + * Default expiry time in seconds if not given by the server. + */ public long getDefaultExpiry() { return defaultExpiry; } + /** + * Default expiry time in seconds if not given by the server. + */ public void setDefaultExpiry(long defaultExpiry) { this.defaultExpiry = defaultExpiry; } + /** + * Minimum expiry time in seconds in case the server returns a lower expiry time + */ public long getMinimumExpiry() { return minimumExpiry; } + /** + * Minimum expiry time in seconds in case the server returns a lower expiry time + */ public void setMinimumExpiry(long minimumExpiry) { this.minimumExpiry = minimumExpiry; } + /** + * A collection of endpoint definitions to use by this Linked Data Client. Can be used to define custom + * endpoint access strategies or in case the ServiceLoader is not working (e.g. in OSGi environments). + */ public void addExcludeUri(String uriPrefix) { excludeUris.add(uriPrefix); } + /** + * A collection of endpoint definitions to use by this Linked Data Client. Can be used to define custom + * endpoint access strategies or in case the ServiceLoader is not working (e.g. in OSGi environments). + */ public Set<String> getExcludeUris() { return excludeUris; } + /** + * A collection of endpoint definitions to use by this Linked Data Client. Can be used to define custom + * endpoint access strategies or in case the ServiceLoader is not working (e.g. in OSGi environments). + */ public void setExcludeUris(Set<String> excludeUris) { this.excludeUris = excludeUris; } @@ -148,19 +202,56 @@ public class ClientConfiguration { } + /** + * A collection of endpoint definitions to use by this Linked Data Client. Can be used to define custom + * endpoint access strategies or in case the ServiceLoader is not working (e.g. in OSGi environments). + */ public void addEndpoint(Endpoint endpoint) { endpoints.add(endpoint); } + /** + * A collection of endpoint definitions to use by this Linked Data Client. Can be used to define custom + * endpoint access strategies or in case the ServiceLoader is not working (e.g. in OSGi environments). + */ public Set<Endpoint> getEndpoints() { return endpoints; } + /** + * A collection of endpoint definitions to use by this Linked Data Client. Can be used to define custom + * endpoint access strategies or in case the ServiceLoader is not working (e.g. in OSGi environments). + */ public void setEndpoints(Set<Endpoint> endpoints) { this.endpoints = endpoints; } - public HttpClient getHttpClient() { + + /** + * A collection of provider definitions to use by this Linked Data Client. Can be used in case the + * ServiceLoader is not working (e.g. in OSGi environments) + */ + public void addProvider(DataProvider provider) { + providers.add(provider); + } + + /** + * A collection of provider definitions to use by this Linked Data Client. Can be used in case the + * ServiceLoader is not working (e.g. in OSGi environments) + */ + public Set<DataProvider> getProviders() { + return providers; + } + + /** + * A collection of provider definitions to use by this Linked Data Client. Can be used in case the + * ServiceLoader is not working (e.g. in OSGi environments) + */ + public void setProviders(Set<DataProvider> providers) { + this.providers = providers; + } + + public HttpClient getHttpClient() { return httpClient; } http://git-wip-us.apache.org/repos/asf/marmotta/blob/ae682e95/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java ---------------------------------------------------------------------- diff --git a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java index e57f10e..717873d 100644 --- a/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java +++ b/libraries/ldclient/ldclient-core/src/main/java/org/apache/marmotta/ldclient/services/ldclient/LDClient.java @@ -65,7 +65,7 @@ public final class LDClient implements LDClientService { /** * A Java service loader loading all implementations of data providers registered on the classpath. */ - private static ServiceLoader<DataProvider> providers = ServiceLoader.load(DataProvider.class); + private static ServiceLoader<DataProvider> defaultProviders = ServiceLoader.load(DataProvider.class); /** * A Java service loader loading all auto-registered endpoint configurations on the classpath. @@ -81,6 +81,7 @@ public final class LDClient implements LDClientService { private ClientConfiguration config; + private List<DataProvider> providers; private List<Endpoint> endpoints; public LDClient() { @@ -92,7 +93,7 @@ public final class LDClient implements LDClientService { this.config = config; - endpoints = new ArrayList<Endpoint>(); + endpoints = new ArrayList<>(); for(Endpoint endpoint : defaultEndpoints) { endpoints.add(endpoint); } @@ -105,6 +106,18 @@ public final class LDClient implements LDClientService { } } + providers = new ArrayList<>(); + for(DataProvider provider : defaultProviders) { + providers.add(provider); + } + providers.addAll(config.getProviders()); + if(log.isInfoEnabled()) { + for(DataProvider provider : providers) { + log.info("- LDClient Probvider: {}", provider.getName()); + } + } + + retrievalSemaphore = new Semaphore(config.getMaxParallelRequests()); if (config.getHttpClient() != null) { @@ -149,10 +162,6 @@ public final class LDClient implements LDClientService { this.client = client; } - - for(DataProvider provider : providers) { - log.info("data provider: {}",provider.getName()); - } } @Override
