Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.infinispan.interceptors.locking;
import org.infinispan.commands.CommandsFactory;
import org.infinispan.commands.DataCommand;
import org.infinispan.commands.LocalFlagAffectedCommand;
import org.infinispan.commands.control.LockControlCommand;
import org.infinispan.commands.read.GetAllCommand;
import org.infinispan.commands.remote.recovery.TxCompletionNotificationCommand;
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.context.Flag;
import org.infinispan.context.InvocationContext;
import org.infinispan.context.impl.TxInvocationContext;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.remoting.inboundhandler.DeliverOrder;
import org.infinispan.statetransfer.OutdatedTopologyException;
import org.infinispan.statetransfer.StateTransferManager;
import org.infinispan.transaction.impl.LocalTransaction;
import org.infinispan.util.concurrent.locks.LockUtil;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* Locking interceptor to be used by pessimistic caches.
* Design note: when a lock "k" needs to be acquired (e.g. cache.put("k", "v")), if the lock owner is the local node,
* no remote call is performed to migrate locking logic to the other (numOwners - 1) lock owners. This is a good
* optimisation for in-vm transactions: if the local node crashes before prepare then the replicated lock information
* would be useless as the tx is rolled back. OTOH for remote hotrod/transactions this additional RPC makes sense because
* there's no such thing as transaction originator node, so this might become a configuration option when HotRod tx are
* in place.
*
* Implementation note: current implementation acquires locks remotely first and then locally. This is required
* by the deadlock detection logic, but might not be optimal: acquiring locks locally first might help to fail fast the
* in the case of keys being locked.
*
* @author Mircea Markus
* @deprecated Since 8.2, no longer public API.
*/
@Deprecated
public class PessimisticLockingInterceptor extends AbstractTxLockingInterceptor {
private CommandsFactory cf;
private StateTransferManager stateTransferManager;
private static final Log log = LogFactory.getLog(PessimisticLockingInterceptor.class);
@Override
protected Log getLog() {
return log;
}
@Inject
public void init(CommandsFactory factory, StateTransferManager stateTransferManager) {
this.cf = factory;
this.stateTransferManager = stateTransferManager;
}
@Override
protected final Object visitDataReadCommand(InvocationContext ctx, DataCommand command) throws Throwable {
try {
if (ctx.isInTxScope() && command.hasFlag(Flag.FORCE_WRITE_LOCK) && !hasSkipLocking(command)) {
Object key = command.getKey();
acquireRemoteIfNeeded(ctx, key, command);
lockOrRegisterBackupLock((TxInvocationContext>) ctx, key, getLockTimeoutMillis(command));
((TxInvocationContext>) ctx).addAffectedKey(key);
}
return invokeNextInterceptor(ctx, command);
} catch (OutdatedTopologyException e) {
// The command will be retried, no need to release this or other locks
throw e;
} catch (Throwable t) {
releaseLocksOnFailureBeforePrepare(ctx);
throw t;
} finally {
if (!ctx.isInTxScope()) lockManager.unlockAll(ctx);
}
}
@Override
public Object visitGetAllCommand(InvocationContext ctx, GetAllCommand command) throws Throwable {
try {
if (ctx.isInTxScope() && command.hasFlag(Flag.FORCE_WRITE_LOCK) && !hasSkipLocking(command)) {
acquireAllRemoteIfNeeded(ctx, command.getKeys(), command);
//noinspection unchecked
lockAllOrRegisterBackupLock((TxInvocationContext>) ctx, (Collection