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/broker/cache MaterializationCache.java ObjectCacheDefaultImpl.java ObjectCacheTwoLevelImpl.java
Date Sat, 31 Dec 2005 19:02:20 GMT
arminw      2005/12/31 11:02:20

  Modified:    src/java/org/apache/ojb/broker/cache Tag: OJB_1_0_RELEASE
                        MaterializationCache.java
                        ObjectCacheDefaultImpl.java
                        ObjectCacheTwoLevelImpl.java
  Log:
  minor performance improvement
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.7   +10 -13    db-ojb/src/java/org/apache/ojb/broker/cache/MaterializationCache.java
  
  Index: MaterializationCache.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/MaterializationCache.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- MaterializationCache.java	21 Dec 2005 22:24:15 -0000	1.1.2.6
  +++ MaterializationCache.java	31 Dec 2005 19:02:20 -0000	1.1.2.7
  @@ -142,14 +142,8 @@
       public Object lookup(Identity oid)
       {
           Object result = null;
  -        if(enabledReadCache)
  -        {
  -            result = doLocalLookup(oid);
  -        }
  -        if(result == null)
  -        {
  -            result = cacheDistributor.lookup(oid);
  -        }
  +        if(enabledReadCache) result = doLocalLookup(oid);
  +        if(result == null) result = cacheDistributor.lookup(oid);
           return result;
       }
   
  @@ -175,10 +169,13 @@
        */
       public void doLocalClear()
       {
  -        if(log.isDebugEnabled()) log.debug("Clear materialization cache");
  -        invokeCounter = 0;
  -        enabledReadCache = false;
  -        objectBuffer.clear();
  +        if(enabledReadCache)
  +        {
  +            if(log.isDebugEnabled()) log.debug("Clear materialization cache");
  +            invokeCounter = 0;
  +            enabledReadCache = false;
  +            if(objectBuffer.size() > 0) objectBuffer.clear();
  +        }
       }
   
       public void clear()
  
  
  
  1.24.2.8  +19 -9     db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java
  
  Index: ObjectCacheDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheDefaultImpl.java,v
  retrieving revision 1.24.2.7
  retrieving revision 1.24.2.8
  diff -u -r1.24.2.7 -r1.24.2.8
  --- ObjectCacheDefaultImpl.java	21 Dec 2005 22:24:15 -0000	1.24.2.7
  +++ ObjectCacheDefaultImpl.java	31 Dec 2005 19:02:20 -0000	1.24.2.8
  @@ -138,7 +138,9 @@
        * static Map held all cached objects
        */
       protected static final Map objectTable = new Hashtable();
  +    private static final Object lock = new Object();
       private static final ReferenceQueue queue = new ReferenceQueue();
  +    private volatile static short counter;
   
       private static long hitCount = 0;
       private static long failCount = 0;
  @@ -200,7 +202,7 @@
       {
           //processQueue();
           objectTable.clear();
  -        identitiesInWork.clear();
  +        if(identitiesInWork.size() > 0) identitiesInWork.clear();
       }
   
       public void doInternalCache(Identity oid, Object obj, int type)
  @@ -341,7 +343,7 @@
       public void beforeRollback(PBStateEvent event)
       {
           synchronizeWithTracedObjects();
  -        identitiesInWork.clear();
  +        if(identitiesInWork.size() > 0) identitiesInWork.clear();
       }
   
       public void beforeCommit(PBStateEvent event)
  @@ -358,7 +360,7 @@
           */
           if(!broker.isInTransaction())
           {
  -            identitiesInWork.clear();
  +            if(identitiesInWork.size() > 0) identitiesInWork.clear();
           }
       }
   
  @@ -368,7 +370,7 @@
   
       public void afterCommit(PBStateEvent event)
       {
  -        identitiesInWork.clear();
  +        if(identitiesInWork.size() > 0) identitiesInWork.clear();
       }
   
       public void afterBegin(PBStateEvent event)
  @@ -397,11 +399,19 @@
   
       private void processQueue()
       {
  -        CacheEntry sv;
  -        while((sv = (CacheEntry) queue.poll()) != null)
  +        // TODO: check this code block.
  +        if(counter++ > 500)
           {
  -            removeTracedIdentity(sv.getOid());
  -            objectTable.remove(buildKey(sv.getOid()));
  +            counter = 0;
  +            synchronized(lock)
  +            {
  +                CacheEntry sv;
  +                while((sv = (CacheEntry) queue.poll()) != null)
  +                {
  +                    removeTracedIdentity(sv.getOid());
  +                    objectTable.remove(buildKey(sv.getOid()));
  +                }
  +            }
           }
       }
   
  
  
  
  1.1.2.17  +22 -11    db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java
  
  Index: ObjectCacheTwoLevelImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/ObjectCacheTwoLevelImpl.java,v
  retrieving revision 1.1.2.16
  retrieving revision 1.1.2.17
  diff -u -r1.1.2.16 -r1.1.2.17
  --- ObjectCacheTwoLevelImpl.java	21 Dec 2005 22:24:15 -0000	1.1.2.16
  +++ ObjectCacheTwoLevelImpl.java	31 Dec 2005 19:02:20 -0000	1.1.2.17
  @@ -118,6 +118,7 @@
       // private boolean enabledReadCache;
       private int invokeCounter;
       private ReferenceQueue queue = new ReferenceQueue();
  +    private short counter;
       private ObjectCacheInternal applicationCache;
       private CopyStrategy copyStrategy;
       private PersistenceBrokerImpl broker;
  @@ -173,10 +174,10 @@
           {
               applicationCacheName = DEF_APP_CACHE;
           }
  -        
  +
           String forceProxyValue = prop.getProperty(FORCE_PROXIES, "false").trim();
           forceProxies = Boolean.valueOf(forceProxyValue).booleanValue();
  -        
  +
           if (forceProxies && broker.getProxyFactory().interfaceRequiredForProxyGeneration()){
               log.warn("'" + FORCE_PROXIES + "' is set to true, however a ProxyFactory implementation
" +
                       "[" + broker.getProxyFactory().getClass().getName() +"] " +
  @@ -184,7 +185,7 @@
                       "that all persistent objects implement an interface, or change the
ProxyFactory setting to a dynamic " +
                       "proxy generator (like ProxyFactoryCGLIBImpl).");
           }
  -        
  +
           Class[] type = new Class[]{PersistenceBroker.class, Properties.class};
           Object[] objects = new Object[]{broker, prop};
           try
  @@ -221,7 +222,7 @@
   
       /**
        * Returns the application cache that this 2-level cache uses.
  -     * 
  +     *
        * @return The application cache
        */
       public ObjectCacheInternal getApplicationCache()
  @@ -410,7 +411,7 @@
           }else{
               broker.getReferenceBroker().retrieveReferences(target, cld, forced);
               broker.getReferenceBroker().retrieveCollections(target, cld, forced);
  -        }    
  +        }
       }
   
       /**
  @@ -477,10 +478,14 @@
        */
       private void processQueue()
       {
  -        CacheEntry sv;
  -        while((sv = (CacheEntry) queue.poll()) != null)
  +        if(counter++ > 500)
           {
  -            sessionCache.remove(sv.oid);
  +            counter = 0;
  +            CacheEntry sv;
  +            while((sv = (CacheEntry) queue.poll()) != null)
  +            {
  +                sessionCache.remove(sv.oid);
  +            }
           }
       }
   
  @@ -636,7 +641,7 @@
                   // copy the field value
                   if(value != null) value = fld.getJdbcType().getFieldType().copy(value);
                   // now make a field-conversion to java-type, because we only
  -                // the sql type of the field
  +                // know the sql type of the field
                   value = fld.getFieldConversion().sqlToJava(value);
                   // set the copied field value in new object
                   fld.getPersistentField().set(target, value);
  @@ -653,12 +658,18 @@
               FieldDescriptor[] flds = cld.getFieldDescriptor(true);
               FieldDescriptor fld;
               int length = flds.length;
  +            /*
  +            TODO: in further OJB versions enhance FieldConversion with a FieldConversion#copy()
  +            method. In this case we can use copies of the java fields instead of tear down
fields to
  +            sql-level for copy. This could speed up two-level cache.
  +            */
               for(int i = 0; i < length; i++)
               {
                   fld = flds[i];
                   // get the value
                   Object value = fld.getPersistentField().get(obj);
  -                // convert value to a supported sql type
  +                // convert value to a supported sql type, because we only
  +                // can copy this type
                   value = fld.getFieldConversion().javaToSql(value);
                   // copy the sql type
                   value = fld.getJdbcType().getFieldType().copy(value);
  
  
  

---------------------------------------------------------------------
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