jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edgarp...@apache.org
Subject svn commit: r279766 - /incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
Date Fri, 09 Sep 2005 13:23:02 GMT
Author: edgarpoce
Date: Fri Sep  9 06:22:50 2005
New Revision: 279766

URL: http://svn.apache.org/viewcvs?rev=279766&view=rev
Log:
jcr-213  Avoid creation of more than one jackrabbit instance with the same configuration.

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/RepositoryImpl.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=279766&r1=279765&r2=279766&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
Fri Sep  9 06:22:50 2005
@@ -78,6 +78,11 @@
     private static Logger log = Logger.getLogger(RepositoryImpl.class);
 
     /**
+     * repository home lock
+     */
+    private static final String REPOSITORY_LOCK = ".lock";
+
+    /**
      * hardcoded uuid of the repository root node
      */
     private static final String ROOT_NODE_UUID = "cafebabe-cafe-babe-cafe-babecafebabe";
@@ -144,8 +149,11 @@
      * @param repConfig
      */
     protected RepositoryImpl(RepositoryConfig repConfig) throws RepositoryException {
+
         this.repConfig = repConfig;
 
+        this.acquireRepositoryLock() ;
+
         // setup file systems
         repStore = repConfig.getFileSystem();
         String fsRootPath = "/meta";
@@ -221,6 +229,37 @@
             }
         });
     }
+    
+    /**
+     * Lock the repository home.
+     * @throws RepositoryException
+     *         if the repository lock can not be acquired
+     */
+    private void acquireRepositoryLock() throws RepositoryException {
+        File home = new File(this.repConfig.getHomeDir());
+        File lock  = new File(home, REPOSITORY_LOCK) ;
+        if (lock.exists()) {
+            throw new RepositoryException("The repository home at " + home.getAbsolutePath()
+ 
+                " appears to be in use. If you are sure it's not in use please delete the
file at " + 
+                lock.getAbsolutePath() + ". Probably the repository was not shutdown properly.");
+        }
+        try {
+            lock.createNewFile() ;
+        } catch (IOException e) {
+            throw new RepositoryException("Unable to create lock file at " + lock.getAbsolutePath());
+        }
+    }
+
+    /**
+     * Release repository lock
+     */
+    private void releaseRepositoryLock() {
+        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.
@@ -688,6 +727,9 @@
 
         // make sure this instance is not used anymore
         disposed = true;
+
+        this.releaseRepositoryLock() ;
+        
     }
 
     /**



Mime
View raw message