Using OpenType class

Hi,

I've created an MBean, i've put it in a first project (A) and put its implementation in a second one (B).

I have access to the methods thanks to the interface from project A in the following way :

MBeanServerConnection conn = connectToJMXServer();

CachesMBean caches = AdminStart.newPlatformMXBeanProxy(conn,CachesMBean.CACHE_MBEAN_NAME,

CachesMBean.class);

When I try to access to a method that has a parameter or return type that isn't a SimpleType (long, int, ...) I get an exception that tells me "can't translate to OpenType"

So I need help because i don't know how to use the class OpenType to convert my Types.

If you get some sample I would appreciate

thank you

[739 byte] By [kaouaa] at [2007-11-27 7:09:52]
# 1

I think you need to give some more information. The methods connectToJMXServer and AdminStart.newPlatformMXBeanProxy are not standard methods. Where do they come from?

It looks as if you should be using JMX.newMBeanProxy instead of AdminStart.newPlatformMXBeanProxy, or if you are on Java 5.0, MBeanServerInvocationHandler.newProxyInstance.

Regards,

蒩monn McManus -- JMX Spec Lead -- http://weblogs.java.net/blog/emcmanus

emcmanusa at 2007-7-12 19:01:18 > top of Java-index,Core,Monitoring & Management...
# 2

Actually i've get the method "newPlatformMXBeanProxy" from JMX class, and eliminate a throw of exception because it didn't recognize my mbeans as MXbeans (i tried and it worked :) )

"connectToJMXServer " is a method which create a connector to the mbeanServer.

i'm on Java 6.0

private MBeanServerConnection connectToJMXServer() throws Exception {

MBeanServerConnection conn;

HashMap map = new HashMap();

map.put("java.naming.factory.initial", RegistryContextFactory.class.getName());

JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(serviceURL));

conn = connector.getMBeanServerConnection();

return conn;

}

public static <T> T newPlatformMXBeanProxy(MBeanServerConnection connection, String mxbeanName, Class<T> mxbeanInterface) throws java.io.IOException

{

final Class interfaceClass = mxbeanInterface;

try {

final ObjectName objName = new ObjectName(mxbeanName);

final Class[] interfaces;

// check if the registered MBean is a notification emitter

boolean emitter = connection.isInstanceOf(objName, NOTIF_EMITTER);

// create an MXBean proxy

return AdminStart.newMXBeanProxy(connection, objName, mxbeanInterface,

emitter);

} catch (InstanceNotFoundException e) {

final IllegalArgumentException iae =

new IllegalArgumentException(mxbeanName +

" not found in the connection.");

iae.initCause(e);

throw iae;

} catch (MalformedObjectNameException e) {

final IllegalArgumentException iae =

new IllegalArgumentException(mxbeanName +

" is not a valid ObjectName format.");

iae.initCause(e);

throw iae;

}

}

public static <T> T newMXBeanProxy(MBeanServerConnection connection,

ObjectName objectName,

Class<T> interfaceClass,

boolean notificationBroadcaster) {

// Check interface for MXBean compliance

//

InvocationHandler handler = new MBeanServerInvocationHandler(

connection, objectName, true);

final Class[] interfaces;

if (notificationBroadcaster) {

interfaces =

new Class<?>[] {interfaceClass, NotificationEmitter.class};

} else

interfaces = new Class[] {interfaceClass};

Object proxy = Proxy.newProxyInstance(

interfaceClass.getClassLoader(),

interfaces,

handler);

return interfaceClass.cast(proxy);

}

thanks

kaouaa at 2007-7-12 19:01:18 > top of Java-index,Core,Monitoring & Management...
# 3

The exception "Can't translate to OpenType" indicates that your MXBean interface doesn't conform to the rules in the MXBean specification <http://java.sun.com/javase/6/docs/api/javax/management/MXBean.html>. The exception trace should indicate which type is untranslatable. You'll either need to change that type or switch to using plain Standard MBeans instead of MXBeans.

emcmanusa at 2007-7-12 19:01:18 > top of Java-index,Core,Monitoring & Management...
# 4
Right I get it now, I used only the method JMX.newMBeanProxy method to make a proxy to my Standard mbeans. I was in the wrong way since the beginning by using JMX.newMXBeanProxy for my standard Mbeans.Thank you for your helpRegards
kaouaa at 2007-7-12 19:01:18 > top of Java-index,Core,Monitoring & Management...