mx4j.server

Class BCELMBeanInvoker

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 $

Field Summary

Fields inherited from class mx4j.server.ReflectionMBeanInvoker

EMPTY_ARGS, EMPTY_PARAMS

Constructor Summary

BCELMBeanInvoker()

Method Summary

static MBeanInvoker
create(MBeanMetaData metadata)
Creates a new MBeanInvoker created on-the-fly by using BCEL.
protected Object
invokeImpl(MBeanMetaData metadata, String method, String[] signature, Object[] args)

Methods inherited from class mx4j.server.CachingReflectionMBeanInvoker

getMethodForAttribute, getStandardAttributeInfo, getStandardManagementMethod, getStandardOperationInfo

Methods inherited from class mx4j.server.ReflectionMBeanInvoker

doInvoke, getAttribute, getMethodForAttribute, getStandardAttributeInfo, getStandardManagementMethod, getStandardOperationInfo, invoke, invokeImpl, setAttribute

Constructor Details

BCELMBeanInvoker

protected BCELMBeanInvoker()

Method Details

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)
            throws Throwable
Overrides:
invokeImpl in interface ReflectionMBeanInvoker

Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.