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

Manik Surtani msurtani at jboss.com
Thu Jan 11 08:49:07 EST 2007


  User: msurtani
  Date: 07/01/11 08:49:07

  Modified:    src/org/jboss/cache        ConsoleListener.java
                        CacheImpl.java Cache.java TreeCacheView.java
                        TreeCacheView2.java
  Added:       src/org/jboss/cache        CacheFactory.java
                        DefaultCacheFactory.java
  Log:
  Changed CacheImpl ctor to be protected, and changed cache factories accordingly
  
  Revision  Changes    Path
  1.14      +5 -5      JBossCache/src/org/jboss/cache/ConsoleListener.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConsoleListener.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/ConsoleListener.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- ConsoleListener.java	3 Jan 2007 17:50:31 -0000	1.13
  +++ ConsoleListener.java	11 Jan 2007 13:49:07 -0000	1.14
  @@ -1,6 +1,5 @@
   package org.jboss.cache;
   
  -import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jgroups.View;
   
   import java.util.Iterator;
  @@ -129,10 +128,14 @@
      public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
      {
         if (pre)
  +      {
            printEvent("DataNode about to be modified: " + fqn);
  +      }
         else
  +      {
            printEvent("DataNode modified: " + fqn);
      }
  +   }
   
      public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
      {
  @@ -364,8 +367,6 @@
   
         try
         {
  -         CacheImpl cache = new CacheImpl();
  -
            String configFileName = DEFAULT_CONFIG_FILE_NAME;
   
            if (args.length >= 1)
  @@ -377,8 +378,7 @@
               System.out.print("No xml config file argument is supplied. Will use jboss-cache.xml from classpath");
            }
   
  -         cache.setConfiguration(new XmlConfigurationParser().parseFile(configFileName));
  -
  +         CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFileName);
            ConsoleListener listener = new ConsoleListener(cache);
            listener.listen();
         }
  
  
  
  1.25      +2 -2      JBossCache/src/org/jboss/cache/CacheImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -b -r1.24 -r1.25
  --- CacheImpl.java	11 Jan 2007 12:24:15 -0000	1.24
  +++ CacheImpl.java	11 Jan 2007 13:49:07 -0000	1.25
  @@ -98,7 +98,7 @@
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @author Brian Stansberry
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Id: CacheImpl.java,v 1.24 2007/01/11 12:24:15 msurtani Exp $
  + * @version $Id: CacheImpl.java,v 1.25 2007/01/11 13:49:07 msurtani Exp $
    *          <p/>
    * @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
    */
  @@ -258,7 +258,7 @@
      /**
       * Constructs an uninitialized CacheImpl.
       */
  -   public CacheImpl() throws Exception
  +   protected CacheImpl() throws Exception
      {
         notifier = new Notifier(this);
         regionManager = new RegionManager(this);
  
  
  
  1.19      +2 -2      JBossCache/src/org/jboss/cache/Cache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Cache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Cache.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- Cache.java	2 Jan 2007 17:15:29 -0000	1.18
  +++ Cache.java	11 Jan 2007 13:49:07 -0000	1.19
  @@ -17,12 +17,12 @@
    * Along with {@link Node}, this is the central construct and basic client API of JBoss Cache and is used for
    * cache-wide operations.
    * <p/>
  - * The cache is constructed using a {@link org.jboss.cache.factories.CacheFactory}.
  + * The cache is constructed using a {@link CacheFactory}.
    * <p/>
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @see Node
  - * @see org.jboss.cache.factories.CacheFactory
  + * @see CacheFactory
    * @since 2.0.0
    */
   public interface Cache
  
  
  
  1.22      +51 -19    JBossCache/src/org/jboss/cache/TreeCacheView.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheView.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -b -r1.21 -r1.22
  --- TreeCacheView.java	3 Jan 2007 17:50:31 -0000	1.21
  +++ TreeCacheView.java	11 Jan 2007 13:49:07 -0000	1.22
  @@ -53,7 +53,7 @@
    * The view itself caches only the nodes, but doesn't cache any of the data (HashMap) associated with it. When
    * data needs to be displayed, the underlying cache will be accessed directly.
    *
  - * @version $Revision: 1.21 $
  + * @version $Revision: 1.22 $
    * @author<a href="mailto:bela at jboss.org">Bela Ban</a> March 27 2003
    */
   public class TreeCacheView implements TreeCacheViewMBean
  @@ -128,14 +128,20 @@
         MBeanServer srv = null;
   
         if (cache_service != null)
  +      {
            this.cache_service = new ObjectName(cache_service);
  +      }
         else
  +      {
            return;
  +      }
   
         // is this the right way to get hold of the JBoss MBeanServer ?
         List servers = MBeanServerFactory.findMBeanServer(null);
         if (servers == null || servers.size() == 0)
  +      {
            throw new Exception("TreeCacheView.init(): no MBeanServers found");
  +      }
         srv = (MBeanServer) servers.get(0);
         log.info("init(): found MBeanServer " + srv);
         cache = (CacheSPI) srv.getAttribute(this.cache_service, "Cache");
  @@ -158,10 +164,12 @@
            if (children != null && children.length > 0)
            {
               for (int i = 0; i < children.length; i++)
  +            {
                  populateTree(dir + "/" + children[i]);
            }
         }
      }
  +   }
   
      void put(Fqn fqn, Map m)
      {
  @@ -233,14 +241,14 @@
            log = LogFactory.getLog(CacheImpl.class);
            srv = MBeanServerFactory.createMBeanServer();
   
  -//            String  FACTORY="org.jboss.cache.transaction.DummyContextFactory";
  -//            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
  -//
  -//            DummyTransactionManager.getInstance();
  +         //            String  FACTORY="org.jboss.cache.transaction.DummyContextFactory";
  +         //            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
  +         //
  +         //            DummyTransactionManager.getInstance();
   
   
  -         cache = new CacheImpl();
  -         Configuration c = new Configuration();
  +         cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
  +         Configuration c = cache.getConfiguration();
            c.setClusterName("TreeCacheGroup");
            c.setClusterConfig(props);
            c.setInitialStateRetrievalTimeout(10000);
  @@ -262,12 +270,12 @@
   
            Runtime.getRuntime().addShutdownHook(new ShutdownThread(cache));
   
  -//            cache.put("/a/b/c", null);
  -//            cache.put("/a/b/c1", null);
  -//            cache.put("/a/b/c2", null);
  -//            cache.put("/a/b1/chat", null);
  -//            cache.put("/a/b1/chat2", null);
  -//            cache.put("/a/b1/chat5", null);
  +         //            cache.put("/a/b/c", null);
  +         //            cache.put("/a/b/c1", null);
  +         //            cache.put("/a/b/c2", null);
  +         //            cache.put("/a/b1/chat", null);
  +         //            cache.put("/a/b1/chat2", null);
  +         //            cache.put("/a/b1/chat5", null);
   
            demo = new TreeCacheView(mbean_name);
            demo.create();
  @@ -469,17 +477,17 @@
            row = evt.getFirstRow();
            col = evt.getColumn();
            if (col == 0)
  -         {  // set()
  +         {// set()
               key = (String) table_model.getValueAt(row, col);
               val = (String) table_model.getValueAt(row, col + 1);
               if (key != null && val != null)
               {
                  // cache.put(selected_node, key, val);
   
  -//                        server.invoke(cache_service, "put",
  -//                                      new Object[]{selected_node, key, val},
  -//                                      new String[]{String.class.getLastElementAsString(),
  -//                                      String.class.getLastElementAsString(), Object.class.getLastElementAsString()});
  +               //                        server.invoke(cache_service, "put",
  +               //                                      new Object[]{selected_node, key, val},
  +               //                                      new String[]{String.class.getLastElementAsString(),
  +               //                                      String.class.getLastElementAsString(), Object.class.getLastElementAsString()});
                  try
                  {
                     cache.put(selected_node, key, val);
  @@ -492,7 +500,7 @@
               }
            }
            else
  -         {          // add()
  +         {// add()
               key = (String) table_model.getValueAt(row, col - 1);
               val = (String) table.getValueAt(row, col);
               if (key != null && val != null)
  @@ -515,7 +523,9 @@
         {
            component_name = ((MyNode) path.getPathComponent(i)).name;
            if (component_name.equals("/"))
  +         {
               continue;
  +         }
            fqn = new Fqn(fqn, component_name);
         }
         data = getData(fqn);
  @@ -700,7 +710,9 @@
            MyNode node = (MyNode) o;
            Object name = node.name;
            if (name.equals(Fqn.SEPARATOR))
  +         {
               continue;
  +         }
            l.add(name);
         }
         System.out.println(" L " + l);
  @@ -714,7 +726,9 @@
         if (num_rows > 0)
         {
            for (int i = 0; i < num_rows; i++)
  +         {
               table_model.removeRow(0);
  +         }
            table_model.fireTableRowsDeleted(0, num_rows - 1);
            repaint();
         }
  @@ -914,7 +928,9 @@
         {
            JTextField fqnTextField = new JTextField();
            if (selected_node != null)
  +         {
               fqnTextField.setText(selected_node.toString());
  +         }
            Object[] information = {"Enter fully qualified name",
                    fqnTextField};
            final String btnString1 = "OK";
  @@ -1055,7 +1071,9 @@
            {
               n = curr.findChild(o);
               if (n == null)
  +            {
                  return null;
  +            }
               curr = n;
            }
            return curr;
  @@ -1067,7 +1085,9 @@
            MyNode child;
   
            if (relative_name == null || getChildCount() == 0)
  +         {
               return null;
  +         }
            for (int i = 0; i < getChildCount(); i++)
            {
               child = (MyNode) getChildAt(i);
  @@ -1077,8 +1097,10 @@
               }
   
               if (child.name.equals(relative_name))
  +            {
                  return child;
            }
  +         }
            return null;
         }
   
  @@ -1088,11 +1110,15 @@
            StringBuffer sb = new StringBuffer();
   
            for (int i = 0; i < indent; i++)
  +         {
               sb.append(" ");
  +         }
            if (!isRoot())
            {
               if (name == null)
  +            {
                  sb.append("/<unnamed>");
  +            }
               else
               {
                  sb.append(TreeCacheGui.SEP.toString() + name);
  @@ -1102,12 +1128,18 @@
            if (getChildCount() > 0)
            {
               if (isRoot())
  +            {
                  indent = 0;
  +            }
               else
  +            {
                  indent += 4;
  +            }
               for (int i = 0; i < getChildCount(); i++)
  +            {
                  sb.append(((MyNode) getChildAt(i)).print(indent));
            }
  +         }
            return sb.toString();
         }
   
  
  
  
  1.21      +50 -11    JBossCache/src/org/jboss/cache/TreeCacheView2.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheView2.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView2.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -b -r1.20 -r1.21
  --- TreeCacheView2.java	3 Jan 2007 17:50:31 -0000	1.20
  +++ TreeCacheView2.java	11 Jan 2007 13:49:07 -0000	1.21
  @@ -12,7 +12,6 @@
   import bsh.util.JConsole;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.jboss.cache.factories.XmlConfigurationParser;
   import org.jgroups.View;
   
   import javax.swing.*;
  @@ -53,7 +52,7 @@
    * The view itself caches only the nodes, but doesn't cache any of the data (HashMap) associated with it. When
    * data needs to be displayed, the underlying cache will be accessed directly.
    *
  - * @version $Revision: 1.20 $
  + * @version $Revision: 1.21 $
    */
   public class TreeCacheView2
   {
  @@ -106,10 +105,12 @@
            if (children != null && children.length > 0)
            {
               for (int i = 0; i < children.length; i++)
  +            {
                  populateTree(dir + "/" + children[i]);
            }
         }
      }
  +   }
   
      void put(String fqn, Map m)
      {
  @@ -155,11 +156,9 @@
            }
            else
            {
  -            cache = new CacheImpl();
  -            cache.setConfiguration(new XmlConfigurationParser().parseFile(resource));
  +            cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(resource);
   
  -            cache.start();
  -//            cache.getNotifier().addCacheListener(new TreeCacheView.MyListener());
  +            //            cache.getNotifier().addCacheListener(new TreeCacheView.MyListener());
               demo = new TreeCacheView2(cache);
               demo.start();
               if (start_directory != null && start_directory.length() > 0)
  @@ -264,7 +263,7 @@
            JConsole bshConsole = new JConsole();
            Interpreter interpreter = new Interpreter(bshConsole);
            interpreter.getNameSpace().importCommands("org.jboss.cache.util");
  -         interpreter.setShowResults(!interpreter.getShowResults()); // show();
  +         interpreter.setShowResults(!interpreter.getShowResults());// show();
            //System.setIn(bshConsole.getInputStream());
            System.setOut(bshConsole.getOut());
            System.setErr(bshConsole.getErr());
  @@ -391,7 +390,7 @@
            row = evt.getFirstRow();
            col = evt.getColumn();
            if (col == 0)
  -         {  // set()
  +         {// set()
               key = (String) table_model.getValueAt(row, col);
               val = (String) table_model.getValueAt(row, col + 1);
               if (key != null && val != null)
  @@ -410,7 +409,7 @@
               }
            }
            else
  -         {          // add()
  +         {// add()
               key = (String) table_model.getValueAt(row, col - 1);
               val = (String) table.getValueAt(row, col);
               if (key != null && val != null)
  @@ -433,12 +432,18 @@
         {
            component_name = ((MyNode) path.getPathComponent(i)).name;
            if (component_name.equals(SEP))
  +         {
               continue;
  +         }
            if (fqn.equals(SEP))
  +         {
               fqn += component_name;
  +         }
            else
  +         {
               fqn = fqn + SEP + component_name;
         }
  +      }
         data = getData(fqn);
         if (data != null)
         {
  @@ -475,8 +480,8 @@
   
      public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, ModificationType modType, Map data)
      {
  -//      data=getData(fqn.toString());
  -//      System.out.println("Data modified: fqn: " +fqn + " data: " +data);
  +      //      data=getData(fqn.toString());
  +      //      System.out.println("Data modified: fqn: " +fqn + " data: " +data);
         populateTable(data);
      }
   
  @@ -622,16 +627,24 @@
         {
            tmp_name = ((MyNode) path[i]).name;
            if (tmp_name.equals(SEP))
  +         {
               continue;
  +         }
            else
  +         {
               sb.append(SEP + tmp_name);
         }
  +      }
         tmp_name = sb.toString();
         if (tmp_name.length() == 0)
  +      {
            return SEP;
  +      }
         else
  +      {
            return tmp_name;
      }
  +   }
   
      void clearTable()
      {
  @@ -640,7 +653,9 @@
         if (num_rows > 0)
         {
            for (int i = 0; i < num_rows; i++)
  +         {
               table_model.removeRow(0);
  +         }
            table_model.fireTableRowsDeleted(0, num_rows - 1);
            repaint();
         }
  @@ -761,8 +776,10 @@
            key = (String) it.next();
            value = get(fqn, key);
            if (value != null)
  +         {
               data.put(key, value);
         }
  +      }
         return data;
      }
   
  @@ -933,7 +950,9 @@
         {
            JTextField fqnTextField = new JTextField();
            if (selected_node != null)
  +         {
               fqnTextField.setText(selected_node);
  +         }
            Object[] information = {"Enter fully qualified name",
                    fqnTextField};
            final String btnString1 = "OK";
  @@ -963,7 +982,9 @@
         {
            JTextField fqnTextField = new JTextField();
            if (selected_node != null)
  +         {
               fqnTextField.setText(selected_node);
  +         }
            Object[] information = {"Enter fully qualified name",
                    fqnTextField};
            final String btnString1 = "OK";
  @@ -993,7 +1014,9 @@
         {
            JTextField fqnTextField = new JTextField();
            if (selected_node != null)
  +         {
               fqnTextField.setText(selected_node);
  +         }
            Object[] information = {"Enter fully qualified name",
                    fqnTextField};
            final String btnString1 = "OK";
  @@ -1224,7 +1247,9 @@
               child_name = tok.nextToken();
               n = curr.findChild(child_name);
               if (n == null)
  +            {
                  return null;
  +            }
               curr = n;
            }
            return curr;
  @@ -1236,7 +1261,9 @@
            MyNode child;
   
            if (relative_name == null || getChildCount() == 0)
  +         {
               return null;
  +         }
            for (int i = 0; i < getChildCount(); i++)
            {
               child = (MyNode) getChildAt(i);
  @@ -1246,8 +1273,10 @@
               }
   
               if (child.name.equals(relative_name))
  +            {
                  return child;
            }
  +         }
            return null;
         }
   
  @@ -1257,11 +1286,15 @@
            StringBuffer sb = new StringBuffer();
   
            for (int i = 0; i < indent; i++)
  +         {
               sb.append(" ");
  +         }
            if (!isRoot())
            {
               if (name == null)
  +            {
                  sb.append("/<unnamed>");
  +            }
               else
               {
                  sb.append(TreeCacheGui2.SEP + name);
  @@ -1271,12 +1304,18 @@
            if (getChildCount() > 0)
            {
               if (isRoot())
  +            {
                  indent = 0;
  +            }
               else
  +            {
                  indent += 4;
  +            }
               for (int i = 0; i < getChildCount(); i++)
  +            {
                  sb.append(((MyNode) getChildAt(i)).print(indent));
            }
  +         }
            return sb.toString();
         }
   
  
  
  
  1.1      date: 2007/01/11 13:49:07;  author: msurtani;  state: Exp;JBossCache/src/org/jboss/cache/CacheFactory.java
  
  Index: CacheFactory.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache;
  
  import org.jboss.cache.config.Configuration;
  import org.jboss.cache.config.ConfigurationException;
  
  /**
   * This factory constructs a cache from a given configuration set, and is also responsible for managing the lifecycle
   * of the cache.
   * <p/>
   * Typical usage would be:
   * <p/>
   * <pre>
   *   CacheFactory factory = DefaultCacheFactory.getInstance();
   *   Cache cache = factory.createCache("replSync-service.xml"); // expects this file to be in classpath
   * <p/>
   *     ...
   *     ...
   * <p/>
   *   factory.stopCache( cache );
   * </pre>
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
   * @see org.jboss.cache.Cache
   * @since 2.0.0
   */
  public interface CacheFactory
  {
     /**
      * Creates and starts a {@link Cache} instance using default configuration settings.  See {@link Configuration} for default values.
      *
      * @return a cache
      * @throws ConfigurationException if there are problems with the default configuration
      */
     Cache createCache() throws ConfigurationException;
  
     /**
      * Creates and optionally starts a {@link Cache} instance using default configuration settings.  See {@link Configuration} for default values.
      *
      * @param start if true, starts the cache
      * @return a cache
      * @throws ConfigurationException if there are problems with the default configuration
      */
     Cache createCache(boolean start) throws ConfigurationException;
  
     /**
      * Creates and starts a {@link org.jboss.cache.Cache} instance
      *
      * @param configFileName the named XML file should exist in the classpath.
      * @return a running {@link org.jboss.cache.Cache} instance
      * @throws org.jboss.cache.config.ConfigurationException
      *          if there are problems with the configuration
      */
     Cache createCache(String configFileName) throws ConfigurationException;
  
     /**
      * Creates {@link Cache} instance, and optionally starts it.
      *
      * @param configFileName the named XML file should exist in the classpath.
      * @param start          if true, the cache is started before returning.
      * @return an optionally running {@link Cache} instance
      * @throws org.jboss.cache.config.ConfigurationException
      *          if there are problems with the configuration
      */
     Cache createCache(String configFileName, boolean start) throws ConfigurationException;
  
     /**
      * Creates a {@link Cache} instance based on a {@link org.jboss.cache.config.Configuration} passed in.
      * <p/>
      * Ensure that the Configuration you pass in is not used by another cache instance in the same JVM, as this may have untoward
      * consequences.  {@link org.jboss.cache.config.Configuration#clone()} is your friend.
      *
      * @param configuration the {@link Configuration} object that is passed in to configure the {@link Cache}.
      * @return a running {@link Cache} instance
      * @throws org.jboss.cache.config.ConfigurationException
      *          if there are problems with the configuration
      */
     Cache createCache(Configuration configuration) throws ConfigurationException;
  
     /**
      * Creates {@link Cache} instance, and optionally starts it, based on a {@link org.jboss.cache.config.Configuration} passed in.
      * <p/>
      * Ensure that the Configuration you pass in is not used by another cache instance in the same JVM, as this may have untoward
      * consequences.  {@link org.jboss.cache.config.Configuration#clone()} is your friend.
      *
      * @param configuration the {@link Configuration} object that is passed in to configure the {@link Cache}.
      * @param start         if true, the cache is started before returning.
      * @return an optionally running {@link Cache} instance
      * @throws org.jboss.cache.config.ConfigurationException
      *          if there are problems with the configuration
      */
     Cache createCache(Configuration configuration, boolean start) throws ConfigurationException;
  }
  
  
  
  1.1      date: 2007/01/11 13:49:07;  author: msurtani;  state: Exp;JBossCache/src/org/jboss/cache/DefaultCacheFactory.java
  
  Index: DefaultCacheFactory.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.jboss.cache.config.Configuration;
  import org.jboss.cache.config.ConfigurationException;
  import org.jboss.cache.factories.XmlConfigurationParser;
  
  /**
   * Default implementation of the Cache Factory that contains only convenient static methods
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
   */
  public class DefaultCacheFactory implements CacheFactory
  {
     private static CacheFactory singleton = null;
     private Log log = LogFactory.getLog(DefaultCacheFactory.class);
  
     /**
      * Protected constructor to prevent instantiation by user code
      */
     protected DefaultCacheFactory()
     {
        // protected constructor to prevent instantiation
     }
  
     public static CacheFactory getInstance()
     {
        if (singleton == null)
        {
           synchronized (DefaultCacheFactory.class)
           {
              if (singleton == null)
              {
                 singleton = new DefaultCacheFactory();
              }
           }
        }
        return singleton;
     }
  
     public Cache createCache() throws ConfigurationException
     {
        return createCache(true);
     }
  
     public Cache createCache(boolean start) throws ConfigurationException
     {
        return createCache(new Configuration(), start);
     }
  
     public Cache createCache(String configFileName) throws ConfigurationException
     {
        return createCache(configFileName, true);
     }
  
     public Cache createCache(String configFileName, boolean start) throws ConfigurationException
     {
        XmlConfigurationParser parser = new XmlConfigurationParser();
        Configuration c = parser.parseFile(configFileName);
        return createCache(c, start);
     }
  
     /**
      * This implementation clones the configuration passed in before using it.
      *
      * @param configuration to use
      * @return a cache
      * @throws ConfigurationException if there are problems with the cfg
      */
     public Cache createCache(Configuration configuration) throws ConfigurationException
     {
        return createCache(configuration, true);
     }
  
     /**
      * This implementation clones the configuration passed in before using it.
      *
      * @param configuration to use
      * @param start         whether to start the cache
      * @return a cache
      * @throws ConfigurationException if there are problems with the cfg
      */
     public Cache createCache(Configuration configuration, boolean start) throws ConfigurationException
     {
        try
        {
           CacheImpl cache = new CacheImpl();
           cache.setConfiguration(configuration);
           if (start) cache.start();
           return cache;
        }
        catch (Exception e)
        {
           if (e instanceof ConfigurationException) throw (ConfigurationException) e;
           throw new RuntimeException(e);
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list