[jboss-cvs] JBossCache/src/org/jboss/cache/factories ...
Manik Surtani
msurtani at jboss.com
Tue Jan 2 13:26:05 EST 2007
User: msurtani
Date: 07/01/02 13:26:05
Modified: src/org/jboss/cache/factories CacheFactoryTest.java
DefaultCacheFactory.java
Log:
Cleaned up cache factory
Revision Changes Path
1.6 +5 -5 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.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- CacheFactoryTest.java 30 Dec 2006 17:49:57 -0000 1.5
+++ CacheFactoryTest.java 2 Jan 2007 18:26:05 -0000 1.6
@@ -36,7 +36,7 @@
public void testFromConfigFileStarted()
{
- cache = (CacheImpl) DefaultCacheFactory.createCache(configFile);
+ cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile);
assertEquals(expected, cache.getConfiguration());
assertTrue("Should have started", cache.isStarted());
@@ -45,7 +45,7 @@
public void testFromConfigFileUnstarted()
{
- cache = (CacheImpl) DefaultCacheFactory.createCache(configFile, false);
+ cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile, false);
assertEquals(expected, cache.getConfiguration());
assertFalse("Should not have started", cache.isStarted());
@@ -55,7 +55,7 @@
public void testFromConfigObjStarted()
{
- cache = (CacheImpl) DefaultCacheFactory.createCache(expected);
+ cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected);
assertTrue("Should have started", cache.isStarted());
@@ -64,7 +64,7 @@
public void testFromConfigObjUnstarted()
{
- cache = (CacheImpl) DefaultCacheFactory.createCache(expected, false);
+ cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
assertFalse("Should not have started", cache.isStarted());
@@ -83,7 +83,7 @@
public void testLifecycle() throws Exception
{
- cache = (CacheImpl) DefaultCacheFactory.createCache(expected, false);
+ cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
assertFalse(cache.isStarted());
cache.start();
assertTrue(cache.isStarted());
1.13 +31 -6 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.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- DefaultCacheFactory.java 30 Dec 2006 17:49:57 -0000 1.12
+++ DefaultCacheFactory.java 2 Jan 2007 18:26:05 -0000 1.13
@@ -16,31 +16,56 @@
*
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
-public class DefaultCacheFactory
+public class DefaultCacheFactory implements CacheFactory
{
- public static Cache createCache() throws ConfigurationException
+ private static CacheFactory singleton = null;
+
+ /**
+ * 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(new Configuration());
}
- public static Cache createCache(String configFileName) throws ConfigurationException
+ public Cache createCache(String configFileName) throws ConfigurationException
{
return createCache(configFileName, true);
}
- public static Cache createCache(String configFileName, boolean start) throws ConfigurationException
+ public Cache createCache(String configFileName, boolean start) throws ConfigurationException
{
XmlConfigurationParser parser = new XmlConfigurationParser();
Configuration c = parser.parseFile(configFileName);
return createCache(c, start);
}
- public static Cache createCache(Configuration configuration) throws ConfigurationException
+ public Cache createCache(Configuration configuration) throws ConfigurationException
{
return createCache(configuration, true);
}
- public static Cache createCache(Configuration configuration, boolean start) throws ConfigurationException
+ public Cache createCache(Configuration configuration, boolean start) throws ConfigurationException
{
try
{
More information about the jboss-cvs-commits
mailing list