Search in sources :

Example 1 with NotCachablePersistenceManager

use of org.apache.felix.cm.NotCachablePersistenceManager in project felix by apache.

the class CachingPersistenceManagerProxy method getDictionaries.

public Enumeration getDictionaries(SimpleFilter filter) throws IOException {
    Lock lock = globalLock.readLock();
    try {
        lock.lock();
        boolean fullyLoaded = this.fullyLoaded;
        if (pm instanceof NotCachablePersistenceManager) {
            fullyLoaded = false;
        }
        // manager and cache all dictionaries whose service.pid is set
        if (!fullyLoaded) {
            lock.unlock();
            lock = globalLock.writeLock();
            lock.lock();
            if (!fullyLoaded) {
                Enumeration fromPm = pm.getDictionaries();
                while (fromPm.hasMoreElements()) {
                    Dictionary next = (Dictionary) fromPm.nextElement();
                    this.cache(next);
                }
                this.fullyLoaded = true;
            }
        }
        // Deep copy the configuration to avoid any threading issue
        Vector<Dictionary> configs = new Vector<Dictionary>();
        for (Dictionary d : cache.values()) {
            if (d.get(Constants.SERVICE_PID) != null && (filter == null || filter.matches(d))) {
                configs.add(copy(d));
            }
        }
        return configs.elements();
    } finally {
        lock.unlock();
    }
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) NotCachablePersistenceManager(org.apache.felix.cm.NotCachablePersistenceManager) Vector(java.util.Vector) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Aggregations

Dictionary (java.util.Dictionary)1 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 NotCachablePersistenceManager (org.apache.felix.cm.NotCachablePersistenceManager)1