[jboss-cvs] JBossAS SVN: r85889 - branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 16 06:15:23 EDT 2009


Author: alesj
Date: 2009-03-16 06:15:23 -0400 (Mon, 16 Mar 2009)
New Revision: 85889

Added:
   branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/Mutex.java
Modified:
   branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
Log:
[JBAS-6330]; create proper lock due to remote usage.

Added: branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/Mutex.java
===================================================================
--- branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/Mutex.java	                        (rev 0)
+++ branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/Mutex.java	2009-03-16 10:15:23 UTC (rev 85889)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.repository;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.AbstractQueuedSynchronizer;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+
+/**
+ * Mutex example taken from AbstractQueuedSynchronizer
+ * javadocs, with some small tweaks.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+class Mutex implements Lock, java.io.Serializable
+{
+   // Our internal helper class
+   private static class Sync extends AbstractQueuedSynchronizer
+   {
+      // Report whether in locked state
+      protected boolean isHeldExclusively()
+      {
+         return getState() == 1;
+      }
+
+      // Acquire the lock if state is zero
+      //
+      // This might be a problem, if someone "double-clicks" on this
+      // as the next thread will block this.
+      // Each lock, needs an unlock! :-)
+      public boolean tryAcquire(int acquires)
+      {
+         return compareAndSetState(0, 1);
+      }
+
+      // Release the lock by setting state to zero
+      protected boolean tryRelease(int releases)
+      {
+         setState(0);
+         return true;
+      }
+
+      // Provide a Condition
+      Condition newCondition()
+      {
+         return new AbstractQueuedSynchronizer.ConditionObject();
+      }
+
+      // Deserialize properly
+      private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
+      {
+         s.defaultReadObject();
+         setState(0); // reset to unlocked state
+      }
+   }
+
+   // The sync object does all the hard work. We just forward to it.
+   private final Sync sync = new Sync();
+
+   public void lock()
+   {
+      sync.acquire(1);
+   }
+
+   public boolean tryLock()
+   {
+      return sync.tryAcquire(1);
+   }
+
+   public void unlock()
+   {
+      sync.release(1);
+   }
+
+   public Condition newCondition()
+   {
+      return sync.newCondition();
+   }
+
+   public boolean isLocked()
+   {
+      return sync.isHeldExclusively();
+   }
+
+   public boolean hasQueuedThreads()
+   {
+      return sync.hasQueuedThreads();
+   }
+
+   public void lockInterruptibly() throws InterruptedException
+   {
+      sync.acquireInterruptibly(1);
+   }
+
+   public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException
+   {
+      return sync.tryAcquireNanos(1, unit.toNanos(timeout));
+   }
+}

Modified: branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
===================================================================
--- branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java	2009-03-16 10:14:49 UTC (rev 85888)
+++ branches/Branch_5_0/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java	2009-03-16 10:15:23 UTC (rev 85889)
@@ -40,7 +40,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.Lock;
 import java.util.zip.ZipInputStream;
 
 import org.jboss.deployers.spi.attachments.Attachments;
@@ -107,7 +107,7 @@
    /** The last time the profile was modified */
    private long lastModified;
    /** A lock for the hot deployment/{@link #getModifiedDeployments()} */
-   private ReentrantReadWriteLock contentLock = new ReentrantReadWriteLock(true);
+   private Lock contentLock = new Mutex();
    /** Should an attempt to overwrite existing content fail in {@link #addDeploymentContent(String, ZipInputStream, DeploymentPhase)}*/
    private boolean failIfAlreadyExists = false;
 
@@ -269,7 +269,7 @@
       // Suspend hot deployment checking
       if( trace )
          log.trace("Aquiring content read lock");
-      contentLock.writeLock().lock();
+      contentLock.lock();
       String repositoryName = null;
       try
       {
@@ -315,7 +315,7 @@
       finally
       {
          // Allow hot deployment checking
-         contentLock.writeLock().unlock();
+         contentLock.unlock();
          if(trace)
             log.trace("Released content write lock");
       }
@@ -423,13 +423,13 @@
    // FIXME!! http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215949#4215949
    public void acquireDeploymentContentLock()
    {
-      contentLock.writeLock().lock();
+      contentLock.lock();
       if( log.isTraceEnabled() )
          log.trace("acquireDeploymentContentLock, have write lock");
    }
    public void releaseDeploymentContentLock()
    {
-      contentLock.writeLock().unlock();
+      contentLock.unlock();
       if( log.isTraceEnabled() )
          log.trace("releaseDeploymentContentLock, gave up write lock");
    }
@@ -529,7 +529,7 @@
          log.trace("Checking applications for modifications");
       if( trace )
          log.trace("Aquiring content read lock");
-      contentLock.readLock().lock();
+      contentLock.lock();
       try
       {
          if( apps != null )
@@ -599,7 +599,7 @@
       }
       finally
       {
-         contentLock.readLock().unlock();
+         contentLock.unlock();
          if( trace )
             log.trace("Released content read lock");
       }




More information about the jboss-cvs-commits mailing list