Skip to content

Instantly share code, notes, and snippets.

@HDBandit
Created July 17, 2016 16:05
Show Gist options
  • Save HDBandit/039be2fe106b3b38947b30b779ea6601 to your computer and use it in GitHub Desktop.
Save HDBandit/039be2fe106b3b38947b30b779ea6601 to your computer and use it in GitHub Desktop.
trait ActorWithJMXSupport extends Actor {
val mBeanServer = ManagementFactory.getPlatformMBeanServer();
val objName = new ObjectName("hdbandit", {
import scala.collection.JavaConverters._
new java.util.Hashtable(
Map(
"name" -> self.path.toStringWithoutAddress,
"type" -> getMXTypeName
).asJava
)
})
def getMXTypeName : String
override def preStart() = mBeanServer.registerMBean(this, objName)
override def postStop() = mBeanServer.unregisterMBean(objName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment