Example usage for java.util.concurrent.locks Lock unlock

List of usage examples for java.util.concurrent.locks Lock unlock

Introduction

In this page you can find the example usage for java.util.concurrent.locks Lock unlock.

Prototype

void unlock();

Source Link

Document

Releases the lock.

Usage

From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java

@Override
public void close() {
    Lock lock = filesLock.readLock();
    lock.lock();//  w ww.  j a v a 2s  .c  o  m
    try {
        doClose();
    } finally {
        lock.unlock();
    }
}

From source file:SoftReferenceCache.java

/**
 * @see java.util.Map#keySet()//w  w w .ja v a2s.co m
 */
public Set<K> keySet() {
    Lock lock = theLock.writeLock();
    lock.lock();
    final Object[] keys;
    try {
        removeQueued();
        keys = theCache.keySet().toArray();
    } finally {
        lock.unlock();
    }
    return new java.util.AbstractSet<K>() {
        @Override
        public Iterator<K> iterator() {
            return new java.util.Iterator<K>() {
                private int index = 0;

                public boolean hasNext() {
                    return index < keys.length - 1;
                }

                public K next() {
                    index++;
                    return (K) keys[index - 1];
                }

                public void remove() {
                    SoftReferenceCache.this.remove(keys[index - 1]);
                }
            };
        }

        @Override
        public int size() {
            return keys.length;
        }
    };
}

From source file:SoftReferenceCache.java

/**
 * @see java.util.Map#remove(java.lang.Object)
 *//*from   w ww . java2s.  c o  m*/
public V remove(Object key) {
    Lock lock = theLock.writeLock();
    lock.lock();
    try {
        removeQueued();
        KeyedSoftReference<V> val = theCache.remove(key);
        return val == null ? null : val.get();
    } finally {
        lock.unlock();
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.BaseService.java

/** {@inheritDoc} */
public void destroy() throws ServiceException {
    Lock writeLock = getReadWriteLock().writeLock();
    writeLock.lock();//from   w w w . ja  va 2s  .c o m
    isDestroyed = true;
    serviceContext = null;
    serviceConfigurations.clear();
    setInitialized(false);
    writeLock.unlock();
    serviceContextRWLock = null;
}

From source file:org.mule.util.queue.DualRandomAccessFileQueueStoreDelegate.java

/**
 * {@inheritDoc}/*w  w  w  .ja  v  a2 s  .  co  m*/
 */
@Override
public void dispose() {
    Lock lock = filesLock.writeLock();
    lock.lock();
    try {
        doClose();
        delete();
    } finally {
        lock.unlock();
    }
}

From source file:com.ignorelist.kassandra.steam.scraper.FileCache.java

@Override
public void put(String key, InputStream value) {
    final Lock writeLock = stripedLock.get(key).writeLock();
    writeLock.lock();/* ww w. j a  v a 2s.c om*/
    try {
        putNonBlocking(key, value);
    } catch (IOException ex) {
        Logger.getLogger(FileCache.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        writeLock.unlock();
    }

}

From source file:com.jayway.jaxrs.hateoas.DefaultHateoasContext.java

/**
 * Checks if the specified class has been registered. If not add the class to the set mapping
 * registred classes./*w  w  w . j a va  2  s. co  m*/
 *
 * @param clazz the class to check
 * @return <code>true</code> if the class has already been registered,
 *         <code>false</code> otherwise.
 */
public boolean isInitialized(Class<?> clazz) {
    Lock readLock = LOCK.readLock();
    try {
        readLock.lock();
        if (initializedClasses.contains(clazz)) {
            return true;
        }
    } finally {
        readLock.unlock();
    }

    Lock writeLock = LOCK.writeLock();
    try {
        writeLock.lock();
        if (!initializedClasses.contains(clazz)) { // check again - things might have changed
            initializedClasses.add(clazz);
            return false;
        }
    } finally {
        writeLock.unlock();
    }

    return true;
}

From source file:com.cloudera.oryx.ml.speed.als.ALSSpeedModel.java

public void pruneX(Collection<String> users) {
    // Keep all users in the new model, or, that have been added since last model
    Lock lock = xLock.writeLock();
    lock.lock();// ww w .  j av a 2 s. co  m
    try {
        X.removeIf(new KeyOnlyBiPredicate<>(new AndPredicate<>(new NotContainsPredicate<>(users),
                new NotContainsPredicate<>(recentNewUsers))));
        recentNewUsers.clear();
    } finally {
        lock.unlock();
    }
}

From source file:com.cloudera.oryx.ml.speed.als.ALSSpeedModel.java

public void pruneY(Collection<String> items) {
    // Keep all items in the new model, or, that have been added since last model
    Lock lock = yLock.writeLock();
    lock.lock();//from   www . ja va 2s  .  c om
    try {
        Y.removeIf(new KeyOnlyBiPredicate<>(new AndPredicate<>(new NotContainsPredicate<>(items),
                new NotContainsPredicate<>(recentNewItems))));
        recentNewItems.clear();
    } finally {
        lock.unlock();
    }
}

From source file:org.codehaus.wadi.location.partitionmanager.local.BasicLocalPartition.java

public void onMessage(Envelope message, MoveIMToPM request) {
    Lock readLock = readWriteLock.readLock();
    readLock.lock();// ww w  . ja  v a  2  s . c  o m
    try {
        LocalPartitionMoveIMToPMAction action = new LocalPartitionMoveIMToPMAction(dispatcher, nameToLocation,
                log);
        action.onMessage(message, request);
    } finally {
        readLock.unlock();
    }
}