You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gn...@apache.org on 2016/10/12 19:56:31 UTC

svn commit: r1764533 - in /aries/trunk/jmx/jmx-core/src: main/java/org/apache/aries/jmx/framework/ test/java/org/apache/aries/jmx/framework/

Author: gnodet
Date: Wed Oct 12 19:56:30 2016
New Revision: 1764533

URL: http://svn.apache.org/viewvc?rev=1764533&view=rev
Log:
[ARIES-1627] Give ability to disable JMX notifications generation for OSGi service and bundle changes

Modified:
    aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
    aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
    aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java
    aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateTest.java
    aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateTest.java

Modified: aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java?rev=1764533&r1=1764532&r2=1764533&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java (original)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java Wed Oct 12 19:56:30 2016
@@ -402,6 +402,9 @@ public class BundleState extends Notific
             if (bundleListener == null) {
                 bundleListener = new BundleListener() {
                     public void bundleChanged(BundleEvent event) {
+                        if (stateConfig != null && !stateConfig.isBundleChangeNotificationEnabled()) {
+                            return;
+                        }
                         try {
                             final Notification notification = new Notification(EVENT, OBJECTNAME,
                                     notificationSequenceNumber.getAndIncrement());

Modified: aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java?rev=1764533&r1=1764532&r2=1764533&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java (original)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java Wed Oct 12 19:56:30 2016
@@ -254,6 +254,9 @@ public class ServiceState extends Notifi
             if (serviceListener == null) {
                 serviceListener = new AllServiceListener() {
                     public void serviceChanged(ServiceEvent serviceevent) {
+                        if (stateConfig != null && !stateConfig.isServiceChangeNotificationEnabled()) {
+                            return;
+                        }
                         try {
                             // Create a notification for the event
                             final Notification notification = new Notification(EVENT, OBJECTNAME,

Modified: aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java?rev=1764533&r1=1764532&r2=1764533&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java (original)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java Wed Oct 12 19:56:30 2016
@@ -39,16 +39,28 @@ public class StateConfig implements Mana
     private static final String ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED = "attributeChangeNotificationEnabled";
     private static final boolean DEFAULT_ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED = true;
 
-    private boolean attributeChangeNotificationEnabled;
+    private static final String SERVICE_CHANGE_NOTIFICATION_ENABLED = "serviceChangeNotificationEnabled";
+    private static final boolean DEFAULT_SERVICE_CHANGE_NOTIFICATION_ENABLED = true;
 
-    public StateConfig() {
-        this(DEFAULT_ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED);
-    }
+    private static final String BUNDLE_CHANGE_NOTIFICATION_ENABLED = "bundleChangeNotificationEnabled";
+    private static final boolean DEFAULT_BUNDLE_CHANGE_NOTIFICATION_ENABLED = true;
+
+    private volatile boolean attributeChangeNotificationEnabled = DEFAULT_ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED;
+    private volatile boolean serviceChangeNotificationEnabled = DEFAULT_SERVICE_CHANGE_NOTIFICATION_ENABLED;
+    private volatile boolean bundleChangeNotificationEnabled = DEFAULT_BUNDLE_CHANGE_NOTIFICATION_ENABLED;
 
-    StateConfig(boolean attributeChangeNotificationEnabled) {
+    void setAttributeChangeNotificationEnabled(boolean attributeChangeNotificationEnabled) {
         this.attributeChangeNotificationEnabled = attributeChangeNotificationEnabled;
     }
 
+    void setServiceChangeNotificationEnabled(boolean serviceChangeNotificationEnabled) {
+        this.serviceChangeNotificationEnabled = serviceChangeNotificationEnabled;
+    }
+
+    void setBundleChangeNotificationEnabled(boolean bundleChangeNotificationEnabled) {
+        this.bundleChangeNotificationEnabled = bundleChangeNotificationEnabled;
+    }
+
     /**
      * Registers this service and returns an instance.
      *
@@ -69,6 +81,10 @@ public class StateConfig implements Mana
     public void updated(Dictionary<String, ?> dictionary) throws ConfigurationException {
         attributeChangeNotificationEnabled = getBoolean(dictionary, ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED,
                 DEFAULT_ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED);
+        serviceChangeNotificationEnabled = getBoolean(dictionary, SERVICE_CHANGE_NOTIFICATION_ENABLED,
+                DEFAULT_SERVICE_CHANGE_NOTIFICATION_ENABLED);
+        bundleChangeNotificationEnabled = getBoolean(dictionary, BUNDLE_CHANGE_NOTIFICATION_ENABLED,
+                DEFAULT_BUNDLE_CHANGE_NOTIFICATION_ENABLED);
     }
 
     /**
@@ -80,6 +96,24 @@ public class StateConfig implements Mana
         return attributeChangeNotificationEnabled;
     }
 
+    /**
+     * Whether or not JMX OSGi service change notifications should be triggered when OSGi service change.
+     *
+     * @return <code>true</code> if OSGi service change notifications are enabled
+     */
+    public boolean isServiceChangeNotificationEnabled() {
+        return serviceChangeNotificationEnabled;
+    }
+
+    /**
+     * Whether or not JMX bundle change notifications should be triggered when bundle change.
+     *
+     * @return <code>true</code> if bundle change notifications are enabled
+     */
+    public boolean isBundleChangeNotificationEnabled() {
+        return bundleChangeNotificationEnabled;
+    }
+
     private static boolean getBoolean(Dictionary<String, ?> dictionary, String propertyName, boolean defaultValue) {
         Object object = (dictionary != null) ? dictionary.get(propertyName) : null;
         if (object == null) {

Modified: aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateTest.java?rev=1764533&r1=1764532&r2=1764533&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateTest.java (original)
+++ aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateTest.java Wed Oct 12 19:56:30 2016
@@ -152,6 +152,20 @@ public class BundleStateTest {
     }
 
     @Test
+    public void testNotificationsForBundleEventsDisabled() throws Exception {
+        StateConfig stateConfig = new StateConfig();
+        stateConfig.setBundleChangeNotificationEnabled(false);
+
+        //holders for Notifications captured
+        List<Notification> received = new LinkedList<Notification>();
+        List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
+
+        createBundle(stateConfig, received, attributeChanges);
+
+        assertEquals(0, received.size());
+    }
+
+    @Test
     public void testLifeCycleOfNotificationSupport() throws Exception {
 
         BundleContext context = mock(BundleContext.class);
@@ -207,7 +221,8 @@ public class BundleStateTest {
 
     @Test
     public void testAttributeNotificationDisabled() throws Exception {
-        StateConfig stateConfig = new StateConfig(false);
+        StateConfig stateConfig = new StateConfig();
+        stateConfig.setAttributeChangeNotificationEnabled(false);
 
         //holders for Notifications captured
         List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();

Modified: aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateTest.java?rev=1764533&r1=1764532&r2=1764533&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateTest.java (original)
+++ aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateTest.java Wed Oct 12 19:56:30 2016
@@ -170,6 +170,20 @@ public class ServiceStateTest {
     }
 
     @Test
+    public void testNotificationsForServiceEventsDisabled() throws Exception {
+        StateConfig stateConfig = new StateConfig();
+        stateConfig.setServiceChangeNotificationEnabled(false);
+
+        //holders for Notifications captured
+        List<Notification> received = new LinkedList<Notification>();
+        List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
+
+        createService(stateConfig, received, attributeChanges);
+
+        assertEquals(0, received.size());
+    }
+
+    @Test
     public void testLifeCycleOfNotificationSupport() throws Exception {
 
         BundleContext context = mock(BundleContext.class);
@@ -222,7 +236,8 @@ public class ServiceStateTest {
 
     @Test
     public void testAttributeNotificationDisabled() throws Exception {
-        StateConfig stateConfig = new StateConfig(false);
+        StateConfig stateConfig = new StateConfig();
+        stateConfig.setAttributeChangeNotificationEnabled(false);
 
         //holders for Notifications captured
         List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();