Hi,
I found you can do like this.
try{
MBeanServer esbServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> nameSet = esbServer.queryNames(new
ObjectName("org.apache.synapse:Type=NHTTPLatencyView,Name=nio-http-*"),
null);
for(ObjectName mBeanName : nameSet) {
org.apache.synapse.transport.nhttp.util.LatencyViewMBean latView =
(org.apache.synapse.transport.nhttp.util.LatencyViewMBean)
MBeanServerInvocationHandler
.newProxyInstance(
esbServer,
mBeanName,
org.apache.synapse.transport.nhttp.util.LatencyViewMBean.class,
false);
System.out.println("
<----------------------------------------------------------- >");
System.out.println("First view" + latView.getLastMinuteAvgLatency());
System.out.println("
<----------------------------------------------------------- >");
}
}catch(Exception e){
e.printStackTrace();
}
On Mon, Dec 2, 2013 at 2:56 PM, Malaka Silva <[email protected]> wrote:
> Hi Guys,
>
> Is there a way to retrieve MBeans using regex
>
> I tried the following. Sample 01 seems to be working. But sample 02 throws
> an exception.
> (javax.management.InstanceNotFoundException:
> org.apache.synapse:Type=NHTTPLatencyView,Name=nio-http-*)
>
> *Sample 01*
> try {
> MBeanServer esbServer = ManagementFactory.getPlatformMBeanServer();
> org.apache.synapse.transport.nhttp.util.LatencyViewMBean latView =
> (org.apache.synapse.transport.nhttp.util.LatencyViewMBean)
> MBeanServerInvocationHandler
> .newProxyInstance(
> esbServer,
> new ObjectName(
> "org.apache.synapse:Type=NHTTPLatencyView,Name=nio-http-http"),
> org.apache.synapse.transport.nhttp.util.LatencyViewMBean.class,
> false);
> System.out.println("
> <----------------------------------------------------------- >");
> System.out.println("First view" + latView.getLastMinuteAvgLatency());
> System.out.println("
> <----------------------------------------------------------- >");
>
> } catch (Throwable e) {
> e.printStackTrace();
> }
>
> *Sample 02*
> try {
> MBeanServer esbServer = ManagementFactory.getPlatformMBeanServer();
> org.apache.synapse.transport.nhttp.util.LatencyViewMBean latView =
> (org.apache.synapse.transport.nhttp.util.LatencyViewMBean)
> MBeanServerInvocationHandler
> .newProxyInstance(
> esbServer,
> new ObjectName(
> "org.apache.synapse:Type=NHTTPLatencyView,Name=nio-http-*"),
> org.apache.synapse.transport.nhttp.util.LatencyViewMBean.class,
> false);
> System.out.println("
> <----------------------------------------------------------- >");
> System.out.println("First view" + latView.getLastMinuteAvgLatency());
> System.out.println("
> <----------------------------------------------------------- >");
>
> } catch (Throwable e) {
> e.printStackTrace();
> }
> --
>
> Best Regards,
>
> Malaka Silva
> Senior Tech Lead
> M: +94 777 219 791
> Tel : 94 11 214 5345
> Fax :94 11 2145300
> LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
> Blog : http://mrmalakasilva.blogspot.com/
>
> WSO2, Inc.
> lean . enterprise . middleware
> http://www.wso2.com/
> http://www.wso2.com/about/team/malaka-silva/<http://wso2.com/about/team/malaka-silva/>
>
> Save a tree -Conserve nature & Save the world for your future. Print this
> email only if it is absolutely necessary.
>
--
Best Regards,
Malaka Silva
Senior Tech Lead
M: +94 777 219 791
Tel : 94 11 214 5345
Fax :94 11 2145300
LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77
Blog : http://mrmalakasilva.blogspot.com/
WSO2, Inc.
lean . enterprise . middleware
http://www.wso2.com/
http://www.wso2.com/about/team/malaka-silva/<http://wso2.com/about/team/malaka-silva/>
Save a tree -Conserve nature & Save the world for your future. Print this
email only if it is absolutely necessary.
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev