use of org.infinispan.commands.write.EvictCommand in project infinispan by infinispan.
the class CacheImpl method evict.
final void evict(K key, long explicitFlags) {
assertKeyNotNull(key);
if (!config.memory().isEvictionEnabled() && config.memory().whenFull() != EvictionStrategy.MANUAL) {
log.evictionDisabled(name);
}
InvocationContext ctx = createSingleKeyNonTxInvocationContext();
EvictCommand command = commandsFactory.buildEvictCommand(key, keyPartitioner.getSegment(key), explicitFlags);
invocationHelper.invoke(ctx, command);
}
use of org.infinispan.commands.write.EvictCommand in project infinispan by infinispan.
the class CallInterceptor method visitRemoveCommand.
private Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command, boolean notifyRemove) throws Throwable {
// It's not worth looking up the entry if we're never going to apply the change.
ValueMatcher valueMatcher = command.getValueMatcher();
if (valueMatcher == ValueMatcher.MATCH_NEVER) {
command.fail();
return null;
}
Object key = command.getKey();
MVCCEntry e = (MVCCEntry) ctx.lookupEntry(key);
Object prevValue = e.getValue();
Object optionalValue = command.getValue();
if (prevValue == null) {
command.nonExistant();
if (valueMatcher.matches(null, optionalValue, null)) {
e.setChanged(true);
e.setRemoved(true);
e.setCreated(false);
if (command instanceof EvictCommand) {
e.setEvicted(true);
}
e.setValue(null);
updateStoreFlags(command, e);
return command.isConditional() ? true : null;
} else {
log.trace("Nothing to remove since the entry doesn't exist in the context or it is null");
command.fail();
return false;
}
}
if (!valueMatcher.matches(prevValue, optionalValue, null)) {
command.fail();
return false;
}
// Refactor this eventually
if (command instanceof EvictCommand) {
e.setEvicted(true);
}
return performRemove(e, ctx, valueMatcher, key, prevValue, optionalValue, command.getMetadata(), notifyRemove, command);
}
use of org.infinispan.commands.write.EvictCommand in project infinispan by infinispan.
the class NotifyHelper method entryCommitted.
public static CompletionStage<Void> entryCommitted(CacheNotifier notifier, FunctionalNotifier functionalNotifier, boolean created, boolean removed, boolean expired, CacheEntry entry, InvocationContext ctx, FlagAffectedCommand command, Object previousValue, Metadata previousMetadata, EvictionManager evictionManager) {
// We only notify if there is no state transfer flag
if (FlagBitSets.extractStateTransferFlag(ctx, command) != null) {
return CompletableFutures.completedNull();
}
CompletionStage<Void> stage;
boolean isWriteOnly = (command instanceof WriteCommand) && ((WriteCommand) command).isWriteOnly();
if (removed) {
if (command instanceof RemoveExpiredCommand) {
// It is possible this command was generated from a store and the value is not in memory, thus we have
// to fall back to the command value and metadata if not present
Object expiredValue = previousValue != null ? previousValue : ((RemoveExpiredCommand) command).getValue();
Metadata expiredMetadata = entry.getMetadata() != null ? entry.getMetadata() : ((RemoveExpiredCommand) command).getMetadata();
stage = notifier.notifyCacheEntryExpired(entry.getKey(), expiredValue, expiredMetadata, ctx);
} else if (command instanceof EvictCommand) {
stage = evictionManager.onEntryEviction(Collections.singletonMap(entry.getKey(), entry), command);
} else if (command instanceof RemoveCommand) {
stage = notifier.notifyCacheEntryRemoved(entry.getKey(), previousValue, entry.getMetadata(), false, ctx, command);
} else if (command instanceof InvalidateCommand) {
stage = notifier.notifyCacheEntryInvalidated(entry.getKey(), previousValue, entry.getMetadata(), false, ctx, command);
} else {
if (expired) {
stage = notifier.notifyCacheEntryExpired(entry.getKey(), previousValue, previousMetadata, ctx);
} else {
stage = notifier.notifyCacheEntryRemoved(entry.getKey(), previousValue, previousMetadata, false, ctx, command);
}
// send remove event when the command is read-write.
if (!isWriteOnly)
functionalNotifier.notifyOnRemove(EntryViews.readOnly(entry.getKey(), previousValue, previousMetadata));
functionalNotifier.notifyOnWriteRemove(entry.getKey());
}
} else {
// Notify entry event after container has been updated
if (created) {
stage = notifier.notifyCacheEntryCreated(entry.getKey(), entry.getValue(), entry.getMetadata(), false, ctx, command);
// when the command is read-write.
if (!isWriteOnly)
functionalNotifier.notifyOnCreate(entry);
functionalNotifier.notifyOnWrite(entry);
} else {
stage = notifier.notifyCacheEntryModified(entry.getKey(), entry.getValue(), entry.getMetadata(), previousValue, previousMetadata, false, ctx, command);
// command is read-write.
if (!isWriteOnly)
functionalNotifier.notifyOnModify(entry, previousValue, previousMetadata);
functionalNotifier.notifyOnWrite(entry);
}
}
return stage;
}
Aggregations