Skip to content
Permalink
Browse files
FELIX-6512 : Support for synchronous registration of persistence mana…
…gers and configuration plugins

Signed-off-by: Raymond Augé <rotty3000@apache.org>
  • Loading branch information
rotty3000 committed Mar 23, 2022
1 parent b6ae88f commit 1540a3037ad535452d0648c9aadcdf0b51700529
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 188 deletions.
@@ -187,6 +187,8 @@ The Apache Felix implementation is configurable with Framework properties. Here
|--|--|--|--|
| `felix.cm.loglevel` | int | `2` | Logging level to use in the absence of an OSGi LogService. See the *Logging* section below. |
| `felix.cm.dir` | String | `BundleContext.getDataFile("config")` | Location of the Configuration Admin configuration files. See the *Configuration Files* section below. |
| `felix.cm.pm` | String | none | The name of the framework context property defining the persistence manager to be used. If this property is not set or empty, the built-in persistence manager (`name=file`) is used. If it is specified it refers to the `name` property of a persistence manager (`org.apache.felix.cm.PersistenceManager`) and that persistence manager needs to be registered. |
| `felix.cm.config.plugins` | String[] | none | The name of the framework context property defining the required configuration plugins. If this property is specified it refers to the `config.plugin.id` property of a configuration plugin (`org.osgi.service.cm.ConfigurationPlugin`) and that configuration plugin must be registered and available. |

### Logging

@@ -171,7 +171,7 @@ private ServiceFactory<PersistenceManager> registerFilePersistenceManager(final
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(Constants.SERVICE_RANKING, Integer.valueOf(Integer.MIN_VALUE));
props.put(PersistenceManager.PROPERTY_NAME, FilePersistenceManager.DEFAULT_PERSISTENCE_MANAGER_NAME);

final ServiceFactory<PersistenceManager> factory = new ServiceFactory<PersistenceManager>()

This file was deleted.

@@ -43,8 +43,6 @@
/** The configuration plugin tracker (optional) */
private final RequiredConfigurationPluginTracker configurationPluginTracker;

private final ActivatorWorkerQueue workerQueue;

private final ConfigurationAdminStarter starter;

public DependencyTracker(final BundleContext bundleContext,
@@ -54,28 +52,23 @@ public DependencyTracker(final BundleContext bundleContext,
{
this.starter = new ConfigurationAdminStarter(bundleContext);

final boolean useQueue = pmName != null || pluginNames != null;
if (useQueue) {
this.workerQueue = new ActivatorWorkerQueue();
} else {
this.workerQueue = null;
}
final boolean hasPlugins = pmName != null || pluginNames != null;
if (pluginNames != null) {
Log.logger.log(LogService.LOG_DEBUG, "Requiring configuration plugins {0}",
new Object[] { Arrays.toString(pluginNames) });
this.configurationPluginTracker = new RequiredConfigurationPluginTracker(bundleContext, workerQueue,
this.configurationPluginTracker = new RequiredConfigurationPluginTracker(bundleContext,
starter, pluginNames);
} else {
this.configurationPluginTracker = null;
if (useQueue) {
if (hasPlugins) {
starter.updatePluginsSet(true);
}
}

if ( pmName != null )
{
Log.logger.log(LogService.LOG_DEBUG, "Using persistence manager {0}", new Object[] {pmName});
this.persistenceManagerTracker = new PersistenceManagerTracker(bundleContext, workerQueue, starter, pmName);
this.persistenceManagerTracker = new PersistenceManagerTracker(bundleContext, starter, pmName);
}
else
{
@@ -93,7 +86,7 @@ public DependencyTracker(final BundleContext bundleContext,
}

final ExtPersistenceManager epm = PersistenceManagerTracker.createPersistenceManagerProxy(defaultPM);
if (useQueue) {
if (hasPlugins) {
starter.setPersistenceManager(epm);
} else {
this.starter.activate(epm);
@@ -106,9 +99,6 @@ public DependencyTracker(final BundleContext bundleContext,
*/
public void stop( )
{
if (this.workerQueue != null) {
this.workerQueue.stop();
}
this.starter.deactivate();
if ( this.persistenceManagerTracker != null )
{
@@ -61,13 +61,9 @@

private final Set<String> registeredPluginNames = new TreeSet<>();

private final ActivatorWorkerQueue workerQueue;

public RequiredConfigurationPluginTracker(final BundleContext bundleContext,
final ActivatorWorkerQueue workerQueue,
final ConfigurationAdminStarter starter,
final String[] pluginNames) throws BundleException, InvalidSyntaxException {
this.workerQueue = workerQueue;
this.starter = starter;
for (final String name : pluginNames) {
requiredNames.add(name);
@@ -114,17 +110,11 @@ public ConfigurationPlugin addingService(final ServiceReference<ConfigurationPlu
}
}
final boolean activateCA = activate;
this.workerQueue.enqueue(new Runnable() {

@Override
public void run() {
if (activateCA) {
starter.updatePluginsSet(true);
}
registeredPluginNames.add(name);
updateRegisteredConfigurationPlugins();
}
});
if (activateCA) {
starter.updatePluginsSet(true);
}
registeredPluginNames.add(name);
updateRegisteredConfigurationPlugins();
}
return plugin;
}
@@ -147,17 +137,11 @@ public void removedService(final ServiceReference<ConfigurationPlugin> reference
bundleContext.ungetService(reference);
}
if (deactivate) {
this.workerQueue.enqueue(new Runnable() {

@Override
public void run() {
if (!hasRequiredPlugins()) {
starter.updatePluginsSet(false);
}
registeredPluginNames.remove(name);
updateRegisteredConfigurationPlugins();
}
});
if (!hasRequiredPlugins()) {
starter.updatePluginsSet(false);
}
registeredPluginNames.remove(name);
updateRegisteredConfigurationPlugins();
}
}
}
@@ -25,7 +25,6 @@

import org.apache.felix.cm.NotCachablePersistenceManager;
import org.apache.felix.cm.PersistenceManager;
import org.apache.felix.cm.impl.ActivatorWorkerQueue;
import org.apache.felix.cm.impl.ConfigurationAdminStarter;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -51,17 +50,13 @@

private final BundleContext bundleContext;

private final ActivatorWorkerQueue workerQueue;

private final ConfigurationAdminStarter starter;

public PersistenceManagerTracker(final BundleContext bundleContext,
final ActivatorWorkerQueue workerQueue,
final ConfigurationAdminStarter starter,
final String pmName)
throws BundleException, InvalidSyntaxException
{
this.workerQueue = workerQueue;
this.starter = starter;
this.bundleContext = bundleContext;
this.persistenceManagerTracker = new ServiceTracker<>(bundleContext,
@@ -108,22 +103,14 @@ public Holder addingService(final ServiceReference<PersistenceManager> reference
Collections.sort(holders);
if ( holders.get(0) == holder )
{
this.workerQueue.enqueue(new Runnable()
if ( oldHolder != null )
{

@Override
public void run()
{
if ( oldHolder != null )
{
starter.unsetPersistenceManager();
}
if (!holder.isActivated()) {
starter.setPersistenceManager(holder.getPersistenceManager());
holder.activate();
}
}
});
starter.unsetPersistenceManager();
}
if (!holder.isActivated()) {
starter.setPersistenceManager(holder.getPersistenceManager());
holder.activate();
}
}
}
return holder;
@@ -145,19 +132,11 @@ public void modifiedService(final ServiceReference<PersistenceManager> reference
Collections.sort(this.holders);
if ( holders.get(0) == holder && oldHolder != null && oldHolder.compareTo(holder) != 0 )
{
this.workerQueue.enqueue(new Runnable()
{

@Override
public void run()
{
starter.unsetPersistenceManager();
if (!holder.isActivated()) {
starter.setPersistenceManager(holder.getPersistenceManager());
holder.activate();
}
}
});
starter.unsetPersistenceManager();
if (!holder.isActivated()) {
starter.setPersistenceManager(holder.getPersistenceManager());
holder.activate();
}
}
}

@@ -174,23 +153,15 @@ public void removedService(final ServiceReference<PersistenceManager> reference,
this.holders.remove(holder);
if ( deactivate )
{
this.workerQueue.enqueue(new Runnable()
starter.unsetPersistenceManager();
if ( !holders.isEmpty() )
{

@Override
public void run()
{
starter.unsetPersistenceManager();
if ( !holders.isEmpty() )
{
Holder h = holders.get(0);
if (!h.isActivated()) {
starter.setPersistenceManager(h.getPersistenceManager());
h.activate();
}
}
Holder h = holders.get(0);
if (!h.isActivated()) {
starter.setPersistenceManager(h.getPersistenceManager());
h.activate();
}
});
}
}
}
}
@@ -80,15 +80,8 @@ public void updateRegisteredConfigurationPlugins(final String propValue) {
};
starter.setPersistenceManager(epm);

final ActivatorWorkerQueue queue = new ActivatorWorkerQueue() {

@Override
public void enqueue(Runnable r) {
r.run();
}
};
final RequiredConfigurationPluginTracker tracker = new RequiredConfigurationPluginTracker(bundleContext,
queue, starter, pluginNames);
starter, pluginNames);

final ServiceReference<ConfigurationPlugin> r1 = Mockito.mock(ServiceReference.class);
Mockito.when(r1.getProperty(RequiredConfigurationPluginTracker.PROPERTY_NAME)).thenReturn("p1");

0 comments on commit 1540a30

Please sign in to comment.