문제

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 ?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top