Skip to main content

Access programmatically to jmx view agent

13 replies [Last post]
abdujaparov
Offline
Joined: 2007-11-03

Hi, how can I access to jmx view agent with a client written by me?
Thanks, bye bye.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
deruelle_jean
Offline
Joined: 2003-06-24

Add this line before the first line of code I sent you :
System.setProperty("org.jboss.j2ee.Serialization", "true");

It should resolve your problem.

Best regards
Jean

abdujaparov
Offline
Joined: 2007-11-03

Hi Jean, thanks a lot whit that line all works!
I've inserted an SbbUsageParameter to googletalk example, I deploy correctly the service but now I don't know how gat the parameter.

Now I'm connected to jmx and I can view the attribute of a MBean with the snippet that you have written.
I've read di slee specs but there it speaks about SleeManagmentMBeanInterface or ServiceUsageMBeanInterface but I haven't find anything about how to get the abject for these interface.

Where can I find these informations?

Thanks again, bye bye.

deruelle_jean
Offline
Joined: 2003-06-24

ObjectName serviceManagementMBean = (ObjectName) rmiserver.invoke(
sleeMBean,
"getServiceManagementMBean",
new Object[] {},
new String[] {});

will allow you to get the ServiceManagementMBean from the SleeManagementMBean.
If you check the SleeManagementMbean interface, you'll see that getServiceManagementMBean is a method of the SleeManagementMBean interface. You have to proceed the same way to get the ServiceUsageMBean from the ServiceManagementMBean.
Since you want to do from your jmx client what is already available in the mobicents management console, you may want to check the code out to get a better grasp on how is it implemented.
You'll find the project here https://mobicents-management.dev.java.net
and the code here https://mobicents-management.dev.java.net/svn/mobicents-management/trunk...

Jean

abdujaparov
Offline
Joined: 2007-11-03

Hi Jean,
I've seen in the jmx console that there are:
[code]
# SbbUsageMBean=ServiceID[GoogleTalkBotService#mobicents#0.1]/SbbID[GoogleTalkBotSbb#mobicents#0.1]
# ServiceUsageMBean=ServiceID[GoogleTalkBotService#mobicents#0.1]
[/code]
Do these 2 MBeans give me the access to SbbUsageParameter?

I've written this code:
[code]
MBeanServerConnection rmiserver = (MBeanServerConnection) ctx.lookup("jmx/rmi/RMIAdaptor");

ObjectName sleeMBean = new ObjectName("slee:ServiceUsageMBean=ServiceID[GoogleTalkBotService#mobicents#0.1]");

javax.slee.usage.SampleStatistics vediamo = (javax.slee.usage.SampleStatistics) rmiserver.invoke(sleeMBean, "getsampleResponseTime", new Object[]{new Boolean(false)}, new String[]{"java.lang.Boolean"});
[/code]

I've read the slee specs and I've found this:
[code]
// sample-type accessor method
public SampleStatistics get(boolean reset)
throws ManagementException;
[/code]

In the SbbUsegeParameter interface I had defined this parameter: public abstract void sampleResponseTime(long value);

When I excecute the code above I receive this error:
[code]
Exception in thread "main" javax.management.ReflectionException: The operation with name getsampleResponseTime could not be found
at com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(StandardMetaDataImpl.java:398)
at javax.management.StandardMBean.invoke(StandardMBean.java:323)
at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:164)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at sun.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.jmx.connector.invoker.InvokerAdaptorService.invoke(InvokerAdaptorService.java:266)
at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.jmx.connector.invoker.SerializableInterceptor.invoke(SerializableInterceptor.java:74)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.invocation.jrmp.server.JRMPProxyFactory.invoke(JRMPProxyFactory.java:179)
at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:818)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:419)
at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NoSuchMethodException: getsampleResponseTime
... 41 more
[/code]

The error tells me that the method getsampleResponseTime doesn't exist and the error is the same if I try to call the method getResponseTime.

What I've tryed to do is correct?

Thanks, bye bye.

deruelle_jean
Offline
Joined: 2003-06-24

you're close. This is because the type is not Object type java.lang.Boolean but the primitive type boolean. this code should work for your use case :

ObjectName sbbUSageMBean = new ObjectName("slee:SbbUsageMBean=ServiceID[GoogleTalkBotService#mobicents#0.1]/SbbID[GoogleTalkBotSbb#mobicents#0.1]");

SampleStatistics sampleStatistics = (SampleStatistics) rmiserver.invoke(sbbUSageMBean, "getResponseTime", new Object[] {Boolean.FALSE}, new String[] {"boolean"});
System.out.println(sampleStatistics.getSampleCount());

Jean

abdujaparov
Offline
Joined: 2007-11-03

Hi Jean, I've tested the code written by you above and now it works!
Thanks a lot again.
Another question, If I want all the statistics of every sbb deployed have I to search the sbbID and the serviceID of all mobicents service through the slee:name=SbbEntitiesMBean?
After that have I to invoke some methods (that I've to search in the slee specs) that give me all the sample or increment parameter?
Thanks a lot again, bye bye.

deruelle_jean
Offline
Joined: 2003-06-24

SbbEntitiesMBean is not the way to go. It is not an MBean that is part of the JAIN SLEE spec. If you use this it won't be portable to another JAIN SLEE implementation.

To do what you want, you'll have to retrieve all active services deployed into the slee through ServiceManagementMBean.
For each of those services you'll have to get the root sbb through the servicedescriptor through the DeploymentMBean.getDescriptor method giving the service Id.
For each root sbb you'll have to get all the sbbs deployed through the sbbdescriptor through the DeploymentMBean.getDescriptor method giving the Root sbb id.
For each sbb you'll have to get the sbbUsageMBean. You'll then have to read its operations through the MBean info metadata and only the operations starting with 'get' as in the JavaBeans convention will correspond to your usage parameters.

I may repeat myself but why don't you check the mobicents management console code since it's already implemented in it ?

Regards
Jean

deruelle_jean
Offline
Joined: 2003-06-24

Here is a snippet of code allowing you to stop the Slee gracefully through a jmx client written by you.

import org.jboss.jmx.adaptor.rmi.RMIAdaptor;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;

....

Hashtable env = new Hashtable();
//replace by the binding address and port of your jboss server jnp
env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
InitialContext ctx = new InitialContext(env);
RMIAdaptor rmiserver = (RMIAdaptor) ctx.lookup("jmx/rmi/RMIAdaptor");

ObjectName sleeMBean = new ObjectName("slee:service=SleeManagement");

//Gracefully stop the SLEE.
rmiserver.invoke(sleeMBean, "stop" ,null,null);

Take care you need a dependency on jboss-jmx.jar since it uses the jboss RMI Adaptor.
On newer Jboss versions you can use directly the MBeanServerConnection from jmx API instead of Jboss :
//RMIAdaptor server = (RMIAdaptor) ctx.lookup("jmx/invoker/RMIAdaptor");
MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor"); :

Regards
Jean

abdujaparov
Offline
Joined: 2007-11-03

Hi Jean,
thanks to your snippets I've succeded connecting to jmx mbean.
I receive an error when I try to execute this:

[code]
rmiserver.getMBeanInfo(name)
[/code]

where rmiserver is: RMIAdaptor and getMBeanInfo return an MBeanInfo object. I receive a null pointer exception, exactly.
I receive this exception because there aren't MBInfo defined?

I'm trying to get statistics from the mobicents service. I've read the slee specs but I don't understand if mobicents give me some statistics and how to get it.
I've read something about usage parameters but I've found only the theory about them where can I find code example? Without the code I don't understand a lot.
Thanks a lot Jean, bye bye.

deruelle_jean
Offline
Joined: 2003-06-24

This code snippet should work to get the MBean Info of the SleeManagementMBean :

Hashtable env = new Hashtable();
//replace by the binding address and port of your jboss server jnp
env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
InitialContext ctx = new InitialContext(env);
MBeanServerConnection rmiserver = (MBeanServerConnection) ctx.lookup("jmx/rmi/RMIAdaptor");

ObjectName sleeMBean = new ObjectName("slee:service=SleeManagement");

//Check the metadata of the SleeManagementMBean.
MBeanInfo info = rmiserver.getMBeanInfo(sleeMBean);
System.out.println(info);

Mobicents won't give you statistics out of the box.
Indeed you can use usage parameters for your service and get the information through JMX after that through the SbbUsageMBean, you can check the jain slee javadocs and checkout the 3pcc example in the mobicents-examples sub project of mobicents located at https://mobicents-examples.dev.java.net. It uses a ThirdPCCSbbUsage usage parameters that make some statistics regarding the sip sessions. Hope that helps.

Best regards
Jean

abdujaparov
Offline
Joined: 2007-11-03

Hi Jean, I've lainched the snippet that you've written above but I receive this exception when is executed "MBeanServerConnection rmiserver = (MBeanServerConnection) ctx.lookup("jmx/rmi/RMIAdaptor");"

This is the exception:
[code]
Exception in thread "main" javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.util.id.GUID; local class incompatible: stream classdesc serialVersionUID = 3289509836244263718, local class serialVersionUID = 6926421946503004889]]
at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1062)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:696)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:583)
at javax.naming.InitialContext.lookup(Unknown Source)
at JMXRmiJMX.main(JMXRmiJMX.java:42)
Caused by: javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.util.id.GUID; local class incompatible: stream classdesc serialVersionUID = 3289509836244263718, local class serialVersionUID = 6926421946503004889]
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:718)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:583)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1056)
... 4 more
Caused by: java.io.InvalidClassException: org.jboss.util.id.GUID; local class incompatible: stream classdesc serialVersionUID = 3289509836244263718, local class serialVersionUID = 6926421946503004889
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.invocation.InvokerInterceptor.readExternal(InvokerInterceptor.java:268)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.proxy.Interceptor.readExternal(Interceptor.java:80)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.jboss.proxy.ClientContainer.readExternal(ClientContainer.java:155)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:648)
... 7 more
[/code]

How can I resolve?
Thanks, bye bye.

abdujaparov
Offline
Joined: 2007-11-03

The error that I've reported is given by mobicents 1.2.0beta over jboss 4.2.2.
I've executed the same code with mobicents 1.0.0.3gs on jboss3.2.8 and I receive an exception on this line " MBeanInfo info = rmiserver.getMBeanInfo(sleeMBean);"

Here follows the exception:
[code]
log4j:WARN No appenders could be found for logger (org.jboss.security.SecurityAssociation).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NullPointerException
at java.util.TreeMap.putAll(Unknown Source)
at javax.management.modelmbean.DescriptorSupport.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.defaultReadObject(Unknown Source)
at javax.management.modelmbean.ModelMBeanAttributeInfo.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:150)
at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:241)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:181)
at org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor.invoke(InvokerAdaptorClientInterceptor.java:75)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70)
at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:70)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)
at $Proxy0.getMBeanInfo(Unknown Source)
at JMXRmiJMX.main(JMXRmiJMX.java:47)
[/code]

In the example 3pcc I've seen how use usage parameters but I don't understand how get the statistics with jmx.
With the snilppet that you've given me hava I to ask something to SleeManagment and this last give me the result?
Thanks a lot, bye bye.

deruelle_jean
Offline
Joined: 2003-06-24

I just tried on mobicents 1.0.03GA with the snippet of code I sent you and it works for me.
Please make sure you use the jbossall-client.jar from the release you're testing against in your test.
For mobicents 1.0.03GA, get the jar from mobicents 1.0.03GA/server/client/jbossall-client.jar
For mobicents 1.2.00_BETA, get the jar from mobicents 1.2.00_BETA/server/client/jbossall-client.jar
(jbossall-client.jar and jain slee api jars as dependencies for your test should be enough)

I don't know where this could come from.
Alternatively try with a brand new mobicents 1.0.03GA freshly downloaded...

Best regards
Jean