[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...

Manik Surtani msurtani at jboss.com
Tue Sep 5 09:26:00 EDT 2006


  User: msurtani
  Date: 06/09/05 09:26:00

  Modified:    src/org/jboss/cache/loader  CacheLoaderManager.java
  Log:
  Fixed NPEs
  
  Revision  Changes    Path
  1.24      +315 -299  JBossCache/src/org/jboss/cache/loader/CacheLoaderManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheLoaderManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/CacheLoaderManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -b -r1.23 -r1.24
  --- CacheLoaderManager.java	17 Aug 2006 21:57:58 -0000	1.23
  +++ CacheLoaderManager.java	5 Sep 2006 13:26:00 -0000	1.24
  @@ -8,8 +8,8 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.Fqn;
  -import org.jboss.cache.TreeCache;
   import org.jboss.cache.config.CacheLoaderConfig;
   import org.jboss.cache.xml.XmlHelper;
   import org.w3c.dom.Element;
  @@ -23,35 +23,35 @@
   /**
    * Manages all cache loader funxtionality.  This class is typically initialised with an XML DOM Element,
    * represeting a cache loader configuration, or a {@see CacheLoaderConfig} object.
  - *
  + * <p/>
    * Usage:
  - *
  + * <p/>
    * <code>
    *  CacheLoaderManager manager = new CacheLoaderManager();
    *  manager.setConfig(myXmlSnippet, myTreeCache);
    *  CacheLoader loader = manager.getCacheLoader();
    * </code>
  - *
  + * <p/>
    * The XML configuration passed in would typically look like:
  - *
  + * <p/>
    * <code><![CDATA[
  -
  -    <config>
  -        <passivation>false</passivation>
  -        <preload>/</preload>
  -
  -        <cacheloader>
  -            <class>org.jboss.cache.loader.FileCacheLoader</class>
  -            <async>true</async>
  -            <fetchPersistentState>false</fetchPersistentState>
  -            <ignoreModifications>false</ignoreModifications>
  -            <properties>
  -                location=/tmp/file
  -            </properties>
  -        </cacheloader>
  -    </config>
  - ]]>
  - </code>
  + * <p/>
  + * <config>
  + * <passivation>false</passivation>
  + * <preload>/</preload>
  + * <p/>
  + * <cacheloader>
  + * <class>org.jboss.cache.loader.FileCacheLoader</class>
  + * <async>true</async>
  + * <fetchPersistentState>false</fetchPersistentState>
  + * <ignoreModifications>false</ignoreModifications>
  + * <properties>
  + * location=/tmp/file
  + * </properties>
  + * </cacheloader>
  + * </config>
  + * ]]>
  + * </code>
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
  @@ -59,24 +59,25 @@
   {
       private static Log log = LogFactory.getLog(CacheLoaderManager.class);
       private CacheLoaderConfig config;
  -    private TreeCache cache;
  +   private CacheSPI cache;
       private CacheLoader loader;
       private boolean fetchPersistentState;
   
       /**
        * Creates a cache loader based on an XML element passed in.
  +    *
        * @param cacheLoaderConfig
        * @throws Exception
        */
  -    public void setConfig(Element cacheLoaderConfig, TreeCache cache) throws Exception
  +   public void setConfig(Element cacheLoaderConfig, CacheSPI cache) throws Exception
       {
           this.cache = cache;
           config = new CacheLoaderConfig();
  -        config.setPassivation( XmlHelper.readBooleanContents(cacheLoaderConfig, "passivation"));
  -        config.setPreload( XmlHelper.readStringContents(cacheLoaderConfig, "preload"));
  +      config.setPassivation(XmlHelper.readBooleanContents(cacheLoaderConfig, "passivation"));
  +      config.setPreload(XmlHelper.readStringContents(cacheLoaderConfig, "preload"));
           config.setShared(XmlHelper.readBooleanContents(cacheLoaderConfig, "shared"));
           NodeList cacheLoaderNodes = cacheLoaderConfig.getElementsByTagName("cacheloader");
  -        for (int i=0; i<cacheLoaderNodes.getLength(); i++)
  +      for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
           {
               Node node = cacheLoaderNodes.item(i);
               if (node.getNodeType() == Node.ELEMENT_NODE)
  @@ -97,11 +98,12 @@
   
       /**
        * Sets a configuration object and creates a cacheloader accordingly.
  +    *
        * @param config
        * @param cache
        * @throws Exception
        */
  -    public void setConfig(CacheLoaderConfig config, TreeCache cache) throws Exception
  +   public void setConfig(CacheLoaderConfig config, CacheSPI cache) throws Exception
       {
           this.config = config == null ? new CacheLoaderConfig() : config;
           this.cache = cache;
  @@ -110,6 +112,7 @@
   
       /**
        * Creates the cache loader based on a cache loader config passed in.
  +    *
        * @return a configured cacheloader
        * @throws IllegalAccessException
        * @throws InstantiationException
  @@ -139,7 +142,10 @@
                       numLoadersWithFetchPersistentState++;
                       fetchPersistentState = true;
                   }
  -                if (numLoadersWithFetchPersistentState > 1) throw new Exception("Invalid cache loader configuration!!  Only ONE cache loader may have fetchPersistentState set to true.  Cache will not start!");
  +            if (numLoadersWithFetchPersistentState > 1)
  +            {
  +               throw new Exception("Invalid cache loader configuration!!  Only ONE cache loader may have fetchPersistentState set to true.  Cache will not start!");
  +            }
                   CacheLoader l = createCacheLoader(cfg, cache);
                   // Only loaders that deal w/ state transfer factor into
                   // whether the overall chain supports ExtendedCacheLoader
  @@ -158,12 +164,13 @@
   
       /**
        * Creates the cache loader based on the configuration.
  +    *
        * @param cfg
        * @param cache
        * @return a cache loader
        * @throws Exception
        */
  -    private CacheLoader createCacheLoader(CacheLoaderConfig.IndividualCacheLoaderConfig cfg, TreeCache cache) throws Exception
  +   private CacheLoader createCacheLoader(CacheLoaderConfig.IndividualCacheLoaderConfig cfg, CacheSPI cache) throws Exception
       {
           // create loader
           CacheLoader tmpLoader = createInstance(cfg.getClassName());
  @@ -181,7 +188,7 @@
               // load props
               tmpLoader.setConfig(cfg.getProperties());
   
  -            tmpLoader.setCache(cache.getCacheSPI());
  +         tmpLoader.setCache(cache);
               // we should not be creating/starting the cache loader here - this should be done in the separate
               // startCacheLoader() method.
   //           tmpLoader.create();
  @@ -202,6 +209,7 @@
   
       /**
        * Performs a preload on the cache based on the cache loader preload configs used when configuring the cache.
  +    *
        * @throws Exception
        */
       public void preloadCache() throws Exception
  @@ -223,11 +231,15 @@
   
           stop = System.currentTimeMillis();
           total = stop - start;
  -        if (log.isDebugEnabled()) log.debug("preloading transient state from cache loader was successful (in " + total + " milliseconds)");
  +      if (log.isDebugEnabled())
  +      {
  +         log.debug("preloading transient state from cache loader was successful (in " + total + " milliseconds)");
  +      }
       }
   
       /**
        * Preloads a specific Fqn into the cache from the configured cacheloader
  +    *
        * @param fqn fqn to preload
        * @param preloadParents whether we preload parents
        * @param preloadChildren whether we preload children
  @@ -285,6 +297,7 @@
   
       /**
        * Overrides generated cache loader with the one provided,for backward compat.
  +    *
        * @param loader
        */
       public void setCacheLoader(CacheLoader loader)
  @@ -338,7 +351,10 @@
           {
               CacheLoaderConfig.IndividualCacheLoaderConfig first = getCacheLoaderConfig().getFirstCacheLoaderConfig();
               if (force ||
  -              (first != null && first.isPurgeOnStartup())) loader.remove(Fqn.ROOT);
  +             (first != null && first.isPurgeOnStartup()))
  +         {
  +            loader.remove(Fqn.ROOT);
  +         }
           }
       }
   }
  
  
  



More information about the jboss-cvs-commits mailing list