jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r544288 - in /jackrabbit/branches/1.3/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/util/ test/java/org/apache/jackrabbit/core/util/
Date Mon, 04 Jun 2007 21:49:44 GMT
Author: jukka
Date: Mon Jun  4 14:49:43 2007
New Revision: 544288

URL: http://svn.apache.org/viewvc?view=rev&rev=544288
Log:
1.3: Merged revision 541650 (JCR-933)

Added:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java
      - copied unchanged from r541651, jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java
    jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/
      - copied from r541651, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/
    jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/RepositoryLockTest.java
      - copied unchanged from r541651, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/RepositoryLockTest.java
    jackrabbit/branches/1.3/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/TestAll.java
      - copied unchanged from r541651, jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/util/TestAll.java
Modified:
    jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java

Modified: jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&rev=544288&r1=544287&r2=544288
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Mon Jun  4 14:49:43 2007
@@ -55,6 +55,7 @@
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ManagedMLRUItemStateCacheFactory;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
+import org.apache.jackrabbit.core.util.RepositoryLock;
 import org.apache.jackrabbit.core.version.VersionManager;
 import org.apache.jackrabbit.core.version.VersionManagerImpl;
 import org.apache.jackrabbit.name.NamespaceResolver;
@@ -69,10 +70,6 @@
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-import java.nio.channels.OverlappingFileLockException;
 import java.security.AccessControlContext;
 import java.security.AccessController;
 import java.util.Arrays;
@@ -105,11 +102,6 @@
     private static Logger log = LoggerFactory.getLogger(RepositoryImpl.class);
 
     /**
-     * repository home lock
-     */
-    private static final String REPOSITORY_LOCK = ".lock";
-
-    /**
      * hardcoded id of the repository root node
      */
     public static final NodeId ROOT_NODE_ID = NodeId.valueOf("cafebabe-cafe-babe-cafe-babecafebabe");
@@ -193,7 +185,7 @@
     /**
      * the lock that guards instantiation of multiple repositories.
      */
-    private FileLock repLock;
+    private RepositoryLock repLock;
 
     /**
      * Clustered node used, <code>null</code> if clustering is not configured.
@@ -232,7 +224,9 @@
 
         this.repConfig = repConfig;
 
-        acquireRepositoryLock();
+        // Acquire a lock on the repository home
+        repLock = new RepositoryLock(repConfig.getHomeDir());
+        repLock.acquire();
 
         // setup file systems
         repStore = repConfig.getFileSystemConfig().createFileSystem();
@@ -393,67 +387,6 @@
     }
 
     /**
-     * Lock the repository home.
-     *
-     * @throws RepositoryException if the repository lock can not be acquired
-     */
-    protected void acquireRepositoryLock() throws RepositoryException {
-        File home = new File(this.repConfig.getHomeDir());
-        File lock = new File(home, REPOSITORY_LOCK);
-
-        if (lock.exists()) {
-            log.warn("Existing lock file at " + lock.getAbsolutePath()
-                    + " detected. Repository was not shut down properly.");
-        } else {
-            try {
-                lock.createNewFile();
-            } catch (IOException e) {
-                throw new RepositoryException(
-                    "Unable to create lock file at " + lock.getAbsolutePath(), e);
-            }
-        }
-        try {
-            repLock = new RandomAccessFile(lock, "rw").getChannel().tryLock();
-        } catch (IOException e) {
-            throw new RepositoryException(
-                "Unable to lock file at " + lock.getAbsolutePath(), e);
-        } catch (OverlappingFileLockException e) {
-            throw new RepositoryException(
-                    "The repository home at " + home.getAbsolutePath()
-                    + " appears to be in use since the file at "
-                    + lock.getAbsolutePath() + " is already locked by the current process.");
-        }
-        if (repLock == null) {
-            throw new RepositoryException(
-                    "The repository home at " + home.getAbsolutePath()
-                    + " appears to be in use since the file at "
-                    + lock.getAbsolutePath() + " is locked by another process.");
-        }
-    }
-
-    /**
-     * Release repository lock
-     */
-    protected void releaseRepositoryLock() {
-        if (repLock != null) {
-            try {
-                FileChannel channel = repLock.channel();
-                repLock.release();
-                channel.close();
-            } catch (IOException e) {
-                // ignore
-            }
-        }
-        repLock = null;
-
-        File home = new File(this.repConfig.getHomeDir());
-        File lock = new File(home, REPOSITORY_LOCK);
-        if (!lock.delete()) {
-            log.error("Unable to release repository lock");
-        }
-    }
-
-    /**
      * Returns the root node uuid.
      * @param fs
      * @return
@@ -1041,7 +974,7 @@
         notifyAll();
 
         // finally release repository lock
-        releaseRepositoryLock();
+        repLock.release();
 
         log.info("Repository has been shutdown");
     }



Mime
View raw message