jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1189087 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java main/java/org/apache/jackrabbit/mk/util/AscendingClock.java test/java/org/apache/jackrabbit/mk/util/AscendingClockTest.java
Date Wed, 26 Oct 2011 09:09:18 GMT
Author: thomasm
Date: Wed Oct 26 09:09:17 2011
New Revision: 1189087

URL: http://svn.apache.org/viewvc?rev=1189087&view=rev
Log:
Ascending clock (so that the timestamps of commits are unique)

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AscendingClock.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/AscendingClockTest.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1189087&r1=1189086&r2=1189087&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Wed Oct 26 09:09:17 2011
@@ -24,10 +24,10 @@ import org.apache.jackrabbit.mk.fs.FileU
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.server.Server;
+import org.apache.jackrabbit.mk.util.AscendingClock;
 import org.apache.jackrabbit.mk.util.Cache;
 import org.apache.jackrabbit.mk.util.CommitGate;
 import org.apache.jackrabbit.mk.util.ExceptionFactory;
-import org.apache.jackrabbit.mk.util.NonDescendingClock;
 import org.apache.jackrabbit.mk.util.PathUtils;
 
 import java.io.IOException;
@@ -66,7 +66,7 @@ public class MemoryKernelImpl implements
 
     private final String name;
     private final AbstractBlobStore ds;
-    private final NonDescendingClock clock = new NonDescendingClock(System.currentTimeMillis());
+    private final AscendingClock clock = new AscendingClock(System.currentTimeMillis());
     private final CommitGate gate = new CommitGate();
     private final Cache<Long, Revision> revisionCache = Cache.newInstance(null, 1024
* 1024);
     private volatile long headRevId;
@@ -415,25 +415,8 @@ public class MemoryKernelImpl implements
         return lastJournal;
     }
 
-    /**
-     * Returns the JSON diff representation of the changes between the specified
-     * revisions. The changes will be consolidated if the specified range
-     * covers intermediary revisions.
-     * <p/>
-     * Format:
-     * <pre>
-     * [ { "id" : "&lt;revisionId&gt;", "ts" : "&lt;revisionTimestamp&gt;",
"msg" : "&lt;commitMessage&gt;", "changes" : "&lt;JSON diff&gt;" }, ... ]
-     * </pre>
-     *
-     * @param fromRevisionId
-     * @param toRevisionId
-     * @param path consider only changes that affected the specified subtree at <code>path</code>;
-     *        if null the default "/" is assumed
-     * @return JSON diff representation of the changes
-     */
-    public String /* JSON diff */ diff(String fromRevisionId, String toRevisionId,
-                                String path) {
-        // todo implement
+    public String diff(String fromRevisionId, String toRevisionId, String path) {
+        // TODO implement if required
         return "";
     }
 
@@ -453,6 +436,7 @@ public class MemoryKernelImpl implements
     }
 
     public String getNodes(String path, String revisionId, int depth, long offset, int count)
{
+        // TODO offset > 0 should mean the properties are not included
         if (count < 0) {
             count = nodeMap.getMaxMemoryChildren();
         }

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AscendingClock.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AscendingClock.java?rev=1189087&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AscendingClock.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/AscendingClock.java
Wed Oct 26 09:09:17 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.mk.util;
+
+/**
+ * A clock that normally returns the current system time, but is guaranteed to
+ * return ascending values (even if the system time is changed), and never the
+ * same value twice. Worst case, it returns incrementing values.
+ */
+public class AscendingClock {
+
+    private long last;
+
+    /**
+     * Create a new clock.
+     *
+     * @param last the time (the next returned value will be at least one
+     *            bigger)
+     */
+    public AscendingClock(long last) {
+        this.last = last;
+    }
+
+    /**
+     * Get the current time, ensuring that the value is always larger than the
+     * last returned time, even if the system time was changed. Worst case, this
+     * method will return the last returned value plus one.
+     *
+     * @return the time in milliseconds since 1970-01-01 (UTC)
+     */
+    public synchronized long time() {
+        long now = System.currentTimeMillis();
+        if (now > last) {
+            last = now;
+        } else {
+            last++;
+        }
+        return last;
+    }
+
+}

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/AscendingClockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/AscendingClockTest.java?rev=1189087&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/AscendingClockTest.java
(added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/AscendingClockTest.java
Wed Oct 26 09:09:17 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.mk.util;
+
+import junit.framework.TestCase;
+
+public class AscendingClockTest extends TestCase {
+
+    public void test() throws InterruptedException {
+        long start, last;
+        last = start = System.currentTimeMillis() + 10000;
+        AscendingClock c = new AscendingClock(start);
+        for (int i = 0; i < 10000; i++) {
+            long t = c.time();
+            assertTrue(t > last);
+            last = t;
+        }
+    }
+
+}



Mime
View raw message