Added bundle STARTING and STOPPING events (FELIX-34).


git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@425319 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
index 20d6a5e..47b4355 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -1186,14 +1186,17 @@
                 return;
             case Bundle.INSTALLED:
                 _resolveBundle(bundle);
+                // No break.
             case Bundle.RESOLVED:
                 info.setState(Bundle.STARTING);
+                fireBundleEvent(BundleEvent.STARTING, bundle);
+                break;
         }
 
         try
         {
             // Set the bundle's activator.
-            bundle.getInfo().setActivator(createBundleActivator(bundle.getInfo()));
+            info.setActivator(createBundleActivator(bundle.getInfo()));
 
             // Activate the bundle if it has an activator.
             if (bundle.getInfo().getActivator() != null)
@@ -1215,11 +1218,9 @@
                 }
             }
 
-            info.setState(Bundle.ACTIVE);
-
             // TODO: CONCURRENCY - Reconsider firing event outside of the
             // bundle lock.
-
+            info.setState(Bundle.ACTIVE);
             fireBundleEvent(BundleEvent.STARTED, bundle);
         }
         catch (Throwable th)
@@ -1510,8 +1511,10 @@
             case Bundle.ACTIVE:
                 // Set bundle state..
                 info.setState(Bundle.STOPPING);
+                fireBundleEvent(BundleEvent.STOPPING, bundle);
+                break;
         }
-            
+
         try
         {
             if (bundle.getInfo().getActivator() != null)
diff --git a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
index f853a9d..b789301 100644
--- a/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
+++ b/org.apache.felix.framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
@@ -477,8 +477,14 @@
         // Fire synchronous bundle listeners immediately on the calling thread.
         fireEventImmediately(m_logger, Request.BUNDLE_EVENT, syncListeners, event);
 
-        // Fire asynchronous bundle listeners on a separate thread.
-        fireEventAsynchronously(m_logger, Request.BUNDLE_EVENT, listeners, event);
+        // The spec says that asynchronous bundle listeners do not get events
+        // of types STARTING or STOPPING.
+        if ((event.getType() != BundleEvent.STARTING) &&
+            (event.getType() != BundleEvent.STOPPING))
+        {
+            // Fire asynchronous bundle listeners on a separate thread.
+            fireEventAsynchronously(m_logger, Request.BUNDLE_EVENT, listeners, event);
+        }
     }
 
     public void fireServiceEvent(ServiceEvent event)
@@ -782,4 +788,4 @@
         public Object[] m_listeners = null;
         public EventObject m_event = null;
     }
-}
\ No newline at end of file
+}