You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2007/03/13 23:15:43 UTC

svn commit: r517910 - /activemq/activeio/trunk/activeio-core/src/main/java/org/apache/activeio/journal/active/ControlFile.java

Author: chirino
Date: Tue Mar 13 15:15:41 2007
New Revision: 517910

URL: http://svn.apache.org/viewvc?view=rev&rev=517910
Log:
did better VM locking strategy where we only put strings in the System properties since other software tends to break when they get stuff in the System properties that is not strings.


Modified:
    activemq/activeio/trunk/activeio-core/src/main/java/org/apache/activeio/journal/active/ControlFile.java

Modified: activemq/activeio/trunk/activeio-core/src/main/java/org/apache/activeio/journal/active/ControlFile.java
URL: http://svn.apache.org/viewvc/activemq/activeio/trunk/activeio-core/src/main/java/org/apache/activeio/journal/active/ControlFile.java?view=diff&rev=517910&r1=517909&r2=517910
==============================================================================
--- activemq/activeio/trunk/activeio-core/src/main/java/org/apache/activeio/journal/active/ControlFile.java (original)
+++ activemq/activeio/trunk/activeio-core/src/main/java/org/apache/activeio/journal/active/ControlFile.java Tue Mar 13 15:15:41 2007
@@ -46,7 +46,6 @@
     private final ByteBufferPacket controlData;
     
     private final static boolean brokenFileLock = "true".equals(System.getProperty("java.nio.channels.FileLock.broken", "false"));
-    private final static boolean disableLocking = "true".equals(System.getProperty("org.apache.activeio.journal.active.DisableLocking", "false"));
 
     private long controlDataVersion=0;
     private FileLock lock;
@@ -68,21 +67,19 @@
      * @throws IOException 
      */
     public void lock() throws IOException {
-        if( disableLocking )
-            return;
-        Set set = getVmLockSet();
-        synchronized (set) {
-            if (lock == null) {
-                if (!set.add(canonicalPath)) {
-                    throw new JournalLockedException("Journal is already opened by this application.");
-                }
 
-                if( !brokenFileLock ) {
-                    lock = channel.tryLock();
-                    if (lock == null) {
-                        set.remove(canonicalPath);
-                        throw new JournalLockedException("Journal is already opened by another application");
-                    }
+        Properties properties = System.getProperties();
+        synchronized(properties) {
+            String lockKey = "org.apache.activeio.journal.active.lockMap:"+canonicalPath;
+            if( properties.setProperty(lockKey, "true")!=null ) {
+                throw new JournalLockedException("Journal is already opened by this application.");
+            }
+
+            if( !brokenFileLock ) {
+                lock = channel.tryLock();
+                if (lock == null) {
+                   properties.remove(lockKey);
+                   throw new JournalLockedException("Journal is already opened by another application");
                 }
             }
         }
@@ -94,33 +91,17 @@
      * @throws IOException
      */
     public void unlock() throws IOException {
-        if( disableLocking )
-            return;
-        
-        Set set = getVmLockSet();
-        synchronized (set) {
+
+        Properties properties = System.getProperties();
+        synchronized(properties) {
             if (lock != null) {
-                set.remove(canonicalPath);
+                String lockKey = "org.apache.activeio.journal.active.lockMap:"+canonicalPath;
+                properties.remove(lockKey);
                 lock.release();
                 lock = null;
             }
         }
     }
-    
-    static private Set getVmLockSet() {
-        if ( lockSet == null ) { 
-            Properties properties = System.getProperties();
-            synchronized(properties) {
-                lockSet = (Set) properties.get("org.apache.activeio.journal.active.lockMap");
-                if( lockSet == null ) {
-                    lockSet = new HashSet();
-                }
-                properties.put("org.apache.activeio.journal.active.lockMap", lockSet);
-            }
-        }
-        return lockSet;
-    }
-
     
     public boolean load() throws IOException {
         long l = file.length();