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 CacheDistributor.java ObjectCacheDefaultImpl.java ObjectCacheTwoLevelImpl.java
Date Sat, 19 Feb 2005 20:11:32 GMT
arminw      2005/02/19 12:11:32

  Modified:    src/java/org/apache/ojb/broker/cache Tag: OJB_1_0_RELEASE
                        CacheDistributor.java ObjectCacheDefaultImpl.java
                        ObjectCacheTwoLevelImpl.java
  Log:
  improve logging
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.3   +45 -22    db-ojb/src/java/org/apache/ojb/broker/cache/Attic/CacheDistributor.java
  
  Index: CacheDistributor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/CacheDistributor.java,v
  retrieving revision 1.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- CacheDistributor.java	7 Feb 2005 20:42:42 -0000	1.7.2.2
  +++ CacheDistributor.java	19 Feb 2005 20:11:31 -0000	1.7.2.3
  @@ -15,14 +15,15 @@
    * limitations under the License.
    */
   
  +import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.Map;
   import java.util.Properties;
  -import java.util.List;
  -import java.util.ArrayList;
   import java.util.StringTokenizer;
   
  +import org.apache.commons.lang.SystemUtils;
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.Identity;
  @@ -48,9 +49,6 @@
    * use a given standard ObjectCache implementation (given by
    * constructor argument).
    * </p>
  - * <p/>
  - * <p/>
  - * </p>
    *
    * @author Matthew Baird  (mattbaird@yahoo.com)
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  @@ -88,8 +86,6 @@
           this.broker = broker;
           this.descriptorBasedCaches = OjbConfigurator.getInstance().getConfigurationFor(null)
                   .getBoolean(DESCRIPTOR_BASED_CACHES, false);
  -        log.info("Use property 'descriptorBasedCaches' is set '" + descriptorBasedCaches
+ "'");
  -
           String exclude = broker.serviceConnectionManager().getConnectionDescriptor().getAttribute(CACHE_EXCLUDES_STRING);
           if(exclude != null)
           {
  @@ -97,7 +93,7 @@
               if(exclude.length() > 0)
               {
                   excludedPackages = createExcludedPackagesList(exclude);
  -                log.info("Exclude packages detected: " + excludedPackages);
  +                log.info("Packages to exclude from caching: " + excludedPackages);
               }
           }
       }
  @@ -108,7 +104,7 @@
       }
   
       /**
  -     * @see ObjectCache#cacheIfNew(org.apache.ojb.broker.Identity, Object)
  +     * @see ObjectCacheInternal#cacheIfNew(org.apache.ojb.broker.Identity, Object)
        */
       public boolean cacheIfNew(Identity oid, Object obj)
       {
  @@ -143,10 +139,6 @@
                       log.error("Error while call method 'clear()' on '" + oc + "'", e);
                   }
               }
  -//            /**
  -//             * then call clear on the caches hashmap.
  -//             */
  -//            caches.clear();
           }
       }
   
  @@ -177,7 +169,7 @@
           if(ocd == null)
           {
               throw new OJBRuntimeException("No object cache descriptor found for " + targetClass
+ ", using PBKey " + broker.getPBKey()
  -                        + ". Please set a cache descriptor in jdbc-connection-descriptor
or in class-descriptor");
  +                    + ". Please set a cache descriptor in jdbc-connection-descriptor or
in class-descriptor");
           }
           else
           {
  @@ -192,7 +184,16 @@
   
                           if(retval == null)
                           {
  -                            retval = prepareAndAddCache(ocd, targetClass);
  +                            if(log.isEnabledFor(Logger.INFO))
  +                            {
  +                                String eol = SystemUtils.LINE_SEPARATOR;
  +                                log.info(eol + "<====" + eol + "Setup new object cache
instance on CLASS LEVEL for" + eol
  +                                        + "PersistenceBroker: " + broker + eol
  +                                        + "descriptorBasedCache: " + descriptorBasedCaches
+ eol
  +                                        + "Class: " + targetClass + eol
  +                                        + "ObjectCache: " + ocd + eol + "====>");
  +                            }
  +                            retval = prepareAndAddCache(targetClass, ocd);
                           }
                       }
                   }
  @@ -204,6 +205,15 @@
   
                           if(retval == null)
                           {
  +                            if(log.isEnabledFor(Logger.INFO))
  +                            {
  +                                String eol = SystemUtils.LINE_SEPARATOR;
  +                                log.info(eol + "<====" + eol + "Setup new object cache
instance on CLASS LEVEL for" + eol
  +                                        + "PersistenceBroker: " + broker + eol
  +                                        + "descriptorBasedCache: " + descriptorBasedCaches
+ eol
  +                                        + "class: " + targetClass + eol
  +                                        + "ObjectCache: " + ocd + eol + "====>");
  +                            }
                               retval = prepareAndAddCache(ocd, ocd);
                           }
                       }
  @@ -214,6 +224,7 @@
               {
                   if(isExcluded(targetClass))
                   {
  +                    if(log.isDebugEnabled()) log.debug("Class '" + targetClass.getName()
+ "' is excluded from being cached");
                       retval = DUMMY_CACHE;
                   }
                   else
  @@ -225,7 +236,17 @@
   
                           if(retval == null)
                           {
  -                            retval = prepareAndAddCache(ocd, jcdAlias);
  +                            if(log.isEnabledFor(Logger.INFO))
  +                            {
  +                                String eol = SystemUtils.LINE_SEPARATOR;
  +                                log.info(eol + "<====" + eol + "Setup new object cache
instance on CONNECTION LEVEL for" + eol
  +                                        + "PersistenceBroker: " + broker + eol
  +                                        + "descriptorBasedCache: " + descriptorBasedCaches
+ eol
  +                                        + "Connection jcdAlias: " + jcdAlias + eol
  +                                        + "Calling class: " + targetClass
  +                                        + "ObjectCache: " + ocd + eol + "====>");
  +                            }
  +                            retval = prepareAndAddCache(jcdAlias, ocd);
                           }
                       }
                   }
  @@ -234,18 +255,18 @@
           return retval;
       }
   
  -    private ObjectCacheInternal prepareAndAddCache(ObjectCacheDescriptor ocd, Object key)
  +    private ObjectCacheInternal prepareAndAddCache(Object key, ObjectCacheDescriptor ocd)
       {
           ObjectCacheInternal cache;
           // before the synchronize method lock this,
           // another thread maybe added same key
           if((cache = lookupCache(key)) != null)
           {
  -            log.info("Contains key '" + key + "', do not create new ObjectCache implementation");
  +            log.info("Key '" + key + "' was already in use no need to create the ObjectCache
instance again");
           }
           else
           {
  -            log.info("Create new ObjectCacheImplementation for '" + key + "'");
  +            if(log.isDebugEnabled()) log.debug("Create new ObjectCache implementation for
" + key);
               try
               {
                   ObjectCache temp = (ObjectCache) ClassHelper.newInstance(ocd.getObjectCache(),
  @@ -257,6 +278,8 @@
                   }
                   else
                   {
  +                    log.info("Specified cache " + ocd.getObjectCache() + " does not implement
"
  +                            + ObjectCacheInternal.class + " and will be wrapped by a helper
class");
                       cache = new ObjectCacheInternalWrapper(temp);
                   }
               }
  @@ -280,7 +303,7 @@
           StringTokenizer tok = new StringTokenizer(theList, DELIMITER_FOR_EXCLUDE);
           String token = null;
           ArrayList result = new ArrayList();
  -        while (tok.hasMoreTokens())
  +        while(tok.hasMoreTokens())
           {
               token = tok.nextToken().trim();
               if(token.length() > 0) result.add(token);
  @@ -295,7 +318,7 @@
               String name = targetClass.getName();
               for(int i = 0; i < excludedPackages.size(); i++)
               {
  -                String exclude =  (String) excludedPackages.get(i);
  +                String exclude = (String) excludedPackages.get(i);
                   if(name.startsWith(exclude))
                   {
                       return true;
  
  
  
  1.24.2.4  +25 -10    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.3
  retrieving revision 1.24.2.4
  diff -u -r1.24.2.3 -r1.24.2.4
  --- ObjectCacheDefaultImpl.java	23 Jan 2005 03:07:31 -0000	1.24.2.3
  +++ ObjectCacheDefaultImpl.java	19 Feb 2005 20:11:31 -0000	1.24.2.4
  @@ -126,7 +126,7 @@
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  -public class ObjectCacheDefaultImpl implements ObjectCache, PBStateListener
  +public class ObjectCacheDefaultImpl implements ObjectCacheInternal, PBStateListener
   {
       private Logger log = LoggerFactory.getLogger(ObjectCacheDefaultImpl.class);
   
  @@ -168,8 +168,6 @@
           timeout = prop == null ? timeout : (Long.parseLong(prop.getProperty(TIMEOUT_PROP,
"" + (60 * 15))) * 1000);
           useSoftReferences = prop == null ?
                   false : (Boolean.valueOf((prop.getProperty(SOFT_REFERENCES_PROP, "true")).trim())).booleanValue();
  -        useSoftReferences = prop == null ?
  -                false : (Boolean.valueOf((prop.getProperty(SOFT_REFERENCES_PROP, "true")).trim())).booleanValue();
           cachingKeyType = prop == null ? 0 : (Integer.parseInt(prop.getProperty(CACHING_KEY_TYPE_PROP,
"0")));
           useAutoSync = prop == null ?
                   false : (Boolean.valueOf((prop.getProperty(AUTOSYNC_PROP, "false")).trim())).booleanValue();
  @@ -186,6 +184,15 @@
               }
           }
           identitiesInWork = new ArrayList();
  +        if(log.isEnabledFor(Logger.INFO))
  +        {
  +            ToStringBuilder buf = new ToStringBuilder(this);
  +            buf.append("timeout", timeout)
  +                    .append("useSoftReferences", useSoftReferences)
  +                    .append("cachingKeyType", cachingKeyType)
  +                    .append("useAutoSync", useAutoSync);
  +            log.info("Setup cache: " + buf.toString());
  +        }
       }
   
       /**
  @@ -198,24 +205,30 @@
           identitiesInWork.clear();
       }
   
  -    /**
  -     * Makes object persistent to the Objectcache.
  -     * I'm using soft-references to allow gc reclaim unused objects
  -     * even if they are still cached.
  -     */
  -    public void cache(Identity oid, Object obj)
  +    public void doInternalCache(Identity oid, Object obj, int type)
       {
           processQueue();
           if((obj != null))
           {
               synchronized(objectTable)
               {
  +                if(log.isDebugEnabled()) log.debug("Cache object " + oid);
                   traceIdentity(oid);
                   objectTable.put(buildKey(oid), buildEntry(obj, oid));
               }
           }
       }
   
  +    /**
  +     * Makes object persistent to the Objectcache.
  +     * I'm using soft-references to allow gc reclaim unused objects
  +     * even if they are still cached.
  +     */
  +    public void cache(Identity oid, Object obj)
  +    {
  +        doInternalCache(oid, obj, ObjectCacheInternal.TYPE_UNKNOWN);
  +    }
  +
       public boolean cacheIfNew(Identity oid, Object obj)
       {
           processQueue();
  @@ -268,6 +281,7 @@
                   when changed in tx but not stored.
                   */
                   traceIdentity(oid);
  +                if(log.isDebugEnabled()) log.debug("Object match " + oid);
               }
           }
           else
  @@ -287,6 +301,7 @@
           {
               removeTracedIdentity(oid);
               objectTable.remove(buildKey(oid));
  +            if(log.isDebugEnabled()) log.debug("Remove object " + oid);
           }
       }
   
  
  
  
  1.1.2.3   +10 -1     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.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- ObjectCacheTwoLevelImpl.java	7 Feb 2005 20:42:42 -0000	1.1.2.2
  +++ ObjectCacheTwoLevelImpl.java	19 Feb 2005 20:11:31 -0000	1.1.2.3
  @@ -35,6 +35,7 @@
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.commons.lang.builder.ToStringBuilder;
   
   /**
    * A two-level {@link ObjectCache} implementation with a session- and an application cache.
The application
  @@ -175,6 +176,13 @@
               throw new MetadataException("Can't setup application cache. Specified application
cache was '"
                       + applicationCacheName + "', copy strategy was '" + copyStrategyName
+ "'", e);
           }
  +        if(log.isEnabledFor(Logger.INFO))
  +        {
  +            ToStringBuilder buf = new ToStringBuilder(this);
  +            buf.append("copyStrategy", copyStrategyName)
  +                    .append("applicationCache", applicationCacheName);
  +            log.info("Setup cache: " + buf.toString());
  +        }
       }
   
       private ObjectCacheInternal getApplicationCache()
  @@ -338,6 +346,7 @@
        */
       public void remove(Identity oid)
       {
  +        if(log.isDebugEnabled()) log.debug("Remove object " + oid);
           sessionCache.remove(oid);
           getApplicationCache().remove(oid);
       }
  
  
  

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