This is an automated email from the ASF dual-hosted git repository.
rotty3000 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 1540a30 FELIX-6512 : Support for synchronous registration of
persistence managers and configuration plugins
1540a30 is described below
commit 1540a3037ad535452d0648c9aadcdf0b51700529
Author: Raymond Augé <[email protected]>
AuthorDate: Mon Mar 21 16:02:45 2022 -0400
FELIX-6512 : Support for synchronous registration of persistence managers
and configuration plugins
Signed-off-by: Raymond Augé <[email protected]>
---
configadmin/README.md | 2 +
.../java/org/apache/felix/cm/impl/Activator.java | 2 +-
.../apache/felix/cm/impl/ActivatorWorkerQueue.java | 90 ----------------------
.../apache/felix/cm/impl/DependencyTracker.java | 20 ++---
.../impl/RequiredConfigurationPluginTracker.java | 36 +++------
.../persistence/PersistenceManagerTracker.java | 67 +++++-----------
.../RequiredConfigurationPluginTrackerTest.java | 9 +--
7 files changed, 38 insertions(+), 188 deletions(-)
diff --git a/configadmin/README.md b/configadmin/README.md
index 43e63cb..14cdee2 100644
--- a/configadmin/README.md
+++ b/configadmin/README.md
@@ -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
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
b/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
index 86138e5..ed6d2bc 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/Activator.java
@@ -171,7 +171,7 @@ public class Activator implements BundleActivator
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>()
diff --git
a/configadmin/src/main/java/org/apache/felix/cm/impl/ActivatorWorkerQueue.java
b/configadmin/src/main/java/org/apache/felix/cm/impl/ActivatorWorkerQueue.java
deleted file mode 100755
index 11892a4..0000000
---
a/configadmin/src/main/java/org/apache/felix/cm/impl/ActivatorWorkerQueue.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.cm.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-import org.osgi.service.log.LogService;
-
-/**
- * The activator worker queue is used to asynchronously activate the
- * configuration admin if it's activation depends on the existence of other
- * services like a configured persistence manager or required configuration
- * plugins.
- */
-public class ActivatorWorkerQueue implements Runnable {
-
- private final ThreadFactory threadFactory;
-
- private final List<Runnable> tasks = new ArrayList<>();
-
- private volatile Thread backgroundThread;
-
- private volatile boolean stopped = false;
-
- public ActivatorWorkerQueue() {
- this.threadFactory = Executors.defaultThreadFactory();
- }
-
- public void stop() {
- synchronized ( this.tasks ) {
- this.stopped = true;
- }
- }
-
- public void enqueue(final Runnable r) {
- synchronized ( this.tasks ) {
- if ( !this.stopped ) {
- this.tasks.add(r);
- if ( this.backgroundThread == null ) {
- this.backgroundThread = this.threadFactory.newThread(this);
- this.backgroundThread.setDaemon(true);
- this.backgroundThread.setName("Apache Felix Configuration
Admin Activator Thread");
- this.backgroundThread.start();
- }
- }
- }
- }
-
- @Override
- public void run() {
- Runnable r;
- do {
- r = null;
- synchronized ( this.tasks ) {
- if ( !this.stopped && !this.tasks.isEmpty() ) {
- r = this.tasks.remove(0);
- } else {
- this.backgroundThread = null;
- }
- }
- if ( r != null ) {
- try {
- r.run();
- } catch ( final Throwable t) {
- // just to be sure our loop never dies
- Log.logger.log(LogService.LOG_ERROR, "Error processing
task", t);
- }
- }
- } while ( r != null );
- }
-}
diff --git
a/configadmin/src/main/java/org/apache/felix/cm/impl/DependencyTracker.java
b/configadmin/src/main/java/org/apache/felix/cm/impl/DependencyTracker.java
index 5c9976c..6f626d9 100755
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/DependencyTracker.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/DependencyTracker.java
@@ -43,8 +43,6 @@ public class DependencyTracker
/** The configuration plugin tracker (optional) */
private final RequiredConfigurationPluginTracker
configurationPluginTracker;
- private final ActivatorWorkerQueue workerQueue;
-
private final ConfigurationAdminStarter starter;
public DependencyTracker(final BundleContext bundleContext,
@@ -54,20 +52,15 @@ public class DependencyTracker
{
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);
}
}
@@ -75,7 +68,7 @@ public class DependencyTracker
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 class DependencyTracker
}
final ExtPersistenceManager epm =
PersistenceManagerTracker.createPersistenceManagerProxy(defaultPM);
- if (useQueue) {
+ if (hasPlugins) {
starter.setPersistenceManager(epm);
} else {
this.starter.activate(epm);
@@ -106,9 +99,6 @@ public class DependencyTracker
*/
public void stop( )
{
- if (this.workerQueue != null) {
- this.workerQueue.stop();
- }
this.starter.deactivate();
if ( this.persistenceManagerTracker != null )
{
diff --git
a/configadmin/src/main/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTracker.java
b/configadmin/src/main/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTracker.java
index 206f0fa..4d2f4b8 100755
---
a/configadmin/src/main/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTracker.java
+++
b/configadmin/src/main/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTracker.java
@@ -61,13 +61,9 @@ public class RequiredConfigurationPluginTracker
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 class RequiredConfigurationPluginTracker
}
}
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 class RequiredConfigurationPluginTracker
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();
}
}
}
diff --git
a/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java
b/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java
index d6628ea..9750176 100644
---
a/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java
+++
b/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java
@@ -25,7 +25,6 @@ import java.util.List;
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 @@ public class PersistenceManagerTracker
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 class PersistenceManagerTracker
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 class PersistenceManagerTracker
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 class PersistenceManagerTracker
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();
}
- });
+ }
}
}
}
diff --git
a/configadmin/src/test/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTrackerTest.java
b/configadmin/src/test/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTrackerTest.java
index 5907e3f..d5034d8 100755
---
a/configadmin/src/test/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTrackerTest.java
+++
b/configadmin/src/test/java/org/apache/felix/cm/impl/RequiredConfigurationPluginTrackerTest.java
@@ -80,15 +80,8 @@ public class RequiredConfigurationPluginTrackerTest {
};
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");