More corner cases for activation policy. (FELIX-749)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@783813 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 32b3e68..5a68525 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1411,7 +1411,8 @@
// Acquire bundle lock.
try
{
- acquireBundleLock(bundle, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE);
+ acquireBundleLock(bundle,
+ Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE);
}
catch (IllegalStateException ex)
{
@@ -1428,6 +1429,8 @@
}
// Record whether the bundle is using its declared activation policy.
+ boolean wasDeferred = bundle.isDeclaredActivationPolicyUsed()
+ && (bundle.getCurrentModule().getDeclaredActivationPolicy() == IModule.LAZY_ACTIVATION);
bundle.setDeclaredActivationPolicyUsed(
(options & Bundle.START_ACTIVATION_POLICY) != 0);
@@ -1483,29 +1486,34 @@
case Bundle.UNINSTALLED:
throw new IllegalStateException("Cannot start an uninstalled bundle.");
case Bundle.STARTING:
+ if (!wasDeferred)
+ {
+ throw new BundleException(
+ "Bundle " + bundle
+ + " cannot be started, since it is starting.");
+ }
+ break;
case Bundle.STOPPING:
throw new BundleException(
"Bundle " + bundle
- + " cannot be started, since it is either starting or stopping.");
+ + " cannot be started, since it is stopping.");
case Bundle.ACTIVE:
return;
case Bundle.INSTALLED:
resolveBundle(bundle);
// No break.
case Bundle.RESOLVED:
+ // Set the bundle's context.
+ bundle.setBundleContext(new BundleContextImpl(m_logger, this, bundle));
+ // At this point, no matter if the bundle's activation policy is
+ // eager or deferred, we need to set the bundle's state to STARTING.
+ // We don't fire a BundleEvent here for this state change, since
+ // STARTING events are only fired if we are invoking the activator,
+ // which we may not do if activation is deferred.
+ setBundleStateAndNotify(bundle, Bundle.STARTING);
break;
}
- // Set the bundle's context.
- bundle.setBundleContext(new BundleContextImpl(m_logger, this, bundle));
-
- // At this point, no matter if the bundle's activation policy is
- // eager or deferred, we need to set the bundle's state to STARTING.
- // We don't fire a BundleEvent here for this state change, since
- // STARTING events are only fired if we are invoking the activator,
- // which we may not do if activation is deferred.
- setBundleStateAndNotify(bundle, Bundle.STARTING);
-
// If the bundle's activation policy is eager or activation has already
// been triggered, then activate the bundle immediately.
if (!bundle.isDeclaredActivationPolicyUsed()
@@ -1550,20 +1558,21 @@
// Acquire bundle lock.
try
{
- acquireBundleLock(bundle, Bundle.STARTING);
+ acquireBundleLock(bundle, Bundle.STARTING | Bundle.ACTIVE);
}
catch (IllegalStateException ex)
{
throw new IllegalStateException(
"Activation only occurs for bundles in STARTING state.");
}
+
try
{
- // Check to see if the bundle's start level is greater than the
- // the framework's active start level.
- if (bundle.getStartLevel(getInitialBundleStartLevel()) > getActiveStartLevel())
+ // If the bundle is already active or its start level is not met,
+ // simply return.
+ if ((bundle.getState() == Bundle.ACTIVE) ||
+ (bundle.getStartLevel(getInitialBundleStartLevel()) > getActiveStartLevel()))
{
- // Ignore persistent starts.
return;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java b/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
index bf58d3c..25eb1c7 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
@@ -595,7 +595,6 @@
syncListeners = m_syncBundleListeners;
}
-System.out.println("+++ FIRING BUNDLE EVENT " + event.getType() + " FROM " + event.getBundle().getSymbolicName());
// Fire synchronous bundle listeners immediately on the calling thread.
fireEventImmediately(m_logger, Request.BUNDLE_EVENT, syncListeners, event);