You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Charles Moulliard <ch...@gmail.com> on 2012/10/03 18:12:19 UTC
Register a bean as a MBean (JMX)
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
Re: Register a bean as a MBean (JMX)
Posted by Charles Moulliard <ch...@gmail.com>.
I have created a ticket to document this :
https://issues.apache.org/jira/browse/KARAF-1891
and committed modification for jmx.conf page of the manual ;-)
On Wed, Oct 3, 2012 at 6:52 PM, Jean-Baptiste Onofré <jb...@nanthrax.net>wrote:
> Hi Charles,
>
> this blueprint descriptor is only valid for Karaf 2.2/2.3.
>
> On trunk, we use Aries JMX: no need to use the MBeanRegistrer, etc.
>
> Just use directly something like this:
>
> <service ref="mbeanImpl" auto-export="interfaces">
> <service-properties>
> <entry key="jmx.objectname" value="org.apache.karaf:type=**
> instance,name=${karaf.name}"/>
> </service-properties>
> </service>
>
> You need nothing more ;)
>
> Regards
> JB
>
>
> On 10/03/2012 06:47 PM, Charles Moulliard wrote:
>
>> 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<http://www.osgi.org/xmlns/blueprint/v1.0.0>
>> "
>> xmlns:xsi="http://www.w3.org/**2001/XMLSchema-instance<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>
>> http://www.osgi.org/xmlns/**blueprint/v1.0.0/blueprint.xsd<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 <ch007m@gmail.com
>> <ma...@gmail.com>> 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<http://www.osgi.org/xmlns/blueprint/v1.0.0>
>> "
>> xmlns:xsi="http://www.w3.org/**2001/XMLSchema-instance<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>
>> http://www.osgi.org/xmlns/**blueprint/v1.0.0/blueprint.xsd<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
>>
>>
>>
> --
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
--
Charles Moulliard
Apache Committer / Sr. Enterprise Architect (RedHat)
Twitter : @cmoulliard | Blog : http://cmoulliard.blogspot.com
Re: Register a bean as a MBean (JMX)
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Charles,
this blueprint descriptor is only valid for Karaf 2.2/2.3.
On trunk, we use Aries JMX: no need to use the MBeanRegistrer, etc.
Just use directly something like this:
<service ref="mbeanImpl" auto-export="interfaces">
<service-properties>
<entry key="jmx.objectname"
value="org.apache.karaf:type=instance,name=${karaf.name}"/>
</service-properties>
</service>
You need nothing more ;)
Regards
JB
On 10/03/2012 06:47 PM, Charles Moulliard wrote:
> 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 <ch007m@gmail.com
> <ma...@gmail.com>> 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
>
>
--
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com
Re: Register a bean as a MBean (JMX)
Posted by Charles Moulliard <ch...@gmail.com>.
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 <ch...@gmail.com> 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
Re: Register a bean as a MBean (JMX)
Posted by Charles Moulliard <ch...@gmail.com>.
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 <ch...@gmail.com> 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