Skip to content

Commit

Permalink
ISPN-922 Fix proposal with backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne authored and mmarkus committed Feb 15, 2011
1 parent 7d6811f commit 4938f73
Show file tree
Hide file tree
Showing 36 changed files with 713 additions and 160 deletions.
58 changes: 32 additions & 26 deletions core/src/main/java/org/infinispan/CacheDelegate.java
Expand Up @@ -89,6 +89,7 @@
/**
* @author Mircea.Markus@jboss.com
* @author Galder Zamarreño
* @author Sanne Grinovero
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
* @since 4.0
*/
Expand Down Expand Up @@ -174,7 +175,7 @@ private void assertKeysNotNull(Map<?, ?> data) {
public final boolean remove(Object key, Object value) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, value);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, value, ctx.getFlags());
return (Boolean) invoker.invoke(ctx, command);
}

Expand All @@ -190,7 +191,7 @@ public final boolean isEmpty() {
public final boolean containsKey(Object key) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key, ctx.getFlags());
Object response = invoker.invoke(ctx, command);
return response != null;
}
Expand All @@ -203,40 +204,43 @@ public final boolean containsValue(Object value) {
public final V get(Object key) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key, ctx.getFlags());
return (V) invoker.invoke(ctx, command);
}

@SuppressWarnings("unchecked")
public final V remove(Object key) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, null);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, null, ctx.getFlags());
return (V) invoker.invoke(ctx, command);
}

public final void clear() {
InvocationContext ctx = getInvocationContext(false);
ClearCommand command = commandsFactory.buildClearCommand();
ClearCommand command = commandsFactory.buildClearCommand(ctx.getFlags());
invoker.invoke(ctx, command);
}

@SuppressWarnings("unchecked")
public Set<K> keySet() {
InvocationContext ctx = getInvocationContext(false);
KeySetCommand command = commandsFactory.buildKeySetCommand();
return (Set<K>) invoker.invoke(getInvocationContext(false), command);
return (Set<K>) invoker.invoke(ctx, command);
}

@SuppressWarnings("unchecked")
public Collection<V> values() {
InvocationContext ctx = getInvocationContext(false);
ValuesCommand command = commandsFactory.buildValuesCommand();
return (Collection<V>) invoker.invoke(getInvocationContext(false), command);
return (Collection<V>) invoker.invoke(ctx, command);
}

@SuppressWarnings("unchecked")
public Set<Map.Entry<K, V>> entrySet() {
InvocationContext ctx = getInvocationContext(false);
EntrySetCommand command = commandsFactory.buildEntrySetCommand();
return (Set<Map.Entry<K, V>>) invoker.invoke(getInvocationContext(false), command);
return (Set<Map.Entry<K, V>>) invoker.invoke(ctx, command);
}

public final void putForExternalRead(K key, V value) {
Expand Down Expand Up @@ -307,8 +311,9 @@ public boolean lock(Collection<? extends K> keys) {
if (keys == null || keys.isEmpty()) {
throw new IllegalArgumentException("Cannot lock empty list of keys");
}
LockControlCommand command = commandsFactory.buildLockControlCommand(keys, false);
return (Boolean) invoker.invoke(getInvocationContext(false), command);
InvocationContext ctx = getInvocationContext(false);
LockControlCommand command = commandsFactory.buildLockControlCommand(keys, false, ctx.getFlags());
return (Boolean) invoker.invoke(ctx, command);
}

@ManagedOperation(description = "Starts the cache.")
Expand Down Expand Up @@ -440,38 +445,39 @@ public Stats getStats() {
public final V put(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime), ctx.getFlags());
return (V) invoker.invoke(ctx, command);
}

@SuppressWarnings("unchecked")
public final V putIfAbsent(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
assertKeyNotNull(key);
InvocationContext context = getInvocationContext(false);
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
InvocationContext ctx = getInvocationContext(false);
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime), ctx.getFlags());
command.setPutIfAbsent(true);
return (V) invoker.invoke(context, command);
return (V) invoker.invoke(ctx, command);
}

public final void putAll(Map<? extends K, ? extends V> map, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
assertKeysNotNull(map);
PutMapCommand command = commandsFactory.buildPutMapCommand(map, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
invoker.invoke(getInvocationContext(false), command);
InvocationContext ctx = getInvocationContext(false);
PutMapCommand command = commandsFactory.buildPutMapCommand(map, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime), ctx.getFlags());
invoker.invoke(ctx, command);
}

@SuppressWarnings("unchecked")
public final V replace(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, null, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, null, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime), ctx.getFlags());
return (V) invoker.invoke(ctx, command);

}

public final boolean replace(K key, V oldValue, V value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit idleTimeUnit) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, oldValue, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime));
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, oldValue, value, lifespanUnit.toMillis(lifespan), idleTimeUnit.toMillis(maxIdleTime), ctx.getFlags());
return (Boolean) invoker.invoke(ctx, command);
}

Expand Down Expand Up @@ -505,30 +511,30 @@ public final NotifyingFuture<V> putAsync(K key, V value, long lifespan, TimeUnit
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle), ctx.getFlags());
return wrapInFuture(invoker.invoke(ctx, command));
}

public final NotifyingFuture<Void> putAllAsync(Map<? extends K, ? extends V> data, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
assertKeysNotNull(data);
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
PutMapCommand command = commandsFactory.buildPutMapCommand(data, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
PutMapCommand command = commandsFactory.buildPutMapCommand(data, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle), ctx.getFlags());
return wrapInFuture(invoker.invoke(ctx, command));
}

public final NotifyingFuture<Void> clearAsync() {
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
ClearCommand command = commandsFactory.buildClearCommand();
ClearCommand command = commandsFactory.buildClearCommand(ctx.getFlags());
return wrapInFuture(invoker.invoke(ctx, command));
}

public final NotifyingFuture<V> putIfAbsentAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle), ctx.getFlags());
command.setPutIfAbsent(true);
return wrapInFuture(invoker.invoke(ctx, command));
}
Expand All @@ -537,31 +543,31 @@ public final NotifyingFuture<V> removeAsync(Object key) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, null);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, null, ctx.getFlags());
return wrapInFuture(invoker.invoke(ctx, command));
}

public final NotifyingFuture<Boolean> removeAsync(Object key, Object value) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, value);
RemoveCommand command = commandsFactory.buildRemoveCommand(key, value, ctx.getFlags());
return wrapInFuture(invoker.invoke(ctx, command));
}

public final NotifyingFuture<V> replaceAsync(K key, V value, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, null, value, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, null, value, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle), ctx.getFlags());
return wrapInFuture(invoker.invoke(ctx, command));
}

public final NotifyingFuture<Boolean> replaceAsync(K key, V oldValue, V newValue, long lifespan, TimeUnit lifespanUnit, long maxIdle, TimeUnit maxIdleUnit) {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContext(false);
ctx.setUseFutureReturnType(true);
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, oldValue, newValue, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle));
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, oldValue, newValue, lifespanUnit.toMillis(lifespan), maxIdleUnit.toMillis(maxIdle), ctx.getFlags());
return wrapInFuture(invoker.invoke(ctx, command));
}

Expand Down
18 changes: 10 additions & 8 deletions core/src/main/java/org/infinispan/commands/CommandsFactory.java
Expand Up @@ -44,6 +44,7 @@
import org.infinispan.commands.write.ReplaceCommand;
import org.infinispan.commands.write.WriteCommand;
import org.infinispan.container.entries.InternalCacheValue;
import org.infinispan.context.Flag;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
Expand All @@ -53,6 +54,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* A factory to build commands, initializing and injecting dependencies accordingly. Commands built for a specific,
Expand All @@ -75,15 +77,15 @@ public interface CommandsFactory {
* @param maxIdleTimeMillis max idle time in milliseconds. -1 if maxIdle is not used.
* @return a PutKeyValueCommand
*/
PutKeyValueCommand buildPutKeyValueCommand(Object key, Object value, long lifespanMillis, long maxIdleTimeMillis);
PutKeyValueCommand buildPutKeyValueCommand(Object key, Object value, long lifespanMillis, long maxIdleTimeMillis, Set<Flag> flags);

/**
* Builds a RemoveCommand
* @param key key to remove
* @param value value to check for ina conditional remove, or null for an unconditional remove.
* @return a RemoveCommand
*/
RemoveCommand buildRemoveCommand(Object key, Object value);
RemoveCommand buildRemoveCommand(Object key, Object value, Set<Flag> flags);

/**
* Builds an InvalidateCommand
Expand Down Expand Up @@ -117,7 +119,7 @@ public interface CommandsFactory {
* @param maxIdleTimeMillis max idle time in milliseconds. -1 if maxIdle is not used.
* @return a ReplaceCommand
*/
ReplaceCommand buildReplaceCommand(Object key, Object oldValue, Object newValue, long lifespanMillis, long maxIdleTimeMillis);
ReplaceCommand buildReplaceCommand(Object key, Object oldValue, Object newValue, long lifespanMillis, long maxIdleTimeMillis, Set<Flag> flags);

/**
* Builds a SizeCommand
Expand All @@ -130,7 +132,7 @@ public interface CommandsFactory {
* @param key key to get
* @return a GetKeyValueCommand
*/
GetKeyValueCommand buildGetKeyValueCommand(Object key);
GetKeyValueCommand buildGetKeyValueCommand(Object key, Set<Flag> flags);

/**
* Builds a KeySetCommand
Expand All @@ -157,13 +159,13 @@ public interface CommandsFactory {
* @param maxIdleTimeMillis max idle time in milliseconds. -1 if maxIdle is not used.
* @return a PutMapCommand
*/
PutMapCommand buildPutMapCommand(Map map, long lifespanMillis, long maxIdleTimeMillis);
PutMapCommand buildPutMapCommand(Map map, long lifespanMillis, long maxIdleTimeMillis, Set<Flag> flags);

/**
* Builds a ClearCommand
* @return a ClearCommand
*/
ClearCommand buildClearCommand();
ClearCommand buildClearCommand(Set<Flag> flags);

/**
* Builds an EvictCommand
Expand Down Expand Up @@ -234,15 +236,15 @@ public interface CommandsFactory {
* @param key key to look up
* @return a ClusteredGetCommand
*/
ClusteredGetCommand buildClusteredGetCommand(Object key);
ClusteredGetCommand buildClusteredGetCommand(Object key, Set<Flag> flags);

/**
* Builds a LockControlCommand to control explicit remote locking
* @param keys keys to lock
* @param implicit whether the lock command was implicit (triggered internally) or explicit (triggered by an API call)
* @return a LockControlCommand
*/
LockControlCommand buildLockControlCommand(Collection keys, boolean implicit);
LockControlCommand buildLockControlCommand(Collection keys, boolean implicit, Set<Flag> flags);

/**
* Builds a RehashControlCommand for coordinating a rehash event. This version of this factory method creates a simple
Expand Down
34 changes: 18 additions & 16 deletions core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java
Expand Up @@ -50,6 +50,7 @@
import org.infinispan.config.Configuration;
import org.infinispan.container.DataContainer;
import org.infinispan.container.entries.InternalCacheValue;
import org.infinispan.context.Flag;
import org.infinispan.context.InvocationContextContainer;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.distribution.DistributionManager;
Expand All @@ -73,6 +74,7 @@
/**
* @author Mircea.Markus@jboss.com
* @author Galder Zamarreño
* @author Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc.
* @since 4.0
*/
public class CommandsFactoryImpl implements CommandsFactory {
Expand Down Expand Up @@ -117,12 +119,12 @@ public void start() {
cacheName = cache.getName();
}

public PutKeyValueCommand buildPutKeyValueCommand(Object key, Object value, long lifespanMillis, long maxIdleTimeMillis) {
return new PutKeyValueCommand(key, value, false, notifier, lifespanMillis, maxIdleTimeMillis);
public PutKeyValueCommand buildPutKeyValueCommand(Object key, Object value, long lifespanMillis, long maxIdleTimeMillis, Set<Flag> flags) {
return new PutKeyValueCommand(key, value, false, notifier, lifespanMillis, maxIdleTimeMillis, flags);
}

public RemoveCommand buildRemoveCommand(Object key, Object value) {
return new RemoveCommand(key, value, notifier);
public RemoveCommand buildRemoveCommand(Object key, Object value, Set<Flag> flags) {
return new RemoveCommand(key, value, notifier, flags);
}

public InvalidateCommand buildInvalidateCommand(Object... keys) {
Expand All @@ -137,8 +139,8 @@ public InvalidateCommand buildInvalidateFromL1Command(boolean forRehash, Collect
return new InvalidateL1Command(forRehash, dataContainer, configuration, distributionManager, notifier, keys);
}

public ReplaceCommand buildReplaceCommand(Object key, Object oldValue, Object newValue, long lifespan, long maxIdleTimeMillis) {
return new ReplaceCommand(key, oldValue, newValue, lifespan, maxIdleTimeMillis);
public ReplaceCommand buildReplaceCommand(Object key, Object oldValue, Object newValue, long lifespan, long maxIdleTimeMillis, Set<Flag> flags) {
return new ReplaceCommand(key, oldValue, newValue, lifespan, maxIdleTimeMillis, flags);
}

public SizeCommand buildSizeCommand() {
Expand Down Expand Up @@ -169,16 +171,16 @@ public EntrySetCommand buildEntrySetCommand() {
return cachedEntrySetCommand;
}

public GetKeyValueCommand buildGetKeyValueCommand(Object key) {
return new GetKeyValueCommand(key, notifier);
public GetKeyValueCommand buildGetKeyValueCommand(Object key, Set<Flag> flags) {
return new GetKeyValueCommand(key, notifier, flags);
}

public PutMapCommand buildPutMapCommand(Map map, long lifespan, long maxIdleTimeMillis) {
return new PutMapCommand(map, notifier, lifespan, maxIdleTimeMillis);
public PutMapCommand buildPutMapCommand(Map map, long lifespan, long maxIdleTimeMillis, Set<Flag> flags) {
return new PutMapCommand(map, notifier, lifespan, maxIdleTimeMillis, flags);
}

public ClearCommand buildClearCommand() {
return new ClearCommand(notifier);
public ClearCommand buildClearCommand(Set<Flag> flags) {
return new ClearCommand(notifier, flags);
}

public EvictCommand buildEvictCommand(Object key) {
Expand Down Expand Up @@ -215,8 +217,8 @@ public StateTransferControlCommand buildStateTransferControlCommand(boolean bloc
return new StateTransferControlCommand(block);
}

public ClusteredGetCommand buildClusteredGetCommand(Object key) {
return new ClusteredGetCommand(key, cacheName);
public ClusteredGetCommand buildClusteredGetCommand(Object key, Set<Flag> flags) {
return new ClusteredGetCommand(key, cacheName, flags);
}

/**
Expand Down Expand Up @@ -319,8 +321,8 @@ public void initializeReplicableCommand(ReplicableCommand c, boolean isRemote) {
}
}

public LockControlCommand buildLockControlCommand(Collection keys, boolean implicit) {
return new LockControlCommand(keys, cacheName, implicit);
public LockControlCommand buildLockControlCommand(Collection keys, boolean implicit, Set<Flag> flags) {
return new LockControlCommand(keys, cacheName, flags, implicit);
}

public RehashControlCommand buildRehashControlCommand(RehashControlCommand.Type type, Address sender) {
Expand Down

0 comments on commit 4938f73

Please sign in to comment.