[jboss-cvs] JBossAS SVN: r80617 - projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/cache.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 6 16:04:49 EST 2008
Author: scott.stark at jboss.org
Date: 2008-11-06 16:04:49 -0500 (Thu, 06 Nov 2008)
New Revision: 80617
Modified:
projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java
Log:
JBVFS-67, add a getInstance(String cacheImpl) factory method
Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java 2008-11-06 20:58:17 UTC (rev 80616)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java 2008-11-06 21:04:49 UTC (rev 80617)
@@ -32,6 +32,8 @@
* Simple vfs cache factory.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 80615 $
*/
public class VFSCacheFactory
{
@@ -51,15 +53,28 @@
*/
public static VFSCache getInstance()
{
+ return getInstance(null);
+ }
+ /**
+ *
+ * Get VFS cache instance.
+ *
+ * @param defaultCacheImpl - the possibly null name of the VFSCache
+ * implementation to use. If null, the {@linkplain VFSUtils.VFS_CACHE_KEY}
+ * system property will be used.
+ *
+ * @return the vfs cache instance
+ */
+ public static VFSCache getInstance(String defaultCacheImpl)
+ {
if (instance == null)
{
synchronized (lock)
{
if (instance == null)
- instance = AccessController.doPrivileged(new VFSCacheCreatorAction());
+ instance = AccessController.doPrivileged(new VFSCacheCreatorAction(defaultCacheImpl));
}
}
-
return instance;
}
@@ -81,11 +96,23 @@
private static class VFSCacheCreatorAction implements PrivilegedAction<VFSCache>
{
+ private String defaultCacheImpl;
+ VFSCacheCreatorAction(String defaultCacheImpl)
+ {
+ this.defaultCacheImpl = defaultCacheImpl;
+ }
+
public VFSCache run()
{
try
{
- String className = System.getProperty(VFSUtils.VFS_CACHE_KEY);
+ // First look to the input cache imple
+ String className = defaultCacheImpl;
+ if(className == null || className.length() == 0)
+ {
+ // Else look at the VFS_CACHE_KEY system property
+ className = System.getProperty(VFSUtils.VFS_CACHE_KEY);
+ }
if (className != null)
{
log.info("Initializing VFSCache [" + className + "] ...");
@@ -93,14 +120,16 @@
Class<?> clazz = cl.loadClass(className);
VFSCache cache = VFSCache.class.cast(clazz.newInstance());
cache.start(); // start here, so we fall back to default no-op in case start fails
+ log.info("Using VFSCache [" + cache + "] ...");
return cache;
}
}
catch (Throwable t)
{
- log.warn("Exception instantiating VFS cache: " + t);
+ log.warn("Exception instantiating VFS cache: ", t);
}
+ log.info("Using VFSCache [NoopVFSCache] ...");
return new NoopVFSCache();
}
}
-}
\ No newline at end of file
+}
More information about the jboss-cvs-commits
mailing list