FELIX-2020 : Unregister service on destroy.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@905942 13f79535-47bb-0310-9956-ffa450edef68
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 0f2224b..543bedb 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
@@ -22,31 +22,15 @@
 import java.util.Dictionary;
 import java.util.Hashtable;
 
-import org.apache.felix.eventadmin.impl.adapter.AbstractAdapter;
-import org.apache.felix.eventadmin.impl.adapter.BundleEventAdapter;
-import org.apache.felix.eventadmin.impl.adapter.FrameworkEventAdapter;
-import org.apache.felix.eventadmin.impl.adapter.LogEventAdapter;
-import org.apache.felix.eventadmin.impl.adapter.ServiceEventAdapter;
+import org.apache.felix.eventadmin.impl.adapter.*;
 import org.apache.felix.eventadmin.impl.dispatch.DefaultThreadPool;
 import org.apache.felix.eventadmin.impl.dispatch.ThreadPool;
-import org.apache.felix.eventadmin.impl.handler.BlacklistingHandlerTasks;
-import org.apache.felix.eventadmin.impl.handler.CacheFilters;
-import org.apache.felix.eventadmin.impl.handler.CacheTopicHandlerFilters;
-import org.apache.felix.eventadmin.impl.handler.CleanBlackList;
-import org.apache.felix.eventadmin.impl.handler.Filters;
-import org.apache.felix.eventadmin.impl.handler.HandlerTasks;
-import org.apache.felix.eventadmin.impl.handler.TopicHandlerFilters;
-import org.apache.felix.eventadmin.impl.security.CacheTopicPermissions;
-import org.apache.felix.eventadmin.impl.security.SecureEventAdminFactory;
-import org.apache.felix.eventadmin.impl.security.TopicPermissions;
-import org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks;
-import org.apache.felix.eventadmin.impl.tasks.DeliverTask;
-import org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks;
+import org.apache.felix.eventadmin.impl.handler.*;
+import org.apache.felix.eventadmin.impl.security.*;
+import org.apache.felix.eventadmin.impl.tasks.*;
 import org.apache.felix.eventadmin.impl.util.LeastRecentlyUsedCacheMap;
 import org.apache.felix.eventadmin.impl.util.LogWrapper;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.*;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.service.event.EventAdmin;
@@ -140,6 +124,8 @@
     // all adapters
     private AbstractAdapter[] adapters;
 
+    private ServiceRegistration managedServiceReg;
+
     public Configuration( BundleContext bundleContext )
     {
         this.bundleContext = bundleContext;
@@ -173,7 +159,7 @@
             }
             Dictionary props = new Hashtable();
             props.put( Constants.SERVICE_PID, PID );
-            bundleContext.registerService( interfaceNames, service, props );
+            managedServiceReg = bundleContext.registerService( interfaceNames, service, props );
         }
         catch ( Throwable t )
         {
@@ -330,6 +316,11 @@
             }
             adapters = null;
         }
+        if ( managedServiceReg != null )
+        {
+            managedServiceReg.unregister();
+            managedServiceReg = null;
+        }
     }
 
     /**