Example usage for java.util.concurrent.locks Condition awaitUninterruptibly

List of usage examples for java.util.concurrent.locks Condition awaitUninterruptibly

Introduction

In this page you can find the example usage for java.util.concurrent.locks Condition awaitUninterruptibly.

Prototype

void awaitUninterruptibly();

Source Link

Document

Causes the current thread to wait until it is signalled.

Usage

From source file:org.apache.hadoop.hdfs.client.ShortCircuitCache.java

ClientMmap getOrCreateClientMmap(ShortCircuitReplica replica, boolean anchored) {
    Condition newCond;/*  ww  w . jav a2 s.  c o  m*/
    lock.lock();
    try {
        while (replica.mmapData != null) {
            if (replica.mmapData instanceof MappedByteBuffer) {
                ref(replica);
                MappedByteBuffer mmap = (MappedByteBuffer) replica.mmapData;
                return new ClientMmap(replica, mmap, anchored);
            } else if (replica.mmapData instanceof Long) {
                long lastAttemptTimeMs = (Long) replica.mmapData;
                long delta = Time.monotonicNow() - lastAttemptTimeMs;
                if (delta < staleThresholdMs) {
                    if (LOG.isTraceEnabled()) {
                        LOG.trace(this + ": can't create client mmap for " + replica + " because we failed to "
                                + "create one just " + delta + "ms ago.");
                    }
                    return null;
                }
                if (LOG.isTraceEnabled()) {
                    LOG.trace(this + ": retrying client mmap for " + replica + ", " + delta
                            + " ms after the previous failure.");
                }
            } else if (replica.mmapData instanceof Condition) {
                Condition cond = (Condition) replica.mmapData;
                cond.awaitUninterruptibly();
            } else {
                Preconditions.checkState(false,
                        "invalid mmapData type " + replica.mmapData.getClass().getName());
            }
        }
        newCond = lock.newCondition();
        replica.mmapData = newCond;
    } finally {
        lock.unlock();
    }
    MappedByteBuffer map = replica.loadMmapInternal();
    lock.lock();
    try {
        if (map == null) {
            replica.mmapData = Long.valueOf(Time.monotonicNow());
            newCond.signalAll();
            return null;
        } else {
            outstandingMmapCount++;
            replica.mmapData = map;
            ref(replica);
            newCond.signalAll();
            return new ClientMmap(replica, map, anchored);
        }
    } finally {
        lock.unlock();
    }
}

From source file:org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache.java

ClientMmap getOrCreateClientMmap(ShortCircuitReplica replica, boolean anchored) {
    Condition newCond;//from   w ww.j av  a2s  . c  o  m
    lock.lock();
    try {
        while (replica.mmapData != null) {
            if (replica.mmapData instanceof MappedByteBuffer) {
                ref(replica);
                MappedByteBuffer mmap = (MappedByteBuffer) replica.mmapData;
                return new ClientMmap(replica, mmap, anchored);
            } else if (replica.mmapData instanceof Long) {
                long lastAttemptTimeMs = (Long) replica.mmapData;
                long delta = Time.monotonicNow() - lastAttemptTimeMs;
                if (delta < mmapRetryTimeoutMs) {
                    if (LOG.isTraceEnabled()) {
                        LOG.trace(this + ": can't create client mmap for " + replica + " because we failed to "
                                + "create one just " + delta + "ms ago.");
                    }
                    return null;
                }
                if (LOG.isTraceEnabled()) {
                    LOG.trace(this + ": retrying client mmap for " + replica + ", " + delta
                            + " ms after the previous failure.");
                }
            } else if (replica.mmapData instanceof Condition) {
                Condition cond = (Condition) replica.mmapData;
                cond.awaitUninterruptibly();
            } else {
                Preconditions.checkState(false, "invalid mmapData type %s",
                        replica.mmapData.getClass().getName());
            }
        }
        newCond = lock.newCondition();
        replica.mmapData = newCond;
    } finally {
        lock.unlock();
    }
    MappedByteBuffer map = replica.loadMmapInternal();
    lock.lock();
    try {
        if (map == null) {
            replica.mmapData = Long.valueOf(Time.monotonicNow());
            newCond.signalAll();
            return null;
        } else {
            outstandingMmapCount++;
            replica.mmapData = map;
            ref(replica);
            newCond.signalAll();
            return new ClientMmap(replica, map, anchored);
        }
    } finally {
        lock.unlock();
    }
}

From source file:org.unitime.timetable.onlinesectioning.MultiLock.java

public UnlockAll lockAll() {
    iLock.lock();//from  w  w w. j  a  v  a2 s .  c o m
    try {
        iLog.debug("Locking all ...");
        while (iAllLocked != null)
            iAllLocked.awaitUninterruptibly();
        iAllLocked = iLock.newCondition();
        while (!iIndividualLocks.isEmpty()) {
            Condition otherCondition = iIndividualLocks.values().iterator().next();
            otherCondition.awaitUninterruptibly();
        }
        iLog.debug("Locked: all");
        return new UnlockAll();
    } finally {
        iLock.unlock();
    }
}

From source file:org.unitime.timetable.onlinesectioning.MultiLock.java

public Unlock lock(Collection<Long> ids) {
    iLock.lock();/*from w w  w. j  a  v  a  2  s  .  co m*/
    try {
        if (ids == null || ids.isEmpty())
            return new Unlock(ids);
        iLog.debug("Locking " + ids + " ...");
        Condition otherCondition = null;
        while ((otherCondition = hasLock(ids)) != null)
            otherCondition.awaitUninterruptibly();
        Condition myCondition = iLock.newCondition();
        for (Long id : ids)
            iIndividualLocks.put(id, myCondition);
        iLog.debug("Locked: " + ids);
        return new Unlock(ids);
    } finally {
        iLock.unlock();
    }
}