@Test public void normalMBeanCanStillBeRegistered() throws Exception { final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); final DynamicMBeanWrapper wrapper = new DynamicMBeanWrapper(new MyNotLifecycleAwareMBean()); final ObjectName on = new ObjectName("org.superbiz.foo:type=dummy2"); try { server.registerMBean(wrapper, on); assertTrue(server.isRegistered(on)); assertEquals("ok", server.invoke(on, "value", new Object[0], null)); } finally { server.unregisterMBean(on); } }
@Override public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException { if (operations.containsKey(actionName)) { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classloader); try { return operations.get(actionName).invoke(instance, params); } catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { logger.error(actionName + "can't be invoked", e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } } throw new MBeanException(new IllegalArgumentException(), actionName + " doesn't exist"); }
DynamicMBeanWrapper implements DynamicMBean, MBeanRegistration { @Override public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException { if (operations.containsKey(actionName)) { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classloader); try { return operations.get(actionName).invoke(instance, params); } catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { logger.error(actionName + "can't be invoked", e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } } throw new MBeanException(new IllegalArgumentException(), actionName + " doesn't exist"); } }
DynamicMBeanWrapper implements DynamicMBean, MBeanRegistration { @Override public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException { if (operations.containsKey(actionName)) { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classloader); try { return operations.get(actionName).invoke(instance, params); } catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { logger.error(actionName + "can't be invoked", e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } } throw new MBeanException(new IllegalArgumentException(), actionName + " doesn't exist"); } DynamicMBeanWrapper(final Object givenInstance);  DynamicMBeanWrapper(final WebBeansContext wc, final Object givenInstance); }
DynamicMBeanWrapper implements DynamicMBean, MBeanRegistration { @Override public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException { if (operations.containsKey(actionName)) { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classloader); try { return operations.get(actionName).invoke(instance, params); } catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { logger.error(actionName + "can't be invoked", e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } } throw new MBeanException(new IllegalArgumentException(), actionName + " doesn't exist"); } DynamicMBeanWrapper(final Object givenInstance);  DynamicMBeanWrapper(final WebBeansContext wc, final Object givenInstance); @Override MBeanInfo getMBeanInfo(); @Override Object getAttribute(final String attribute); @Override void setAttribute(final Attribute attribute); @Override AttributeList getAttributes(final String[] attributes); @Override AttributeList setAttributes(final AttributeList attributes); @Override Object invoke(final String actionName, final Object[] params, final String[] signature); @Override ObjectName preRegister(final MBeanServer server, final ObjectName name); @Override void postRegister(final Boolean registrationDone); @Override void preDeregister(); @Override void postDeregister(); }
DynamicMBeanWrapper implements DynamicMBean, MBeanRegistration { @Override public Object invoke(final String actionName, final Object[] params, final String[] signature) throws MBeanException, ReflectionException { if (operations.containsKey(actionName)) { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classloader); try { return operations.get(actionName).invoke(instance, params); } catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { logger.error(actionName + "can't be invoked", e); } finally { Thread.currentThread().setContextClassLoader(oldCl); } } throw new MBeanException(new IllegalArgumentException(), actionName + " doesn't exist"); } DynamicMBeanWrapper(final Object givenInstance);  DynamicMBeanWrapper(final WebBeansContext wc, final Object givenInstance); @Override MBeanInfo getMBeanInfo(); @Override Object getAttribute(final String attribute); @Override void setAttribute(final Attribute attribute); @Override AttributeList getAttributes(final String[] attributes); @Override AttributeList setAttributes(final AttributeList attributes); @Override Object invoke(final String actionName, final Object[] params, final String[] signature); @Override ObjectName preRegister(final MBeanServer server, final ObjectName name); @Override void postRegister(final Boolean registrationDone); @Override void preDeregister(); @Override void postDeregister(); static final Logger logger; }