org.infinispan.interceptors.locking.OptimisticLockingInterceptor Maven / Gradle / Ivy
package org.infinispan.interceptors.locking;
import org.infinispan.InvalidCacheUsageException;
import org.infinispan.commands.DataCommand;
import org.infinispan.commands.control.LockControlCommand;
import org.infinispan.commands.read.GetAllCommand;
import org.infinispan.commands.read.GetKeyValueCommand;
import org.infinispan.commands.tx.PrepareCommand;
import org.infinispan.commands.write.ApplyDeltaCommand;
import org.infinispan.commands.write.DataWriteCommand;
import org.infinispan.commands.write.PutMapCommand;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.container.entries.CacheEntry;
import org.infinispan.container.entries.RepeatableReadEntry;
import org.infinispan.context.Flag;
import org.infinispan.context.InvocationContext;
import org.infinispan.context.impl.TxInvocationContext;
import org.infinispan.factories.annotations.Start;
import org.infinispan.util.concurrent.IsolationLevel;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import java.util.Collection;
import static org.infinispan.commons.util.Util.toStr;
import static org.infinispan.commons.util.Util.toStr;
/**
* Locking interceptor to be used by optimistic transactional caches.
*
* @author Mircea Markus
* @deprecated Since 8.2, no longer public API.
*/
@Deprecated
public class OptimisticLockingInterceptor extends AbstractTxLockingInterceptor {
private boolean needToMarkReads;
private static final Log log = LogFactory.getLog(OptimisticLockingInterceptor.class);
private static final boolean trace = log.isTraceEnabled();
@Override
protected Log getLog() {
return log;
}
@Start
public void start() {
needToMarkReads = cacheConfiguration.clustering().cacheMode() == CacheMode.LOCAL &&
cacheConfiguration.locking().writeSkewCheck() &&
cacheConfiguration.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ &&
!cacheConfiguration.unsafe().unreliableReturnValues();
}
private void markKeyAsRead(InvocationContext ctx, DataCommand command, boolean forceRead) {
if (needToMarkReads && ctx.isInTxScope() &&
(forceRead || !command.hasFlag(Flag.IGNORE_RETURN_VALUES))) {
TxInvocationContext tctx = (TxInvocationContext) ctx;
tctx.getCacheTransaction().addReadKey(command.getKey());
}
}
@Override
public Object visitPrepareCommand(TxInvocationContext ctx, PrepareCommand command) throws Throwable {
final Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy