jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1127552 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store: LockableFileRevision.java PersistentId.java SimpleRevisionStore.java
Date Wed, 25 May 2011 15:27:05 GMT
Author: stefan
Date: Wed May 25 15:27:05 2011
New Revision: 1127552

URL: http://svn.apache.org/viewvc?rev=1127552&view=rev
Log:
MicroKernel prototype (WIP)

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java
Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/LockableFileRevision.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java?rev=1127552&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/PersistentId.java
Wed May 25 15:27:05 2011
@@ -0,0 +1,68 @@
+/*
+ * 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.store;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ *
+ */
+public class PersistentId {
+
+    private final File file;
+
+    private final ReentrantReadWriteLock rwLock;
+
+    private String id;
+
+    public PersistentId(File file) throws IOException {
+        rwLock = new ReentrantReadWriteLock();
+
+        this.file = file;
+
+        if (!file.exists()) {
+            set(null);
+        } else {
+            id = get();
+        }
+    }
+
+    public String get() throws IOException {
+        rwLock.readLock().lock();
+        try {
+            return id;
+        } finally {
+            rwLock.readLock().unlock();
+        }
+    }
+
+    public void set(String id) throws IOException {
+        rwLock.writeLock().lock();
+        try {
+            DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
+            out.writeUTF(id);
+            out.close();
+            this.id = id;
+        } finally {
+            rwLock.writeLock().unlock();
+        }
+    }
+}

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java?rev=1127552&r1=1127551&r2=1127552&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/SimpleRevisionStore.java
Wed May 25 15:27:05 2011
@@ -35,7 +35,7 @@ public class SimpleRevisionStore impleme
 
     boolean initialized;
     File dataDir;
-    LockableFileRevision headRev;
+    PersistentId headRev;
 
     public SimpleRevisionStore() throws Exception {
         initialized = false;
@@ -50,7 +50,7 @@ public class SimpleRevisionStore impleme
         if (! homeDir.exists()) {
             homeDir.mkdirs();
         }
-        headRev = new LockableFileRevision(new File(homeDir, "HEAD"));
+        headRev = new PersistentId(new File(homeDir, "HEAD"));
         dataDir = new File(homeDir, "data");
         if (! dataDir.exists()) {
             dataDir.mkdir();
@@ -166,7 +166,7 @@ public class SimpleRevisionStore impleme
         return new File(dataDir, buf.toString());
     }
 
-    private static String toHex(byte[] bytes) {
+    static String toHex(byte[] bytes) {
         char[] chars = new char[2 * bytes.length];
         for (int i = 0; i < bytes.length; i++) {
             chars[2 * i] = HEX_CHARS[(bytes[i] & 0xF0) >>> 4];



Mime
View raw message