2
votes

I'm using Play Framework (Scala) to build my app and need to expose some internal administration tools via JMX. What is the recommended or the best way to use JMX Mbeans with Play Framework. I don't use Spring.

1

1 Answers

2
votes

You could define a global settings object and register your MBeans there. Minimal example:

trait SampleMBean {
  def greetings: String
}

class Sample extends SampleMBean {
  override def greetings = "Hello!"
}

object Global extends GlobalSettings {

  lazy val mbeanServer: MBeanServer = ManagementFactory.getPlatformMBeanServer()

  override def onStart(app: Application): Unit = {
    mbeanServer.registerMBean(new Sample, new ObjectName("com.example:type=Sample"))
  }

  override def onStop(app: Application): Unit = {
    mbeanServer.unregisterMBean(new ObjectName("com.example:type=Sample"))
  }

}

Keep in mind that onStart will be called after the first request to the server, if it's running in DEV mode.