aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1697665 - in /aries/trunk/jmx: jmx-core-whiteboard/src/main/java/org/apache/aries/jmx/core/whiteboard/ jmx-core/src/main/java/org/apache/aries/jmx/ jmx-core/src/main/java/org/apache/aries/jmx/agent/ jmx-core/src/main/java/org/apache/aries/...
Date Tue, 25 Aug 2015 12:32:41 GMT
Author: davidb
Date: Tue Aug 25 12:32:40 2015
New Revision: 1697665

URL: http://svn.apache.org/r1697665
Log:
ARIES-1365 ServiceState attribute notifications slow down startup/shutdown time considerably

Committing this patch on behalf of Joel Richard with many thanks.

Added:
    aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java
Modified:
    aries/trunk/jmx/jmx-core-whiteboard/src/main/java/org/apache/aries/jmx/core/whiteboard/Activator.java
    aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/Activator.java
    aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java
    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/BundleStateMBeanHandler.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/ServiceStateMBeanHandler.java
    aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanHandlerTest.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/ServiceStateMBeanHandlerTest.java
    aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateTest.java

Modified: aries/trunk/jmx/jmx-core-whiteboard/src/main/java/org/apache/aries/jmx/core/whiteboard/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core-whiteboard/src/main/java/org/apache/aries/jmx/core/whiteboard/Activator.java?rev=1697665&r1=1697664&r2=1697665&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core-whiteboard/src/main/java/org/apache/aries/jmx/core/whiteboard/Activator.java
(original)
+++ aries/trunk/jmx/jmx-core-whiteboard/src/main/java/org/apache/aries/jmx/core/whiteboard/Activator.java
Tue Aug 25 12:32:40 2015
@@ -28,6 +28,7 @@ import org.apache.aries.jmx.framework.Bu
 import org.apache.aries.jmx.framework.Framework;
 import org.apache.aries.jmx.framework.PackageState;
 import org.apache.aries.jmx.framework.ServiceState;
+import org.apache.aries.jmx.framework.StateConfig;
 import org.apache.aries.jmx.util.ObjectNameUtils;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
@@ -80,6 +81,7 @@ public class Activator implements Bundle
   private static final String PROVISIONING_SERVICE = "org.osgi.service.provisioning.ProvisioningService";
 
   private Logger logger;
+  private StateConfig stateConfig;
 
   private class MBeanServiceProxy<T> implements ServiceFactory
   {
@@ -150,10 +152,12 @@ public class Activator implements Bundle
     tracker = new ServiceTracker(context, filter, this);
     tracker.open();
 
+    stateConfig = StateConfig.register(context);
+
     registerMBean(ServiceStateMBean.class.getName(), new Factory<ServiceStateMBean>()
{
       public ServiceStateMBean create()
       {
-        return new ServiceState(ctx, logger);
+        return new ServiceState(ctx, stateConfig, logger);
       }
     }, ServiceStateMBean.OBJECTNAME, _serviceStateMbean );
   }
@@ -176,6 +180,7 @@ public class Activator implements Bundle
 
   public void stop(BundleContext context) throws Exception
   {
+    stateConfig = null;
     tracker.close();
   }
 
@@ -339,7 +344,7 @@ public class Activator implements Bundle
           @Override
           public BundleStateMBean create(PackageAdmin pa, StartLevel sl)
           {
-            return new BundleState(ctx, pa, sl, logger);
+            return new BundleState(ctx, pa, sl, stateConfig, logger);
           }
         }, BundleStateMBean.OBJECTNAME, _bundleState);
       }

Modified: aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/Activator.java?rev=1697665&r1=1697664&r2=1697665&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/Activator.java (original)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/Activator.java Tue Aug 25
12:32:40 2015
@@ -18,6 +18,7 @@ package org.apache.aries.jmx;
 
 import org.apache.aries.jmx.agent.JMXAgent;
 import org.apache.aries.jmx.agent.JMXAgentImpl;
+import org.apache.aries.jmx.framework.StateConfig;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
@@ -39,11 +40,12 @@ public class Activator implements Bundle
      * @see org.osgi.framework.BundleActivator#start(BundleContext)
      */
     public void start(BundleContext context) throws Exception {
+        StateConfig stateConfig = StateConfig.register(context);
         logger = new Logger(context);
         //starting logger
         logger.open();
         logger.log(LogService.LOG_DEBUG, "Starting JMX OSGi bundle");
-        agent = new JMXAgentImpl(context, logger);
+        agent = new JMXAgentImpl(context, stateConfig, logger);
         agent.start();
     }
 

Modified: aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java?rev=1697665&r1=1697664&r2=1697665&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java (original)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/agent/JMXAgentImpl.java Tue
Aug 25 12:32:40 2015
@@ -40,6 +40,7 @@ import org.apache.aries.jmx.framework.Bu
 import org.apache.aries.jmx.framework.FrameworkMBeanHandler;
 import org.apache.aries.jmx.framework.PackageStateMBeanHandler;
 import org.apache.aries.jmx.framework.ServiceStateMBeanHandler;
+import org.apache.aries.jmx.framework.StateConfig;
 import org.apache.aries.jmx.framework.wiring.BundleWiringStateMBeanHandler;
 import org.apache.aries.jmx.permissionadmin.PermissionAdminMBeanHandler;
 import org.apache.aries.jmx.provisioning.ProvisioningServiceMBeanHandler;
@@ -66,16 +67,19 @@ public class JMXAgentImpl implements JMX
      */
     private Map<MBeanServer, Boolean> mbeanServers;
     private Map<MBeanHandler, Boolean> mbeansHandlers;
+    private StateConfig stateConfig;
     private BundleContext context;
     private Logger logger;
 
     /**
      * Constructs new JMXAgent.
      *
+     * @param stateConfig
      * @param logger @see org.apache.aries.jmx.Logger
      */
-    public JMXAgentImpl(BundleContext context, Logger logger) {
+    public JMXAgentImpl(BundleContext context, StateConfig stateConfig, Logger logger) {
         this.context = context;
+        this.stateConfig = stateConfig;
         this.logger = logger;
         this.mbeanServers = new IdentityHashMap<MBeanServer, Boolean>();
         this.mbeansHandlers = new IdentityHashMap<MBeanHandler, Boolean>();
@@ -92,13 +96,13 @@ public class JMXAgentImpl implements JMX
         MBeanHandler frameworkHandler = new FrameworkMBeanHandler(agentContext);
         mbeansHandlers.put(frameworkHandler, Boolean.FALSE);
         frameworkHandler.open();
-        MBeanHandler bundleStateHandler = new BundleStateMBeanHandler(agentContext);
+        MBeanHandler bundleStateHandler = new BundleStateMBeanHandler(agentContext, stateConfig);
         mbeansHandlers.put(bundleStateHandler, Boolean.FALSE);
         bundleStateHandler.open();
         MBeanHandler revisionsStateHandler = new BundleWiringStateMBeanHandler(agentContext);
         mbeansHandlers.put(revisionsStateHandler, Boolean.FALSE);
         revisionsStateHandler.open();
-        MBeanHandler serviceStateHandler = new ServiceStateMBeanHandler(agentContext);
+        MBeanHandler serviceStateHandler = new ServiceStateMBeanHandler(agentContext, stateConfig);
         mbeansHandlers.put(serviceStateHandler, Boolean.FALSE);
         serviceStateHandler.open();
         MBeanHandler packageStateHandler = new PackageStateMBeanHandler(agentContext);

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=1697665&r1=1697664&r2=1697665&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
Tue Aug 25 12:32:40 2015
@@ -81,6 +81,7 @@ public class BundleState extends Notific
     protected BundleContext bundleContext;
     protected PackageAdmin packageAdmin;
     protected StartLevel startLevel;
+    protected StateConfig stateConfig;
 
     protected ExecutorService eventDispatcher;
     protected BundleListener bundleListener;
@@ -92,10 +93,11 @@ public class BundleState extends Notific
     // notification type description
     public static String BUNDLE_EVENT = "org.osgi.bundle.event";
 
-    public BundleState(BundleContext bundleContext, PackageAdmin packageAdmin, StartLevel
startLevel, Logger logger) {
+    public BundleState(BundleContext bundleContext, PackageAdmin packageAdmin, StartLevel
startLevel, StateConfig stateConfig, Logger logger) {
         this.bundleContext = bundleContext;
         this.packageAdmin = packageAdmin;
         this.startLevel = startLevel;
+        this.stateConfig = stateConfig;
         this.logger = logger;
     }
 
@@ -433,6 +435,10 @@ public class BundleState extends Notific
     }
 
     protected AttributeChangeNotification getAttributeChangeNotification(BundleEvent event)
throws IOException {
+        if (stateConfig != null && !stateConfig.isAttributeChangeNotificationEnabled())
{
+            return null;
+        }
+
         int eventType = event.getType();
         switch (eventType) {
         case BundleEvent.INSTALLED:

Modified: aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleStateMBeanHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleStateMBeanHandler.java?rev=1697665&r1=1697664&r2=1697665&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleStateMBeanHandler.java
(original)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleStateMBeanHandler.java
Tue Aug 25 12:32:40 2015
@@ -45,6 +45,7 @@ import org.osgi.service.startlevel.Start
 public class BundleStateMBeanHandler implements MBeanHandler {
 
     private JMXAgentContext agentContext;
+    private StateConfig stateConfig;
     private Logger logger;
     private String name;
     private StandardMBean mbean;
@@ -54,8 +55,9 @@ public class BundleStateMBeanHandler imp
     private ServiceReference startLevelRef;
 
 
-    public BundleStateMBeanHandler(JMXAgentContext agentContext) {
+    public BundleStateMBeanHandler(JMXAgentContext agentContext, StateConfig stateConfig)
{
         this.agentContext = agentContext;
+        this.stateConfig = stateConfig;
         this.bundleContext = agentContext.getBundleContext();
         this.logger = agentContext.getLogger();
         this.name = ObjectNameUtils.createFullObjectName(bundleContext, OBJECTNAME);
@@ -69,7 +71,7 @@ public class BundleStateMBeanHandler imp
         PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
         startLevelRef = bundleContext.getServiceReference(StartLevel.class.getName());
         StartLevel startLevel = (StartLevel) bundleContext.getService(startLevelRef);
-        bundleStateMBean = new BundleState(bundleContext, packageAdmin, startLevel, logger);
+        bundleStateMBean = new BundleState(bundleContext, packageAdmin, startLevel, stateConfig,
logger);
         try {
             mbean = new RegistrableStandardEmitterMBean(bundleStateMBean, BundleStateMBean.class);
         } catch (NotCompliantMBeanException e) {

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=1697665&r1=1697664&r2=1697665&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
Tue Aug 25 12:32:40 2015
@@ -69,6 +69,7 @@ public class ServiceState extends Notifi
 
     protected Logger logger;
     private BundleContext bundleContext;
+    private StateConfig stateConfig;
 
     protected ExecutorService eventDispatcher;
     protected AllServiceListener serviceListener;
@@ -80,11 +81,12 @@ public class ServiceState extends Notifi
     // notification type description
     public static String SERVICE_EVENT = "org.osgi.service.event";
 
-    public ServiceState(BundleContext bundleContext, Logger logger) {
+    public ServiceState(BundleContext bundleContext, StateConfig stateConfig, Logger logger)
{
         if (bundleContext == null) {
             throw new IllegalArgumentException("Argument bundleContext cannot be null");
         }
         this.bundleContext = bundleContext;
+        this.stateConfig = stateConfig;
         this.logger = logger;
     }
 
@@ -287,6 +289,10 @@ public class ServiceState extends Notifi
     }
 
     protected AttributeChangeNotification getAttributeChangeNotification(ServiceEvent serviceevent)
throws IOException {
+        if (stateConfig != null && !stateConfig.isAttributeChangeNotificationEnabled())
{
+            return null;
+        }
+
         int eventType = serviceevent.getType();
         switch (eventType) {
         case ServiceEvent.REGISTERED:

Modified: aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java?rev=1697665&r1=1697664&r2=1697665&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java
(original)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java
Tue Aug 25 12:32:40 2015
@@ -42,6 +42,7 @@ import org.osgi.service.log.LogService;
 public class ServiceStateMBeanHandler implements MBeanHandler {
 
     private JMXAgentContext agentContext;
+    private StateConfig stateConfig;
     private String name;
     private StandardMBean mbean;
     private ServiceState serviceStateMBean;
@@ -49,8 +50,9 @@ public class ServiceStateMBeanHandler im
     private Logger logger;
 
 
-    public ServiceStateMBeanHandler(JMXAgentContext agentContext) {
+    public ServiceStateMBeanHandler(JMXAgentContext agentContext, StateConfig stateConfig)
{
         this.agentContext = agentContext;
+        this.stateConfig = stateConfig;
         this.bundleContext = agentContext.getBundleContext();
         this.logger = agentContext.getLogger();
         this.name = ObjectNameUtils.createFullObjectName(bundleContext, OBJECTNAME);
@@ -60,7 +62,7 @@ public class ServiceStateMBeanHandler im
      * @see org.apache.aries.jmx.MBeanHandler#open()
      */
     public void open() {
-        serviceStateMBean = new ServiceState(bundleContext, logger);
+        serviceStateMBean = new ServiceState(bundleContext, stateConfig, logger);
         try {
             mbean = new RegistrableStandardEmitterMBean(serviceStateMBean, ServiceStateMBean.class);
         } catch (NotCompliantMBeanException e) {

Added: 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=1697665&view=auto
==============================================================================
--- aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java
(added)
+++ aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/StateConfig.java
Tue Aug 25 12:32:40 2015
@@ -0,0 +1,95 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+/**
+ * Configuration for {@link BundleState} and {@link ServiceState}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class StateConfig implements ManagedService {
+
+    private static final String PID = StateConfig.class.getName();
+
+    private static final String ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED = "attributeChangeNotificationEnabled";
+    private static final boolean DEFAULT_ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED = true;
+
+    private boolean attributeChangeNotificationEnabled;
+
+    public StateConfig() {
+        this(DEFAULT_ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED);
+    }
+
+    StateConfig(boolean attributeChangeNotificationEnabled) {
+        this.attributeChangeNotificationEnabled = attributeChangeNotificationEnabled;
+    }
+
+    /**
+     * Registers this service and returns an instance.
+     *
+     * @param context the bundle context
+     * @return the service instance
+     * @throws IOException
+     */
+    public static StateConfig register(BundleContext context) throws IOException {
+        Dictionary<String, Object> serviceProps = new Hashtable<String, Object>();
+        serviceProps.put("service.pid", PID);
+
+        StateConfig stateConfig = new StateConfig();
+        context.registerService(ManagedService.class, stateConfig, serviceProps);
+        return stateConfig;
+    }
+
+    @Override
+    public void updated(Dictionary<String, ?> dictionary) throws ConfigurationException
{
+        attributeChangeNotificationEnabled = getBoolean(dictionary, ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED,
+                DEFAULT_ATTRIBUTE_CHANGE_NOTIFICATION_ENABLED);
+    }
+
+    /**
+     * Whether or not JMX attribute change notifications should be triggered when attributes
change.
+     *
+     * @return <code>true</code> if attribute change notifications are enabled
+     */
+    public boolean isAttributeChangeNotificationEnabled() {
+        return attributeChangeNotificationEnabled;
+    }
+
+    private static boolean getBoolean(Dictionary<String, ?> dictionary, String propertyName,
boolean defaultValue) {
+        Object object = (dictionary != null) ? dictionary.get(propertyName) : null;
+        if (object == null) {
+            return defaultValue;
+        } else if (object instanceof Boolean) {
+            return (Boolean) object;
+        } else {
+            String string = object.toString();
+            return !string.isEmpty() ? Boolean.parseBoolean(string) : defaultValue;
+        }
+    }
+
+}

Modified: aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanHandlerTest.java?rev=1697665&r1=1697664&r2=1697665&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanHandlerTest.java
(original)
+++ aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanHandlerTest.java
Tue Aug 25 12:32:40 2015
@@ -64,7 +64,7 @@ public class BundleStateMBeanHandlerTest
         JMXAgent agent = mock(JMXAgent.class);
         JMXAgentContext agentContext = new JMXAgentContext(context, agent, logger);
 
-        BundleStateMBeanHandler handler = new BundleStateMBeanHandler(agentContext);
+        BundleStateMBeanHandler handler = new BundleStateMBeanHandler(agentContext, new StateConfig());
         handler.open();
 
         assertNotNull(handler.getMbean());

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=1697665&r1=1697664&r2=1697665&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
Tue Aug 25 12:32:40 2015
@@ -53,16 +53,15 @@ import org.osgi.service.startlevel.Start
 
 public class BundleStateTest {
 
-    @Test
-    public void testNotificationsForBundleEvents() throws Exception {
-
+    private void createBundle(StateConfig stateConfig, final List<Notification> received,
+                              final List<AttributeChangeNotification> attributeChanges)
throws Exception {
         BundleContext context = mock(BundleContext.class);
         when(context.getBundles()).thenReturn(new Bundle [] {});
         PackageAdmin admin = mock(PackageAdmin.class);
         StartLevel startLevel = mock(StartLevel.class);
         Logger logger = mock(Logger.class);
 
-        BundleState bundleState = new BundleState(context, admin, startLevel, logger);
+        BundleState bundleState = new BundleState(context, admin, startLevel, stateConfig,
logger);
 
         Bundle b1 = mock(Bundle.class);
         when(b1.getBundleId()).thenReturn(new Long(9));
@@ -84,10 +83,6 @@ public class BundleStateTest {
         bundleState.preRegister(server, objectName);
         bundleState.postRegister(true);
 
-        //holders for Notifications captured
-        final List<Notification> received = new LinkedList<Notification>();
-        final List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
-
         //add NotificationListener to receive the events
         bundleState.addNotificationListener(new NotificationListener() {
             public void handleNotification(Notification notification, Object handback) {
@@ -117,6 +112,17 @@ public class BundleStateTest {
         assertTrue(dispatcher.isShutdown());
         dispatcher.awaitTermination(2, TimeUnit.SECONDS);
         assertTrue(dispatcher.isTerminated());
+    }
+
+    @Test
+    public void testNotificationsForBundleEvents() throws Exception {
+        StateConfig stateConfig = new StateConfig();
+
+        //holders for Notifications captured
+        List<Notification> received = new LinkedList<Notification>();
+        List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
+
+        createBundle(stateConfig, received, attributeChanges);
 
         assertEquals(2, received.size());
         Notification installed = received.get(0);
@@ -153,7 +159,7 @@ public class BundleStateTest {
         StartLevel startLevel = mock(StartLevel.class);
         Logger logger = mock(Logger.class);
 
-        BundleState bundleState = new BundleState(context, admin, startLevel, logger);
+        BundleState bundleState = new BundleState(context, admin, startLevel, new StateConfig(),
logger);
 
         MBeanServer server1 = mock(MBeanServer.class);
         MBeanServer server2 = mock(MBeanServer.class);
@@ -198,4 +204,17 @@ public class BundleStateTest {
 
 
     }
+
+    @Test
+    public void testAttributeNotificationDisabled() throws Exception {
+        StateConfig stateConfig = new StateConfig(false);
+
+        //holders for Notifications captured
+        List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
+        createBundle(stateConfig, new LinkedList<Notification>(), attributeChanges);
+
+        assertEquals(0, attributeChanges.size());
+    }
+
+
 }

Modified: aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandlerTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandlerTest.java?rev=1697665&r1=1697664&r2=1697665&view=diff
==============================================================================
--- aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandlerTest.java
(original)
+++ aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandlerTest.java
Tue Aug 25 12:32:40 2015
@@ -51,7 +51,7 @@ public class ServiceStateMBeanHandlerTes
         JMXAgent agent = mock(JMXAgent.class);
         JMXAgentContext agentContext = new JMXAgentContext(context, agent, logger);
 
-        ServiceStateMBeanHandler handler = new ServiceStateMBeanHandler(agentContext);
+        ServiceStateMBeanHandler handler = new ServiceStateMBeanHandler(agentContext, new
StateConfig());
         handler.open();
 
         assertNotNull(handler.getMbean());

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=1697665&r1=1697664&r2=1697665&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
Tue Aug 25 12:32:40 2015
@@ -64,13 +64,12 @@ import org.osgi.framework.ServiceReferen
 public class ServiceStateTest {
 
 
-    @Test
-    public void testNotificationsForServiceEvents() throws Exception {
-
+    private void createService(StateConfig stateConfig, final List<Notification> received,
+                               final List<AttributeChangeNotification> attributeChanges)
throws Exception {
         BundleContext context = mock(BundleContext.class);
         Logger logger = mock(Logger.class);
 
-        ServiceState serviceState = new ServiceState(context, logger);
+        ServiceState serviceState = new ServiceState(context, stateConfig, logger);
 
         ServiceReference reference = mock(ServiceReference.class);
         Bundle b1 = mock(Bundle.class);
@@ -99,9 +98,6 @@ public class ServiceStateTest {
         serviceState.preRegister(server, objectName);
         serviceState.postRegister(true);
 
-        //holders for Notifications captured
-        final List<Notification> received = new LinkedList<Notification>();
-        final List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
 
         //add NotificationListener to receive the events
         serviceState.addNotificationListener(new NotificationListener() {
@@ -132,6 +128,17 @@ public class ServiceStateTest {
         assertTrue(dispatcher.isShutdown());
         dispatcher.awaitTermination(2, TimeUnit.SECONDS);
         assertTrue(dispatcher.isTerminated());
+    }
+
+    @Test
+    public void testNotificationsForServiceEvents() throws Exception {
+        StateConfig stateConfig = new StateConfig();
+
+        //holders for Notifications captured
+        List<Notification> received = new LinkedList<Notification>();
+        List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
+
+        createService(stateConfig, received, attributeChanges);
 
         assertEquals(2, received.size());
         Notification registered = received.get(0);
@@ -168,7 +175,7 @@ public class ServiceStateTest {
         BundleContext context = mock(BundleContext.class);
         Logger logger = mock(Logger.class);
 
-        ServiceState serviceState = new ServiceState(context, logger);
+        ServiceState serviceState = new ServiceState(context, new StateConfig(), logger);
 
         MBeanServer server1 = mock(MBeanServer.class);
         MBeanServer server2 = mock(MBeanServer.class);
@@ -213,4 +220,15 @@ public class ServiceStateTest {
 
     }
 
+    @Test
+    public void testAttributeNotificationDisabled() throws Exception {
+        StateConfig stateConfig = new StateConfig(false);
+
+        //holders for Notifications captured
+        List<AttributeChangeNotification> attributeChanges = new LinkedList<AttributeChangeNotification>();
+        createService(stateConfig, new LinkedList<Notification>(), attributeChanges);
+
+        assertEquals(0, attributeChanges.size());
+    }
+
 }



Mime
View raw message