mx4j.server
Class BCELMBeanInvoker
java.lang.Object
|
+--mx4j.server.ReflectedMBeanInvoker
|
+--mx4j.server.BCELMBeanInvoker
- All Implemented Interfaces:
- MBeanInvoker
- public class BCELMBeanInvoker
- extends ReflectedMBeanInvoker
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 ReflectionException, MBeanException, IllegalArgumentException
{
if (method.equals("start") && args.length == 0)
{
try
{
((ServiceMBean)metadata.mbean).start();
return null;
}
catch (ClassCastException x) {}
catch (Exception x)
{
throw new MBeanException(x);
}
catch (IllegalAccessError x) {}
catch (Error x)
{
throw new MBeanException(new RuntimeErrorException(x));
}
}
else if (method.equals("getServices") && args.length == 1)
{
try
{
return ((ServiceMBean)metadata.mbean).getServices((ServiceSelector)args[0]);
}
catch (ClassCastException x) {}
catch (Exception x)
{
throw new MBeanException(x);
}
catch (IllegalAccessError x) {}
catch (Error x)
{
throw new MBeanException(new RuntimeErrorException(x));
}
}
else
{
super.invokeImpl(metadata, method, signature, args);
}
}
}
- Version:
- $Revision: 1.8 $
- Author:
- Simone Bordet
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)
getLogger
protected Logger getLogger()
invokeImpl
protected java.lang.Object invokeImpl(MBeanMetaData metadata,
java.lang.String method,
java.lang.String[] signature,
java.lang.Object[] args)
throws ReflectionException,
MBeanException,
java.lang.IllegalArgumentException
- Overrides:
invokeImpl
in class ReflectedMBeanInvoker
Copyright © 2001-2002 MX4J Team. All Rights Reserved.