felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1361527 - in /felix/trunk/configadmin/src: main/java/org/apache/felix/cm/impl/ test/java/org/apache/felix/cm/integration/
Date Sat, 14 Jul 2012 11:59:30 GMT
Author: fmeschbe
Date: Sat Jul 14 11:59:29 2012
New Revision: 1361527

URL: http://svn.apache.org/viewvc?rev=1361527&view=rev
Log:
FELIX-3596 ConfigurationEvents should only be synchronously delivered to listeners registered
as SynchronousConfigurationEventListener (this is a service interface not a marker interface).
Adapted test cases to verify async delivery to SynchronousConfigurationEventListener implementations
registered as ConfigurationEventListener services.

Modified:
    felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationListenerTest.java
    felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/FELIX2813_ConfigurationAdminStartupTest.java

Modified: felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java?rev=1361527&r1=1361526&r2=1361527&view=diff
==============================================================================
--- felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
(original)
+++ felix/trunk/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
Sat Jul 14 11:59:29 2012
@@ -135,6 +135,9 @@ public class ConfigurationManager implem
     // the ConfigurationEvent listeners
     private ServiceTracker configurationListenerTracker;
 
+    // the synchronous ConfigurationEvent listeners
+    private ServiceTracker syncConfigurationListenerTracker;
+
     // service tracker for managed services
     private ManagedServiceTracker managedServiceTracker;
 
@@ -221,6 +224,9 @@ public class ConfigurationManager implem
         // configurationlistener support
         configurationListenerTracker = new ServiceTracker( bundleContext, ConfigurationListener.class.getName(),
null );
         configurationListenerTracker.open();
+        syncConfigurationListenerTracker = new ServiceTracker( bundleContext,
+            SynchronousConfigurationListener.class.getName(), null );
+        syncConfigurationListenerTracker.open();
 
         // initialize the asynchonous updater thread
         ThreadGroup tg = new ThreadGroup( "Configuration Admin Service" );
@@ -330,6 +336,11 @@ public class ConfigurationManager implem
             configurationListenerTracker.close();
         }
 
+        if ( syncConfigurationListenerTracker != null )
+        {
+            syncConfigurationListenerTracker.close();
+        }
+
         if ( logTracker != null )
         {
             logTracker.close();
@@ -734,16 +745,32 @@ public class ConfigurationManager implem
 
     void fireConfigurationEvent( int type, String pid, String factoryPid )
     {
-        FireConfigurationEvent event = new FireConfigurationEvent( type, pid, factoryPid
);
-        event.fireSynchronousEvents();
-        if ( event.hasConfigurationEventListeners() )
+        // prevent event senders
+        FireConfigurationEvent asyncSender = new FireConfigurationEvent( this.configurationListenerTracker,
type, pid,
+            factoryPid );
+        FireConfigurationEvent syncSender = new FireConfigurationEvent( this.syncConfigurationListenerTracker,
type,
+            pid, factoryPid );
+
+        // send synchronous events
+        if ( syncSender.hasConfigurationEventListeners() )
+        {
+            syncSender.run();
+        }
+        else
+        {
+            log( LogService.LOG_DEBUG, "No SynchronousConfigurationListeners to send {0}
event to.", new Object[]
+                { syncSender.getTypeName() } );
+        }
+
+        // schedule asynchronous events
+        if ( asyncSender.hasConfigurationEventListeners() )
         {
-            eventThread.schedule( event );
+            eventThread.schedule( asyncSender );
         }
         else
         {
             log( LogService.LOG_DEBUG, "No ConfigurationListeners to send {0} event to.",
new Object[]
-                { event.getTypeName() } );
+                { asyncSender.getTypeName() } );
         }
     }
 
@@ -1890,13 +1917,13 @@ public class ConfigurationManager implem
 
         private ConfigurationEvent event;
 
-        private FireConfigurationEvent( final int type, final String pid, final String factoryPid)
+        private FireConfigurationEvent( final ServiceTracker listenerTracker, final int type,
final String pid, final String factoryPid)
         {
             this.type = type;
             this.pid = pid;
             this.factoryPid = factoryPid;
 
-            final ServiceReference[] srs = configurationListenerTracker.getServiceReferences();
+            final ServiceReference[] srs = listenerTracker.getServiceReferences();
             if ( srs == null || srs.length == 0 )
             {
                 this.listenerReferences = null;
@@ -1910,28 +1937,13 @@ public class ConfigurationManager implem
                 this.listenerProvider = new Bundle[srs.length];
                 for ( int i = 0; i < srs.length; i++ )
                 {
-                    this.listeners[i] = ( ConfigurationListener ) configurationListenerTracker.getService(
srs[i] );
+                    this.listeners[i] = ( ConfigurationListener ) listenerTracker.getService(
srs[i] );
                     this.listenerProvider[i] = srs[i].getBundle();
                 }
             }
         }
 
 
-        void fireSynchronousEvents()
-        {
-            if ( hasConfigurationEventListeners() && getServiceReference() != null
)
-            {
-                for ( int i = 0; i < this.listeners.length; i++ )
-                {
-                    if ( this.listeners[i] instanceof SynchronousConfigurationListener )
-                    {
-                        sendEvent( i );
-                    }
-                }
-            }
-        }
-
-
         boolean hasConfigurationEventListeners()
         {
             return this.listenerReferences != null;

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationListenerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationListenerTest.java?rev=1361527&r1=1361526&r2=1361527&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationListenerTest.java
(original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationListenerTest.java
Sat Jul 14 11:59:29 2012
@@ -31,6 +31,7 @@ import org.osgi.framework.ServiceRegistr
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationEvent;
 import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.cm.SynchronousConfigurationListener;
 
 
 @RunWith(JUnit4TestRunner.class)
@@ -113,14 +114,27 @@ public class ConfigurationListenerTest e
     {
         final String pid = "test_listener";
         Configuration config = configure( pid, null, false );
+
+        // Synchronous listener expecting synchronous events being
+        // registered as a SynchronousConfigurationListener
         final TestListener testListener = new SynchronousTestListener();
-        final ServiceRegistration listener = this.bundleContext.registerService( ConfigurationListener.class.getName(),
-            testListener, null );
+        final ServiceRegistration listener = this.bundleContext.registerService(
+            SynchronousConfigurationListener.class.getName(), testListener, null );
+
+        // Synchronous listener expecting asynchronous events being
+        // registered as a regular ConfigurationListener
+        final TestListener testListenerAsync = new SynchronousTestListener();
+        final ServiceRegistration listenerAsync = this.bundleContext.registerService(
+            ConfigurationListener.class.getName(), testListenerAsync, null );
+
         int eventCount = 0;
+        int eventCountAsync = 0;
+
         try
         {
             delay();
             testListener.assertNoEvent();
+            testListenerAsync.assertNoEvent();
 
             config.update( new Hashtable<String, Object>()
             {
@@ -130,6 +144,7 @@ public class ConfigurationListenerTest e
             } );
             delay();
             testListener.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, false, ++eventCount
);
+            testListenerAsync.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, true,
++eventCountAsync );
 
             config.update( new Hashtable<String, Object>()
             {
@@ -139,18 +154,22 @@ public class ConfigurationListenerTest e
             } );
             delay();
             testListener.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, false, ++eventCount
);
+            testListenerAsync.assertEvent( ConfigurationEvent.CM_UPDATED, pid, null, true,
++eventCountAsync );
 
             config.setBundleLocation( "new_Location" );
             delay();
             testListener.assertEvent( ConfigurationEvent.CM_LOCATION_CHANGED, pid, null,
false, ++eventCount );
+            testListenerAsync.assertEvent( ConfigurationEvent.CM_LOCATION_CHANGED, pid, null,
true, ++eventCountAsync );
 
             config.update();
             testListener.assertNoEvent();
+            testListenerAsync.assertNoEvent();
 
             config.delete();
             config = null;
             delay();
             testListener.assertEvent( ConfigurationEvent.CM_DELETED, pid, null, false, ++eventCount
);
+            testListenerAsync.assertEvent( ConfigurationEvent.CM_DELETED, pid, null, true,
++eventCountAsync );
         }
         finally
         {
@@ -167,6 +186,7 @@ public class ConfigurationListenerTest e
             }
 
             listener.unregister();
+            listenerAsync.unregister();
         }
     }
 }

Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/FELIX2813_ConfigurationAdminStartupTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/FELIX2813_ConfigurationAdminStartupTest.java?rev=1361527&r1=1361526&r2=1361527&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/FELIX2813_ConfigurationAdminStartupTest.java
(original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/integration/FELIX2813_ConfigurationAdminStartupTest.java
Sat Jul 14 11:59:29 2012
@@ -38,6 +38,7 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.cm.ConfigurationEvent;
 import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.service.cm.SynchronousConfigurationListener;
 
 
 @RunWith(JUnit4TestRunner.class)
@@ -62,7 +63,9 @@ public class FELIX2813_ConfigurationAdmi
         final TestListener listener = new TestListener();
         bundleContext.registerService( ConfigurationListener.class.getName(), listener, null
);
         final TestListener syncListener = new SynchronousTestListener();
-        bundleContext.registerService( ConfigurationListener.class.getName(), syncListener,
null );
+        bundleContext.registerService( SynchronousConfigurationListener.class.getName(),
syncListener, null );
+        final TestListener syncListenerAsync = new SynchronousTestListener();
+        bundleContext.registerService( ConfigurationListener.class.getName(), syncListenerAsync,
null );
         bundleContext.addServiceListener( this, "(" + Constants.OBJECTCLASS + "=" + ConfigurationAdmin.class.getName()
             + ")" );
 
@@ -95,6 +98,7 @@ public class FELIX2813_ConfigurationAdmi
         delay();
         listener.assertEvent( ConfigurationEvent.CM_UPDATED, "test", null, true, 1 );
         syncListener.assertEvent( ConfigurationEvent.CM_UPDATED, "test", null, false, 1 );
+        syncListenerAsync.assertEvent( ConfigurationEvent.CM_UPDATED, "test", null, true,
1 );
     }
 
 



Mime
View raw message