[infinispan-commits] Infinispan SVN: r1645 - in trunk/core/src/main/java/org/infinispan: manager and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Mar 31 09:11:26 EDT 2010


Author: mircea.markus
Date: 2010-03-31 09:11:26 -0400 (Wed, 31 Mar 2010)
New Revision: 1645

Added:
   trunk/core/src/main/java/org/infinispan/CacheSupport.java
   trunk/core/src/main/java/org/infinispan/manager/CacheContainer.java
Modified:
   trunk/core/src/main/java/org/infinispan/CacheDelegate.java
   trunk/core/src/main/java/org/infinispan/manager/CacheManager.java
Log:
ongoing work on hotrod client

Modified: trunk/core/src/main/java/org/infinispan/CacheDelegate.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/CacheDelegate.java	2010-03-31 12:55:19 UTC (rev 1644)
+++ trunk/core/src/main/java/org/infinispan/CacheDelegate.java	2010-03-31 13:11:26 UTC (rev 1645)
@@ -95,7 +95,7 @@
  */
 @SurvivesRestarts
 @MBean(objectName = CacheDelegate.OBJECT_NAME, description = "Component that acts as a manager, factory and container for caches in the system.")
-public class CacheDelegate<K, V> implements AdvancedCache<K, V> {
+public class CacheDelegate<K, V> extends CacheSupport<K,V> implements AdvancedCache<K, V> {
    public static final String OBJECT_NAME = "Cache";
    protected InvocationContextContainer icc;
    protected CommandsFactory commandsFactory;
@@ -117,7 +117,6 @@
    // as above for ResponseGenerator
    private ResponseGenerator responseGenerator;
    private DistributionManager distributionManager;
-   private long defaultLifespan, defaultMaxIdleTime;
    private ThreadLocal<PreInvocationContext> flagHolder = new ThreadLocal<PreInvocationContext>();
 
    public CacheDelegate(String name) {
@@ -156,24 +155,12 @@
       this.distributionManager = distributionManager; 
    }
 
-   public final V putIfAbsent(K key, V value) {
-      return putIfAbsent(key, value, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
-   }
-
    public final boolean remove(Object key, Object value) {
       InvocationContext ctx = getInvocationContext(false);
       RemoveCommand command = commandsFactory.buildRemoveCommand(key, value);
       return (Boolean) invoker.invoke(ctx, command);
    }
 
-   public final boolean replace(K key, V oldValue, V newValue) {
-      return replace(key, oldValue, newValue, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
-   }
-
-   public final V replace(K key, V value) {
-      return replace(key, value, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
-   }
-
    public final int size() {
       SizeCommand command = commandsFactory.buildSizeCommand();
       return (Integer) invoker.invoke(icc.createNonTxInvocationContext(), command);
@@ -201,10 +188,6 @@
       return (V) invoker.invoke(ctx, command);
    }
 
-   public final V put(K key, V value) {
-      return put(key, value, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
-   }
-
    @SuppressWarnings("unchecked")
    public final V remove(Object key) {
       InvocationContext ctx = getInvocationContext(false);
@@ -212,10 +195,6 @@
       return (V) invoker.invoke(ctx, command);
    }
 
-   public final void putAll(Map<? extends K, ? extends V> map) {
-      putAll(map, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
-   }
-
    public final void clear() {
       InvocationContext ctx = getInvocationContext(false);
       ClearCommand command = commandsFactory.buildClearCommand();
@@ -508,14 +487,6 @@
       }
    }
 
-   public final NotifyingFuture<V> putAsync(K key, V value) {
-      return putAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
-   public final NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit) {
-      return putAsync(key, value, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
    public final NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
       InvocationContext ctx = getInvocationContext(false);
       ctx.setUseFutureReturnType(true);
@@ -523,14 +494,6 @@
       return wrapInFuture(invoker.invoke(ctx, command));
    }
 
-   public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data) {
-      return putAllAsync(data, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
-   public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit unit) {
-      return putAllAsync(data, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
    public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
       InvocationContext ctx = getInvocationContext(false);
       ctx.setUseFutureReturnType(true);
@@ -545,14 +508,6 @@
       return wrapInFuture(invoker.invoke(ctx, command));
    }
 
-   public final NotifyingFuture<V> putIfAbsentAsync(K key, V value) {
-      return putIfAbsentAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
-   public final NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit) {
-      return putIfAbsentAsync(key, value, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
    public final NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
       InvocationContext ctx = getInvocationContext(false);
       ctx.setUseFutureReturnType(true);
@@ -575,14 +530,6 @@
       return wrapInFuture(invoker.invoke(ctx, command));
    }
 
-   public final NotifyingFuture<V> replaceAsync(K key, V value) {
-      return replaceAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
-   public final NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit) {
-      return replaceAsync(key, value, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
    public final NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
       InvocationContext ctx = getInvocationContext(false);
       ctx.setUseFutureReturnType(true);
@@ -590,14 +537,6 @@
       return wrapInFuture(invoker.invoke(ctx, command));
    }
 
-   public final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
-      return replaceAsync(key, oldValue, newValue, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
-   public final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit) {
-      return replaceAsync(key, oldValue, newValue, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
-   }
-
    public final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
       InvocationContext ctx = getInvocationContext(false);
       ctx.setUseFutureReturnType(true);
@@ -605,26 +544,6 @@
       return wrapInFuture(invoker.invoke(ctx, command));
    }
 
-   public final V put(K key, V value, long lifespan, TimeUnit unit) {
-      return put(key, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
-   }
-
-   public final V putIfAbsent(K key, V value, long lifespan, TimeUnit unit) {
-      return putIfAbsent(key, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
-   }
-
-   public final void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit unit) {
-      putAll(map, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
-   }
-
-   public final V replace(K key, V value, long lifespan, TimeUnit unit) {
-      return replace(key, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
-   }
-
-   public final boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit) {
-      return replace(key, oldValue, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
-   }
-
    public AdvancedCache<K, V> getAdvancedCache() {
       return this;
    }

Added: trunk/core/src/main/java/org/infinispan/CacheSupport.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/CacheSupport.java	                        (rev 0)
+++ trunk/core/src/main/java/org/infinispan/CacheSupport.java	2010-03-31 13:11:26 UTC (rev 1645)
@@ -0,0 +1,108 @@
+package org.infinispan;
+
+import org.infinispan.util.concurrent.NotifyingFuture;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+public abstract class CacheSupport<K,V> implements Cache<K,V> {
+   protected long defaultLifespan;
+   protected long defaultMaxIdleTime;
+
+   protected CacheSupport() {
+      this(0,0);
+   }
+
+   protected CacheSupport(long defaultLifespan, long defaultMaxIdleTime) {
+      this.defaultLifespan = defaultLifespan;
+      this.defaultMaxIdleTime = defaultMaxIdleTime;
+   }
+
+   public final V put(K key, V value) {
+      return put(key, value, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final void putAll(Map<? extends K, ? extends V> map) {
+      putAll(map, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final NotifyingFuture<V> putAsync(K key, V value) {
+      return putAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final V putIfAbsent(K key, V value) {
+      return putIfAbsent(key, value, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit unit) {
+      return putAsync(key, value, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data) {
+      return putAllAsync(data, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit unit) {
+      return putAllAsync(data, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<V> putIfAbsentAsync(K key, V value) {
+      return putIfAbsentAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit unit) {
+      return putIfAbsentAsync(key, value, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit unit) {
+      return replaceAsync(key, value, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
+      return replaceAsync(key, oldValue, newValue, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<V> replaceAsync(K key, V value) {
+      return replaceAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit unit) {
+      return replaceAsync(key, oldValue, newValue, lifespan, unit, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS);
+   }
+
+   public final V put(K key, V value, long lifespan, TimeUnit unit) {
+      return put(key, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final V putIfAbsent(K key, V value, long lifespan, TimeUnit unit) {
+      return putIfAbsent(key, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit unit) {
+      putAll(map, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final V replace(K key, V value, long lifespan, TimeUnit unit) {
+      return replace(key, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final boolean replace(K key, V oldValue, V newValue) {
+      return replace(key, oldValue, newValue, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final V replace(K key, V value) {
+      return replace(key, value, defaultLifespan, MILLISECONDS, defaultMaxIdleTime, MILLISECONDS);
+   }
+
+   public final boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit unit) {
+      return replace(key, oldValue, value, lifespan, unit, defaultMaxIdleTime, MILLISECONDS);
+   }
+}

Added: trunk/core/src/main/java/org/infinispan/manager/CacheContainer.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/manager/CacheContainer.java	                        (rev 0)
+++ trunk/core/src/main/java/org/infinispan/manager/CacheContainer.java	2010-03-31 13:11:26 UTC (rev 1645)
@@ -0,0 +1,43 @@
+package org.infinispan.manager;
+
+import org.infinispan.Cache;
+
+/**
+ * Acts as an container of {@link org.infinispan.Cache}s. Each cache in the container is identified by a name.
+ * It also contains a <b>default</b> cache.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+public interface CacheContainer {
+   /**
+    * Retrieves the default cache associated with this cache container.
+    * <p/>
+    * As such, this method is always guaranteed to return the default cache.
+    * <p />
+    * <b>NB:</b> Shared caches are supported (and in fact encouraged) but if they are used it's the users responsibility to
+    * ensure that <i>at least one</i> but <i>only one</i> caller calls stop() on the cache, and it does so with the awareness
+    * that others may be using the cache.
+    *
+    * @return the default cache.
+    */
+   <K, V> Cache<K, V> getCache();
+
+   /**
+    * Retrieves a named cache from the system.  If the cache has been previously created with the same name, the running
+    * cache instance is returned.  Otherwise, this method attempts to create the cache first.
+    * <p/>
+    * In the case of a {@link CacheManager}: when creating a new cache, this method will use the configuration passed in to the CacheManager on construction,
+    * as a template, and then optionally apply any overrides previously defined for the named cache using the {@link
+    * CacheManager#defineConfiguration(String, org.infinispan.config.Configuration)} or {@link CacheManager#defineConfiguration(String, String, org.infinispan.config.Configuration)}
+    * methods, or declared in the configuration file.
+    * <p />
+    * <b>NB:</b> Shared caches are supported (and in fact encouraged) but if they are used it's the users responsibility to
+    * ensure that <i>at least one</i> but <i>only one</i> caller calls stop() on the cache, and it does so with the awareness
+    * that others may be using the cache.
+    *
+    * @param cacheName name of cache to retrieve
+    * @return a cache instance identified by cacheName
+    */
+   <K, V> Cache<K, V> getCache(String cacheName);
+}

Modified: trunk/core/src/main/java/org/infinispan/manager/CacheManager.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/manager/CacheManager.java	2010-03-31 12:55:19 UTC (rev 1644)
+++ trunk/core/src/main/java/org/infinispan/manager/CacheManager.java	2010-03-31 13:11:26 UTC (rev 1645)
@@ -59,7 +59,7 @@
  */
 @Scope(Scopes.GLOBAL)
 @SurvivesRestarts
-public interface CacheManager extends Lifecycle, Listenable {
+public interface CacheManager extends Lifecycle, Listenable, CacheContainer {
    /**
     * Defines a named cache's configuration using the following algorithm:
     * <p/>
@@ -107,37 +107,6 @@
    Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride);
 
    /**
-    * Retrieves the default cache associated with this cache manager.
-    * <p/>
-    * As such, this method is always guaranteed to return the default cache.
-    * <p />
-    * <b>NB:</b> Shared caches are supported (and in fact encouraged) but if they are used it's the users responsibility to
-    * ensure that <i>at least one</i> but <i>only one</i> caller calls stop() on the cache, and it does so with the awareness
-    * that others may be using the cache.
-    *
-    * @return the default cache.
-    */
-   <K, V> Cache<K, V> getCache();
-
-   /**
-    * Retrieves a named cache from the system.  If the cache has been previously created with the same name, the running
-    * cache instance is returned.  Otherwise, this method attempts to create the cache first.
-    * <p/>
-    * When creating a new cache, this method will use the configuration passed in to the CacheManager on construction,
-    * as a template, and then optionally apply any overrides previously defined for the named cache using the {@link
-    * #defineConfiguration(String, Configuration)} or {@link #defineConfiguration(String, String, Configuration)}
-    * methods, or declared in the configuration file.
-    * <p />
-    * <b>NB:</b> Shared caches are supported (and in fact encouraged) but if they are used it's the users responsibility to
-    * ensure that <i>at least one</i> but <i>only one</i> caller calls stop() on the cache, and it does so with the awareness
-    * that others may be using the cache.
-    *
-    * @param cacheName name of cache to retrieve
-    * @return a cache instance identified by cacheName
-    */
-   <K, V> Cache<K, V> getCache(String cacheName);
-
-   /**
     * @return the name of the cluster.  Null if running in local mode.
     */
    String getClusterName();



More information about the infinispan-commits mailing list