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

Vladmir Blagojevic vladimir.blagojevic at jboss.com
Thu Jan 4 22:45:05 EST 2007


  User: vblagojevic
  Date: 07/01/04 22:45:05

  Modified:    src/org/jboss/cache/factories  UnitTestCacheFactory.java
  Log:
  recovery of overwritten version 1.2
  
  Revision  Changes    Path
  1.4       +111 -68   JBossCache/src/org/jboss/cache/factories/UnitTestCacheFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UnitTestCacheFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/UnitTestCacheFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- UnitTestCacheFactory.java	4 Jan 2007 05:35:37 -0000	1.3
  +++ UnitTestCacheFactory.java	5 Jan 2007 03:45:05 -0000	1.4
  @@ -6,23 +6,27 @@
    */
   package org.jboss.cache.factories;
   
  +import java.io.InputStream;
  +
   import org.jboss.cache.Cache;
   import org.jboss.cache.CacheImpl;
  +import org.jboss.cache.config.CacheLoaderConfig;
   import org.jboss.cache.config.Configuration;
  -import org.jboss.cache.config.Configuration.CacheMode;
   import org.jboss.cache.config.ConfigurationException;
  +import org.jboss.cache.config.EvictionConfig;
  +import org.jboss.cache.config.Configuration.CacheMode;
   import org.jboss.cache.xml.XmlHelper;
   import org.w3c.dom.Element;
   import org.w3c.dom.NodeList;
   
  -import java.io.InputStream;
  -
   /**
    * Cache factory used by unit tests.
  + *
  + * 
    */
   public class UnitTestCacheFactory
   {
  -   public static String JGROUPS_CHANNEL = "udp";//use udp by default
  +   public static String JGROUPS_CHANNEL = "udp"; //use udp by default
      public static String JGROUPS_STACK_TYPE = "jgroups.stack";
      public static String DEFAULT_CONFIGURATION_FILE = "META-INF/unit-test-cache-service.xml";
   
  @@ -55,7 +59,18 @@
      public static Configuration createConfiguration(CacheMode mode, boolean useEviction, boolean usePassivation) throws ConfigurationException
      {
         UnitTestXmlConfigurationParser parser = new UnitTestXmlConfigurationParser();
  -      Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE, mode);
  +      Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE,mode);
  +      
  +      if(!useEviction)
  +      {
  +         c.setEvictionConfig(null);
  +      }
  +      
  +      if(!usePassivation)
  +      {
  +         c.setCacheLoaderConfig(null);
  +      }
  +      
         return c;
      }
   
  @@ -80,30 +95,58 @@
         }
      }
   
  +   public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared) throws Exception
  +   {
  +      return getSingleCacheLoaderConfig(preload, cacheloaderClass, properties, async, fetchPersistentState, shared, false);
  +   }
  +
  +   public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
  +   {
  +      return getSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties, async, fetchPersistentState, shared, purgeOnStartup);
  +   }
  +
  +   protected static CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
  +   {
  +      String xml = "<config>\n" +
  +              "<passivation>" + passivation + "</passivation>\n" +
  +              "<preload>" + preload + "</preload>\n" +
  +              "<cacheloader>\n" +
  +              "<class>" + cacheloaderClass + "</class>\n" +
  +              "<properties>" + properties + "</properties>\n" +
  +              "<async>" + async + "</async>\n" +
  +              "<shared>" + shared + "</shared>\n" +
  +              "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
  +              "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
  +              "</cacheloader>\n" +
  +              "</config>";
  +      Element element = XmlHelper.stringToElement(xml);
  +      return XmlConfigurationParser.parseCacheLoaderConfig(element);
  +   }
  +   
      private static class UnitTestXmlConfigurationParser extends XmlConfigurationParser
      {
   
         public Configuration parseFile(String filename, CacheMode mode)
         {
  -         return parseStream(getAsInputStreamFromClassLoader(DEFAULT_CONFIGURATION_FILE), mode);
  +         return parseStream(getAsInputStreamFromClassLoader(DEFAULT_CONFIGURATION_FILE),mode);         
         }
   
  -      public Configuration parseStream(InputStream stream, CacheMode mode)
  +      public Configuration parseStream(InputStream stream,CacheMode mode)
         {
            // loop through all elements in XML.
            if (stream == null) throw new ConfigurationException("Input stream for configuration xml is null!");
   
  -         Element root = XmlHelper.getDocumentRoot(stream);
  -         Element mbeanElement = getMBeanElement(root);
  +          Element root= XmlHelper.getDocumentRoot(stream);
  +          Element mbeanElement= getMBeanElement(root);
   
            ParsedAttributes attributes = extractAttributes(mbeanElement);
   
            // Special handling for the old separate property for
            // eviction policy -- just cache it and use with the eviction XML
  -         String defaultEvictionClass = attributes.stringAttribs.remove("EvictionPolicyClass");
  +          String defaultEvictionClass = (String) attributes.stringAttribs.remove("EvictionPolicyClass");
   
            // Deal with rename of the old property that controlled MBean registration
  -         String keepStats = attributes.stringAttribs.remove("UseMbean");
  +          String keepStats = (String) attributes.stringAttribs.remove("UseMbean");
            if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
            {
               attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
  @@ -124,7 +167,7 @@
               if (stackName.startsWith(JGROUPS_CHANNEL))
               {
                  Element jgroupsStack = (Element) stack.getElementsByTagName("config").item(0);
  -               if (mode == CacheMode.REPL_ASYNC && !stackName.contains("-"))
  +                if(mode == CacheMode.REPL_ASYNC && !stackName.contains("-"))
                  {
                     c.setClusterConfig(jgroupsStack);
                     c.setCacheMode(CacheMode.REPL_ASYNC);
  
  
  



More information about the jboss-cvs-commits mailing list