jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1453792 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: MongoJournal.java MongoStore.java
Date Thu, 07 Mar 2013 11:59:22 GMT
Author: jukka
Date: Thu Mar  7 11:59:21 2013
New Revision: 1453792

URL: http://svn.apache.org/r1453792
Log:
OAK-633: SegmentMK: Hierarchy of journals

Extract MongoJournal to a separate file

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoJournal.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoJournal.java?rev=1453792&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoJournal.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoJournal.java
Thu Mar  7 11:59:21 2013
@@ -0,0 +1,76 @@
+/*
+ * 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.util.concurrent.TimeUnit;
+
+import com.google.common.collect.ImmutableMap;
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBObject;
+
+class MongoJournal implements Journal {
+
+    private static final long UPDATE_INTERVAL =
+            TimeUnit.NANOSECONDS.convert(10, TimeUnit.MILLISECONDS);
+
+    private final DBCollection journals;
+
+    private final String name;
+
+    private long nextUpdate = System.nanoTime() - 2 * UPDATE_INTERVAL;
+
+    private RecordId head = getHead();
+
+    MongoJournal(DBCollection journals, String name) {
+        this.journals = journals;
+        this.name = name;
+    }
+
+    @Override
+    public synchronized RecordId getHead() {
+        long now = System.nanoTime();
+        if (now >= nextUpdate) {
+            DBObject journal = journals.findOne(new BasicDBObject("_id", name));
+            head = RecordId.fromString(journal.get("head").toString());
+            nextUpdate = now + UPDATE_INTERVAL;
+        }
+        return head;
+    }
+
+    @Override
+    public boolean setHead(RecordId base, RecordId head) {
+        DBObject baseObject = new BasicDBObject(
+                ImmutableMap.of("_id", name, "head", base.toString()));
+        DBObject headObject = new BasicDBObject(
+                ImmutableMap.of("_id", name, "head", head.toString()));
+        if (journals.findAndModify(baseObject, headObject) != null) {
+            this.head = head;
+            nextUpdate = System.nanoTime() + UPDATE_INTERVAL;
+            return true;
+        } else if (base.equals(this.head)) {
+            // force an update at next getHead() call
+            nextUpdate = System.nanoTime();
+        }
+        return false;
+    }
+
+    @Override
+    public void merge() {
+        throw new UnsupportedOperationException();
+    }
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java?rev=1453792&r1=1453791&r2=1453792&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MongoStore.java
Thu Mar  7 11:59:21 2013
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.plugin
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.Callable;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState;
 
@@ -33,9 +32,6 @@ import com.mongodb.Mongo;
 
 public class MongoStore implements SegmentStore {
 
-    private static final long UPDATE_INTERVAL =
-            TimeUnit.NANOSECONDS.convert(10, TimeUnit.MILLISECONDS);
-
     private final DBCollection segments;
 
     private final DBCollection journals;
@@ -67,46 +63,8 @@ public class MongoStore implements Segme
     }
 
     @Override
-    public Journal getJournal(final String name) {
-        return new Journal() {
-
-            private long nextUpdate = System.nanoTime() - 2 * UPDATE_INTERVAL;
-
-            private RecordId head = getHead();
-
-            @Override
-            public synchronized RecordId getHead() {
-                long now = System.nanoTime();
-                if (now >= nextUpdate) {
-                    DBObject journal = journals.findOne(new BasicDBObject("_id", name));
-                    head = RecordId.fromString(journal.get("head").toString());
-                    nextUpdate = now + UPDATE_INTERVAL;
-                }
-                return head;
-            }
-
-            @Override
-            public boolean setHead(RecordId base, RecordId head) {
-                DBObject baseObject = new BasicDBObject(
-                        ImmutableMap.of("_id", name, "head", base.toString()));
-                DBObject headObject = new BasicDBObject(
-                        ImmutableMap.of("_id", name, "head", head.toString()));
-                if (journals.findAndModify(baseObject, headObject) != null) {
-                    this.head = head;
-                    nextUpdate = System.nanoTime() + UPDATE_INTERVAL;
-                    return true;
-                } else if (base.equals(this.head)) {
-                    // force an update at next getHead() call
-                    nextUpdate = System.nanoTime();
-                }
-                return false;
-            }
-
-            @Override
-            public void merge() {
-                throw new UnsupportedOperationException();
-            }
-        };
+    public Journal getJournal(String name) {
+        return new MongoJournal(journals, name);
     }
 
     @Override



Mime
View raw message