Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 81123 invoked from network); 10 Oct 2007 13:13:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Oct 2007 13:13:01 -0000 Received: (qmail 83674 invoked by uid 500); 10 Oct 2007 13:12:48 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 83650 invoked by uid 500); 10 Oct 2007 13:12:48 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 83641 invoked by uid 99); 10 Oct 2007 13:12:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Oct 2007 06:12:48 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Oct 2007 13:12:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A14981A9832; Wed, 10 Oct 2007 06:12:39 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r583465 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java Date: Wed, 10 Oct 2007 13:12:39 -0000 To: commits@jackrabbit.apache.org From: thomasm@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071010131239.A14981A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: thomasm Date: Wed Oct 10 06:12:38 2007 New Revision: 583465 URL: http://svn.apache.org/viewvc?rev=583465&view=rev Log: JCR-1170: Repository lock keeps file open Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java?rev=583465&r1=583464&r2=583465&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/RepositoryLock.java Wed Oct 10 06:12:38 2007 @@ -51,7 +51,7 @@ /** * Logger instance. */ - private static final Logger log = + private static final Logger LOG = LoggerFactory.getLogger(RepositoryLock.class); /** @@ -63,6 +63,11 @@ * The lock file within the given directory. */ private final File file; + + /** + * The random access file. + */ + private RandomAccessFile randomAccessFile; /** * Unique identifier (canonical path name) of the locked directory. @@ -108,12 +113,26 @@ */ public void acquire() throws RepositoryException { if (file.exists()) { - log.warn("Existing lock file " + file + " detected." + LOG.warn("Existing lock file " + file + " detected." + " Repository was not shut down properly."); } - try { - lock = new RandomAccessFile(file, "rw").getChannel().tryLock(); + tryLock(); + } catch (RepositoryException e) { + closeRandomAccessFile(); + throw e; + } + } + + /** + * Try to lock the random access file. + * + * @throws RepositoryException + */ + private void tryLock() throws RepositoryException { + try { + randomAccessFile = new RandomAccessFile(file, "rw"); + lock = randomAccessFile.getChannel().tryLock(); } catch (IOException e) { throw new RepositoryException( "Unable to create or lock file " + file, e); @@ -150,11 +169,25 @@ try { System.setProperty(identifier, identifier); } catch (SecurityException e) { - log.warn("Unable to set system property: " + identifier, e); + LOG.warn("Unable to set system property: " + identifier, e); } } } } + + /** + * Close the random access file if it is open, and set it to null. + */ + private void closeRandomAccessFile() { + if (randomAccessFile != null) { + try { + randomAccessFile.close(); + } catch (IOException e) { + LOG.warn("Unable to close the random access file " + file, e); + } + randomAccessFile = null; + } + } /** * Releases repository lock. @@ -169,10 +202,11 @@ // ignore } lock = null; + closeRandomAccessFile(); } if (!file.delete()) { - log.error("Unable to release repository lock"); + LOG.warn("Unable to delete repository lock file"); } // JCR-933: see #acquire() @@ -180,9 +214,9 @@ try { System.getProperties().remove(identifier); } catch (SecurityException e) { - log.error("Unable to clear system property: " + identifier, e); + LOG.error("Unable to clear system property: " + identifier, e); } } } - + }