FELIX-2431 : EventAdmin service unregistered but not registered again on ConfigAdmin startup

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@989232 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/eventadmin/impl/DEPENDENCIES b/eventadmin/impl/DEPENDENCIES
new file mode 100644
index 0000000..be382e0
--- /dev/null
+++ b/eventadmin/impl/DEPENDENCIES
@@ -0,0 +1,36 @@
+Apache Felix Event Admin
+Copyright 2006-2010 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2009).
+Licensed under the Apache License 2.0. 
+
+This product includes software developed at
+Sun Microsystems, Inc.
+Copyright (c) 1994-2000.
+Licensed under a BSD license.
+
+
+II. Used Software
+
+This product uses software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2009).
+Licensed under the Apache License 2.0. 
+
+
+III. License Summary
+- Apache License 2.0
+- BSD License
diff --git a/eventadmin/impl/pom.xml b/eventadmin/impl/pom.xml
index d249294..5c9b67d1 100644
--- a/eventadmin/impl/pom.xml
+++ b/eventadmin/impl/pom.xml
@@ -49,6 +49,20 @@
         </dependency>
     </dependencies>
     <build>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+            </resource>
+            <resource>
+                <targetPath>META-INF</targetPath>
+                <directory>${basedir}</directory>
+                <includes>
+                    <include>LICENSE*</include>
+                    <include>NOTICE</include>
+                    <include>DEPENDENCIES</include>
+                </includes>
+            </resource>
+        </resources>
         <plugins>
             <plugin>
                 <groupId>org.apache.felix</groupId>
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
index 34ac45c..85d1e6c 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
@@ -156,11 +156,9 @@
         {
             Object service = new ManagedService()
             {
-                public synchronized void updated( Dictionary properties ) throws ConfigurationException
+                public void updated( Dictionary properties ) throws ConfigurationException
                 {
-                    configure( properties );
-                    stop();
-                    start();
+                    updateFromConfigAdmin(properties);
                 }
             };
             // add meta type provider if interfaces are available
@@ -185,6 +183,43 @@
         }
     }
 
+    void updateFromConfigAdmin(final Dictionary config)
+    {
+        // do this in the background as we don't want to stop
+        // the config admin
+        new Thread()
+        {
+
+            public void run()
+            {
+                final ThreadPool aSyncPool;
+                final ThreadPool syncPool;
+                synchronized ( Configuration.this )
+                {
+                    // we will shutdown the pools later
+                    // to make the downtime as small as possible
+                    aSyncPool = m_async_pool;
+                    m_async_pool = null;
+                    syncPool = m_sync_pool;
+                    m_sync_pool = null;
+                    Configuration.this.stop();
+                    Configuration.this.configure( config );
+                    Configuration.this.start();
+                }
+                if (aSyncPool != null )
+                {
+                    aSyncPool.close();
+                }
+                if ( syncPool != null )
+                {
+                    syncPool.close();
+                }
+            }
+
+        }.start();
+
+    }
+
     /**
      * Configures this instance.
      */
@@ -262,7 +297,7 @@
         }
     }
 
-    public synchronized void start()
+    private void start()
     {
         LogWrapper.getLogger().log(LogWrapper.LOG_DEBUG,
                 PROP_CACHE_SIZE + "=" + m_cacheSize);
@@ -320,9 +355,9 @@
     }
 
     /**
-     * Called to stop the event admin and restart it.
+     * Called to stop the event admin.
      */
-    public synchronized void stop()
+    private void stop()
     {
         // We need to unregister manually
         if ( m_registration != null )
@@ -335,7 +370,7 @@
             m_admin.stop();
             m_admin = null;
         }
-        if ( m_async_pool != null )
+        if (m_async_pool != null )
         {
             m_async_pool.close();
             m_async_pool = null;
@@ -354,20 +389,24 @@
      * down which is somewhat cumbersome given that the spec asks for return in
      * a timely manner.
      */
-    public synchronized void destroy()
+    public void destroy()
     {
-        if ( m_adapters != null )
+        synchronized ( this )
         {
-            for(int i=0;i<m_adapters.length;i++)
+            if ( m_adapters != null )
             {
-                m_adapters[i].destroy(m_bundleContext);
+                for(int i=0;i<m_adapters.length;i++)
+                {
+                    m_adapters[i].destroy(m_bundleContext);
+                }
+                m_adapters = null;
             }
-            m_adapters = null;
-        }
-        if ( m_managedServiceReg != null )
-        {
-            m_managedServiceReg.unregister();
-            m_managedServiceReg = null;
+            if ( m_managedServiceReg != null )
+            {
+                m_managedServiceReg.unregister();
+                m_managedServiceReg = null;
+            }
+            stop();
         }
     }