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

Manik Surtani msurtani at jboss.com
Sat Dec 30 12:49:57 EST 2006


  User: msurtani
  Date: 06/12/30 12:49:57

  Modified:    src/org/jboss/cache/factories      NodeFactory.java
                        CacheFactoryTest.java DefaultCacheFactory.java
                        CacheFactory.java InterceptorChainFactory.java
  Log:
  Major changes to restructure cache and node object model
  
  Revision  Changes    Path
  1.16      +35 -35    JBossCache/src/org/jboss/cache/factories/NodeFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NodeFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/NodeFactory.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- NodeFactory.java	20 Nov 2006 03:53:54 -0000	1.15
  +++ NodeFactory.java	30 Dec 2006 17:49:57 -0000	1.16
  @@ -6,34 +6,32 @@
    */
   package org.jboss.cache.factories;
   
  -import java.util.Map;
  -
   import org.jboss.cache.CacheSPI;
  -import org.jboss.cache.DataNode;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  -import org.jboss.cache.NodeImpl;
  -import org.jboss.cache.OptimisticTreeNode;
  -import org.jboss.cache.Cache;
  +import org.jboss.cache.NodeSPI;
  +import org.jboss.cache.UnversionedNode;
  +import org.jboss.cache.VersionedNode;
   import org.jboss.cache.optimistic.DataVersion;
   import org.jboss.cache.optimistic.TransactionWorkspace;
   import org.jboss.cache.optimistic.WorkspaceNode;
   import org.jboss.cache.optimistic.WorkspaceNodeImpl;
   
  +import java.util.Map;
  +
   /**
    * A factory that generates nodes.
  - * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    *
  + * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
   public class NodeFactory
   {
      private static NodeFactory _singleton;
   
  -   public static final byte NODE_TYPE_TREENODE = 1;
  -
  -   public static final byte NODE_TYPE_WORKSPACE_NODE = 2;
  -
  -   public static final byte NODE_TYPE_OPTIMISTIC_NODE = 3;
  +   public enum NodeType
  +   {
  +      UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE;
  +   }
   
      /**
       * private empty ctor
  @@ -44,6 +42,7 @@
   
      /**
       * Singleton accessor
  +    *
       * @return a singleton instance of the NodeFactory
       */
      public static NodeFactory getInstance()
  @@ -54,9 +53,9 @@
      }
   
      /**
  -    * Creates a new {@link DataNode} instance.
  +    * Creates a new {@link Node} instance.
       * 
  -    * @param nodeType  either {@link #NODE_TYPE_TREENODE} or {@link #NODE_TYPE_TREENODE}
  +    * @param nodeType  either {@link org.jboss.cache.factories.NodeFactory.NodeType#UNVERSIONED_NODE} or {@link org.jboss.cache.factories.NodeFactory.NodeType#VERSIONED_NODE}
       * @param childName the new node's name
       * @param fqn       the new node's Fqn
       * @param parent    the new node's parent
  @@ -66,19 +65,18 @@
       *                  <code>false</code> if param <code>data</code>'s contents
       *                  should be copied into the new node's data field.
       * @param cache     the cache to which the new node will be added
  -    * 
       * @return  the new node
       */
  -   public DataNode createDataNode(byte nodeType, Object childName, Fqn fqn, Node parent, Map data, boolean mapSafe,
  +   public Node createDataNode(NodeType nodeType, Object childName, Fqn fqn, Node parent, Map data, boolean mapSafe,
            DataVersion version, CacheSPI cache)
      {
         switch (nodeType)
         {
  -         case NODE_TYPE_TREENODE :
  -            return new NodeImpl(childName, fqn, data, mapSafe, cache);
  -         case NODE_TYPE_OPTIMISTIC_NODE :
  -            return new OptimisticTreeNode(childName, fqn, parent, data, cache);
  -         default :
  +         case UNVERSIONED_NODE:
  +            return new UnversionedNode(childName, fqn, data, mapSafe, cache);
  +         case VERSIONED_NODE:
  +            return new VersionedNode(childName, fqn, parent, data, cache);
  +         default:
               throw new IllegalArgumentException();
         }
      }
  @@ -86,8 +84,9 @@
      /**
       * Creates a node of the same type of the node passed in as a template.  The template passed in is entirely unaffected
       * and is not related in any way to the new node except that they will share the same type.
  -    * @deprecated - passing in childName and fqn shuld be redundant.
  +    *
       * @return TreeNode
  +    * @deprecated - passing in childName and fqn shuld be redundant.
       */
      public Node createNode(Object childName, Fqn fqn, Node parent, Map data, CacheSPI cache)
      {
  @@ -101,6 +100,7 @@
   
      /**
       * same as above, passing in an explicit version
  +    *
       * @deprecated - passing in childName and fqn shuld be redundant.
       */
      public Node createNodeOfType(Node template, Object childName, Fqn fqn, Node parent, Map data, CacheSPI cache,
  @@ -114,24 +114,24 @@
            return createWorkspaceNode(dataNodeParent, workspace);
         }
   
  -      if (parent instanceof DataNode)
  +      if (parent instanceof NodeSPI)
         {
  -         if (template instanceof OptimisticTreeNode)
  -            return createDataNode(NODE_TYPE_OPTIMISTIC_NODE, childName, fqn, parent, data, false, version, cache);
  -         if (template instanceof NodeImpl)
  -            return createDataNode(NODE_TYPE_TREENODE, childName, fqn, parent, data, false, null, cache);
  +         if (template instanceof VersionedNode)
  +            return createDataNode(NodeType.VERSIONED_NODE, childName, fqn, parent, data, false, version, cache);
  +         if (template instanceof UnversionedNode)
  +            return createDataNode(NodeType.UNVERSIONED_NODE, childName, fqn, parent, data, false, null, cache);
         }
         return null;
      }
   
      public WorkspaceNode createWorkspaceNode(Node dataNode, TransactionWorkspace workspace)
      {
  -      return new WorkspaceNodeImpl(dataNode, workspace);
  +      return new WorkspaceNodeImpl((NodeSPI) dataNode, workspace);
      }
   
  -   public DataNode createRootDataNode(byte type, CacheSPI cache)
  +   public NodeSPI createRootDataNode(NodeType type, CacheSPI cache)
      {
  -      return (DataNode) this.createDataNode(type, null, Fqn.ROOT, null, null, false, null, cache);
  +      return (NodeSPI) createDataNode(type, null, Fqn.ROOT, null, null, false, null, cache);
      }
   
   }
  
  
  
  1.5       +76 -77    JBossCache/src/org/jboss/cache/factories/CacheFactoryTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheFactoryTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/CacheFactoryTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- CacheFactoryTest.java	31 Oct 2006 06:57:27 -0000	1.4
  +++ CacheFactoryTest.java	30 Dec 2006 17:49:57 -0000	1.5
  @@ -7,24 +7,23 @@
   package org.jboss.cache.factories;
   
   import junit.framework.TestCase;
  -import org.jboss.cache.TreeCacheProxyImpl;
  -import org.jboss.cache.lock.IsolationLevel;
  +import org.jboss.cache.CacheImpl;
   import org.jboss.cache.config.Configuration;
  +import org.jboss.cache.lock.IsolationLevel;
   
   /**
  - *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
   public class CacheFactoryTest extends TestCase
   {
       Configuration expected;
       String configFile = "META-INF/replSync-service.xml";
  -    private TreeCacheProxyImpl cache;
  +   private CacheImpl cache;
   
       protected void setUp()
       {
           XmlConfigurationParser parser = new XmlConfigurationParser();
  -        expected = parser.parseFile( configFile );
  +      expected = parser.parseFile(configFile);
       }
   
       protected void tearDown()
  @@ -37,7 +36,7 @@
   
       public void testFromConfigFileStarted()
       {
  -        cache = (TreeCacheProxyImpl) DefaultCacheFactory.createCache(configFile);
  +      cache = (CacheImpl) DefaultCacheFactory.createCache(configFile);
           assertEquals(expected, cache.getConfiguration());
   
           assertTrue("Should have started", cache.isStarted());
  @@ -46,7 +45,7 @@
   
       public void testFromConfigFileUnstarted()
       {
  -        cache = (TreeCacheProxyImpl) DefaultCacheFactory.createCache(configFile, false);
  +      cache = (CacheImpl) DefaultCacheFactory.createCache(configFile, false);
           assertEquals(expected, cache.getConfiguration());
   
           assertFalse("Should not have started", cache.isStarted());
  @@ -56,7 +55,7 @@
   
       public void testFromConfigObjStarted()
       {
  -        cache = (TreeCacheProxyImpl) DefaultCacheFactory.createCache(expected);
  +      cache = (CacheImpl) DefaultCacheFactory.createCache(expected);
   
           assertTrue("Should have started", cache.isStarted());
   
  @@ -65,7 +64,7 @@
   
       public void testFromConfigObjUnstarted()
       {
  -        cache = (TreeCacheProxyImpl) DefaultCacheFactory.createCache(expected, false);
  +      cache = (CacheImpl) DefaultCacheFactory.createCache(expected, false);
   
           assertFalse("Should not have started", cache.isStarted());
   
  @@ -84,7 +83,7 @@
   
       public void testLifecycle() throws Exception
       {
  -        cache = (TreeCacheProxyImpl) DefaultCacheFactory.createCache(expected, false);
  +      cache = (CacheImpl) DefaultCacheFactory.createCache(expected, false);
           assertFalse(cache.isStarted());
           cache.start();
           assertTrue(cache.isStarted());
  
  
  
  1.12      +4 -4      JBossCache/src/org/jboss/cache/factories/DefaultCacheFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DefaultCacheFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/DefaultCacheFactory.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -b -r1.11 -r1.12
  --- DefaultCacheFactory.java	31 Oct 2006 06:57:27 -0000	1.11
  +++ DefaultCacheFactory.java	30 Dec 2006 17:49:57 -0000	1.12
  @@ -7,7 +7,7 @@
   package org.jboss.cache.factories;
   
   import org.jboss.cache.Cache;
  -import org.jboss.cache.TreeCache;
  +import org.jboss.cache.CacheImpl;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.config.ConfigurationException;
   
  @@ -44,14 +44,14 @@
      {
         try
         {
  -         TreeCache cache = new TreeCache();
  +         CacheImpl cache = new CacheImpl();
            cache.setConfiguration(configuration);
            if (start) cache.start();
  -         return cache.getCacheSPI();
  +         return cache;
         }
         catch (Exception e)
         {
  -         if (e instanceof ConfigurationException) throw(ConfigurationException) e;
  +         if (e instanceof ConfigurationException) throw (ConfigurationException) e;
            throw new RuntimeException(e);
         }
      }
  
  
  
  1.4       +0 -0      JBossCache/src/org/jboss/cache/factories/CacheFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  
  
  
  1.35      +11 -14    JBossCache/src/org/jboss/cache/factories/InterceptorChainFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InterceptorChainFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/InterceptorChainFactory.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -b -r1.34 -r1.35
  --- InterceptorChainFactory.java	15 Nov 2006 15:16:40 -0000	1.34
  +++ InterceptorChainFactory.java	30 Dec 2006 17:49:57 -0000	1.35
  @@ -8,8 +8,8 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.CacheImpl;
   import org.jboss.cache.CacheSPI;
  -import org.jboss.cache.TreeCache;
   import org.jboss.cache.interceptors.*;
   import org.jboss.cache.loader.CacheLoaderManager;
   import org.jboss.cache.util.Util;
  @@ -18,7 +18,7 @@
   import java.util.List;
   
   /**
  - * Factory class that builds an interceptor chain based on TreeCache config.
  + * Factory class that builds an interceptor chain based on CacheImpl config.
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
  @@ -26,7 +26,7 @@
   {
      private static Log log = LogFactory.getLog(InterceptorChainFactory.class);
   
  -   public Interceptor buildInterceptorChain(TreeCache cache) throws IllegalAccessException, ClassNotFoundException, InstantiationException
  +   public Interceptor buildInterceptorChain(CacheImpl cache) throws IllegalAccessException, ClassNotFoundException, InstantiationException
      {
         if (cache.getConfiguration().isNodeLockingOptimistic())
         {
  @@ -123,9 +123,8 @@
       * <p/>
       * CallInterceptor is always present at the top, the others may or may not be present
       */
  -   private Interceptor createPessimisticInterceptorChain(TreeCache treeCache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
  +   private Interceptor createPessimisticInterceptorChain(CacheImpl cache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
      {
  -      CacheSPI cache = treeCache.getCacheSPI();
         Interceptor call_interceptor = null;
         Interceptor lock_interceptor = null;
         Interceptor repl_interceptor = null;
  @@ -143,7 +142,7 @@
   
   
         call_interceptor = createInterceptor(CallInterceptor.class, cache);
  -      ((CallInterceptor) call_interceptor).setTreeCacheInstance(treeCache);
  +      ((CallInterceptor) call_interceptor).setTreeCacheInstance(cache);
   
         if (cache.getBuddyManager() != null)
         {
  @@ -358,9 +357,9 @@
            addInterceptor(first, lock_interceptor);
         }
   
  -      if (treeCache.getConfiguration().getEvictionConfig() != null && treeCache.getConfiguration().getEvictionConfig().isValidConfig())
  +      if (cache.getConfiguration().getEvictionConfig() != null && cache.getConfiguration().getEvictionConfig().isValidConfig())
         {
  -         eviction_interceptor = createInterceptor(treeCache.getEvictionInterceptorClass(), cache);
  +         eviction_interceptor = createInterceptor(cache.getEvictionInterceptorClass(), cache);
            if (first == null)
            {
               first = eviction_interceptor;
  @@ -388,10 +387,8 @@
         return setLastInterceptorPointer(first, call_interceptor);
      }
   
  -   private Interceptor createOptimisticInterceptorChain(TreeCache treeCache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
  +   private Interceptor createOptimisticInterceptorChain(CacheImpl cache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
      {
  -
  -      CacheSPI cache = treeCache.getCacheSPI();
         Interceptor txInterceptor = null, replicationInterceptor = null, lockInterceptor = null, validationInterceptor = null;
         Interceptor createIfNotExistsInterceptor = null, nodeInterceptor = null, invokerInterceptor = null, activationInterceptor = null;
         Interceptor passivationInterceptor = null, cacheLoaderInterceptor = null, cacheStoreInterceptor = null, first = null;
  @@ -443,11 +440,11 @@
         nodeInterceptor = createInterceptor(OptimisticNodeInterceptor.class, cache);
   
         invokerInterceptor = createInterceptor(CallInterceptor.class, cache);
  -      ((CallInterceptor) invokerInterceptor).setTreeCacheInstance(treeCache);
  +      ((CallInterceptor) invokerInterceptor).setTreeCacheInstance(cache);
   
  -      if (treeCache.getConfiguration().getEvictionConfig() != null && treeCache.getConfiguration().getEvictionConfig().isValidConfig())
  +      if (cache.getConfiguration().getEvictionConfig() != null && cache.getConfiguration().getEvictionConfig().isValidConfig())
         {
  -         evictionInterceptor = createInterceptor(treeCache.getEvictionInterceptorClass(), cache);
  +         evictionInterceptor = createInterceptor(cache.getEvictionInterceptorClass(), cache);
         }
   
         if (first == null) first = invocationCtxInterceptor;
  
  
  



More information about the jboss-cvs-commits mailing list