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]

# 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 >
