-
Notifications
You must be signed in to change notification settings - Fork 0
Programming Model
#The problem The runtime management of OSGi based applications has to deal with difficulties which are based on the modular and dynamic concept of the platform. As lots of artifacts may be installed and running in an OSGi container there is a matter of still being able to manage them using a small tool set. Thus siad it is a problem if every single module of an application offers or requires another way to monitor or control its resources. Different approaches (command shell vs. GUI) and different technologies (Web Console vs. Rich Client) might be used which implies several problems ranging from long reaction times in critical cases or security concerns.
The concepts and technologies to solve this are offered by JMX (Java Management Extensions) but are not integrated with the concepts of OSGi.
MAEXO builds a bridge between both worlds.
#JMX resources as OSGi services The main idea is publishing the core components of the JMX infrastructure as services to the OSGi registry. This way any interested party may track their life cycles and perform actions on them. This approach is called the white board pattern. If for example a bundle listens on MBean servers and MBeans it can register them at the time they appear and unregister them if they disappear. This is exactly what the MAEXO Switch Board does.
In other words: If a bundle needs to export an MBean it just registers the instance as an OSGi service using its MBean interface and the desired object name as a property. It does not need to know where and how to lookup the appropriate MBean server.
The same idea holds for working with MBean notifications. An instance of a notification listener can be published as OSGi service and the Switch Board will transparently add it to existing MBean server connections.
#Examples The following examples demonstrate how to publish a standard MBean from a bundle using Java code, Spring DM and Declarative Services. In all cases the Switch Board bundle and a bundle providing an MBean server (e.g. maexo-server.platform) must be installed and activated.
##Java
// the class Example is an implementation of the interface ExampleMBean
ExampleMBean exampleMBean = new Example();
// create object name
ObjectName objectName = new ObjectName("com.buschmais.maexo.example:type=ExampleMBean");
// create the service properties
Dictionary<String, Object> mbeanServiceProperties = new Hashtable<String, Object>();
mbeanServiceProperties.put(ObjectName.class.getName(),objectName);
// register the MBean as service, e.g. within the start() method of the bundle activator
ServiceReference exampleMBeanServiceReference = bundleContext.registerService(ExampleMBean.class, exampleMBean, mbeanServiceProperties);
...
// unregister the MBean service, e.g. within the stop() method of the bundle activator
exampleMBeanServiceReference.unregister();
##Spring Dynamic Modules
<bean id="exampleMBean" class="com.buschmais.maexo.example.Example" />
<osgi:service ref="exampleMBean" interface="com.buschmais.maexo.example.ExampleMBean">
<osgi:service-properties>
<entry key="objectName" value="com.buschmais.maexo.example:type=ExampleMBean" />
</osgi:service-properties>
</osgi:service>
</bean>
##Declarative Services
<implementation class="com.buschmais.maexo.example.Example" />
<property name="objectName" value="com.buschmais.maexo.example:type=ExampleMBean" />
<service>
<provide interface="com.buschmais.maexo.example.ExampleMBean" />
</service>