8 Replies Latest reply on Nov 7, 2008 4:29 AM by alesj

    JBVFS-67, VFSCacheFactory.getInstance(String defaultCacheImp

    starksm64

      I want to add a VFSCacheFactory.getInstance(String defaultCacheImpl) factory method so we can set the cache to use in the beans descriptor rather than having to set a system property. I would say this value takes precedence over the system property:

       public static VFSCache getInstance()
       {
       return getInstance(null);
       }
       public static VFSCache getInstance(String defaultCacheImpl)
       {
       if (instance == null)
       {
       synchronized (lock)
       {
       if (instance == null)
       instance = AccessController.doPrivileged(new VFSCacheCreatorAction(defaultCacheImpl));
       }
       }
       return instance;
       }
      
       private static class VFSCacheCreatorAction implements PrivilegedAction<VFSCache>
       {
       private String defaultCacheImpl;
       VFSCacheCreatorAction(String defaultCacheImpl)
       {
       this.defaultCacheImpl = defaultCacheImpl;
       }
      
       public VFSCache run()
       {
       try
       {
       String className = defaultCacheImpl;
       if(className == null)
       className = System.getProperty(VFSUtils.VFS_CACHE_KEY);
       if (className != null)
       {
       log.info("Initializing VFSCache [" + className + "] ...");
       ClassLoader cl = VFSCacheFactory.class.getClassLoader();
       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.info("Using VFSCache [NoopVFSCache] ...");
       return new NoopVFSCache();
       }
       }