[jboss-cvs] JBossAS SVN: r82636 - projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 6 14:10:51 EST 2009


Author: ALRubinger
Date: 2009-01-06 14:10:49 -0500 (Tue, 06 Jan 2009)
New Revision: 82636

Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
Log:
[EJBTHREE-1653] Revert due to regression: svn merge -r 82615:82614

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java	2009-01-06 18:59:30 UTC (rev 82635)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java	2009-01-06 19:10:49 UTC (rev 82636)
@@ -35,10 +35,9 @@
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
@@ -189,11 +188,8 @@
    
    protected boolean reinitialize = false;
    
-   private static final int TOTAL_PERMITS = Integer.MAX_VALUE;
-   
    // To support clean startup/shutdown
-   private final Semaphore semaphore = new Semaphore(TOTAL_PERMITS, true);
-   private final Lock invocationLock = new SemaphoreLock(this.semaphore);
+   private ReadWriteLock containerLock = new ReentrantReadWriteLock(true);
    
    private static final Interceptor[] currentInvocationStack = new Interceptor[] { new CurrentInvocationInterceptor() };
    
@@ -863,9 +859,8 @@
 
    public void create() throws Exception
    {
-      // Acquire all permits, blocking invocation lock until start()
-      this.semaphore.acquire(TOTAL_PERMITS);
-      
+      // Lock until start()
+      this.getContainerLock().lock();
       /*
       initializeClassContainer();
       for (int i = 0; i < constructors.length; i++)
@@ -883,17 +878,7 @@
    {
       this.lockedStart();
       
-      // We should not be able to acquire a permit here
-      if (!this.semaphore.tryAcquire())
-      {
-         // Make all permits available to invocation lock
-         this.semaphore.release(TOTAL_PERMITS);
-      }
-      else
-      {
-         // Release the one we just acquired
-         this.semaphore.release();
-      }
+      this.getContainerLock().unlock();
    }
    
    // Everything must be done in start to make sure all dependencies have been satisfied
@@ -926,21 +911,7 @@
 
    public final void stop() throws Exception
    {
-      // Allow re-entrance
-      if (this.semaphore.tryAcquire())
-      {
-         try
-         {
-            // Acquire all remaining permits, blocking invocation lock
-            this.semaphore.acquire(TOTAL_PERMITS - 1);
-         }
-         catch (InterruptedException e)
-         {
-            this.semaphore.release();
-            
-            throw e;
-         }
-      }
+      this.getContainerLock().lockInterruptibly();
       
       this.lockedStop();
    }
@@ -972,9 +943,6 @@
       
       // TODO: clean up BeanContainer?
       //super.cleanup();
-      
-      // Release all permits acquired in create()/stop()
-      this.semaphore.release(TOTAL_PERMITS);
    }
 
    @SuppressWarnings("unchecked")
@@ -1619,9 +1587,14 @@
    
    public Lock getInvocationLock()
    {
-      return this.invocationLock;
+      return this.containerLock.readLock();
    }
-
+   
+   private Lock getContainerLock()
+   {
+      return this.containerLock.writeLock();
+   }
+   
    // to make sure we have a dependency on the TransactionManager
    // note that the actual tx interceptors don't make use of the injected tm
    @Inject
@@ -1634,66 +1607,4 @@
    {
       return getObjectName().getCanonicalName();
    }
-   
-   /**
-    * {@link java.util.concurrent.locks.Lock} facade for this container's semaphore
-    * @author Paul Ferraro
-    */
-   private static class SemaphoreLock implements Lock
-   {
-      private final Semaphore semaphore;
-      
-      SemaphoreLock(Semaphore semaphore)
-      {
-         this.semaphore = semaphore;
-      }
-      
-      /**
-       * @see java.util.concurrent.locks.Lock#lock()
-       */
-      public void lock()
-      {
-         this.semaphore.acquireUninterruptibly();
-      }
-
-      /**
-       * @see java.util.concurrent.locks.Lock#lockInterruptibly()
-       */
-      public void lockInterruptibly() throws InterruptedException
-      {
-         this.semaphore.acquire();
-      }
-
-      /**
-       * @see java.util.concurrent.locks.Lock#newCondition()
-       */
-      public Condition newCondition()
-      {
-         throw new UnsupportedOperationException();
-      }
-
-      /**
-       * @see java.util.concurrent.locks.Lock#tryLock()
-       */
-      public boolean tryLock()
-      {
-         return this.semaphore.tryAcquire();
-      }
-
-      /**
-       * @see java.util.concurrent.locks.Lock#tryLock(long, java.util.concurrent.TimeUnit)
-       */
-      public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException
-      {
-         return this.semaphore.tryAcquire(timeout, unit);
-      }
-
-      /**
-       * @see java.util.concurrent.locks.Lock#unlock()
-       */
-      public void unlock()
-      {
-         this.semaphore.release();
-      }
-   }
 }




More information about the jboss-cvs-commits mailing list