mx4j.server
Class BCELMBeanInvoker
java.lang.Object
mx4j.server.ReflectionMBeanInvoker
mx4j.server.CachingReflectionMBeanInvoker
mx4j.server.BCELMBeanInvoker
- All Implemented Interfaces:
- MBeanInvoker
- public class BCELMBeanInvoker
- extends CachingReflectionMBeanInvoker
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);
}
}
- Version:
- $Revision: 1.14 $
Method Summary |
static MBeanInvoker |
create(MBeanMetaData metadata)
Creates a new MBeanInvoker created on-the-fly by using BCEL. |
protected java.lang.Object |
invokeImpl(MBeanMetaData metadata,
java.lang.String method,
java.lang.String[] signature,
java.lang.Object[] args)
Performs the actual invocation of the MBean's method. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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)
invokeImpl
protected java.lang.Object invokeImpl(MBeanMetaData metadata,
java.lang.String method,
java.lang.String[] signature,
java.lang.Object[] args)
throws java.lang.Throwable
- Description copied from class:
ReflectionMBeanInvoker
- Performs the actual invocation of the MBean's method.
Exceptions thrown by the MBean's methods should not be catched, since
ReflectionMBeanInvoker.doInvoke(mx4j.server.MBeanMetaData, java.lang.String, java.lang.String[], java.lang.Object[])
takes care of converting them to JMX exceptions.
- Overrides:
invokeImpl
in class ReflectionMBeanInvoker
- Throws:
java.lang.Throwable
Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.