mx4j.server

Class BCELMBeanInvoker

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 $

Constructor Summary
protected BCELMBeanInvoker()
Method Summary
static MBeanInvokercreate(MBeanMetaData metadata)
Creates a new MBeanInvoker created on-the-fly by using BCEL.
protected ObjectinvokeImpl(MBeanMetaData metadata, String method, String[] signature, Object[] args)

Constructor Detail

BCELMBeanInvoker

protected BCELMBeanInvoker()

Method Detail

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 Object invokeImpl(MBeanMetaData metadata, String method, String[] signature, Object[] args)
Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.