jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1451165 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: osgi/Activator.java plugins/segment/SegmentNodeStoreService.java
Date Thu, 28 Feb 2013 10:11:00 GMT
Author: jukka
Date: Thu Feb 28 10:11:00 2013
New Revision: 1451165

URL: http://svn.apache.org/r1451165
Log:
OAK-593: Segment-based MK

Make SegmentMK usable in OSGi environments

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java

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=1451165&r1=1451164&r2=1451165&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 Feb 28 10:11:00 2013
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
 import org.apache.jackrabbit.oak.spi.lifecycle.OakInitializer;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -44,7 +45,9 @@ public class Activator implements Bundle
 
     private BundleContext context;
 
-    private ServiceTracker tracker;
+    private ServiceTracker microKernelTracker;
+
+    private ServiceTracker nodeStoreTracker;
 
     private final OsgiIndexProvider indexProvider = new OsgiIndexProvider();
 
@@ -68,14 +71,18 @@ public class Activator implements Bundle
         validatorProvider.start(bundleContext);
         repositoryInitializerTracker.setObserver(this);
         repositoryInitializerTracker.start(bundleContext);
-        tracker = new ServiceTracker(
+        microKernelTracker = new ServiceTracker(
                 context, MicroKernel.class.getName(), this);
-        tracker.open();
+        microKernelTracker.open();
+        nodeStoreTracker = new ServiceTracker(
+                context, NodeStore.class.getName(), this);
+        nodeStoreTracker.open();
     }
 
     @Override
     public void stop(BundleContext bundleContext) throws Exception {
-        tracker.close();
+        nodeStoreTracker.close();
+        microKernelTracker.close();
         indexProvider.stop();
         indexHookProvider.stop();
         validatorProvider.stop();
@@ -86,21 +93,32 @@ public class Activator implements Bundle
 
     @Override
     public Object addingService(ServiceReference reference) {
-        MicroKernel kernel = (MicroKernel) context.getService(reference);
-        OakInitializer.initialize(new KernelNodeStore(kernel),
-                repositoryInitializerTracker, indexHookProvider);
-            Oak oak = new Oak(kernel)
-                    .with(new CompositeHook(
+        Object service = context.getService(reference);
+        if (service instanceof MicroKernel) {
+            MicroKernel kernel = (MicroKernel) service;
+            services.put(reference, context.registerService(
+                    NodeStore.class.getName(),
+                    new KernelNodeStore(kernel),
+                    new Properties()));
+        } else if (service instanceof NodeStore) {
+            NodeStore store = (NodeStore) service;
+            OakInitializer.initialize(
+                    store, repositoryInitializerTracker, indexHookProvider);
+            Oak oak = new Oak(store)
+                .with(new CompositeHook(
                         // TODO: DefaultTypeEditor is JCR specific and does not belong here
                         new DefaultTypeEditor(),
                         new ValidatingHook(validatorProvider)))
-                    .with(indexProvider)
-                    .with(indexHookProvider);
+                .with(indexProvider)
+                .with(indexHookProvider);
             services.put(reference, context.registerService(
                     ContentRepository.class.getName(),
                     oak.createContentRepository(),
                     new Properties()));
-            return kernel;
+        } else {
+            service = null;
+        }
+        return service;
     }
 
     @Override

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java?rev=1451165&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java
Thu Feb 28 10:11:00 2013
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jackrabbit.oak.plugins.segment;
+
+import java.net.UnknownHostException;
+import java.util.Dictionary;
+import java.util.UUID;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.osgi.service.component.ComponentContext;
+
+import com.mongodb.Mongo;
+
+@Component(policy = ConfigurationPolicy.REQUIRE)
+@Service(NodeStore.class)
+public class SegmentNodeStoreService extends SegmentNodeStore {
+
+    @Property(description="The unique name of this instance")
+    public static final String NAME = "name";
+
+    @Property(description="MongoDB host", value="localhost")
+    public static final String HOST = "host";
+
+    @Property(description="MongoDB host", intValue=27017)
+    public static final String PORT = "port";
+
+    @Property(description="MongoDB database", value="Oak")
+    public static final String DB = "db";
+
+    @Property(description="Cache size (MB)", intValue=200)
+    public static final String CACHE = "cache";
+
+    private static final long MB = 1024 * 1024;
+
+    private String name;
+
+    private Mongo mongo;
+
+    private final SegmentStore[] store;
+
+    public SegmentNodeStoreService(final SegmentStore[] store) {
+        super(new SegmentStore() {
+            @Override
+            public RecordId getJournalHead(String name) {
+                return store[0].getJournalHead(name);
+            }
+            @Override
+            public boolean setJournalHead(
+                    String name, RecordId head, RecordId base) {
+                return store[0].setJournalHead(name, head, base);
+            }
+            @Override
+            public Segment readSegment(UUID segmentId) {
+                return store[0].readSegment(segmentId);
+            }            
+            @Override
+            public void createSegment(Segment segment) {
+                store[0].createSegment(segment);
+            }
+            @Override
+            public void createSegment(
+                    UUID segmentId, byte[] bytes, int offset, int len) {
+                store[0].createSegment(segmentId, bytes, offset, len);
+            }
+            @Override
+            public void deleteSegment(UUID segmentId) {
+                store[0].deleteSegment(segmentId);
+            }
+        });
+        this.store = store;
+    }
+
+    public SegmentNodeStoreService() {
+        this(new SegmentStore[0]);
+    }
+
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    @Activate
+    public void activate(ComponentContext context) throws UnknownHostException {
+        Dictionary<?, ?> properties = context.getProperties();
+        name = "" + properties.get(NAME);
+
+        String host = String.valueOf(properties.get(HOST));
+        int port = Integer.parseInt(String.valueOf(properties.get(PORT)));
+        String db = String.valueOf(properties.get(DB));
+        int cache = Integer.parseInt(String.valueOf(properties.get(CACHE)));
+
+        mongo = new Mongo(host, port);
+        store[0] = new MongoStore(mongo.getDB(db), cache * MB);
+    }
+
+    @Deactivate
+    public void deactivate() {
+        mongo.close();
+    }
+
+}



Mime
View raw message