jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1330887 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/osgi/ test/java/org/apache/jackrabbit/oak/plugins/name/
Date Thu, 26 Apr 2012 14:47:47 GMT
Author: thomasm
Date: Thu Apr 26 14:47:47 2012
New Revision: 1330887

URL: http://svn.apache.org/viewvc?rev=1330887&view=rev
Log:
OAK-28 Query implementation (make index provider osgiable)

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1330887&r1=1330886&r2=1330887&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Thu Apr 26 14:47:47 2012
@@ -62,11 +62,14 @@ public class ContentRepositoryImpl imple
         this(new MicroKernelImpl());
     }
 
-    public ContentRepositoryImpl(MicroKernel mk) {
+    private ContentRepositoryImpl(MicroKernel mk) {
+        this(mk, new Indexer(mk));
+    }
+
+    public ContentRepositoryImpl(MicroKernel mk, QueryIndexProvider indexProvider) {
         microKernel = mk;
         valueFactory = new CoreValueFactoryImpl(microKernel);
         nodeStore = new KernelNodeStore(microKernel, valueFactory);
-        QueryIndexProvider indexProvider = new Indexer(mk);
         queryEngine = new QueryEngineImpl(microKernel, valueFactory, indexProvider);
 
         // FIXME: workspace setup must be done elsewhere...

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java?rev=1330887&r1=1330886&r2=1330887&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
Thu Apr 26 14:47:47 2012
@@ -36,6 +36,8 @@ public class Activator implements Bundle
 
     private ServiceTracker tracker;
 
+    private OsgiIndexProvider indexProvider;
+
     private final Map<ServiceReference, ServiceRegistration> services =
             new HashMap<ServiceReference, ServiceRegistration>();
 
@@ -47,11 +49,14 @@ public class Activator implements Bundle
         tracker = new ServiceTracker(
                 context, MicroKernel.class.getName(), this);
         tracker.open();
+        indexProvider = new OsgiIndexProvider();
+        indexProvider.start(bundleContext);
     }
 
     @Override
     public void stop(BundleContext bundleContext) throws Exception {
-        tracker.open();
+        tracker.close();
+        indexProvider.stop();
     }
 
     //-------------------------------------------< ServiceTrackerCustomizer >---
@@ -63,7 +68,7 @@ public class Activator implements Bundle
             MicroKernel kernel = (MicroKernel) service;
             services.put(reference, context.registerService(
                     ContentRepository.class.getName(),
-                    new ContentRepositoryImpl(kernel),
+                    new ContentRepositoryImpl(kernel, indexProvider),
                     new Properties()));
             return service;
         } else {
@@ -74,11 +79,12 @@ public class Activator implements Bundle
 
     @Override
     public void modifiedService(ServiceReference reference, Object service) {
+        // nothing to do
     }
 
     @Override
     public void removedService(ServiceReference reference, Object service) {
-        ServiceRegistration registration = services.get(reference);
+        ServiceRegistration registration = services.remove(reference);
         registration.unregister();
         context.ungetService(reference);
     }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java?rev=1330887&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
Thu Apr 26 14:47:47 2012
@@ -0,0 +1,76 @@
+package org.apache.jackrabbit.oak.osgi;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.query.index.QueryIndex;
+import org.apache.jackrabbit.oak.query.index.QueryIndexProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class OsgiIndexProvider implements ServiceTrackerCustomizer, QueryIndexProvider {
+
+    private BundleContext context;
+
+    private ServiceTracker tracker;
+
+    private final Map<ServiceReference, QueryIndexProvider> providers =
+        new HashMap<ServiceReference, QueryIndexProvider>();
+
+    public void start(BundleContext bundleContext) throws Exception {
+        context = bundleContext;
+        tracker = new ServiceTracker(
+                bundleContext, QueryIndexProvider.class.getName(), this);
+        tracker.open();
+    }
+
+    public void stop() throws Exception {
+        tracker.close();
+    }
+
+    @Override
+    public Object addingService(ServiceReference reference) {
+        Object service = context.getService(reference);
+        if (service instanceof QueryIndexProvider) {
+            QueryIndexProvider provider = (QueryIndexProvider) service;
+            providers.put(reference, provider);
+            return service;
+        } else {
+            context.ungetService(reference);
+            return null;
+        }
+    }
+
+    @Override
+    public void modifiedService(ServiceReference reference, Object service) {
+        // nothing to do
+    }
+
+    @Override
+    public void removedService(ServiceReference reference, Object service) {
+        providers.remove(reference);
+        context.ungetService(reference);
+    }
+
+    @Override
+    public void init() {
+        // nothing to do
+    }
+
+    @Override
+    public List<QueryIndex> getQueryIndexes(MicroKernel mk) {
+        if (providers.size() == 0) {
+            return Collections.emptyList();
+        } else if (providers.size() == 1) {
+            return providers.get(0).getQueryIndexes(mk);
+        } else {
+            // TODO combine indexes
+            return null;
+        }
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java?rev=1330887&r1=1330886&r2=1330887&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
Thu Apr 26 14:47:47 2012
@@ -16,19 +16,17 @@
 */
 package org.apache.jackrabbit.oak.plugins.name;
 
-import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import static org.junit.Assert.assertEquals;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-
 public class NamespaceMappingsTest {
 
     @Test
     public void testMappings() throws Exception {
-        ContentRepository repository = new ContentRepositoryImpl(new MicroKernelImpl());
+        ContentRepository repository = new ContentRepositoryImpl();
         ContentSession session = repository.login(null, "default");
         NamespaceMappings r = new NamespaceMappings(session);
 



Mime
View raw message