-
1. Re: (JMX) Simplest way to use a custom MBean in Fuse?
ffang Jul 9, 2013 1:12 AM (in response to vikingsteve)Hi,
You don't need explicitly have InstrumentationManagerImpl definition in blueprint.xml, as it would be enabled automatically when it detect there is a MBeanServer OSGi service.
What you can do is get InstrumentationManager from the bus and register your customer mbean directly on it, some code like
InstrumentationManager imanager = bus.getExtension(InstrumentationManager.class);
final MyServiceMBeanImpl mbImpl = new MyServiceMBeanImpl();
final ObjectName oName = new ObjectName("org.apache.cxf:type=foo,name=bar");// what ever ObjectName works for you
imanager.register(mbImpl, oName);
Freeman
-
2. Re: (JMX) Simplest way to use a custom MBean in Fuse?
vikingsteve Jul 9, 2013 3:15 AM (in response to ffang)Hi Freeman, thanks for your answer.
Firstly, a bus? Sorry, I haven't configured or used a bus before. Can you please elaborate. Is BusFactory.getDefaultBus() ok ?
Secondly, can I somehow register my MBean in blueprint.xml (I would prefer to do it there, rather than in code) - is that possible?
Thanks again,
Steve.
-
3. Re: (JMX) Simplest way to use a custom MBean in Fuse?
ffang Jul 9, 2013 3:41 AM (in response to vikingsteve)Hi,
No, you can't resigster your customer MBean all through code.
However, you can inject cxf bus into your MBeanImpl and register there.
Some configuration like
<bean id ="myMbeanImpl" class="com.mycompany.myservice.MyServiceMBeanImpl>
<property name="bus" ref="cxf" />
</bean>
This can simply inject a bus into your customer MBean which you can use to register your MBean.
Freeman
-
4. Re: (JMX) Simplest way to use a custom MBean in Fuse?
vikingsteve Jul 9, 2013 3:52 AM (in response to ffang)Hi Freeman,
Does my bean for "cxf" bus already exist, or do I need to define it somehow?
Since bus.getExtension(InstrumentationManager.class) is returning null.
I set a breakpoint and I can see the bus has state RUNNING and has 31 extensions... just not the InstrumentationManager.
Cheers, Steve
-
5. Re: (JMX) Simplest way to use a custom MBean in Fuse?
ffang Jul 9, 2013 4:12 AM (in response to vikingsteve)Hi,
You needn't define "cxf" bus bean, you can use it directly.
I just test it and I can get the InstrumentationManager from bus.
Post your blueprint.xml here so that I can take a close look.
Ensure you are usig JBoss FUSE 6 and didn't change any default configuration and so there's a javax.management.MBeanServer OSGi service available.
And I will attachment my test tar FYI, I just revise a bit from the secure-soap example shipped with JBoss Fuse kit, you can see how to get InstrumentationManager from the bus.
Freeman
-
secure-soap.tar 57.5 KB
-
-
6. Re: (JMX) Simplest way to use a custom MBean in Fuse?
vikingsteve Jul 9, 2013 5:46 AM (in response to ffang)Hi,
I'm using JBoss Fuse 6.0.0.redhat-024.
It just occurred to me that perhaps I shouldn't be trying to register my MBean in the constructor of myServiceMBeanRegistration?
Is this ok, or should I set "cxf" and "myServiceBean" as properties, and trigger the registration via some sort of "PostConstruct" (if so, how?)
<bean id="myServiceMBean" class="com.mycompany.myservice.jmx.MyServiceMBeanImpl"> <property name="abcService" ref="abcService"/> </bean> <bean id="myServiceMBeanRegistration" class="com.mycompany.myservice.jmx.MyServiceMBeanRegistration"> <argument ref="cxf" /> <argument ref="myServiceMBean" /> </bean> Otherwise if this looks ok, I can anonymize the class names and post my full blueprint.xml
Cheers, Steve
-
7. Re: (JMX) Simplest way to use a custom MBean in Fuse?
ffang Jul 9, 2013 5:32 AM (in response to vikingsteve)Yes, you can register your mbean whereever you want, I just show you the way how you can inject cxf bus.
-
8. Re: (JMX) Simplest way to use a custom MBean in Fuse?
vikingsteve Jul 9, 2013 6:34 AM (in response to ffang)Hi Freeman, here it is:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<cm:property-placeholder id="cmProps" persistent-id="com.mycompany.myservice">
<cm:default-properties>
<cm:property name="a.b.c.1" value=""/>
<cm:property name="a.b.c.2" value=""/>
</cm:default-properties>
</cm:property-placeholder>
<!-- for quartz scheduler -->
<bean class="org.fusesource.fabric.camel.MasterComponent" />
<camel:camelContext id="MyServiceCamelContext">
<camel:propertyPlaceholder id="properties" location="blueprint:cmProps"/>
<camel:routeBuilder ref="MyServiceRoute"/>
</camel:camelContext>
<!-- ws client -->
<jaxws:client id="a" address="${b}" wsdlLocation="${c}" serviceName="s:d" serviceClass="e" xmlns:s="f" />
<http:conduit name="{a}b">
<http:client AllowChunking="false" ProxyServer="proxy" ProxyServerPort="80" NonProxyHosts="localhost|127.0.0.1"/>
</http:conduit>
<!-- a bunch of datasources, beans and services go here-->
<!-- a bunch of datasources, beans and services go here-->
<!-- a bunch of datasources, beans and services go here-->
<!-- jmx -->
<bean id="myServiceMBean" class="com.mycompany.myservice.jmx.MyServiceMBeanImpl">
<property name="abcService" ref="abcService"/>
</bean>
<bean id="myServiceMBeanRegistration" class="com.mycompany.myservice.jmx.MyServiceMBeanRegistration">
<argument ref="cxf" />
<argument ref="myServiceMBean" />
</bean>
<!-- routes -->
<bean id="MyServiceRoute" class="com.mycompany.myservice.routes.MyServiceRoute"/>
</blueprint>
Wondering also if I need some special dependency?
-
9. Re: (JMX) Simplest way to use a custom MBean in Fuse?
ffang Jul 9, 2013 6:51 AM (in response to vikingsteve)Hi,
So from this configuration
bus.getExtension(InstrumentationManager.class) is returning null, right?
I don't see any special reason why it could be null.
Anyway, try add a bus property for com.mycompany.myservice.jmx.MyServiceMBeanRegistration and using
<property name="bus" ref="cxf" />
to see if it helps,
and also ensure this bundle have Import-Package like
Also please post result of
ls|grep -B 5 MBeanServer
and
cxf:list-busses
from console.
You can also add code like
System.out.println("the bus is " + bus.getId());
to see if the bus Id get injected match the one used for your customer bundle.
Freeman
-
10. Re: (JMX) Simplest way to use a custom MBean in Fuse?
vikingsteve Jul 9, 2013 7:33 AM (in response to ffang)Hi,
Right, bus.getExtension(InstrumentationManager.class) is returning null.
Regarding using <property name="bus" ref="cxf" /> for my registration bean, this uses the bus setter method, so if I have a method named doRegistration, how and when do I trigger it? Normally in spring I would have used @PostConstruct for something like this. [edit: I found the answer: init-method="doRegistration", works great!]
I added the Import-Pacakge.
admin@server1> ls|grep -B 5 MBeanServer
Apache Karaf :: Management (18) provides:
-----------------------------------------
org.osgi.service.blueprint.container.BlueprintContainer
org.osgi.service.cm.ManagedService
javax.management.MBeanServer
admin@server1> cxf:list-busses
Name State
[com.mycompany.someservice-webservice-cxf972689576] [RUNNING ]
[com.mycompany.myservice-service-cxf1868655190] [RUNNING ] ***
[com.mycompany.coolservice.coolservice-xyzclient-cxf478040164] [RUNNING ]
*** the bus id with 3 stars was printed by the log statement "the bus is" + bus.getId()
I'm running a fabric with relevant profile and one container, server1.
Cheers
Steve
-
11. Re: (JMX) Simplest way to use a custom MBean in Fuse?
ffang Jul 9, 2013 10:50 AM (in response to vikingsteve)Hi,
It looks good to me.
Could you please append a testcase which I can build and deploy, so that I can take a close look why bus.getExtension(InstrumentationManager.class) return null for your case.
-
12. Re: (JMX) Simplest way to use a custom MBean in Fuse?
vikingsteve Jul 11, 2013 3:40 AM (in response to ffang)Thanks, I uploaded a simple test case, to build it: mvn clean install
To run it:
features:addurl mvn:com.foo.myservice/myservice-feature/1.0.0-SNAPSHOT/xml/features
features:install foo-myservice
list | grep -i foo
In the logs I was seeing:
Error: org.osgi.service.blueprint.container.ComponentDefinitionException: Unresolved ref/idref to component: cxf
What is missing to make the cxf bus available here?
-
13. Re: (JMX) Simplest way to use a custom MBean in Fuse?
ffang Jul 11, 2013 4:47 AM (in response to vikingsteve)Hi,
In your testcase, there's no CXF endpoint defined in the blueprint.xml, so the cxf bus bean can't be auto wire-in.
Also if there's no CXF related endpoint, you shouldn't use CXF InstrumentationManagerImpl to register your customer MBean.
Previously I thought you're going to use CXF endpoint as the service.
Freeman
-
14. Re: (JMX) Simplest way to use a custom MBean in Fuse?
vikingsteve Jul 11, 2013 5:23 AM (in response to ffang)Hi Freeman,
That's correct, this service does not define a <cxf:cxfEndpoint ... /> to expose a WS.
It does however use a WS client defined by <jaxws:client ... /> and <http:conduit ... /> to talk to an external WS.
Given my situation, how do I register my MBean?
Thank you again,
Steve