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:com.mastfrog.netty.http.client.CookieStore.java

public void remove(String name) {
    Lock writeLock = lock.writeLock();
    try {//from  www .ja  v  a2  s.c  o m
        writeLock.lock();
        for (Iterator<DateCookie> it = cookies.iterator(); it.hasNext();) {
            DateCookie ck = it.next();
            if (name.equals(ck.getName())) {
                it.remove();
            }
        }
    } finally {
        writeLock.unlock();
    }
}

From source file:org.springframework.integration.hazelcast.HazelcastLocalInstanceRegistrar.java

private void syncConfigurationMultiMap(HazelcastInstance hazelcastInstance) {
    Lock lock = hazelcastInstance.getLock(SPRING_INTEGRATION_INTERNAL_CLUSTER_LOCK);
    lock.lock();/*from w  w  w  .j  ava 2 s.  c  o  m*/
    try {
        MultiMap<SocketAddress, SocketAddress> multiMap = hazelcastInstance
                .getMultiMap(SPRING_INTEGRATION_INTERNAL_CLUSTER_MULTIMAP);
        for (HazelcastInstance localInstance : Hazelcast.getAllHazelcastInstances()) {
            SocketAddress localInstanceSocketAddress = localInstance.getLocalEndpoint().getSocketAddress();
            if (multiMap.size() == 0) {
                multiMap.put(localInstanceSocketAddress, localInstanceSocketAddress);
            } else {
                multiMap.put(multiMap.keySet().iterator().next(), localInstanceSocketAddress);
            }
        }
    } finally {
        lock.unlock();
    }
}

From source file:org.geotools.gce.imagemosaic.catalog.GTDataStoreGranuleCatalog.java

public void removeType(String typeName) throws IOException {
    Utilities.ensureNonNull("featureType", typeName);
    final Lock lock = rwLock.writeLock();
    try {//from ww w .j  a  v a2  s. com
        lock.lock();
        checkStore();

        tileIndexStore.removeSchema(typeName);
        removeTypeName(typeName);

    } finally {
        lock.unlock();
    }

}

From source file:org.apache.synapse.endpoints.algorithms.WeightedRoundRobin.java

public void changeWeight(int pos, int weight) {
    Lock writeLock = lock.writeLock();
    writeLock.lock();//from   w  w w  .  ja va  2  s  .  c o m
    try {
        EndpointState state = null;
        for (EndpointState s : endpointStates) {
            if (s.getEndpointPosition() == pos) {
                state = s;
            }
        }

        if (state == null) {
            throw new SynapseException("The specified endpoint position cannot be found");
        }

        state.weight = weight;

        calculate();

        reset(null);
    } finally {
        writeLock.unlock();
    }
}

From source file:org.pepstock.jem.node.tasks.JobTask.java

/**
 * Loads all roles defined for a specific user.
 * @param user user to extract its roles
 * @return a list of roles assigned to the user
 * @throws NodeMessageException if any error occurs retrievin gthe roles
 *//* ww w  . j ava2  s  . c o m*/
private List<Role> loadRoles(User user) throws NodeMessageException {
    // creates Hazelcast predicate to extract all roles and permissions
    // assigned to user
    RolesQueuePredicate predicate = new RolesQueuePredicate();
    predicate.setUser(user);

    List<Role> myroles = null;
    // gets map and performs predicate!
    IMap<String, Role> rolesMap = Main.getHazelcast().getMap(Queues.ROLES_MAP);
    Lock lock = Main.getHazelcast().getLock(Queues.ROLES_MAP_LOCK);
    boolean isLock = false;
    try {
        isLock = lock.tryLock(10, TimeUnit.SECONDS);
        if (isLock) {
            myroles = new ArrayList<Role>(rolesMap.values(predicate));
        } else {
            throw new NodeMessageException(NodeMessage.JEMC119E, Queues.ROLES_MAP);
        }
    } catch (Exception e) {
        throw new NodeMessageException(NodeMessage.JEMC119E, e, Queues.ROLES_MAP);
    } finally {
        if (isLock) {
            lock.unlock();
        }
    }
    return myroles;
}

From source file:com.cloudera.oryx.ml.serving.als.model.ALSServingModel.java

void addKnownItems(String user, Collection<String> items) {
    ObjSet<String> knownItemsForUser = doGetKnownItems(user);

    if (knownItemsForUser == null) {
        Lock writeLock = xLock.writeLock();
        writeLock.lock();/*  w w w.  j ava 2 s. c o m*/
        try {
            // Check again
            knownItemsForUser = knownItems.get(user);
            if (knownItemsForUser == null) {
                knownItemsForUser = HashObjSets.newMutableSet();
                knownItems.put(user, knownItemsForUser);
            }
        } finally {
            writeLock.unlock();
        }
    }

    synchronized (knownItemsForUser) {
        knownItemsForUser.addAll(items);
    }
}

From source file:be.fgov.kszbcss.rhq.websphere.config.CellConfiguration.java

<T> T execute(SessionAction<T> action) throws JMException, ConnectorException, InterruptedException {
    // Note: a read lock can't be upgraded to a write lock, so we need to acquire a write
    // lock first.
    Lock readLock = sessionLock.readLock();
    Lock writeLock = sessionLock.writeLock();
    writeLock.lockInterruptibly();/*from  w ww  .  j a v  a  2s.  com*/
    try {
        if (destroyed) {
            throw new IllegalStateException("Object already destroyed; not accepting any new requests");
        }
        if (session == null) {
            session = new Session("rhq-websphere-plugin", false);
            if (log.isDebugEnabled()) {
                log.debug("New session created: " + session);
            }
        }
        readLock.lockInterruptibly();
    } finally {
        writeLock.unlock();
    }
    if (log.isDebugEnabled()) {
        log.debug("Start executing action " + action + " on session " + session);
    }
    try {
        return action.execute(configService, appManagement, session);
    } finally {
        readLock.unlock();
        if (log.isDebugEnabled()) {
            log.debug("Finished executing action " + action + " on session " + session);
        }
    }
}

From source file:org.oesf.eque.services.impl.QueueDispatcherImpl.java

@Override
public Integer allocateNumber() throws NoFreePlaceAvailableException {

    Lock atomic = this.lock;

    try {// ww  w . j  a v  a  2  s .c  om
        atomic.lock();

        occupiedQueue.add(freeQueue.element());
        Integer allocatedNumber = freeQueue.remove();
        LOG.debug("QDS-34C5F87A3F23: The on-demand allocated number is: \"{}\"", allocatedNumber);

        notifyStateChange(allocatedNumber, LocalDateTime.now(), FREE, OCCUPIED);
        return allocatedNumber;

    } catch (IllegalStateException ex) { // occupiedQueue.add()

        LOG.error("QDS-0EAE6367CEEE: Can not occupy a number.");
        throw new ChangeStateException();

    } catch (NoSuchElementException ex) { // freeQueue .element() | .remove()

        LOG.debug("QDS-3A2DFE3EE673: Allocating a new place number.");
        throw new NoFreePlaceAvailableException();

    } finally {
        atomic.unlock();
    }
}

From source file:org.mule.security.oauth.BaseOAuthClientFactory.java

/**
 * This method creates an instance of/*from  w  ww  .j ava 2s.c  o  m*/
 * {@link org.mule.security.oauth.OAuth2Adapter} which concrete type depends on
 * the return of
 * {@link BaseOAuthClientFactory#getAdapterClass} The
 * adapter is fully initialized and interfaces such as
 * {@link Initialisable},
 * {@link MuleContextAware} and
 * {@link Startable} are respected by invoking the
 * corresponding methods in case the adapter implements them. Finally, the
 * {@link OAuth2Connector#postAuth()} method is invoked.
 * 
 * @param key the of the object at the object store
 */
@Override
public final OAuth2Adapter makeObject(String key) throws Exception {
    OAuthState state = null;
    Lock lock = this.getLock(key);
    lock.lock();

    try {
        if (!this.objectStore.contains(key)) {
            throw new NotAuthorizedException(String.format(
                    "There is no access token stored under the key %s . You need to call the <authorize> message processor. The key will be given to you via a flow variable after the OAuth dance is completed. You can extract it using flowVars['tokenId'].",
                    key));
        }

        state = this.retrieveOAuthState(key, true);
    } finally {
        lock.unlock();
    }

    OAuth2Adapter connector = this.getAdapterClass().getConstructor(OAuth2Manager.class)
            .newInstance(this.oauthManager);

    connector.setConsumerKey(oauthManager.getDefaultUnauthorizedConnector().getConsumerKey());
    connector.setConsumerSecret(oauthManager.getDefaultUnauthorizedConnector().getConsumerSecret());
    connector.setAccessToken(state.getAccessToken());
    connector.setAuthorizationUrl(state.getAuthorizationUrl());
    connector.setAccessTokenUrl(state.getAccessTokenUrl());
    connector.setRefreshToken(state.getRefreshToken());

    this.setCustomAdapterProperties(connector, state);

    if (connector instanceof MuleContextAware) {
        ((MuleContextAware) connector).setMuleContext(oauthManager.getMuleContext());
    }
    if (connector instanceof Initialisable) {
        ((Initialisable) connector).initialise();
    }
    if (connector instanceof Startable) {
        ((Startable) connector).start();
    }

    this.oauthManager.postAuth(connector, key);
    return connector;
}

From source file:net.myrrix.online.ServerRecommender.java

private static FastIDSet getIDsFromKeys(FastByIDMap<float[]> map, Lock readLock, FastIDSet tagIDs) {
    readLock.lock();//w  ww .ja  v a2  s .co  m
    try {
        FastIDSet ids = new FastIDSet(map.size());
        LongPrimitiveIterator it = map.keySetIterator();
        while (it.hasNext()) {
            long id = it.nextLong();
            if (!tagIDs.contains(id)) {
                ids.add(id);
            }
        }
        return ids;
    } finally {
        readLock.unlock();
    }
}