org.infinispan.remoting.inboundhandler.action.LockAction Maven / Gradle / Ivy
package org.infinispan.remoting.inboundhandler.action;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.infinispan.context.impl.TxInvocationContext;
import org.infinispan.interceptors.locking.ClusteringDependentLogic;
import org.infinispan.util.concurrent.locks.LockListener;
import org.infinispan.util.concurrent.locks.LockManager;
import org.infinispan.util.concurrent.locks.LockPromise;
import org.infinispan.util.concurrent.locks.LockState;
import org.infinispan.util.concurrent.locks.RemoteLockCommand;
import org.infinispan.util.concurrent.locks.TransactionalRemoteLockCommand;
/**
* An {@link Action} implementation that acquire the locks.
*
* It returns {@link ActionStatus#READY} when the locks are available to acquired or the acquisition failed (timeout or
* deadlock).
*
* @author Pedro Ruivo
* @since 8.0
*/
public class LockAction extends BaseLockingAction implements LockListener {
private final LockManager lockManager;
private final CompletableFuture notifier;
private volatile LockPromise lockPromise;
public LockAction(LockManager lockManager, @SuppressWarnings("deprecation") ClusteringDependentLogic clusteringDependentLogic) {
super(clusteringDependentLogic);
this.lockManager = lockManager;
notifier = new CompletableFuture<>();
}
@Override
protected ActionStatus checking(ActionState ignored) {
LockPromise promise = lockPromise;
if (promise != null && promise.isAvailable()) {
cas(InternalState.CHECKING, InternalState.READY);
return ActionStatus.READY;
} else {
return ActionStatus.NOT_READY;
}
}
@Override
protected ActionStatus init(ActionState state) {
if (!cas(InternalState.INIT, InternalState.CHECKING)) {
return ActionStatus.NOT_READY; //another thread is making progress
}
final Object lockOwner = getLockOwner(state);
final long timeout = state.getTimeout();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy