@SuppressWarnings("unchecked")
public Object invoke(Invocation invocation) throws Throwable
{
MethodInvocation mi = (MethodInvocation) invocation;
KernelControllerContext context = (KernelControllerContext) mi.getArguments()[0];
JMX jmx = (JMX)invocation.resolveClassAnnotation(JMX.class);
ObjectName objectName = null;
if (jmx != null)
{
String jmxName = jmx.name();
if (jmxName != null && jmxName.length() > 0)
objectName = new ObjectName(jmxName);
}
if (objectName == null)
{
// try to build one from the bean name
String name = (String) context.getName();
if (name.contains(":"))
{
objectName = new ObjectName(name);
}
else
{
objectName = new ObjectName("test:name='" + name + "'");
}
}
if (server == null)
{
throw new RuntimeException("No MBeanServer was injected");
}
if ("setKernelControllerContext".equals(mi.getMethod().getName()))
{
Class intfClass = null;
boolean registerDirectly = false;
if (jmx != null)
{
intfClass = jmx.exposedInterface();
registerDirectly = jmx.registerDirectly();
}
Object mbean = (registerDirectly ? context.getTarget()
: new StandardMBean(context.getTarget(), intfClass));
server.registerMBean(mbean, objectName);
log.info("Registered MBean " + objectName);
}
else
{