This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.nosql.couchbase-resourceprovider-1.0.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-nosql-couchbase-resourceprovider.git
commit a360fa4cacf5f9f947b436223256289e7b8dc0b0 Author: Stefan Seifert <sseif...@apache.org> AuthorDate: Wed May 20 15:13:31 2015 +0000 SLING-4381 simplify couchbase client reference git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/nosql/couchbase-resourceprovider@1680597 13f79535-47bb-0310-9956-ffa450edef68 --- .../CouchbaseNoSqlResourceProviderFactory.java | 52 ++++------------------ .../CouchbaseNoSqlResourceProviderIT.java | 2 +- ...chbaseNoSqlResourceProviderTransactionalIT.java | 2 +- 3 files changed, 10 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/apache/sling/nosql/couchbase/resourceprovider/impl/CouchbaseNoSqlResourceProviderFactory.java b/src/main/java/org/apache/sling/nosql/couchbase/resourceprovider/impl/CouchbaseNoSqlResourceProviderFactory.java index 3f20e6c..84ffbf3 100644 --- a/src/main/java/org/apache/sling/nosql/couchbase/resourceprovider/impl/CouchbaseNoSqlResourceProviderFactory.java +++ b/src/main/java/org/apache/sling/nosql/couchbase/resourceprovider/impl/CouchbaseNoSqlResourceProviderFactory.java @@ -22,7 +22,6 @@ import java.util.Map; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.Service; @@ -32,13 +31,8 @@ import org.apache.sling.commons.osgi.PropertiesUtil; import org.apache.sling.nosql.couchbase.client.CouchbaseClient; import org.apache.sling.nosql.generic.adapter.NoSqlAdapter; import org.apache.sling.nosql.generic.resource.AbstractNoSqlResourceProviderFactory; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; import org.osgi.service.component.ComponentContext; import org.osgi.service.event.EventAdmin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * {@link ResourceProviderFactory} implementation that uses couchbase as @@ -48,10 +42,11 @@ import org.slf4j.LoggerFactory; @Service(value = ResourceProviderFactory.class) public class CouchbaseNoSqlResourceProviderFactory extends AbstractNoSqlResourceProviderFactory { - @Property(label = "Couchbase Client ID", description = "ID referencing the matching couchbase client configuration and bucket for caching.", value = CouchbaseNoSqlResourceProviderFactory.COUCHBASE_CLIENT_ID_DEFAULT) - static final String COUCHBASE_CLIENT_ID_PROPERTY = "couchbaseClientID"; - private static final String COUCHBASE_CLIENT_ID_DEFAULT = "caravan-resourceprovider-couchbase"; - + /** + * Couchbase Client ID for Couchbase Resource Provier + */ + public static final String COUCHBASE_CLIENT_ID = "sling-resourceprovider-couchbase"; + @Property(label = "Cache Key Prefix", description = "Prefix for caching keys.", value = CouchbaseNoSqlResourceProviderFactory.CACHE_KEY_PREFIX_DEFAULT) static final String CACHE_KEY_PREFIX_PROPERTY = "cacheKeyPrefix"; private static final String CACHE_KEY_PREFIX_DEFAULT = "sling-resource:"; @@ -59,52 +54,21 @@ public class CouchbaseNoSqlResourceProviderFactory extends AbstractNoSqlResource @Property(label = "Root paths", description = "Root paths for resource provider.", cardinality = Integer.MAX_VALUE) static final String PROVIDER_ROOTS_PROPERTY = ResourceProvider.ROOTS; + @Reference(target = "(" + CouchbaseClient.CLIENT_ID_PROPERTY + "=" + COUCHBASE_CLIENT_ID + ")") + private CouchbaseClient couchbaseClient; + @Reference private EventAdmin eventAdmin; - private String couchbaseClientId; - private ServiceReference couchbaseClientServiceReference; private NoSqlAdapter noSqlAdapter; - private static final Logger log = LoggerFactory.getLogger(CouchbaseNoSqlResourceProviderFactory.class); - @Activate private void activate(ComponentContext componentContext, Map<String, Object> config) { - CouchbaseClient couchbaseClient = null; - try { - couchbaseClientId = PropertiesUtil.toString(config.get(COUCHBASE_CLIENT_ID_PROPERTY), - COUCHBASE_CLIENT_ID_DEFAULT); - BundleContext bundleContext = componentContext.getBundleContext(); - ServiceReference[] serviceReferences = bundleContext.getServiceReferences( - CouchbaseClient.class.getName(), "(" + CouchbaseClient.CLIENT_ID_PROPERTY + "=" + couchbaseClientId + ")"); - if (serviceReferences.length == 1) { - couchbaseClientServiceReference = serviceReferences[0]; - couchbaseClient = (CouchbaseClient)bundleContext.getService(couchbaseClientServiceReference); - } - else if (serviceReferences.length > 1) { - log.error("Multiple couchbase clients registered for client id '{}', caching is disabled.", - couchbaseClientId); - } - else { - log.error("No couchbase clients registered for client id '{}', caching is disabled.", couchbaseClientId); - } - } - catch (InvalidSyntaxException ex) { - log.error("Invalid service filter, couchbase caching is disabled.", ex); - } - String cacheKeyPrefix = PropertiesUtil .toString(config.get(CACHE_KEY_PREFIX_PROPERTY), CACHE_KEY_PREFIX_DEFAULT); noSqlAdapter = new CouchbaseNoSqlAdapter(couchbaseClient, cacheKeyPrefix); } - @Deactivate - private void deactivate(ComponentContext componentContext) { - if (couchbaseClientServiceReference != null) { - componentContext.getBundleContext().ungetService(couchbaseClientServiceReference); - } - } - @Override protected NoSqlAdapter getNoSqlAdapter() { return noSqlAdapter; diff --git a/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java b/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java index ed64041..cacf7f8 100644 --- a/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java +++ b/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java @@ -43,7 +43,7 @@ public class CouchbaseNoSqlResourceProviderIT extends AbstractNoSqlResourceProvi context.registerInjectActivateService( new CouchbaseClientImpl(), ImmutableMap.<String, Object> builder() - .put(CouchbaseClient.CLIENT_ID_PROPERTY, "caravan-resourceprovider-couchbase") + .put(CouchbaseClient.CLIENT_ID_PROPERTY, CouchbaseNoSqlResourceProviderFactory.COUCHBASE_CLIENT_ID) .put("couchbaseHosts", System.getProperty("couchbaseHosts", "localhost:8091")) .put("bucketName", System.getProperty("bucketName", "resource-test")).build()); diff --git a/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java b/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java index 3c62e9d..76f87a5 100644 --- a/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java +++ b/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java @@ -43,7 +43,7 @@ public class CouchbaseNoSqlResourceProviderTransactionalIT extends AbstractNoSql context.registerInjectActivateService( new CouchbaseClientImpl(), ImmutableMap.<String, Object> builder() - .put(CouchbaseClient.CLIENT_ID_PROPERTY, "caravan-resourceprovider-couchbase") + .put(CouchbaseClient.CLIENT_ID_PROPERTY, CouchbaseNoSqlResourceProviderFactory.COUCHBASE_CLIENT_ID) .put("couchbaseHosts", System.getProperty("couchbaseHosts", "localhost:8091")) .put("bucketName", System.getProperty("bucketName", "resource-test")).build()); -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.