Pregunta

How would you implement Spring like annotation based JMX feature. If class is marked by @ManagedResource methods of the class marked with @ManagedOperation are automatically exposed via JMX.

I would like to avoid creating interfaces with MBean notation. I'm using Play with Guice framework. The naive approach first comes to mind:

  • Iterate over all classes managed by Guice
  • If class is marked with annotation, create new interface which fits MBean notation. Amend class, amended class should implement new created interface.
  • Register instance of the class in MBean server.

Second step will be done using byte code manipulation tool, for example ASM. Is it possible to do it with ASM ? How would you implement such feature ?

¿Fue útil?

Solución

Technically, you don't need an interface. MBeans are entirely described by metadata. You can implement your own custom implementation of DynamicMBean which returns the appropriate description of your management "interface" (without actually creating said interface). no crazy byte code manipulation necessary, just basic reflection.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top