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.util.concurrent.locks.impl;
import org.infinispan.commons.util.Util;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.context.InvocationContext;
import org.infinispan.factories.KnownComponentNames;
import org.infinispan.factories.annotations.ComponentName;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.jmx.annotations.DataType;
import org.infinispan.jmx.annotations.MBean;
import org.infinispan.jmx.annotations.ManagedAttribute;
import org.infinispan.util.concurrent.TimeoutException;
import org.infinispan.util.concurrent.locks.DeadlockDetectedException;
import org.infinispan.util.concurrent.locks.ExtendedLockPromise;
import org.infinispan.util.concurrent.locks.KeyAwareLockListener;
import org.infinispan.util.concurrent.locks.KeyAwareLockPromise;
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.logging.Log;
import org.infinispan.util.logging.LogFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import static java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater;
/**
* The default {@link LockManager} implementation for transactional and non-transactional caches.
*
* @author Pedro Ruivo
* @since 8.0
*/
@MBean(objectName = "LockManager", description = "Manager that handles MVCC locks for entries")
public class DefaultLockManager implements LockManager {
private static final Log log = LogFactory.getLog(DefaultLockManager.class);
private static final boolean trace = log.isTraceEnabled();
private static final AtomicReferenceFieldUpdater UPDATER =
newUpdater(CompositeLockPromise.class, LockState.class, "lockState");
protected LockContainer lockContainer;
protected Configuration configuration;
protected ScheduledExecutorService scheduler;
@Inject
public void inject(LockContainer container, Configuration configuration,
@ComponentName(KnownComponentNames.TIMEOUT_SCHEDULE_EXECUTOR) ScheduledExecutorService executorService) {
this.lockContainer = container;
this.configuration = configuration;
this.scheduler = executorService;
}
@Override
public KeyAwareLockPromise lock(Object key, Object lockOwner, long time, TimeUnit unit) {
Objects.requireNonNull(key, "Key must be non null");
Objects.requireNonNull(lockOwner, "Lock owner must be non null");
Objects.requireNonNull(unit, "Time unit must be non null");
if (trace) {
log.tracef("Lock key=%s for owner=%s. timeout=%s (%s)", key, lockOwner, time, unit);
}
ExtendedLockPromise promise = lockContainer.acquire(key, lockOwner, time, unit);
return new KeyAwareExtendedLockPromise(promise, key, unit.toMillis(time)).scheduleLockTimeoutTask(scheduler);
}
@Override
public KeyAwareLockPromise lockAll(Collection> keys, Object lockOwner, long time, TimeUnit unit) {
Objects.requireNonNull(keys, "Keys must be non null");
Objects.requireNonNull(lockOwner, "Lock owner must be non null");
Objects.requireNonNull(unit, "Time unit must be non null");
if (keys.isEmpty()) {
if (trace) {
log.tracef("Lock all: no keys found for owner=%s", lockOwner);
}
return KeyAwareLockPromise.NO_OP;
} else if (keys.size() == 1) {
//although will have the cost of creating an iterator, at least, we don't need to enter the synchronized section.
return lock(keys.iterator().next(), lockOwner, time, unit);
}
final Set