[jboss-cvs] JBossAS SVN: r75331 - in projects/jboss-mdr/trunk: src/main/org/jboss/metadata/plugins/cache and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 3 04:03:33 EDT 2008


Author: alesj
Date: 2008-07-03 04:03:33 -0400 (Thu, 03 Jul 2008)
New Revision: 75331

Added:
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyCacheFactory.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyFactory.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/ConcurrentLRUCachePolicyFactory.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCache.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheFactory.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheItem.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/LRUCachePolicyFactory.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/SynchronizedCachePolicyFactory.java
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/TimedCachePolicyFactory.java
Modified:
   projects/jboss-mdr/trunk/pom.xml
   projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/DefaultCacheFactory.java
Log:
[JBMDR-26]; include JBoss Cache.
Implementing real cache (factories).

Modified: projects/jboss-mdr/trunk/pom.xml
===================================================================
--- projects/jboss-mdr/trunk/pom.xml	2008-07-03 07:21:25 UTC (rev 75330)
+++ projects/jboss-mdr/trunk/pom.xml	2008-07-03 08:03:33 UTC (rev 75331)
@@ -85,6 +85,11 @@
       <artifactId>jboss-common-core</artifactId>
       <version>2.2.5.GA</version>
     </dependency>
+    <dependency>
+      <groupId>org.jboss.cache</groupId>
+      <artifactId>jbosscache-core</artifactId>
+      <version>2.1.1.GA</version>
+    </dependency>
     <!-- Test dependencies -->
     <dependency>
       <groupId>org.jboss</groupId>

Copied: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyCacheFactory.java (from rev 75304, projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/DefaultCacheFactory.java)
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyCacheFactory.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyCacheFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,187 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.CachePolicy;
+
+/**
+ * Cache policy cache factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CachePolicyCacheFactory implements CacheFactory
+{
+   private static final Logger log = Logger.getLogger(CachePolicyCacheFactory.class);
+
+   private CachePolicyFactory factory;
+   private List<CachePolicy> policies;
+
+   public CachePolicyCacheFactory(CachePolicyFactory factory)
+   {
+      if (factory == null)
+         throw new IllegalArgumentException("Null factory");
+      this.factory = factory;
+      this.policies = new ArrayList<CachePolicy>();
+   }
+
+   public String createFqn(Object owner)
+   {
+      return null;
+   }
+
+   /**
+    * Create cache policy.
+    *
+    * @return the cache policy
+    */
+   protected CachePolicy createCachePolicy()
+   {
+      try
+      {
+         CachePolicy policy = factory.createCachePolicy();
+         policy.create();
+         policy.start();
+         policies.add(policy);
+         return policy;
+      }
+      catch (Exception e)
+      {
+         if (e instanceof RuntimeException)
+            throw (RuntimeException)e;
+         else
+            throw new RuntimeException(e);
+      }
+   }
+
+   public <K, V> Cache<K, V> createCache(Class<K> keyClass, Class<V> valueClass, String rootFqn)
+   {
+      return new CachePolicyCache<K,V>(createCachePolicy());
+   }
+
+   public <V> CacheItem<V> createCacheItem(Class<V> valueClass, String rootFqn)
+   {
+      return new CachePolicyCacheItem<V>(createCachePolicy());
+   }
+
+   /**
+    * Stop created policies.
+    */
+   public void stop()
+   {
+      ListIterator<CachePolicy> iter = policies.listIterator(policies.size());
+      while(iter.hasPrevious())
+      {
+         CachePolicy policy = iter.previous();
+         try
+         {
+            policy.stop();
+         }
+         catch (Throwable t)
+         {
+            log.debug("Exception while stopping policy: " + policy + ", problem: " + t);
+         }
+      }
+   }
+
+   /**
+    * Destroy created policies.
+    */
+   public void destroy()
+   {
+      ListIterator<CachePolicy> iter = policies.listIterator(policies.size());
+      while(iter.hasPrevious())
+      {
+         CachePolicy policy = iter.previous();
+         try
+         {
+            policy.destroy();
+         }
+         catch (Throwable t)
+         {
+            log.debug("Exception while destroying policy: " + policy + ", problem: " + t);
+         }
+      }
+      policies.clear();
+   }
+
+   @SuppressWarnings("unchecked")
+   private static class CachePolicyCache<K, V> implements Cache<K, V>
+   {
+      private CachePolicy policy;
+
+      private CachePolicyCache(CachePolicy policy)
+      {
+         if (policy == null)
+            throw new IllegalArgumentException("Null policy");
+         this.policy = policy;
+      }
+
+      public V put(K key, V value)
+      {
+         V old = (V)policy.get(key);
+         policy.insert(key, value);
+         return old;
+      }
+
+      public V get(K key)
+      {
+         return (V)policy.get(key);
+      }
+
+      public V remove(K key)
+      {
+         V old = (V)policy.get(key);
+         policy.remove(key);
+         return old;
+      }
+
+      public void clear()
+      {
+         policy.flush();
+      }
+   }
+
+   private static class CachePolicyCacheItem<V> extends CachePolicyCache<Object, V> implements CacheItem<V>
+   {
+      private static final Object KEY = "<KEY>";
+
+      private CachePolicyCacheItem(CachePolicy policy)
+      {
+         super(policy);
+      }
+
+      public V put(V value)
+      {
+         return put(KEY, value);
+      }
+
+      public V get()
+      {
+         return get(KEY);
+      }
+   }
+}
\ No newline at end of file

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyFactory.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyFactory.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/CachePolicyFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import org.jboss.util.CachePolicy;
+
+/**
+ * Cache policy factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface CachePolicyFactory
+{
+   /**
+    * Create cache policy.
+    *
+    * @return the cache policy
+    */
+   CachePolicy createCachePolicy();
+}
\ No newline at end of file

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/ConcurrentLRUCachePolicyFactory.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/ConcurrentLRUCachePolicyFactory.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/ConcurrentLRUCachePolicyFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,63 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.util.CachePolicy;
+import org.jboss.util.LRUCachePolicy;
+
+/**
+ * Concurrent LRU cache policy factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ConcurrentLRUCachePolicyFactory implements CachePolicyFactory
+{
+   private int min;
+   private int max;
+
+   public ConcurrentLRUCachePolicyFactory(int min, int max)
+   {
+      this.min = min;
+      this.max = max;
+   }
+
+   public CachePolicy createCachePolicy()
+   {
+      return new ConcurrentLRUCachePolicy(min, max);
+   }
+
+   private class ConcurrentLRUCachePolicy extends LRUCachePolicy
+   {
+      private ConcurrentLRUCachePolicy(int min, int max)
+      {
+         super(min, max);
+      }
+
+      protected Map createMap()
+      {
+         return new ConcurrentHashMap();
+      }
+   }
+}
\ No newline at end of file

Modified: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/DefaultCacheFactory.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/DefaultCacheFactory.java	2008-07-03 07:21:25 UTC (rev 75330)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/DefaultCacheFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -30,8 +30,8 @@
 {
    public String createFqn(Object owner)
    {
-      Class<?> clazz = owner.getClass();
-      return clazz.getSimpleName() + "_" + System.identityHashCode(owner);
+      // no need for fqn
+      return null;
    }
 
    public <K, V> Cache<K, V> createCache(Class<K> keyClass, Class<V> valueClass, String rootFqn)

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCache.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCache.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCache.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+/**
+ * JBoss Cache cache.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JBossCacheCache<K, V> implements Cache<K, V>
+{
+   private String fqn;
+   private org.jboss.cache.Cache<K,V> cache;
+
+   public JBossCacheCache(String fqn, org.jboss.cache.Cache<K, V> cache)
+   {
+      if (fqn == null)
+         throw new IllegalArgumentException("Null fqn");
+      if (cache == null)
+         throw new IllegalArgumentException("Null cache");
+
+      this.fqn = fqn;
+      this.cache = cache;
+   }
+
+   public V put(K key, V value)
+   {
+      return cache.put(fqn, key, value);
+   }
+
+   public V get(K key)
+   {
+      return cache.get(fqn, key);
+   }
+
+   public V remove(K key)
+   {
+      return cache.remove(fqn, key);
+   }
+
+   public void clear()
+   {
+      cache.clearData(fqn);
+   }
+}
\ No newline at end of file

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheFactory.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheFactory.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,160 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.jboss.cache.config.Configuration;
+import org.jboss.logging.Logger;
+
+/**
+ * JBoss Cache cache factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JBossCacheCacheFactory implements CacheFactory
+{
+   private final Logger log = Logger.getLogger(getClass());
+
+   private String file;
+   private Configuration configuration;
+   private List<org.jboss.cache.Cache> caches;
+
+   public JBossCacheCacheFactory()
+   {
+      caches = new ArrayList<org.jboss.cache.Cache>();
+   }
+
+   public JBossCacheCacheFactory(String file)
+   {
+      this();
+      this.file = file;
+   }
+
+   public JBossCacheCacheFactory(Configuration configuration)
+   {
+      this();
+      this.configuration = configuration;
+   }
+
+   public String createFqn(Object owner)
+   {
+      Class<?> clazz = owner.getClass();
+      return clazz.getSimpleName() + "-" + System.identityHashCode(owner);
+   }
+
+   /**
+    * Create cache factory.
+    *
+    * @return the cache factory
+    */
+   protected <K, V> org.jboss.cache.CacheFactory<K, V> createFactory()
+   {
+      return new org.jboss.cache.DefaultCacheFactory<K, V>();
+   }
+
+   /**
+    * Create cache.
+    *
+    * @param factory the cache factory
+    * @return new cache instance
+    */
+   protected <K, V> org.jboss.cache.Cache<K, V> createCache(org.jboss.cache.CacheFactory<K, V> factory)
+   {
+      if (file != null)
+         return factory.createCache(file);
+      else if (configuration != null)
+         return factory.createCache(configuration);
+      else
+         return factory.createCache();
+   }
+
+   /**
+    * Get cache.
+    * Store it, in order to do proper stop/destroy.
+    *
+    * @param factory the cache factory
+    * @return new cache instance
+    */
+   private <K, V> org.jboss.cache.Cache<K, V> getCache(org.jboss.cache.CacheFactory<K, V> factory)
+   {
+      org.jboss.cache.Cache<K, V> cache = createCache(factory);
+      caches.add(cache);
+      return cache;
+   }
+
+   public <K, V> Cache<K, V> createCache(Class<K> keyClass, Class<V> valueClass, String rootFqn)
+   {
+      org.jboss.cache.CacheFactory<K, V> factory = createFactory();
+      org.jboss.cache.Cache<K, V> cache = getCache(factory);
+      return new JBossCacheCache<K,V>(rootFqn, cache);
+   }
+
+   public <V> CacheItem<V> createCacheItem(Class<V> valueClass, String rootFqn)
+   {
+      org.jboss.cache.CacheFactory<Object, V> factory = createFactory();
+      org.jboss.cache.Cache<Object, V> cache = getCache(factory);
+      return new JBossCacheCacheItem<V>(rootFqn, cache);
+   }
+
+   /**
+    * Stop created cache.
+    */
+   public void stop()
+   {
+      ListIterator<org.jboss.cache.Cache> iter = caches.listIterator(caches.size());
+      while(iter.hasPrevious())
+      {
+         org.jboss.cache.Cache cache = iter.previous();
+         try
+         {
+            cache.stop();
+         }
+         catch (Throwable t)
+         {
+            log.debug("Exception while stopping cache: " + cache + ", problem: " + t);
+         }
+      }
+   }
+
+   /**
+    * Destroy created policies.
+    */
+   public void destroy()
+   {
+      ListIterator<org.jboss.cache.Cache> iter = caches.listIterator(caches.size());
+      while(iter.hasPrevious())
+      {
+         org.jboss.cache.Cache cache = iter.previous();
+         try
+         {
+            cache.destroy();
+         }
+         catch (Throwable t)
+         {
+            log.debug("Exception while destroying cache: " + cache + ", problem: " + t);
+         }
+      }
+   }
+}

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheItem.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheItem.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/JBossCacheCacheItem.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import org.jboss.cache.Cache;
+
+/**
+ * JBoss Cache cache item.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JBossCacheCacheItem<V> extends JBossCacheCache<Object, V> implements CacheItem<V>
+{
+   private static final Object KEY = "<KEY>";
+
+   public JBossCacheCacheItem(String fqn, Cache<Object, V> objectVCache)
+   {
+      super(fqn, objectVCache);
+   }
+
+   public V put(V value)
+   {
+      return put(KEY, value);
+   }
+
+   public V get()
+   {
+      return get(KEY);
+   }
+}
\ No newline at end of file

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/LRUCachePolicyFactory.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/LRUCachePolicyFactory.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/LRUCachePolicyFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import org.jboss.util.CachePolicy;
+import org.jboss.util.LRUCachePolicy;
+
+/**
+ * LRU cache policy factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class LRUCachePolicyFactory implements CachePolicyFactory
+{
+   private int min;
+   private int max;
+
+   public LRUCachePolicyFactory(int min, int max)
+   {
+      this.min = min;
+      this.max = max;
+   }
+
+   public CachePolicy createCachePolicy()
+   {
+      return new LRUCachePolicy(min, max);
+   }
+}
\ No newline at end of file

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/SynchronizedCachePolicyFactory.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/SynchronizedCachePolicyFactory.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/SynchronizedCachePolicyFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import org.jboss.util.CachePolicy;
+import org.jboss.util.SynchronizedCachePolicy;
+
+/**
+ * Synchronized cache policy factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class SynchronizedCachePolicyFactory implements CachePolicyFactory
+{
+   private CachePolicyFactory factory;
+
+   public SynchronizedCachePolicyFactory(CachePolicyFactory factory)
+   {
+      if (factory == null)
+         throw new IllegalArgumentException("Null factory");
+      this.factory = factory;
+   }
+
+   public CachePolicy createCachePolicy()
+   {
+      CachePolicy policy = factory.createCachePolicy();
+      return new SynchronizedCachePolicy(policy);
+   }
+}
\ No newline at end of file

Added: projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/TimedCachePolicyFactory.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/TimedCachePolicyFactory.java	                        (rev 0)
+++ projects/jboss-mdr/trunk/src/main/org/jboss/metadata/plugins/cache/TimedCachePolicyFactory.java	2008-07-03 08:03:33 UTC (rev 75331)
@@ -0,0 +1,61 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.cache;
+
+import org.jboss.util.CachePolicy;
+import org.jboss.util.TimedCachePolicy;
+
+/**
+ * Timed cache policy factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TimedCachePolicyFactory implements CachePolicyFactory
+{
+   private int defaultLifetime;
+   private boolean threadSafe;
+   private int resolution;
+
+   public TimedCachePolicyFactory()
+   {
+      this(30*60, false, 0);
+   }
+
+   public TimedCachePolicyFactory(int defaultLifetime)
+   {
+      this(defaultLifetime, false, 0);
+   }
+
+   public TimedCachePolicyFactory(int defaultLifetime, boolean threadSafe, int resolution)
+   {
+      this.defaultLifetime = defaultLifetime;
+      this.threadSafe = threadSafe;
+      if( resolution <= 0 )
+         resolution = 60;
+      this.resolution = resolution;
+   }
+
+   public CachePolicy createCachePolicy()
+   {
+      return new TimedCachePolicy(defaultLifetime, threadSafe, resolution);
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list