[infinispan-commits] Infinispan SVN: r1096 - in trunk/core/src: main/java/org/infinispan/loaders and 6 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Nov 3 18:51:13 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-11-03 18:51:12 -0500 (Tue, 03 Nov 2009)
New Revision: 1096

Modified:
   trunk/core/src/main/java/org/infinispan/AbstractDelegatingAdvancedCache.java
   trunk/core/src/main/java/org/infinispan/AdvancedCache.java
   trunk/core/src/main/java/org/infinispan/CacheDelegate.java
   trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java
   trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java
   trunk/core/src/test/java/org/infinispan/api/ForceWriteLockTest.java
   trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java
   trunk/core/src/test/java/org/infinispan/api/mvcc/PutForExternalReadTest.java
   trunk/core/src/test/java/org/infinispan/distribution/AsyncAPISyncDistTest.java
   trunk/core/src/test/java/org/infinispan/distribution/DistSkipRemoteLookupTest.java
   trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java
   trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java
   trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java
Log:
[ISPN-251] (Create a better mechanism for passing in Flags)

Modified: trunk/core/src/main/java/org/infinispan/AbstractDelegatingAdvancedCache.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/AbstractDelegatingAdvancedCache.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/main/java/org/infinispan/AbstractDelegatingAdvancedCache.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -8,12 +8,9 @@
 import org.infinispan.factories.ComponentRegistry;
 import org.infinispan.interceptors.base.CommandInterceptor;
 import org.infinispan.remoting.rpc.RpcManager;
-import org.infinispan.util.concurrent.NotifyingFuture;
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
 /**
  * Similar to {@link org.infinispan.AbstractDelegatingCache}, but for {@link AdvancedCache}.
@@ -78,114 +75,11 @@
       return cache.getDataContainer();
    }
 
-   public void putForExternalRead(K key, V value, Flag... flags) {
-      cache.putForExternalRead(key, value, flags);
+   public AdvancedCache<K, V> withFlags(Flag... flags) {
+      cache.withFlags(flags);
+      return this;
    }
 
-   public V put(K key, V value, Flag... flags) {
-      return cache.put(key, value, flags);
-   }
-
-   public V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      return cache.put(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit, flags);
-   }
-
-   public V putIfAbsent(K key, V value, Flag... flags) {
-      return cache.putIfAbsent(key, value, flags);
-   }
-
-   public V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      return cache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit, flags);
-   }
-
-   public void putAll(Map<? extends K, ? extends V> map, Flag... flags) {
-      cache.putAll(map, flags);
-   }
-
-   public void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      cache.putAll(map, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit, flags);
-   }
-
-   public V remove(Object key, Flag... flags) {
-      return cache.remove(key, flags);
-   }
-
-   public void clear(Flag... flags) {
-      cache.clear(flags);
-   }
-
-   public V replace(K k, V v, Flag... flags) {
-      return cache.replace(k, v, flags);
-   }
-
-   public boolean replace(K k, V oV, V nV, Flag... flags) {
-      return cache.replace(k, oV, nV, flags);
-   }
-
-   public V replace(K k, V v, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      return cache.replace(k, v, lifespan, lifespanUnit, maxIdle, maxIdleUnit, flags);
-   }
-
-   public boolean replace(K k, V oV, V nV, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      return cache.replace(k, oV, nV, lifespan, lifespanUnit, maxIdle, maxIdleUnit, flags);
-   }
-
-   public NotifyingFuture<V> putAsync(K key, V value, Flag... flags) {
-      return cache.putAsync(key, value, flags);
-   }
-
-   public NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      return cache.putAsync(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit, flags);
-   }
-
-   public NotifyingFuture<V> putIfAbsentAsync(K key, V value, Flag... flags) {
-      return cache.putIfAbsentAsync(key, value, flags);
-   }
-
-   public NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      return cache.putIfAbsentAsync(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit, flags);
-   }
-
-   public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> map, Flag... flags) {
-      return cache.putAllAsync(map, flags);
-   }
-
-   public NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      return cache.putAllAsync(map, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit, flags);
-   }
-
-   public NotifyingFuture<V> removeAsync(Object key, Flag... flags) {
-      return cache.removeAsync(key, flags);
-   }
-
-   public NotifyingFuture<Void> clearAsync(Flag... flags) {
-      return cache.clearAsync(flags);
-   }
-
-   public NotifyingFuture<V> replaceAsync(K k, V v, Flag... flags) {
-      return cache.replaceAsync(k, v, flags);
-   }
-
-   public NotifyingFuture<Boolean> replaceAsync(K k, V oV, V nV, Flag... flags) {
-      return cache.replaceAsync(k, oV, nV, flags);
-   }
-
-   public NotifyingFuture<V> replaceAsync(K k, V v, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      return cache.replaceAsync(k, v, lifespan, lifespanUnit, maxIdle, maxIdleUnit, flags);
-   }
-
-   public NotifyingFuture<Boolean> replaceAsync(K k, V oV, V nV, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      return cache.replaceAsync(k, oV, nV, lifespan, lifespanUnit, maxIdle, maxIdleUnit, flags);
-   }
-
-   public boolean containsKey(Object key, Flag... flags) {
-      return cache.containsKey(key, flags);
-   }
-
-   public V get(Object key, Flag... flags) {
-      return cache.get(key, flags);
-   }
-
    public void lock(K key) {
       cache.lock(key);
    }

Modified: trunk/core/src/main/java/org/infinispan/AdvancedCache.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/AdvancedCache.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/main/java/org/infinispan/AdvancedCache.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -8,12 +8,9 @@
 import org.infinispan.factories.ComponentRegistry;
 import org.infinispan.interceptors.base.CommandInterceptor;
 import org.infinispan.remoting.rpc.RpcManager;
-import org.infinispan.util.concurrent.NotifyingFuture;
 
 import java.util.Collection;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
 /**
  * An advanced interface that exposes additional methods not available on {@link Cache}.
@@ -22,7 +19,19 @@
  * @since 4.0
  */
 public interface AdvancedCache<K, V> extends Cache<K, V> {
+
    /**
+    * A builder-style method that adds flags to any API call.  For example, consider the following code snippet:
+    * <pre>
+    *   cache.withFlags(Flag.FORCE_WRITE_LOCK).get(key);
+    * </pre>
+    * will invoke a cache.get() with a write lock forced.
+    * @param flags a set of flags to apply.  See the {@link Flag} documentation.
+    * @return a cache on which a real operation is to be invoked.
+    */
+   AdvancedCache<K, V> withFlags(Flag... flags);
+
+   /**
     * Adds a custom interceptor to the interceptor chain, at specified position, where the first interceptor in the
     * chain is at position 0 and the last one at NUM_INTERCEPTORS - 1.
     *
@@ -109,60 +118,4 @@
    InvocationContextContainer getInvocationContextContainer();
 
    DataContainer getDataContainer();
-
-   void putForExternalRead(K key, V value, Flag... flags);
-
-   V put(K key, V value, Flag... flags);
-
-   V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags);
-
-   V putIfAbsent(K key, V value, Flag... flags);
-
-   V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags);
-
-   void putAll(Map<? extends K, ? extends V> map, Flag... flags);
-
-   void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags);
-
-   V remove(Object key, Flag... flags);
-
-   void clear(Flag... flags);
-
-   V replace(K k, V v, Flag... flags);
-
-   boolean replace(K k, V oV, V nV, Flag... flags);
-
-   V replace(K k, V v, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags);
-
-   boolean replace(K k, V oV, V nV, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags);
-
-
-   // -- async methods --
-   NotifyingFuture<V> putAsync(K key, V value, Flag... flags);
-
-   NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags);
-
-   NotifyingFuture<V> putIfAbsentAsync(K key, V value, Flag... flags);
-
-   NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags);
-
-   NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> map, Flag... flags);
-
-   NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags);
-
-   NotifyingFuture<V> removeAsync(Object key, Flag... flags);
-
-   NotifyingFuture<Void> clearAsync(Flag... flags);
-
-   NotifyingFuture<V> replaceAsync(K k, V v, Flag... flags);
-
-   NotifyingFuture<Boolean> replaceAsync(K k, V oV, V nV, Flag... flags);
-
-   NotifyingFuture<V> replaceAsync(K k, V v, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags);
-
-   NotifyingFuture<Boolean> replaceAsync(K k, V oV, V nV, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags);
-
-   boolean containsKey(Object key, Flag... flags);
-
-   V get(Object key, Flag... flags);
 }

Modified: trunk/core/src/main/java/org/infinispan/CacheDelegate.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/CacheDelegate.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/main/java/org/infinispan/CacheDelegate.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -40,6 +40,7 @@
 import org.infinispan.container.DataContainer;
 import org.infinispan.container.entries.InternalCacheEntry;
 import org.infinispan.context.Flag;
+import static org.infinispan.context.Flag.*;
 import org.infinispan.context.InvocationContext;
 import org.infinispan.context.InvocationContextContainer;
 import org.infinispan.eviction.EvictionManager;
@@ -71,8 +72,10 @@
 
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -110,6 +113,7 @@
    // as above for ResponseGenerator
    private ResponseGenerator responseGenerator;
    private long defaultLifespan, defaultMaxIdleTime;
+   private ThreadLocal<PreInvocationContext> flagHolder = new ThreadLocal<PreInvocationContext>();
 
    public CacheDelegate(String name) {
       this.name = name;
@@ -150,11 +154,9 @@
    }
 
    public final boolean remove(Object key, Object value) {
-      if (value instanceof Flag) {
-         // this can happen!
-         log.warn("Did you intend to call Cache.remove(Object, Object), with a Flag as value, or did you intend to call Cache.remove(Object, Flag... )?  If it was the latter and you are just passing in one flag, please cast this to an array of Flag, e.g., remove(key, new Flag[]{flag}) to ensure the correct method gets called!");
-      }
-      return remove(key, value, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      RemoveCommand command = commandsFactory.buildRemoveCommand(key, value);
+      return (Boolean) invoker.invoke(ctx, command);
    }
 
    public final boolean replace(K key, V oldValue, V newValue) {
@@ -175,23 +177,32 @@
    }
 
    public final boolean containsKey(Object key) {
-      return containsKey(key, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
+      Object response = invoker.invoke(ctx, command);
+      return response != null;
    }
 
    public final boolean containsValue(Object value) {
       throw new UnsupportedOperationException("Go away");
    }
 
+   @SuppressWarnings("unchecked")
    public final V get(Object key) {
-      return get(key, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
+      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) {
-      return remove(key, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      RemoveCommand command = commandsFactory.buildRemoveCommand(key, null);
+      return (V) invoker.invoke(ctx, command);
    }
 
    public final void putAll(Map<? extends K, ? extends V> map) {
@@ -199,26 +210,49 @@
    }
 
    public final void clear() {
-      clear((Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      ClearCommand command = commandsFactory.buildClearCommand();
+      invoker.invoke(ctx, command);
    }
 
+   @SuppressWarnings("unchecked")
    public Set<K> keySet() {
       KeySetCommand command = commandsFactory.buildKeySetCommand();
       return (Set<K>) invoker.invoke(icc.createNonTxInvocationContext(), command);
    }
 
+   @SuppressWarnings("unchecked")
    public Collection<V> values() {
       ValuesCommand command = commandsFactory.buildValuesCommand();
       return (Collection<V>) invoker.invoke(icc.createNonTxInvocationContext(), command);
    }
 
+   @SuppressWarnings("unchecked")
    public Set<Map.Entry<K, V>> entrySet() {
       EntrySetCommand command = commandsFactory.buildEntrySetCommand();
       return (Set<Map.Entry<K, V>>) invoker.invoke(icc.createNonTxInvocationContext(), command);
    }
 
    public final void putForExternalRead(K key, V value) {
-      putForExternalRead(key, value, (Flag[]) null);
+      Transaction ongoingTransaction = null;
+      try {
+         if (transactionManager != null && (ongoingTransaction = transactionManager.getTransaction()) != null) {
+            transactionManager.suspend();
+         }
+         // if the entry exists then this should be a no-op.
+         withFlags(FAIL_SILENTLY, FORCE_ASYNCHRONOUS, ZERO_LOCK_ACQUISITION_TIMEOUT, PUT_FOR_EXTERNAL_READ).putIfAbsent(key, value);
+      }
+      catch (Exception e) {
+         if (log.isDebugEnabled()) log.debug("Caught exception while doing putForExternalRead()", e);
+      }
+      finally {
+         try {
+            if (ongoingTransaction != null) transactionManager.resume(ongoingTransaction);
+         }
+         catch (Exception e) {
+            log.debug("Had problems trying to resume a transaction after putForExternalread()", e);
+         }
+      }
    }
 
    public final void evict(K key) {
@@ -243,7 +277,11 @@
    }
 
    private InvocationContext getInvocationContext() {
-      return icc.createInvocationContext();
+      InvocationContext ctx = icc.createInvocationContext();
+      PreInvocationContext pic = flagHolder.get();
+      if (pic != null && !pic.flags.isEmpty()) ctx.setFlags(pic.flags);
+      flagHolder.remove();
+      return ctx;
    }
 
    public void lock(K key) {
@@ -305,211 +343,13 @@
       return componentRegistry;
    }
 
-   public final void putForExternalRead(K key, V value, Flag... flags) {
-      InvocationContext invocationContext = getInvocationContext();
-      if (flags != null) invocationContext.setFlags(flags);
-      Transaction ongoingTransaction = null;
-      try {
-         if (transactionManager != null && (ongoingTransaction = transactionManager.getTransaction()) != null) {
-            transactionManager.suspend();
-         }
-         // if the entry exists then this should be a no-op.
-         putIfAbsent(key, value, Flag.FAIL_SILENTLY, Flag.FORCE_ASYNCHRONOUS, Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.PUT_FOR_EXTERNAL_READ);
-      }
-      catch (Exception e) {
-         if (log.isDebugEnabled()) log.debug("Caught exception while doing putForExternalRead()", e);
-      }
-      finally {
-         try {
-            if (ongoingTransaction != null) transactionManager.resume(ongoingTransaction);
-         }
-         catch (Exception e) {
-            log.debug("Had problems trying to resume a transaction after putForExternalread()", e);
-         }
-      }
-   }
-
-   public final V put(K key, V value, Flag... flags) {
-      return put(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   @SuppressWarnings("unchecked")
-   public final V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleTimeUnit.toMillis(maxIdleTime));
-      return (V) invoker.invoke(ctx, command);
-   }
-
-   public final V putIfAbsent(K key, V value, Flag... flags) {
-      return putIfAbsent(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   @SuppressWarnings("unchecked")
-   public final V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      InvocationContext context = getInvocationContext();
-      context.setFlags(flags);
-      PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleTimeUnit.toMillis(maxIdleTime));
-      command.setPutIfAbsent(true);
-      return (V) invoker.invoke(context, command);
-   }
-
-   public final void putAll(Map<? extends K, ? extends V> map, Flag... flags) {
-      putAll(map, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   public final void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      PutMapCommand command = commandsFactory.buildPutMapCommand(map, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS.toMillis(defaultMaxIdleTime));
-      invoker.invoke(ctx, command);
-   }
-
-   @SuppressWarnings("unchecked")
-   public final V remove(Object key, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      RemoveCommand command = commandsFactory.buildRemoveCommand(key, null);
-      return (V) invoker.invoke(ctx, command);
-   }
-
-   public final boolean remove(Object key, Object oldValue, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      RemoveCommand command = commandsFactory.buildRemoveCommand(key, oldValue);
-      return (Boolean) invoker.invoke(ctx, command);
-   }
-
-   public final void clear(Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ClearCommand command = commandsFactory.buildClearCommand();
-      invoker.invoke(ctx, command);
-   }
-
-   public final V replace(K k, V v, Flag... flags) {
-      return replace(k, v, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   public final boolean replace(K k, V oV, V nV, Flag... flags) {
-      return replace(k, oV, nV, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   @SuppressWarnings("unchecked")
-   public final V replace(K k, V v, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ReplaceCommand command = commandsFactory.buildReplaceCommand(k, null, v, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
-      return (V) invoker.invoke(ctx, command);
-   }
-
-   public final boolean replace(K k, V oV, V nV, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ReplaceCommand command = commandsFactory.buildReplaceCommand(k, oV, nV, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
-      return (Boolean) invoker.invoke(ctx, command);
-   }
-
-   public final NotifyingFuture<V> putAsync(K key, V value, Flag... flags) {
-      return putAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   public final NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ctx.setUseFutureReturnType(true);
-      PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleTimeUnit.toMillis(maxIdleTime));
-      return wrapInFuture(invoker.invoke(ctx, command));
-   }
-
-   public final NotifyingFuture<V> putIfAbsentAsync(K key, V value, Flag... flags) {
-      return putIfAbsentAsync(key, value, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   public final NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ctx.setUseFutureReturnType(true);
-      PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleTimeUnit.toMillis(maxIdleTime));
-      command.setPutIfAbsent(true);
-      return wrapInFuture(invoker.invoke(ctx, command));
-   }
-
-   public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> map, Flag... flags) {
-      return putAllAsync(map, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ctx.setUseFutureReturnType(true);
-      PutMapCommand command = commandsFactory.buildPutMapCommand(map, MILLISECONDS.toMillis(MILLISECONDS.toMillis(defaultLifespan)), MILLISECONDS.toMillis(MILLISECONDS.toMillis(defaultMaxIdleTime)));
-      return wrapInFuture(invoker.invoke(ctx, command));
-   }
-
-   public final NotifyingFuture<V> removeAsync(Object key, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ctx.setUseFutureReturnType(true);
-      RemoveCommand command = commandsFactory.buildRemoveCommand(key, null);
-      return wrapInFuture(invoker.invoke(ctx, command));
-   }
-
-   public final NotifyingFuture<Void> clearAsync(Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ctx.setUseFutureReturnType(true);
-      ClearCommand command = commandsFactory.buildClearCommand();
-      return wrapInFuture(invoker.invoke(ctx, command));
-   }
-
-   public final NotifyingFuture<V> replaceAsync(K k, V v, Flag... flags) {
-      return replaceAsync(k, v, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   public final NotifyingFuture<Boolean> replaceAsync(K k, V oV, V nV, Flag... flags) {
-      return replaceAsync(k, oV, nV, MILLISECONDS.toMillis(defaultLifespan), MILLISECONDS, MILLISECONDS.toMillis(defaultMaxIdleTime), MILLISECONDS, flags);
-   }
-
-   public final NotifyingFuture<V> replaceAsync(K k, V v, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ctx.setUseFutureReturnType(true);
-      ReplaceCommand command = commandsFactory.buildReplaceCommand(k, null, v, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
-      return wrapInFuture(invoker.invoke(ctx, command));
-   }
-
-   public final NotifyingFuture<Boolean> replaceAsync(K k, V oV, V nV, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      ctx.setUseFutureReturnType(true);
-      ReplaceCommand command = commandsFactory.buildReplaceCommand(k, oV, nV, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
-      return wrapInFuture(invoker.invoke(ctx, command));
-   }
-
-   public final boolean containsKey(Object key, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
-      Object response = invoker.invoke(ctx, command);
-      return response != null;
-   }
-
-   @SuppressWarnings("unchecked")
-   public final V get(Object key, Flag... flags) {
-      InvocationContext ctx = getInvocationContext();
-      if (flags != null) ctx.setFlags(flags);
-      GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
-      return (V) invoker.invoke(ctx, command);
-   }
-
    public ComponentStatus getStatus() {
       return componentRegistry.getStatus();
    }
 
-   /** 
-    * Returns String representation of ComponentStatus enumeration in order to avoid 
-    * class not found exceptions in JMX tools that don't have access to infinispan classes.
+   /**
+    * Returns String representation of ComponentStatus enumeration in order to avoid class not found exceptions in JMX
+    * tools that don't have access to infinispan classes.
     */
    @ManagedAttribute(description = "Returns the cache status")
    @Metric(displayName = "Cache status", dataType = DataType.TRAIT, displayType = DisplayType.SUMMARY)
@@ -533,8 +373,8 @@
       return name;
    }
 
-   /** 
-    * Returns the cache name. If this is the default cache, it returns a more friendly name. 
+   /**
+    * Returns the cache name. If this is the default cache, it returns a more friendly name.
     */
    @ManagedAttribute(description = "Returns the cache name")
    @Metric(displayName = "Cache name", dataType = DataType.TRAIT, displayType = DisplayType.SUMMARY)
@@ -567,12 +407,19 @@
       return cacheManager;
    }
 
+   @SuppressWarnings("unchecked")
    public final V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
-      return put(key, value, lifespan, lifespanUnit, maxIdleTime, idleTimeUnit, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
+      return (V) invoker.invoke(ctx, command);
    }
 
+   @SuppressWarnings("unchecked")
    public final V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
-      return putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, idleTimeUnit, (Flag[]) null);
+      InvocationContext context = getInvocationContext();
+      PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
+      command.setPutIfAbsent(true);
+      return (V) invoker.invoke(context, command);
    }
 
    public final void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
@@ -580,12 +427,18 @@
       invoker.invoke(getInvocationContext(), command);
    }
 
+   @SuppressWarnings("unchecked")
    public final V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
-      return replace(key, value, lifespan, lifespanUnit, maxIdleTime, idleTimeUnit, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      ReplaceCommand command = commandsFactory.buildReplaceCommand(key, null, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
+      return (V) invoker.invoke(ctx, command);
+
    }
 
    public final boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
-      return replace(key, oldValue, value, lifespan, lifespanUnit, maxIdleTime, idleTimeUnit, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      ReplaceCommand command = commandsFactory.buildReplaceCommand(key, oldValue, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
+      return (Boolean) invoker.invoke(ctx, command);
    }
 
    /**
@@ -711,7 +564,10 @@
    }
 
    public final NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
-      return replaceAsync(key, value, lifespan, lifespanUnit, maxIdle, maxIdleUnit, (Flag[]) null);
+      InvocationContext ctx = getInvocationContext();
+      ctx.setUseFutureReturnType(true);
+      ReplaceCommand command = commandsFactory.buildReplaceCommand(key, null, value, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
+      return wrapInFuture(invoker.invoke(ctx, command));
    }
 
    public final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue) {
@@ -763,4 +619,28 @@
    public RpcManager getRpcManager() {
       return rpcManager;
    }
+
+   public AdvancedCache<K, V> withFlags(Flag... flags) {
+      if (flags != null && flags.length > 0) {
+         PreInvocationContext pic = flagHolder.get();
+         if (pic == null)
+            flagHolder.set(new PreInvocationContext(flags));
+         else
+            flagHolder.set(pic.add(flags));
+      }
+      return this;
+   }
+
+   private static final class PreInvocationContext {
+      EnumSet<Flag> flags;
+
+      private PreInvocationContext(Flag[] flags) {
+         this.flags = flags != null && flags.length > 0 ? EnumSet.copyOf(Arrays.asList(flags)) : EnumSet.noneOf(Flag.class);
+      }
+
+      private PreInvocationContext add(Flag[] newFlags) {
+         if (newFlags != null && newFlags.length > 0) flags.addAll(Arrays.asList(newFlags));
+         return this;
+      }
+   }
 }

Modified: trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/main/java/org/infinispan/loaders/CacheLoaderManagerImpl.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -123,8 +123,7 @@
             }
 
             for (InternalCacheEntry e : state)
-               cache.getAdvancedCache().put(e.getKey(), e.getValue(), e.getLifespan(), MILLISECONDS,
-                                            e.getMaxIdle(), MILLISECONDS, SKIP_CACHE_STATUS_CHECK);
+               cache.getAdvancedCache().withFlags(SKIP_CACHE_STATUS_CHECK).put(e.getKey(), e.getValue(), e.getLifespan(), MILLISECONDS, e.getMaxIdle(), MILLISECONDS);
 
             if (log.isDebugEnabled()) stop = System.currentTimeMillis();
             if (log.isDebugEnabled()) total = stop - start;

Modified: trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -32,6 +32,7 @@
 import org.infinispan.context.Flag;
 import org.infinispan.context.InvocationContext;
 import org.infinispan.context.InvocationContextContainer;
+import static org.infinispan.context.Flag.CACHE_MODE_LOCAL;
 import org.infinispan.context.impl.RemoteTxInvocationContext;
 import org.infinispan.factories.annotations.Inject;
 import org.infinispan.factories.annotations.Start;
@@ -67,7 +68,7 @@
 public class StateTransferManagerImpl implements StateTransferManager {
 
    RpcManager rpcManager;
-   AdvancedCache cache;
+   AdvancedCache<Object, Object> cache;
    Configuration configuration;
    DataContainer dataContainer;
    CacheLoaderManager clm;
@@ -87,6 +88,7 @@
    volatile Address stateSender;
 
    @Inject
+   @SuppressWarnings("unchecked")
    public void injectDependencies(RpcManager rpcManager, AdvancedCache cache, Configuration configuration,
                                   DataContainer dataContainer, CacheLoaderManager clm, Marshaller marshaller,
                                   TransactionLog transactionLog, InterceptorChain interceptorChain, InvocationContextContainer invocationContextContainer,
@@ -226,7 +228,7 @@
          if (trace) log.trace("Mods = {0}", Arrays.toString(mods));
          for (WriteCommand mod : mods) {
             commandsFactory.initializeReplicableCommand(mod);
-            ctx.setFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STATUS_CHECK);
+            ctx.setFlags(CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STATUS_CHECK);
             interceptorChain.invoke(ctx, mod);
          }
 
@@ -262,7 +264,7 @@
                RemoteTxInvocationContext ctx = invocationContextContainer.createRemoteTxInvocationContext();
                RemoteTransaction transaction = txTable.createRemoteTransaction(command.getGlobalTransaction(), command.getModifications());
                ctx.setRemoteTransaction(transaction);
-               ctx.setFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STATUS_CHECK);
+               ctx.setFlags(CACHE_MODE_LOCAL, Flag.SKIP_CACHE_STATUS_CHECK);
                interceptorChain.invoke(ctx, command);
             } else {
                if (trace) log.trace("Prepare {0} not in tx log; not applying", command);
@@ -327,7 +329,7 @@
       try {
          Set<InternalCacheEntry> set = (Set<InternalCacheEntry>) marshaller.objectFromObjectStream(i);
          for (InternalCacheEntry se : set)
-            cache.put(se.getKey(), se.getValue(), se.getLifespan(), MILLISECONDS, se.getMaxIdle(), MILLISECONDS, Flag.CACHE_MODE_LOCAL);
+            cache.withFlags(CACHE_MODE_LOCAL).put(se.getKey(), se.getValue(), se.getLifespan(), MILLISECONDS, se.getMaxIdle(), MILLISECONDS);
       } catch (Exception e) {
          dataContainer.clear();
          throw new StateTransferException(e);

Modified: trunk/core/src/test/java/org/infinispan/api/ForceWriteLockTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/ForceWriteLockTest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/api/ForceWriteLockTest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -32,7 +32,7 @@
       advancedCache.put("k","v");
       assertNotLocked(advancedCache,"k");
       tm.begin();
-      advancedCache.get("k", Flag.FORCE_WRITE_LOCK);
+      advancedCache.withFlags(Flag.FORCE_WRITE_LOCK).get("k");
 
       InvocationContext ic = advancedCache.getInvocationContextContainer().getInvocationContext();
       CacheEntry cacheEntry = ic.getLookedUpEntries().get("k");

Modified: trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -2,7 +2,7 @@
 
 import org.infinispan.AdvancedCache;
 import org.infinispan.config.Configuration;
-import org.infinispan.context.Flag;
+import static org.infinispan.context.Flag.CACHE_MODE_LOCAL;
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.testng.annotations.Test;
 
@@ -43,10 +43,10 @@
       localCache1 = cache(0, "local").getAdvancedCache();
       localCache2 = cache(1, "local").getAdvancedCache();
 
-      invalSyncCache2.put("k", "v", Flag.CACHE_MODE_LOCAL);
+      invalSyncCache2.withFlags(CACHE_MODE_LOCAL).put("k", "v");
       assert invalSyncCache2.get("k").equals("v");
       assert invalSyncCache1.get("k") == null;
-      invalAsyncCache2.put("k", "v", Flag.CACHE_MODE_LOCAL);
+      invalAsyncCache2.withFlags(CACHE_MODE_LOCAL).put("k", "v");
       assert invalAsyncCache2.get("k").equals("v");
       assert invalAsyncCache1.get("k") == null;
 

Modified: trunk/core/src/test/java/org/infinispan/api/mvcc/PutForExternalReadTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/mvcc/PutForExternalReadTest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/api/mvcc/PutForExternalReadTest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -3,11 +3,11 @@
 import org.easymock.EasyMock;
 import static org.easymock.EasyMock.*;
 import org.infinispan.Cache;
+import static org.infinispan.context.Flag.CACHE_MODE_LOCAL;
 import org.infinispan.commands.remote.CacheRpcCommand;
 import org.infinispan.commands.write.PutKeyValueCommand;
 import org.infinispan.commands.write.RemoveCommand;
 import org.infinispan.config.Configuration;
-import org.infinispan.context.Flag;
 import org.infinispan.remoting.rpc.ResponseFilter;
 import org.infinispan.remoting.rpc.ResponseMode;
 import org.infinispan.remoting.rpc.RpcManager;
@@ -301,8 +301,8 @@
     * @throws Exception
     */
    private void cacheModeLocalTest(boolean transactional) throws Exception {
-      Cache cache1 = cache(0, "replSync");
-      Cache cache2 = cache(1, "replSync");
+      Cache<Object, Object> cache1 = cache(0, "replSync");
+      Cache<Object, Object> cache2 = cache(1, "replSync");
       TransactionManager tm1 = TestingUtil.getTransactionManager(cache1);
       TransactionManager tm2 = TestingUtil.getTransactionManager(cache2);
       RpcManager rpcManager = EasyMock.createMock(RpcManager.class);
@@ -316,7 +316,7 @@
          if (transactional)
             tm1.begin();
 
-         cache1.getAdvancedCache().putForExternalRead(key, value, Flag.CACHE_MODE_LOCAL);
+         cache1.getAdvancedCache().withFlags(CACHE_MODE_LOCAL).putForExternalRead(key, value);
 
          if (transactional)
             tm1.commit();

Modified: trunk/core/src/test/java/org/infinispan/distribution/AsyncAPISyncDistTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/AsyncAPISyncDistTest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/distribution/AsyncAPISyncDistTest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -2,7 +2,7 @@
 
 import org.infinispan.Cache;
 import org.infinispan.config.Configuration;
-import org.infinispan.context.Flag;
+import static org.infinispan.context.Flag.SKIP_REMOTE_LOOKUP;
 import org.infinispan.replication.AsyncAPISyncReplTest;
 import org.infinispan.test.data.Key;
 import org.infinispan.util.Util;
@@ -31,7 +31,7 @@
    @Override
    protected void assertOnAllCaches(Key k, String v) {
       Object real;
-      assert Util.safeEquals((real = c1.getAdvancedCache().get(k, Flag.SKIP_REMOTE_LOOKUP)), v) : "Error on cache 1.  Expected " + v + " and got " + real;
-      assert Util.safeEquals((real = c2.getAdvancedCache().get(k, Flag.SKIP_REMOTE_LOOKUP)), v) : "Error on cache 2.  Expected " + v + " and got " + real;
+      assert Util.safeEquals((real = c1.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).get(k)), v) : "Error on cache 1.  Expected " + v + " and got " + real;
+      assert Util.safeEquals((real = c2.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).get(k)), v) : "Error on cache 2.  Expected " + v + " and got " + real;
    }
 }
\ No newline at end of file

Modified: trunk/core/src/test/java/org/infinispan/distribution/DistSkipRemoteLookupTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/DistSkipRemoteLookupTest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/distribution/DistSkipRemoteLookupTest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -14,7 +14,7 @@
       assertIsNotInL1(c3, k1);
       assertIsNotInL1(c4, k1);
 
-      assert c4.getAdvancedCache().get(k1, SKIP_REMOTE_LOOKUP) == null;
+      assert c4.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).get(k1) == null;
 
       assertOwnershipAndNonOwnership(k1);
    }
@@ -28,7 +28,7 @@
       assertIsNotInL1(c3, k1);
       assertIsNotInL1(c4, k1);
 
-      assert c4.getAdvancedCache().putIfAbsent(k1, "new_val", SKIP_REMOTE_LOOKUP) == null;
+      assert c4.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).putIfAbsent(k1, "new_val") == null;
 
       assertIsInContainerImmortal(c1, k1);
       assertIsInContainerImmortal(c2, k1);
@@ -45,7 +45,7 @@
       assertIsNotInL1(c3, k1);
       assertIsNotInL1(c4, k1);
 
-      assert c4.getAdvancedCache().put(k1, "new_val", SKIP_REMOTE_LOOKUP) == null;
+      assert c4.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).put(k1, "new_val") == null;
       assert c3.get(k1).equals("new_val");
       assertOnAllCachesAndOwnership(k1, "new_val");
    }

Modified: trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -3,7 +3,7 @@
 import org.infinispan.Cache;
 import org.infinispan.commands.write.WriteCommand;
 import org.infinispan.config.Configuration;
-import org.infinispan.context.Flag;
+import static org.infinispan.context.Flag.CACHE_MODE_LOCAL;
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.infinispan.test.data.Key;
 import org.infinispan.util.Util;
@@ -44,7 +44,7 @@
    private void initC2(Key k) {
       Cache c1 = cache(0,getClass().getSimpleName());
       Cache c2 = cache(1,getClass().getSimpleName());
-      c2.getAdvancedCache().put(k, "v", Flag.CACHE_MODE_LOCAL);
+      c2.getAdvancedCache().withFlags(CACHE_MODE_LOCAL).put(k, "v");
    }
 
    public void testAsyncMethods() throws ExecutionException, InterruptedException {

Modified: trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -7,7 +7,7 @@
 import org.infinispan.commands.write.ClearCommand;
 import org.infinispan.commands.write.InvalidateCommand;
 import org.infinispan.config.Configuration;
-import org.infinispan.context.Flag;
+import static org.infinispan.context.Flag.CACHE_MODE_LOCAL;
 import org.infinispan.remoting.rpc.ResponseFilter;
 import org.infinispan.remoting.rpc.ResponseMode;
 import org.infinispan.remoting.rpc.RpcManager;
@@ -45,9 +45,9 @@
    public void testRemove() throws Exception {
       AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
-      cache1.put("key", "value", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value");
       assertEquals("value", cache1.get("key"));
-      cache2.put("key", "value", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value");
       assertEquals("value", cache2.get("key"));
 
       replListener(cache2).expectAny();
@@ -214,7 +214,7 @@
    public void testPutIfAbsent() {
       AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
-      assert null == cache2.put("key", "value", Flag.CACHE_MODE_LOCAL);
+      assert null == cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value");
       assert cache2.get("key").equals("value");
       assert cache1.get("key") == null;
 
@@ -225,7 +225,7 @@
       assert cache1.get("key").equals("value");
       assert cache2.get("key") == null;
 
-      assert null == cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      assert null == cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
 
       assert cache1.get("key").equals("value");
       assert cache2.get("key").equals("value2");
@@ -239,8 +239,8 @@
    public void testRemoveIfPresent() {
       AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
-      cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1");
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key").equals("value1");
       assert cache2.get("key").equals("value2");
 
@@ -260,8 +260,8 @@
    public void testClear() {
       AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
-      cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1");
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key").equals("value1");
       assert cache2.get("key").equals("value2");
 
@@ -276,7 +276,7 @@
    public void testReplace() {
       AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
@@ -285,7 +285,7 @@
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      assert null == cache1.put("key", "valueN", Flag.CACHE_MODE_LOCAL);
+      assert null == cache1.withFlags(CACHE_MODE_LOCAL).put("key", "valueN");
 
       replListener(cache2).expect(InvalidateCommand.class);
       cache1.replace("key", "value1");
@@ -298,7 +298,7 @@
    public void testReplaceWithOldVal() {
       AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
@@ -307,7 +307,7 @@
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      assert null == cache1.put("key", "valueN", Flag.CACHE_MODE_LOCAL);
+      assert null == cache1.withFlags(CACHE_MODE_LOCAL).put("key", "valueN");
 
       assert !cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
 
@@ -325,12 +325,12 @@
    public void testLocalOnlyClear() {
       AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
-      cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1");
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key").equals("value1");
       assert cache2.get("key").equals("value2");
 
-      cache1.clear(Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).clear();
 
       assert cache1.get("key") == null;
       assert cache2.get("key") != null;

Modified: trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java	2009-11-03 17:23:29 UTC (rev 1095)
+++ trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java	2009-11-03 23:51:12 UTC (rev 1096)
@@ -7,7 +7,7 @@
 import org.infinispan.commands.write.RemoveCommand;
 import org.infinispan.commands.write.ReplaceCommand;
 import org.infinispan.config.Configuration;
-import org.infinispan.context.Flag;
+import static org.infinispan.context.Flag.CACHE_MODE_LOCAL;
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.testng.annotations.Test;
 
@@ -58,7 +58,7 @@
    public void remove() {
       AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
-      cache2.put("key", "value", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value");
       assert cache2.get("key").equals("value");
       assert cache1.get("key") == null;
 
@@ -69,8 +69,8 @@
       assert cache1.get("key") == null;
       assert cache2.get("key") == null;
 
-      cache1.put("key", "value", Flag.CACHE_MODE_LOCAL);
-      cache2.put("key", "value", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value");
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value");
       assert cache1.get("key").equals("value");
       assert cache2.get("key").equals("value");
 
@@ -85,7 +85,7 @@
    public void testPutIfAbsent() {
       AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
-      cache2.put("key", "valueOld", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "valueOld");
       assert cache2.get("key").equals("valueOld");
       assert cache1.get("key") == null;
 
@@ -96,7 +96,7 @@
       assert cache1.get("key").equals("value");
       assert cache2.get("key").equals("value");
 
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
 
       assert cache1.get("key").equals("value");
       assert cache2.get("key").equals("value2");
@@ -110,8 +110,8 @@
    public void testRemoveIfPresent() {
       AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
-      cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1");
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key").equals("value1");
       assert cache2.get("key").equals("value2");
 
@@ -131,8 +131,8 @@
    public void testClear() {
       AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
-      cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1");
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key").equals("value1");
       assert cache2.get("key").equals("value2");
 
@@ -147,7 +147,7 @@
    public void testReplace() {
       AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
@@ -156,7 +156,7 @@
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      cache1.put("key", "valueN", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "valueN");
 
       replListener(cache2).expect(ReplaceCommand.class);
       cache1.replace("key", "value1");
@@ -169,7 +169,7 @@
    public void testReplaceWithOldVal() {
       AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
@@ -178,7 +178,7 @@
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
 
-      cache1.put("key", "valueN", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "valueN");
 
       cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
 
@@ -196,12 +196,12 @@
    public void testLocalOnlyClear() {
       AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
       AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
-      cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
-      cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1");
+      cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2");
       assert cache1.get("key").equals("value1");
       assert cache2.get("key").equals("value2");
 
-      cache1.clear(Flag.CACHE_MODE_LOCAL);
+      cache1.withFlags(CACHE_MODE_LOCAL).clear();
 
       assert cache1.get("key") == null;
       assert cache2.get("key") != null;



More information about the infinispan-commits mailing list