Search in sources :

Example 21 with Lock

use of java.util.concurrent.locks.Lock in project tomcat by apache.

the class ContainerBase method getCluster.

/**
     * Return the Cluster with which this Container is associated.  If there is
     * no associated Cluster, return the Cluster associated with our parent
     * Container (if any); otherwise return <code>null</code>.
     */
@Override
public Cluster getCluster() {
    Lock readLock = clusterLock.readLock();
    readLock.lock();
    try {
        if (cluster != null)
            return cluster;
        if (parent != null)
            return parent.getCluster();
        return null;
    } finally {
        readLock.unlock();
    }
}
Also used : ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 22 with Lock

use of java.util.concurrent.locks.Lock in project tomcat by apache.

the class StandardContext method resourcesStop.

/**
     * Deallocate resources and destroy proxy.
     * @return <code>true</code> if no error occurred
     */
public boolean resourcesStop() {
    boolean ok = true;
    Lock writeLock = resourcesLock.writeLock();
    writeLock.lock();
    try {
        if (resources != null) {
            resources.stop();
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log.error(sm.getString("standardContext.resourcesStop"), t);
        ok = false;
    } finally {
        writeLock.unlock();
    }
    return ok;
}
Also used : ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 23 with Lock

use of java.util.concurrent.locks.Lock in project tomcat by apache.

the class StandardContext method setLoader.

@Override
public void setLoader(Loader loader) {
    Lock writeLock = loaderLock.writeLock();
    writeLock.lock();
    Loader oldLoader = null;
    try {
        // Change components if necessary
        oldLoader = this.loader;
        if (oldLoader == loader)
            return;
        this.loader = loader;
        // Stop the old component if necessary
        if (getState().isAvailable() && (oldLoader != null) && (oldLoader instanceof Lifecycle)) {
            try {
                ((Lifecycle) oldLoader).stop();
            } catch (LifecycleException e) {
                log.error("StandardContext.setLoader: stop: ", e);
            }
        }
        // Start the new component if necessary
        if (loader != null)
            loader.setContext(this);
        if (getState().isAvailable() && (loader != null) && (loader instanceof Lifecycle)) {
            try {
                ((Lifecycle) loader).start();
            } catch (LifecycleException e) {
                log.error("StandardContext.setLoader: start: ", e);
            }
        }
    } finally {
        writeLock.unlock();
    }
    // Report this property change to interested listeners
    support.firePropertyChange("loader", oldLoader, loader);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) WebappLoader(org.apache.catalina.loader.WebappLoader) Loader(org.apache.catalina.Loader) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 24 with Lock

use of java.util.concurrent.locks.Lock in project tomcat by apache.

the class NotificationInfo method addNotifType.

// --------------------------------------------------------- Public Methods
/**
     * Add a new notification type to the set managed by an MBean.
     *
     * @param notifType The new notification type
     */
public void addNotifType(String notifType) {
    Lock writeLock = notifTypesLock.writeLock();
    writeLock.lock();
    try {
        String[] results = new String[notifTypes.length + 1];
        System.arraycopy(notifTypes, 0, results, 0, notifTypes.length);
        results[notifTypes.length] = notifType;
        notifTypes = results;
        this.info = null;
    } finally {
        writeLock.unlock();
    }
}
Also used : Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 25 with Lock

use of java.util.concurrent.locks.Lock in project tomcat by apache.

the class NotificationInfo method toString.

/**
     * Return a string representation of this notification descriptor.
     */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder("NotificationInfo[");
    sb.append("name=");
    sb.append(name);
    sb.append(", description=");
    sb.append(description);
    sb.append(", notifTypes=");
    Lock readLock = notifTypesLock.readLock();
    readLock.lock();
    try {
        sb.append(notifTypes.length);
    } finally {
        readLock.unlock();
    }
    sb.append("]");
    return (sb.toString());
}
Also used : Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Aggregations

Lock (java.util.concurrent.locks.Lock)717 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)171 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)144 ReentrantLock (java.util.concurrent.locks.ReentrantLock)96 Test (org.junit.Test)57 ArrayList (java.util.ArrayList)41 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)36 IOException (java.io.IOException)33 CountDownLatch (java.util.concurrent.CountDownLatch)30 HashMap (java.util.HashMap)22 Triple (org.apache.clerezza.commons.rdf.Triple)21 Map (java.util.Map)20 Ignite (org.apache.ignite.Ignite)17 Condition (java.util.concurrent.locks.Condition)15 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)13 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)13 HashSet (java.util.HashSet)13 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)12 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)11