Search in sources :

Example 11 with PersistenceManager

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

the class PersistenceManagerTracker method addingService.

@Override
public Holder addingService(final ServiceReference<PersistenceManager> reference) {
    final PersistenceManager pm = this.bundleContext.getService(reference);
    if (pm != null) {
        final ExtPersistenceManager extPM = createPersistenceManagerProxy(pm);
        final Holder holder = new Holder(reference, extPM);
        synchronized (this.holders) {
            final Holder oldHolder = this.holders.isEmpty() ? null : this.holders.get(0);
            this.holders.add(holder);
            Collections.sort(holders);
            if (holders.get(0) == holder) {
                this.workerQueue.enqueue(new Runnable() {

                    @Override
                    public void run() {
                        if (oldHolder != null) {
                            deactivate();
                        }
                        activate(holder.getPersistenceManager());
                    }
                });
            }
        }
        return holder;
    }
    return null;
}
Also used : NotCachablePersistenceManager(org.apache.felix.cm.NotCachablePersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager)

Example 12 with PersistenceManager

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

the class ConfigurationManagerTest method test_listConfigurations_cached.

@Test
public void test_listConfigurations_cached() throws Exception {
    String pid = "testDefaultPersistenceManager";
    PersistenceManager pm = new MockPersistenceManager();
    Dictionary<String, Object> dictionary = new Hashtable<>();
    dictionary.put("property1", "value1");
    dictionary.put(Constants.SERVICE_PID, pid);
    pm.store(pid, dictionary);
    ConfigurationManager configMgr = new ConfigurationManager(new CachingPersistenceManagerProxy(pm), null);
    ConfigurationImpl[] conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
    assertEquals(1, conf.length);
    assertEquals(2, conf[0].getProperties(true).size());
    dictionary = new Hashtable<>();
    dictionary.put("property1", "value2");
    pid = "testDefaultPersistenceManager";
    dictionary.put(Constants.SERVICE_PID, pid);
    pm.store(pid, dictionary);
    conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
    assertEquals(1, conf.length);
    assertEquals(2, conf[0].getProperties(true).size());
    // verify that the property in the configurations cache was used
    assertEquals("value1", conf[0].getProperties(true).get("property1"));
}
Also used : PersistenceManager(org.apache.felix.cm.PersistenceManager) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) Hashtable(java.util.Hashtable) CachingPersistenceManagerProxy(org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) Test(org.junit.Test)

Example 13 with PersistenceManager

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

the class CachingPersistenceManagerProxyTest method createAndPopulatePersistenceManager.

private PersistenceManager createAndPopulatePersistenceManager() throws IOException {
    final PersistenceManager pm = new MockPersistenceManager();
    pm.store(PID_A, createConfiguration(PID_A, null));
    pm.store(PID_B, createConfiguration(PID_B, null));
    pm.store(PID_C, createConfiguration(PID_C, null));
    pm.store(FA_PID_A, createConfiguration(FA_PID_A, FACTORY_PID_A));
    pm.store(FA_PID_B, createConfiguration(FA_PID_B, FACTORY_PID_A));
    pm.store(FA_PID_C, createConfiguration(FA_PID_C, FACTORY_PID_A));
    pm.store(FB_PID_A, createConfiguration(FB_PID_A, FACTORY_PID_B));
    pm.store(FB_PID_B, createConfiguration(FB_PID_B, FACTORY_PID_B));
    return pm;
}
Also used : MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager)

Example 14 with PersistenceManager

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

the class CachingPersistenceManagerProxyTest method test_caching_is_applied.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void test_caching_is_applied() throws Exception {
    String pid = "testDefaultPersistenceManager";
    SimpleFilter filter = SimpleFilter.parse("(&(service.pid=" + pid + ")(property1=value1))");
    PersistenceManager pm = new MockPersistenceManager();
    CachingPersistenceManagerProxy cpm = new CachingPersistenceManagerProxy(pm);
    Dictionary dictionary = new Hashtable();
    dictionary.put("property1", "value1");
    dictionary.put(Constants.SERVICE_PID, pid);
    pm.store(pid, dictionary);
    Collection<Dictionary> list = cpm.getDictionaries(filter);
    assertEquals(1, list.size());
    dictionary = new Hashtable();
    dictionary.put("property1", "value2");
    pid = "testDefaultPersistenceManager";
    dictionary.put(Constants.SERVICE_PID, pid);
    pm.store(pid, dictionary);
    list = cpm.getDictionaries(filter);
    assertEquals(1, list.size());
}
Also used : Dictionary(java.util.Dictionary) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) Hashtable(java.util.Hashtable) SimpleFilter(org.apache.felix.cm.impl.SimpleFilter) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) Test(org.junit.Test)

Example 15 with PersistenceManager

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

the class PersistenceManagerProxyTest method test_caching_is_avoided.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_caching_is_avoided() throws Exception {
    String pid = "testDefaultPersistenceManager";
    SimpleFilter filter = SimpleFilter.parse("(&(service.pid=" + pid + ")(property1=value1))");
    PersistenceManager pm = new MockNotCachablePersistenceManager();
    PersistenceManagerProxy cpm = new PersistenceManagerProxy(pm);
    Dictionary dictionary = new Hashtable();
    dictionary.put("property1", "value1");
    dictionary.put(Constants.SERVICE_PID, pid);
    pm.store(pid, dictionary);
    Collection<Dictionary> list = cpm.getDictionaries(filter);
    assertEquals(1, list.size());
    dictionary = new Hashtable();
    dictionary.put("property1", "value2");
    pid = "testDefaultPersistenceManager";
    dictionary.put(Constants.SERVICE_PID, pid);
    pm.store(pid, dictionary);
    list = cpm.getDictionaries(filter);
    assertEquals(0, list.size());
}
Also used : Dictionary(java.util.Dictionary) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) Hashtable(java.util.Hashtable) SimpleFilter(org.apache.felix.cm.impl.SimpleFilter) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager)

Aggregations

PersistenceManager (org.apache.felix.cm.PersistenceManager)15 Hashtable (java.util.Hashtable)8 MockPersistenceManager (org.apache.felix.cm.MockPersistenceManager)7 MockNotCachablePersistenceManager (org.apache.felix.cm.MockNotCachablePersistenceManager)6 Dictionary (java.util.Dictionary)5 List (java.util.List)3 FilePersistenceManager (org.apache.felix.cm.file.FilePersistenceManager)3 CachingPersistenceManagerProxy (org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 Enumeration (java.util.Enumeration)2 SimpleFilter (org.apache.felix.cm.impl.SimpleFilter)2 FabricException (io.fabric8.api.FabricException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 MockBundleContext (org.apache.felix.cm.MockBundleContext)1 NotCachablePersistenceManager (org.apache.felix.cm.NotCachablePersistenceManager)1 EncryptingPersistenceManager (org.apache.felix.cm.file.EncryptingPersistenceManager)1 PersistenceManagerProxy (org.apache.felix.cm.impl.persistence.PersistenceManagerProxy)1