User: mnf999  
  Date: 01/08/01 11:28:43

  Modified:    src/main/org/jboss/ejb/plugins AbstractInstanceCache.java
  Log:
  the bean lock manager from Bill
  
  Revision  Changes    Path
  1.16      +30 -47    jboss/src/main/org/jboss/ejb/plugins/AbstractInstanceCache.java
  
  Index: AbstractInstanceCache.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInstanceCache.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AbstractInstanceCache.java        2001/07/20 20:07:15     1.15
  +++ AbstractInstanceCache.java        2001/08/01 18:28:43     1.16
  @@ -39,6 +39,8 @@
   import org.jboss.ejb.EntityEnterpriseContext;
   import org.jboss.ejb.DeploymentException;
   import org.jboss.ejb.Container;
  +import org.jboss.ejb.BeanLock;
  +import org.jboss.ejb.BeanLockManager;
   import org.jboss.metadata.MetaData;
   import org.jboss.metadata.XmlLoadable;
   import org.jboss.logging.Logger;
  @@ -61,7 +63,7 @@
   * @author <a href="[EMAIL PROTECTED]">Bill Burke</a>
   * @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
   *
  -* @version $Revision: 1.15 $
  +* @version $Revision: 1.16 $
   *
   *   <p><b>Revisions:</b>
   *
  @@ -74,6 +76,12 @@
   *   <li> Commented the getLock removeLock, temporarely, might need to come back 
when we go beyond
   *        locking at the context level and lock by ID  
   *   </ul>
  +* <p><b>2001/07/26: billb</b>
  +* <ol>
  +*   <li>Locking is now separate from EntityEnterpriseContext objects and is now
  +*   encapsulated in BeanLock and BeanLockManager.  Did this because the lifetime
  +*   of an EntityLock is sometimes longer than the lifetime of the ctx.
  +* </ol>
   */
   public abstract class AbstractInstanceCache
   implements InstanceCache, XmlLoadable, Monitorable, MetricsConstants
  @@ -117,13 +125,13 @@
                        }
                }
        }
  -  public Map retrieveStatistic()
  -  {
  -    return null;
  -  }
  -  public void resetStatistic()
  -  {
  -  }
  +     public Map retrieveStatistic()
  +     {
  +             return null;
  +     }
  +     public void resetStatistic()
  +     {
  +     }
        
        // Public --------------------------------------------------------
        public void setJMSMonitoringEnabled(boolean enable) {m_jmsMonitoring = enable;}
  @@ -234,6 +242,9 @@
                                // run without having acquired the cache lock via 
getCacheLock()
                                throw new IllegalStateException("INSERTING AN ALREADY 
EXISTING BEAN, ID = " + key);
                        }
  +                     //Create a lock in the lock manager, as long as there an 
instance in cache we keep 
  +                     // the lock in the manager, since get will increase the ref 
count on the lock
  +                     getContainer().getLockManager().getLock(key);
                }
        }
        /* From InstanceCache interface */
  @@ -271,7 +282,9 @@
                                getCache().remove(id);
                        }
                }
  -     //      removeLock(id);
  +             // When we introduced the bean in the cache we used the get to 
increase the lock count
  +             // now we decrease it and if the count is zero the manager will 
release the object from memory
  +             getContainer().getLockManager().removeLockRef(id);
        }
        
        public boolean isActive(Object id)
  @@ -279,41 +292,6 @@
                // Check whether an object with the given id is available in the cache
                return getCache().peek(id) != null;
        }
  -     /**
  -     * Creates (if necessary) and returns an object used as mutex to sync 
passivation
  -     * activity with other activities, in particular incoming invoking calls. <br>
  -     * The mutex is automatically removed when the corrispondent id is removed from
  -     * the cache, either by passivation or by removal.
  -     * This method must be synchronized with its dual, {@link #removeLock}.
  -     */
  -/*   public synchronized Sync getLock(Object id)
  -     {
  -             Sync mutex = (Sync)m_lockMap.get(id);
  -             if (mutex == null)
  -             {
  -                     mutex = new BeanSemaphore(1);
  -                     m_lockMap.put(id, mutex);
  -             }
  -             return mutex;
  -     }
  -     */
  -     /**
  -     * Removes the mutex associated with the given id.
  -     * This method must be synchronized with its dual, {@link #getLock}.
  -     */
  -/*   protected synchronized void removeLock(Object id)
  -     {
  -             Object mutex = m_lockMap.get(id);
  -             if (mutex != null)
  -             {
  -                     if (mutex instanceof BeanSemaphore)
  -                     {
  -                             ((BeanSemaphore)mutex).invalidate();
  -                     }
  -                     m_lockMap.remove(id);
  -             }
  -     }
  -*/   
        // XmlLoadable implementation ----------------------------------------------
        public void importXml(Element element) throws DeploymentException
        {
  @@ -660,8 +638,9 @@
                                                * marcf: this is still very valid but 
the first lock is on the ctx directly
                                                * this is part of the rework of the 
buzy wait bug
                                                */
  -                                             //Sync mutex = (Sync)getLock(id);
  -                                             synchronized (ctx) {
  +                                             BeanLock lock = 
getContainer().getLockManager().getLock(id);
  +                                             lock.sync();
  +                                             try { 
                                                        
                                                        // marcf: the mutex is not 
good as we need a thread reentrant one, for now we
                                                        // use straight 
synchronization on the ctx as there is a one-one relationship
  @@ -725,7 +704,6 @@
                                                                                       
         // bean failed, and fix it. See EJB 1.1, 6.4.1
                                                                                       
         passivate(ctx);
                                                                                       
         executed();
  -                     //                                                             
         removeLock(id);
                                                                                       
         freeContext(ctx);
                                                                                       
         
                                                                                       
         logPassivation(id);
  @@ -742,6 +720,11 @@
                                                        }// synchronized(cacheLock)
                                                
                                                }//synchronized(ctx)
  +                                             finally
  +                                             {
  +                                                     lock.releaseSync();
  +                                                     
getContainer().getLockManager().removeLockRef(id);
  +                                             }
                                        }//execute
                                };// Passivation job definition
                                
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to