Example usage for java.util.concurrent.locks ReentrantLock getQueueLength

List of usage examples for java.util.concurrent.locks ReentrantLock getQueueLength

Introduction

In this page you can find the example usage for java.util.concurrent.locks ReentrantLock getQueueLength.

Prototype

public final int getQueueLength() 

Source Link

Document

Returns an estimate of the number of threads waiting to acquire this lock.

Usage

From source file:io.tilt.minka.business.impl.SemaphoreImpl.java

private Permission checkState(final Action action) {
    if (action.getScope() == Scope.LOCAL) {
        final ReentrantLock lock = g(action);
        if (lock.isHeldByCurrentThread()) {
            logger.error("{}: {} lock already acquired by YOU ! CHECK YOUR CODE !", getClass().getSimpleName(),
                    action);//from  w  ww  . ja va 2  s .com
            return DENIED;
            //throw new RuntimeException("Come on check your code consistency pal !");
        } else if (lock.isLocked()) {
            logger.error("{}: {} lock already acquired by {} thread ! and holds: {} more",
                    getClass().getSimpleName(), action, lock.isHeldByCurrentThread() ? "current" : "sibling",
                    lock.getQueueLength());
            return DENIED;
        }
    } else if (action.getScope() == Scope.GLOBAL) {
        // TODO
    }

    // in the case of not being slave to those master to me or any (got that?)
    // i simply let them acquire, otherwise behead it !
    for (final Entry<Action, Rule> entry : rules.entrySet()) {
        final List<Action> related = entry.getValue().getRelated(PARENT);
        if (!related.isEmpty()) {
            if (isLocked(entry.getKey()) && (related.contains(ANY) || related.contains(action))) {
                if (!rules.get(action).getRelated(CHILD).contains(entry.getKey())) {
                    logger.warn(
                            "{}: {} Cannot be acquired because not Child of previously acquired Parent lock: {}",
                            getClass().getSimpleName(), action, entry.getKey());
                    return DENIED;
                }
            }
        }
    }

    return null;
}