Example usage for org.apache.commons.transaction.locking GenericLock acquire

List of usage examples for org.apache.commons.transaction.locking GenericLock acquire

Introduction

In this page you can find the example usage for org.apache.commons.transaction.locking GenericLock acquire.

Prototype

public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility,
        long timeoutMSecs) throws InterruptedException 

Source Link

Usage

From source file:org.apache.slide.store.ExtendedStore.java

public void exclusiveTransientLock(String uri) throws ServiceAccessException {
    Xid txId = (Xid) activeTransactionBranch.get();
    if (txId != null) {
        try {//from   ww  w.  j a v a  2s  .  c om
            GenericLock lock = (GenericLock) lockManager.atomicGetOrCreateLock(uri);
            if (lock.getLockLevel(txId) != 1) {
                Object owner = lock.getOwner();
                getLogger().log(
                        "Try lock: " + txId + " tries " + uri
                                + (owner != null ? " ---> " + owner.toString() + " has it" : ""),
                        LOG_CHANNEL, Logger.DEBUG);
                if (!lock.acquire(txId, 1, true, true, timeout)) {
                    throw new ServiceAccessException(this, new ConflictException(uri));
                }
                ((HashSet) locks.get()).add(lock);
                getLogger().log("Has lock: " + txId + " locks " + uri, LOG_CHANNEL, Logger.DEBUG);
            }
        } catch (InterruptedException e) {
            throw new ServiceAccessException(this, new ConflictException(uri));
        }
    }
}