db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/odmg/locking InMemoryLockMapImpl.java
Date Fri, 03 Oct 2003 14:23:49 GMT
arminw      2003/10/03 07:23:49

  Modified:    src/java/org/apache/ojb/odmg/locking
                        InMemoryLockMapImpl.java
  Log:
  fix bug in lock cleanup
  
  Revision  Changes    Path
  1.11      +32 -41    db-ojb/src/java/org/apache/ojb/odmg/locking/InMemoryLockMapImpl.java
  
  Index: InMemoryLockMapImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/locking/InMemoryLockMapImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- InMemoryLockMapImpl.java	6 Feb 2003 21:14:13 -0000	1.10
  +++ InMemoryLockMapImpl.java	3 Oct 2003 14:23:49 -0000	1.11
  @@ -54,18 +54,17 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.odmg.TransactionImpl;
  +import org.apache.ojb.odmg.TxManagerFactory;
  +
   import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Vector;
   
  -import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.odmg.TransactionImpl;
  -import org.apache.ojb.odmg.TxManagerFactory;
  -import org.apache.ojb.odmg.HasBroker;
  -
   /**
    *
    * We use a HashMap and synchronize blocks of access for a get "check" then put
  @@ -98,11 +97,8 @@
        */
       public LockEntry getWriter(Object obj)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  -        /* @todo smarter solution in future */
  +    	checkTimedOutLocks();
  +        /* TODO: smarter solution in future */
           // fix/workaround
           // When Identity needs new id's we must overgive
           // the a target broker when run with multiple databases
  @@ -129,7 +125,7 @@
        */
       private PersistenceBroker getBroker()
       {
  -        return ((HasBroker) TxManagerFactory.instance().getCurrentTransaction()).getBroker();
  +        return TxManagerFactory.instance().getCurrentTransaction().getBroker();
       }
   
       /**
  @@ -138,10 +134,8 @@
        */
       public Collection getReaders(Object obj)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  +    	checkTimedOutLocks();
  +
           Identity oid = new Identity(obj,getBroker());
   
           ObjectLocks objectLocks = null;
  @@ -165,10 +159,8 @@
        */
       public boolean addReader(TransactionImpl tx, Object obj)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  +        checkTimedOutLocks();
  +
           Identity oid = new Identity(obj,getBroker());
           LockEntry reader = new LockEntry(oid.toString(),
                   tx.getGUID(),
  @@ -200,10 +192,8 @@
        */
       public void removeReader(TransactionImpl tx, Object obj)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  +        checkTimedOutLocks();
  +
           Identity oid = new Identity(obj, getBroker());
           String oidString = oid.toString();
           ObjectLocks objectLocks = null;
  @@ -240,10 +230,8 @@
        */
       public void removeWriter(LockEntry writer)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  +        checkTimedOutLocks();
  +
           String oidString = writer.getOidString();
           ObjectLocks objectLocks = null;
           synchronized (locktable)
  @@ -280,10 +268,8 @@
        */
       public boolean upgradeLock(LockEntry reader)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  +        checkTimedOutLocks();
  +
           String oidString = reader.getOidString();
           ObjectLocks objectLocks = null;
           synchronized (locktable)
  @@ -316,10 +302,8 @@
        */
       public boolean setWriter(TransactionImpl tx, Object obj)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  +        checkTimedOutLocks();
  +
           Identity oid = new Identity(obj, tx.getBroker());
           LockEntry writer = new LockEntry(oid.toString(),
                   tx.getGUID(),
  @@ -351,10 +335,8 @@
        */
       public boolean hasReadLock(TransactionImpl tx, Object obj)
       {
  -    	if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  -    	{
  -    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  -    	}
  +        checkTimedOutLocks();
  +
           Identity oid = new Identity(obj,getBroker());
           ObjectLocks objectLocks = null;
           synchronized (locktable)
  @@ -379,6 +361,15 @@
                   return false;
               }
           }
  +    }
  +
  +    private void checkTimedOutLocks()
  +    {
  +        if (System.currentTimeMillis() - m_lastCleanupAt > CLEANUP_FREQUENCY)
  +    	{
  +    		removeTimedOutLocks(AbstractLockStrategy.DEFAULT_LOCK_TIMEOUT);
  +            m_lastCleanupAt = System.currentTimeMillis();
  +    	}
       }
   
   	/**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message