You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2014/09/20 12:22:40 UTC
svn commit: r1626412 - in /felix/sandbox/pderop/dependencymanager-prototype:
org.apache.felix.dependencymanager.samples/
org.apache.felix.dependencymanager/
org.apache.felix.dependencymanager/src/org/apache/felix/dm/
org.apache.felix.dependencymanager/...
Author: pderop
Date: Sat Sep 20 10:22:39 2014
New Revision: 1626412
URL: http://svn.apache.org/r1626412
Log:
Improved the way parallel components are configured: now the "org.apache.felix.dependencymanager.parallel" OSGi system property can be set to
"*" (meaning all components will be handled in parallel), or to a list of component classname prefixes, possibly starting with "!".
This allows to enable parallelism for only a subset of components, or for all components, excepts for some given components ...
See design.txt file for for more informations.
Modified:
felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd
felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/design.txt
felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java
felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/Activator.java
felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentScheduler.java
Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd?rev=1626412&r1=1626411&r2=1626412&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager.samples/bnd.bnd Sat Sep 20 10:22:39 2014
@@ -24,7 +24,7 @@ Private-Package: \
org.apache.felix.dependencymanager.samples.hello
-runproperties: \
org.apache.felix.log.maxSize=100000,\
- org.apache.felix.dependencymanager.parallel=true,\
+ org.apache.felix.dependencymanager.parallel=!org.apache.felix.dependencymanager.samples.hello, *,\
org.apache.felix.dependencymanager.runtime.log=debug
-plugin: org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin;log=debug;\
path:=${workspace}/org.apache.felix.dependencymanager.annotation/generated/org.apache.felix.dependencymanager.annotation.jar
Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/design.txt
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/design.txt?rev=1626412&r1=1626411&r2=1626412&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/design.txt (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/design.txt Sat Sep 20 10:22:39 2014
@@ -22,11 +22,34 @@ This prototype demonstrates the new conc
* Added support for concurrent mode: To allow components to be handled in parallel, you can now
register in the OSGi service registry a threadpool (java.util.concurrent.Executor) service with
a "target=org.apache.felix.dependencymanager" service property, and you also have to set the
- "org.apache.felix.dependencymanager.parallel=true" system property. This will allow to handle all
- component dependencies and all component lifecycle callbacks concurrently. Notice that component
- events are still handled serially. The only difference is that multiple components can be handled
- in parallel. See the
+ "org.apache.felix.dependencymanager.parallel" system property to either "*", or to a list of
+ component classnames prefixes. This will allow to handle all component dependencies and all
+ component lifecycle callbacks concurrently. Notice that component events are still handled
+ serially. The only difference is that multiple components can be handled in parallel. See the
org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/DispatchExecutor.java for for
informations.
+For example:
+
+- if you want to enable parallelism for all components, just set the system property:
+
+org.apache.felix.dependencymanager.parallel=*
+
+- if you want to enable parallelism for some components whose class names is starting with foo.bar
+ and foo.zoo:
+
+org.apache.felix.dependencymanager.parallel=foo.bar, foo.zoo
+
+- if yo uwant to enable parallelism for all components, except for components whose class names
+ start with "foo.notparallel":
+
+org.apache.felix.dependencymanager.parallel=!foo.parallel, *
+
+
+
+
+
+
+
+
Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java?rev=1626412&r1=1626411&r2=1626412&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/DependencyManager.java Sat Sep 20 10:22:39 2014
@@ -81,7 +81,6 @@ public class DependencyManager {
private final Logger m_logger;
private final List<Component> m_components = new CopyOnWriteArrayList<>();
private volatile Executor m_threadPool;
- private volatile boolean m_setThreadPoolMethodCalled = false;
// service registry cache
private static ServiceRegistryCache m_serviceRegistryCache;
@@ -141,18 +140,9 @@ public class DependencyManager {
/**
* Sets a threadpool to this dependency manager. All added/removed components will then be handled
* in parallel, using the provided threadpool.
- *
- * Notice that you can also enable parallelism by registering an Executor in the OSGi service registry with
- * a "target=org.apache.felix.dependencymanager" system property. In this case, you also need to set
- * the "org.apache.felix.dependencymanager.parallel=true" system property. When doing so:
- * <p><ul>
- * <li> All Dependency Manager
- * <li>Activators will then be handled concurrently, except if they explicitly invoke setThreadPool(null)
- * </ul>
*/
public DependencyManager setThreadPool(Executor threadPool) {
m_threadPool = threadPool;
- m_setThreadPoolMethodCalled = true;
return this;
}
@@ -198,7 +188,7 @@ public class DependencyManager {
*/
public void add(Component c) {
m_components.add(c);
- if (useComponentScheduler()) {
+ if (useComponentSchedulerFor(c)) {
ComponentScheduler.instance().add(c);
} else {
if (m_threadPool != null) {
@@ -215,7 +205,7 @@ public class DependencyManager {
* @param service the service to remove
*/
public void remove(Component c) {
- if (useComponentScheduler()) {
+ if (useComponentSchedulerFor(c)) {
ComponentScheduler.instance().remove(c);
} else {
((ComponentContext) c).stop();
@@ -713,21 +703,42 @@ public class DependencyManager {
}
/**
- * Determine if the component scheduler should be used. The scheduler is used when the {@link #PARALLEL} system
- * property is set to "true" *AND* when the {@link #setThreadPool(Executor)} method has never been invoked.
+ * Determine if the component scheduler should be used for a given component. The scheduler is used if all the
+ * following conditions are true:
+ * - The user has not set a threadpool using {@link #setThreadPool(Executor)}.
+ * - the {@link #PARALLEL} system property is set to a comma separated list of prefix of component classnames
+ * which have to be activated using the threadpool. Notice that prefixes can be negated using "!".
*
* When used, the scheduler will bufferize all activated DM components until a threadpool with a
- * {@link #THREADPOOL} service property is registered in the OSGi registry. And at the point where the threadpool
- * comes in, then all bufferized components will be activated using that threadpool.
+ * {@link #THREADPOOL} service property is registered in the OSGi registry. And at the point where the
+ * threadpool comes in, then all bufferized components will be activated using that threadpool.
* This simple mechanism allows to avoid to use a start level service in order to wait for the threadpool before
* activating any DM components.
*
- * Notice that if the {@link #PARALLEL} system property is configured, you can call {@link #setThreadPool(Executor)}
- * with a null parameter: This will ensure that the component won't be handled in parallel, even if a threadpool is
- * registered in the service registry.
* @return true if the component scheduler should be used, false if not.
*/
- private boolean useComponentScheduler() {
- return ! m_setThreadPoolMethodCalled && "true".equalsIgnoreCase(m_context.getProperty(DependencyManager.PARALLEL));
+ private boolean useComponentSchedulerFor(Component c) {
+ if (m_threadPool != null) {
+ return false;
+ }
+
+ String parallel = m_context.getProperty(DependencyManager.PARALLEL);
+ if (parallel != null) {
+ for (String prefix : parallel.trim().split(",")) {
+ boolean not = prefix.startsWith("!");
+ if (not) {
+ prefix = prefix.substring(1);
+ }
+ if ("*".equals(prefix)) {
+ return !not;
+ }
+
+ if (c.getComponentDeclaration().getClassName().startsWith(prefix)) {
+ return !not;
+ }
+ }
+ }
+
+ return false;
}
}
Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/Activator.java?rev=1626412&r1=1626411&r2=1626412&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/Activator.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/Activator.java Sat Sep 20 10:22:39 2014
@@ -36,7 +36,7 @@ import org.osgi.framework.BundleContext;
public class Activator extends DependencyActivatorBase {
@Override
public void init(BundleContext ctx, DependencyManager mgr) throws Exception {
- boolean parallelModeEnabled = Boolean.valueOf(ctx.getProperty(DependencyManager.PARALLEL));
+ boolean parallelModeEnabled = ctx.getProperty(DependencyManager.PARALLEL) != null;
if (parallelModeEnabled) {
mgr.add(createComponent()
Modified: felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentScheduler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentScheduler.java?rev=1626412&r1=1626411&r2=1626412&view=diff
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentScheduler.java (original)
+++ felix/sandbox/pderop/dependencymanager-prototype/org.apache.felix.dependencymanager/src/org/apache/felix/dm/impl/ComponentScheduler.java Sat Sep 20 10:22:39 2014
@@ -32,6 +32,14 @@ import org.apache.felix.dm.context.Compo
* When a DependencyManager is not explicitly configured with a threadpool, and when parallel mode is enabled,
* then added components are delegated to this class, which will cache all added components until one threadpool
* is registered in the OSGi service registry.
+ *
+ * Parallel mode can be enabled by default by doing this:
+ *
+ * - register a threadpool (java.util.concurrent.Executor) into the OSGi service registry with the
+ * "target=org.apache.felix.dependencymanager" property.
+ *
+ * - and set the "org.apache.felix.dependencymanager.parallel" system property to either "*" or to some component classname
+ * prefixes. Note that you can specify several class name prefixes, and that some prefixes can be negated using "!".
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/