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

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

Introduction

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

Prototype

public int getLockLevel(Object ownerId) 

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   w  w  w  .  j  a v  a2s  .  co m*/
            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));
        }
    }
}