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;
}
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"));
}
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;
}
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());
}
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());
}
Aggregations