use of org.apache.felix.cm.PersistenceManager in project felix by apache.
the class ConfigurationManager method getPersistenceManagers.
// ---------- internal -----------------------------------------------------
private CachingPersistenceManagerProxy[] getPersistenceManagers() {
int currentPmtCount = persistenceManagerTracker.getTrackingCount();
if (persistenceManagers == null || currentPmtCount > pmtCount) {
List pmList = new ArrayList();
CachingPersistenceManagerProxy[] pm;
ServiceReference<?>[] refs = persistenceManagerTracker.getServiceReferences();
if (refs == null || refs.length == 0) {
pm = new CachingPersistenceManagerProxy[0];
} else {
// sort the references according to the cmRanking property
if (refs.length > 1) {
Arrays.sort(refs, RankingComparator.SRV_RANKING);
}
// create the service array from the sorted set of referenecs
for (int i = 0; i < refs.length; i++) {
Object service = persistenceManagerTracker.getService(refs[i]);
if (service != null) {
CachingPersistenceManagerProxy proxy = getProxyForPersistenceManager((PersistenceManager) service);
if (proxy == null) {
proxy = new CachingPersistenceManagerProxy((PersistenceManager) service);
}
pmList.add(proxy);
}
}
pm = (CachingPersistenceManagerProxy[]) pmList.toArray(new CachingPersistenceManagerProxy[pmList.size()]);
}
pmtCount = currentPmtCount;
persistenceManagers = pm;
}
return persistenceManagers;
}
use of org.apache.felix.cm.PersistenceManager in project felix by apache.
the class CachingPersistenceManagerProxyTest 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();
CachingPersistenceManagerProxy cpm = new CachingPersistenceManagerProxy(pm);
Dictionary dictionary = new Hashtable();
dictionary.put("property1", "value1");
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
Enumeration dictionaries = cpm.getDictionaries(filter);
List list = Collections.list(dictionaries);
assertEquals(1, list.size());
dictionary = new Hashtable();
dictionary.put("property1", "value2");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
dictionaries = cpm.getDictionaries(filter);
list = Collections.list(dictionaries);
assertEquals(1, list.size());
}
use of org.apache.felix.cm.PersistenceManager in project felix by apache.
the class CachingPersistenceManagerProxyTest method test_caching_is_applied.
@SuppressWarnings({ "rawtypes", "unchecked" })
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);
Enumeration dictionaries = cpm.getDictionaries(filter);
List list = Collections.list(dictionaries);
assertEquals(1, list.size());
dictionary = new Hashtable();
dictionary.put("property1", "value2");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
dictionaries = cpm.getDictionaries(filter);
list = Collections.list(dictionaries);
assertEquals(1, list.size());
}
use of org.apache.felix.cm.PersistenceManager in project felix by apache.
the class Activator method start.
@Override
public void start(final BundleContext bundleContext) throws BundleException {
// setup log
Log.logger.start(bundleContext);
// register default file persistence manager
final PersistenceManager defaultPM = this.registerFilePersistenceManager(bundleContext);
if (defaultPM == null) {
throw new BundleException("Unable to register default persistence manager.");
}
String configuredPM = bundleContext.getProperty(CM_CONFIG_PM);
if (configuredPM != null && configuredPM.isEmpty()) {
configuredPM = null;
}
try {
this.tracker = new PersistenceManagerTracker(bundleContext, defaultPM, configuredPM);
} catch (InvalidSyntaxException iae) {
Log.logger.log(LogService.LOG_ERROR, "Cannot create the persistence manager tracker", iae);
throw new BundleException(iae.getMessage(), iae);
}
}
use of org.apache.felix.cm.PersistenceManager in project felix by apache.
the class Activator method registerFilePersistenceManager.
private PersistenceManager registerFilePersistenceManager(final BundleContext bundleContext) {
try {
final FilePersistenceManager fpm = new FilePersistenceManager(bundleContext, bundleContext.getProperty(CM_CONFIG_DIR));
final Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.SERVICE_DESCRIPTION, "Platform Filesystem Persistence Manager");
props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
props.put(Constants.SERVICE_RANKING, new Integer(Integer.MIN_VALUE));
props.put(PersistenceManager.PROPERTY_NAME, FilePersistenceManager.DEFAULT_PERSISTENCE_MANAGER_NAME);
filepmRegistration = bundleContext.registerService(PersistenceManager.class, fpm, props);
return fpm;
} catch (final IllegalArgumentException iae) {
Log.logger.log(LogService.LOG_ERROR, "Cannot create the FilePersistenceManager", iae);
}
return null;
}
Aggregations