Search in sources :

Example 6 with LockStoreImpl

use of com.hazelcast.concurrent.lock.LockStoreImpl in project hazelcast by hazelcast.

the class UnlockIfLeaseExpiredOperation method run.

@Override
public void run() throws Exception {
    LockStoreImpl lockStore = getLockStore();
    int lockVersion = lockStore.getVersion(key);
    ILogger logger = getLogger();
    if (version == lockVersion) {
        if (logger.isFinestEnabled()) {
            logger.finest("Releasing a lock owned by " + lockStore.getOwnerInfo(key) + " after lease timeout!");
        }
        forceUnlock();
    } else {
        if (logger.isFinestEnabled()) {
            logger.finest("Won't unlock since lock version is not matching expiration version: " + lockVersion + " vs " + version);
        }
    }
}
Also used : LockStoreImpl(com.hazelcast.concurrent.lock.LockStoreImpl) ILogger(com.hazelcast.logging.ILogger)

Example 7 with LockStoreImpl

use of com.hazelcast.concurrent.lock.LockStoreImpl in project hazelcast by hazelcast.

the class AwaitOperation method run.

@Override
public void run() throws Exception {
    LockStoreImpl lockStore = getLockStore();
    if (!lockStore.lock(key, getCallerUuid(), threadId, getReferenceCallId(), leaseTime)) {
        throw new IllegalMonitorStateException("Current thread is not owner of the lock! -> " + lockStore.getOwnerInfo(key));
    }
    if (expired) {
        response = false;
    } else {
        lockStore.removeSignalKey(getWaitKey());
        lockStore.removeAwait(key, conditionId, getCallerUuid(), threadId);
        response = true;
    }
}
Also used : LockStoreImpl(com.hazelcast.concurrent.lock.LockStoreImpl)

Example 8 with LockStoreImpl

use of com.hazelcast.concurrent.lock.LockStoreImpl in project hazelcast by hazelcast.

the class AwaitOperation method shouldWait.

@Override
public boolean shouldWait() {
    LockStoreImpl lockStore = getLockStore();
    boolean canAcquireLock = lockStore.canAcquireLock(key, getCallerUuid(), threadId);
    if (!canAcquireLock) {
        return true;
    }
    return !lockStore.hasSignalKey(getWaitKey());
}
Also used : LockStoreImpl(com.hazelcast.concurrent.lock.LockStoreImpl)

Example 9 with LockStoreImpl

use of com.hazelcast.concurrent.lock.LockStoreImpl in project hazelcast by hazelcast.

the class AwaitOperation method onWaitExpire.

@Override
public void onWaitExpire() {
    expired = true;
    LockStoreImpl lockStore = getLockStore();
    lockStore.removeSignalKey(getWaitKey());
    lockStore.removeAwait(key, conditionId, getCallerUuid(), threadId);
    boolean locked = lockStore.lock(key, getCallerUuid(), threadId, getReferenceCallId(), leaseTime);
    if (locked) {
        // expired & acquired lock, send FALSE
        sendResponse(false);
    } else {
        // expired but could not acquire lock, no response atm
        lockStore.registerExpiredAwaitOp(this);
    }
}
Also used : LockStoreImpl(com.hazelcast.concurrent.lock.LockStoreImpl)

Example 10 with LockStoreImpl

use of com.hazelcast.concurrent.lock.LockStoreImpl in project hazelcast by hazelcast.

the class BeforeAwaitOperation method beforeRun.

@Override
public void beforeRun() throws Exception {
    LockStoreImpl lockStore = getLockStore();
    boolean isLockOwner = lockStore.isLockedBy(key, getCallerUuid(), threadId);
    ensureOwner(lockStore, isLockOwner);
}
Also used : LockStoreImpl(com.hazelcast.concurrent.lock.LockStoreImpl)

Aggregations

LockStoreImpl (com.hazelcast.concurrent.lock.LockStoreImpl)23 LockServiceImpl (com.hazelcast.concurrent.lock.LockServiceImpl)2 LockStoreContainer (com.hazelcast.concurrent.lock.LockStoreContainer)2 ILogger (com.hazelcast.logging.ILogger)2 ConditionKey (com.hazelcast.concurrent.lock.ConditionKey)1 LockResource (com.hazelcast.concurrent.lock.LockResource)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 MultiMap (com.hazelcast.core.MultiMap)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1