The code that I tried to use is for Karaf 3.X.

The following blueprint file works fine :

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
           xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0
              http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>

    <!-- ServiceMBean -->
    <bean id="serviceMBean"
class="com.fusesource.poc.service.impl.MyService"/>

    <service ref="serviceMBean" auto-export="interfaces">
        <service-properties>
            <!-- Karaf 3.x -->
            <entry key="jmx.objectname"
value="com.fusesource.poc.service:type=service,name=feedback" />
            -->
        </service-properties>
    </service>

    <!-- Reference to the MBean Server -->
    <reference id="mbeanServer" interface="javax.management.MBeanServer">
        <reference-listener ref="mbeanRegistrer"
bind-method="registerMBeanServer" unbind-method="unregisterMBeanServer"/>
    </reference>

    <!-- MBean Registrer -->
    <!-- method destroy has been added after karaf 2.2.x
destroy-method="destroy" -->
    <bean id="mbeanRegistrer"
class="org.apache.karaf.management.MBeanRegistrer" init-method="init">
        <property name="mbeans">
            <map>
                <entry
value="com.fusesource.poc.service:type=service,name=feedback"
key-ref="serviceMBean"/>
            </map>
        </property>
    </bean>

</blueprint>

On Wed, Oct 3, 2012 at 6:12 PM, Charles Moulliard <[email protected]> wrote:

> Hi,
>
> I have developed a small project to register a bean as a JMX Mbean. The
> code looks the same as org.apache.karaf.web.management.internal.Web of
> Karaf
>
> 1. Interface
>
> package com.fusesource.poc.service;
>
> public interface ServiceMBean {
>
>     String sayHello();
>
> }
>
> 2. Impl
>
> package com.fusesource.poc.service.impl;
>
> import com.fusesource.poc.service.ServiceMBean;
>
> import javax.management.NotCompliantMBeanException;
> import javax.management.StandardMBean;
>
> public class MyService extends StandardMBean implements ServiceMBean {
>
>     public MyService() throws NotCompliantMBeanException {
>         super(ServiceMBean.class);
>     }
>
>     @Override
>     public String sayHello() {
>         return ">> Good morning from Weather Team";
>     }
> }
>
> 3. Blueprint
>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
>            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>            xsi:schemaLocation="
>            http://www.osgi.org/xmlns/blueprint/v1.0.0
>               http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>
>
>     <bean id="service" class="com.fusesource.poc.service.impl.MyService"/>
>
>     <service ref="service" auto-export="interfaces">
>         <service-properties>
>             <entry key="jmx.objectname"
> value="com.fusesource.poc.service:type=service,name=feedback" />
>         </service-properties>
>     </service>
>
> </blueprint>
>
> Remark : no error is reported in the console of karaf
>
> Unfortunately, when my bundle is started, I cannot see it registered in
> MBean server - JConsole. Is there something that I missed ?
>
> Regards
>
> --
> Charles Moulliard
> Apache Committer / Sr. Enterprise Architect (RedHat)
> Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com
>
>
>


-- 
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com

Reply via email to