mx4j.server
Class BCELMBeanInvoker
- MBeanInvoker
public class BCELMBeanInvoker
MBeanInvoker that generates on-the-fly implementations to call standard MBeans directly, instead of using reflection.
It uses the
BCEL to generate the required bytecode on-the-fly.
The generated class is named "mx4j.server.BCELMBeanInvokerGenerated", and it's loaded into the JVM by a different
classloader for each MBean. This classloader has the MBean classloader as parent.
Below is an example of the generated code; beware that the management interface and all parameter's classes must be
public, otherwise an IllegalAccessError is thrown and the invocation falls back to use reflection (but with a significant
overhead - throwing an exception is expensive).
public interface ServiceMBean
{
public void start();
public Collection getServices(ServiceSelector selector);
}
public class BCELMBeanInvokerGenerated extends BCELMBeanInvoker
{
protected Object invokeImpl(MBeanMetaData metadata, String method, String[] signature, Object[] args)
throws Throwable
{
if (method.equals("start") && args.length == 0)
{
try
{
((ServiceMBean)metadata.mbean).start();
return null;
}
catch (ClassCastException x) {}
catch (IllegalAccessError x) {}
}
else if (method.equals("getServices") && args.length == 1)
{
try
{
return ((ServiceMBean)metadata.mbean).getServices((ServiceSelector)args[0]);
}
catch (ClassCastException x) {}
catch (IllegalAccessError x) {}
}
return super.invokeImpl(metadata, method, signature, args);
}
}
BCELMBeanInvoker
protected BCELMBeanInvoker()
create
public static MBeanInvoker create(MBeanMetaData metadata)
Creates a new MBeanInvoker created on-the-fly by using BCEL.
It must be synchronized since BCEL is not thread safe, and uses static variables
(refer to org.apache.bcel.generic.Type.getArgumentTypes(...) for further details)
Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.